Skip to content

Commit

Permalink
Merge pull request #67 from imFaizanAhmed/issue-63
Browse files Browse the repository at this point in the history
Issue 63
  • Loading branch information
muhammadtahasuhail committed Dec 20, 2020
2 parents e2886fc + a5c6da1 commit 6477b5b
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 1 deletion.
139 changes: 139 additions & 0 deletions app/resources/collection/blocks/Blocks/OpenCV/ObjectDetector.vc
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"version": "1.0",
"package": {
"name": "ObjectDetector",
"version": "1.0.0",
"description": "Performs Object Detection on Image",
"author": "Faizan Ahmed",
"image": ""
},
"design": {
"board": "Python3-Noetic",
"graph": {
"blocks": [

{
"id": "100",
"type": "basic.input",
"data": {
"name": "",
"pins": [
{
"index": "0",
"name": "",
"value": "0"
}
],
"virtual": true
},
"position": {
"x": 64,
"y": 144
}
},

{
"id": "200",
"type": "basic.output",
"data": {
"name": "",
"pins": [
{
"index": "0",
"name": "",
"value": "0"
}
],
"virtual": true
},
"position": {
"x": 752,
"y": 144
}
},

{
"id": "300",
"type": "basic.code",
"data": {
"code": "# import required packages\nimport cv2\nimport argparse\nimport numpy as np\nfrom time import sleep\nfrom wires.wire_img import Wire_Read, Wire_Write\n\nclassName = []\n#Target Classes name\nclassesFile = 'backend/modules/yolov3.txt'\n\nwith open(classesFile,'rt') as f:\n className = f.read().rstrip('\\n').split('\\n')\n\ndef findObjects(outputs, img):\n confThreshold = 0.5\n nmsThreshold = 0.3\n hT, wT, cT = img.shape\n bbox = []\n classIds = []\n confs = []\n\n for output in outputs:\n for det in output:\n scores = det[5:]\n classId = np.argmax(scores)\n confidence = scores[classId]\n if confidence > confThreshold:\n #get height and weight of box\n w,h = int(det[2] * wT), int(det[3] * hT)\n #as det[0] and det[1] are x,y of center of box so these are converted to starting\n #x and y\n x,y = int((det[0]*wT) - w/2), int((det[1]*hT) - h/2)\n bbox.append([x,y,w,h])\n classIds.append(classId)\n confs.append(float(confidence))\n #print(len(bbox))\n \n indices = cv2.dnn.NMSBoxes(bbox, confs, confThreshold, nmsThreshold)\n for i in indices:\n i = i[0]\n box = bbox[i]\n x,y,w,h = box[0],box[1],box[2],box[3]\n cv2.rectangle(img,(x,y),(x+w, y+h),(255,0,255),2)\n #print(len(className))\n cv2.putText(img,f'{className[classIds[i]].upper()} {int(confs[i]*100)}%',\n (x,y-10),cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255,0,255),2)\n \ndef ObjectDetector( input_wires, output_wires, parameters ):\n shm_r = Wire_Read(input_wires[0])\n shm_w = Wire_Write(output_wires[0]) \n #loading video cam\n \n #width and height of Target Frame\n whT = 320\n #confidence threshold \n \n #lower it is more aggrestive it will\n \n\n \n \n \n print(\"className:\", className)\n \n #print(len(className))\n modelConfiguration = 'backend/modules/yolov3.cfg'\n modelWeights = 'backend/modules/yolov3.weights'\n\n #loading YOLO Model from Darknet\n net = cv2.dnn.readNetFromDarknet(modelConfiguration,modelWeights)\n net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)\n net.setPreferableTarget(cv2.dnn. DNN_TARGET_CPU)\n\n\n\n \n while True:\n img = shm_r.get()\n #converting img to blob\n blob = cv2.dnn.blobFromImage(img, 1/255,(whT,whT),[0,0,0],1, crop = False)\n\n #Passing blob to network\n net.setInput(blob)\n\n #geting Layers Name\n layerNames = net.getLayerNames()\n #print(layerNames)\n #print(net.getUnconnectedOutLayers())\n outputNames = [layerNames[i[0]-1] for i in net.getUnconnectedOutLayers()]\n #print(outputNames)\n\n #forward Pass\n outputs = net.forward(outputNames)\n #print(outputs[0].shape)\n #print(outputs[1].shape)\n #print(outputs[2].shape)\n\n findObjects(outputs,img) \n shm_w.add(img)\n ",
"params": [],
"ports": {
"in": [
{
"name": "100"
}
],
"out": [
{
"name": "200"
}
]
}
},
"position": {
"x": 248,
"y": 88
},
"size": {
"width": 384,
"height": 256
}
},

{
"id": "400",
"type": "basic.constant",
"data": {
"name": "Lower Thresh",
"value": "85",
"local": true
},
"position": {
"x": 328,
"y": 10
}
},
{
"id": "401",
"type": "basic.constant",
"data": {
"name": "Upper Thresh",
"value": "255",
"local": true
},
"position": {
"x": 428,
"y": 10
}
}

],

"wires": [
{
"source": {
"block": "",
"port": ""
},
"target": {
"block": "",
"port": ""
}
},

{
"source": {
"block": "",
"port": ""
},
"target": {
"block": "",
"port": ""
}
}
]
}
},
"dependencies": {}
}
9 changes: 9 additions & 0 deletions docs/_pages/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ Extension: .vc
- Output: BGR Image with Detections.
- Parameters: Bounding Box Info ('box') / Image with Detections ('image')

### Object Detector

![alt_text]({{ "assets/images/icons/objectDetector.png" | absolute_url }})

- Description: Detects objects in an Image using YOLOv3.
- Input: BGR Image
- Output: BGR Image with Detections.
- Parameters: Bounding Box Info ('box') / Image with Detections ('image')

### Image Read

![alt_text]({{ "assets/images/icons/imageread.png" | absolute_url }})
Expand Down
57 changes: 56 additions & 1 deletion docs/_pages/install.md → docs/_pages/usermanual.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
permalink: /install/

title: "Installation"
title: "User Manual"

sidebar:
nav: "docs"
Expand Down Expand Up @@ -99,6 +99,61 @@ cd visualcircuit
npm start
```

#### Well Done! you have Successfully Installed the VisualCircuit

![alt_text]({{ "assets/images/Vc.png" | absolute_url }})


Now it's time to play with it.

## Build first application:

We are now going to create our first running robotics application using Visual Circuit.

First of all, on the top right corner you will find some options like Basic, Block, and etc.

![alt_text]({{ "assets/images/right top.png" | absolute_url }})

Click on the Blocks and following menu will be poped up.

![alt_text]({{ "assets/images/blocks.png" | absolute_url }})

Expand the openCV.

![alt_text]({{ "assets/images/openCV.png" | absolute_url }})



Select the camera and place it.


![alt_text]({{ "assets/images/camera.png" | absolute_url }})

Again go to openCV. This time select the screen and place it.

![alt_text]({{ "assets/images/screen.png" | absolute_url }})

Now connect the camera to screen. click and hold on the out going edge of camera and join it to the in comming edge of screen.
![alt_text]({{ "assets/gif/connection.gif" | absolute_url }})

#### Your application has been setted up. It's time to execute your first application.
To do so, first saved your application by pressing ctrl+s. It will ask you to name your application.

![alt_text]({{ "assets/images/saving.png" | absolute_url }})

After doing that click on the files from the top left corner and following menu will be poped up.

![alt_text]({{ "assets/images/left top.png" | absolute_url }})

Go to build and press Python-ROS-Neotic
![alt_text]({{ "assets/images/running app.png" | absolute_url }})

#### Here you go your application is setted up. Congratulations buddy.








Expand Down
1 change: 1 addition & 0 deletions docs/assets/gif/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All GIFs here.
Binary file added docs/assets/gif/connection.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/Vc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/blocks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/icons/objectDetector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/left top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/openCV.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/right top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/running app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/saving.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6477b5b

Please sign in to comment.