summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRishi-k-s <rishikrishna.sr@gmail.com>2024-04-21 14:23:02 +0530
committerRishi-k-s <rishikrishna.sr@gmail.com>2024-04-21 14:23:02 +0530
commitfe82835456cdda514955debfb369fa3ce517dd1f (patch)
tree1afd453805d2b8fca808b0603bf82b9373f09b02
parentd9a5b5b317ee144105ac58f711581194b427d15c (diff)
added to the main proj from test
-rw-r--r--main.py45
-rw-r--r--output.json2
-rw-r--r--test.py61
3 files changed, 54 insertions, 54 deletions
diff --git a/main.py b/main.py
index ec2a423..68350b7 100644
--- a/main.py
+++ b/main.py
@@ -1,20 +1,45 @@
+import serial.tools.list_ports
from roboflow import Roboflow
import json
+
+ports = serial.tools.list_ports.comports()
+serialInst = serial.Serial()
+count = 0
+
rf = Roboflow(api_key="otKMUXAELXaU2XZsT77M")
project = rf.workspace().project("biomedical-wastes")
model = project.version(3).model
-# infer on a local image
json_response = model.predict("./syringe.jpg", confidence=40, overlap=30).json()
-threshold = 0.8
-for prediction in json_response["predictions"]:
- if prediction["confidence"] > threshold:
- # Do something specific
- print("Syringe detected!")
- break;
+portsList = []
+# portvar = ""
+for onePort in ports:
+ portsList.append(str(onePort))
+ print (str(onePort))
+
+val = "9"
+
+for x in range(0,len(portsList)):
+ if portsList[x].startswith("COM" + str(val)):
+ portvar = "COM" + str(val)
+ print (portvar)
-# save the JSON response to a file
-with open('output.json', 'w') as f:
- json.dump(json_response, f)
+serialInst.baudrate = 115200
+serialInst.port = portvar
+serialInst.open()
+isTest= True;
+while isTest:
+ threshold = 0.8
+ for prediction in json_response["predictions"]:
+ if prediction["confidence"] > threshold:
+ # Do something specific
+ print("Syringe detected!")
+ cmd = "INJD"
+ serialInst.write(cmd.encode('utf-8'))
+ isTest=False
+ # save the JSON response to a file
+ with open('output.json', 'w') as f:
+ json.dump(json_response, f)
+ break; \ No newline at end of file
diff --git a/output.json b/output.json
index fb86731..59dcb28 100644
--- a/output.json
+++ b/output.json
@@ -1 +1 @@
-{"predictions": [{"x": 221.0, "y": 466.0, "width": 284.0, "height": 196.0, "confidence": 0.9601893424987793, "class": "1", "class_id": 1, "detection_id": "8eb9dbc2-edba-41dd-b688-8c6fdb3c30a5", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}, {"x": 180.0, "y": 306.0, "width": 304.0, "height": 288.0, "confidence": 0.9401327967643738, "class": "1", "class_id": 1, "detection_id": "39c0f674-3d35-4f99-8b2d-f6aa6f26a865", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}, {"x": 351.5, "y": 608.5, "width": 81.0, "height": 41.0, "confidence": 0.9194074869155884, "class": "0", "class_id": 0, "detection_id": "1f440d8b-c133-4c3a-b4ea-2fa43fa94a29", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}, {"x": 384.0, "y": 575.5, "width": 66.0, "height": 43.0, "confidence": 0.9019243717193604, "class": "0", "class_id": 0, "detection_id": "3081c5bf-49ab-42ca-8827-b0ab3ed604b1", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}], "image": {"width": "1024", "height": "683"}} \ No newline at end of file
+{"predictions": [{"x": 221.0, "y": 466.0, "width": 284.0, "height": 196.0, "confidence": 0.9601893424987793, "class": "1", "class_id": 1, "detection_id": "a74d9dad-a652-4b0d-a4d5-fa06848c0dcf", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}, {"x": 180.0, "y": 306.0, "width": 304.0, "height": 288.0, "confidence": 0.9401327967643738, "class": "1", "class_id": 1, "detection_id": "c39691ab-c8dd-48c0-b3cd-c60d8f984e72", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}, {"x": 351.5, "y": 608.5, "width": 81.0, "height": 41.0, "confidence": 0.9194074869155884, "class": "0", "class_id": 0, "detection_id": "f600118a-f6d7-45c2-9c86-23d2741e34f2", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}, {"x": 384.0, "y": 575.5, "width": 66.0, "height": 43.0, "confidence": 0.9019243717193604, "class": "0", "class_id": 0, "detection_id": "9f6758e7-9525-4b86-a62f-670068124993", "image_path": "./syringe.jpg", "prediction_type": "ObjectDetectionModel"}], "image": {"width": "1024", "height": "683"}} \ No newline at end of file
diff --git a/test.py b/test.py
index 70fc4dc..d5609a8 100644
--- a/test.py
+++ b/test.py
@@ -1,60 +1,35 @@
-import serial.tools.list_ports
-from roboflow import Roboflow
-import json
-
-ports = serial.tools.list_ports.comports()
-serialInst = serial.Serial()
-
-rf = Roboflow(api_key="otKMUXAELXaU2XZsT77M")
-project = rf.workspace().project("biomedical-wastes")
-model = project.version(3).model
-
-json_response = model.predict("./syringe.jpg", confidence=40, overlap=30).json()
-
-portsList = []
-# portvar = ""
-for onePort in ports:
- portsList.append(str(onePort))
- print (str(onePort))
-
-val = "9"
-for x in range(0,len(portsList)):
- if portsList[x].startswith("COM" + str(val)):
- portvar = "COM" + str(val)
- print (portvar)
-serialInst.baudrate = 115200
-serialInst.port = portvar
-serialInst.open()
-isTest= True;
-while isTest:
- threshold = 0.8
- for prediction in json_response["predictions"]:
- if prediction["confidence"] > threshold:
- # Do something specific
- print("Syringe detected!")
- cmd = "INJD"
- serialInst.write(cmd.encode('utf-8'))
- isTest=False
- break;
- # save the JSON response to a file
- with open('output.json', 'w') as f:
- json.dump(json_response, f)
+
-
+from roboflow import Roboflow
+import json
+rf = Roboflow(api_key="otKMUXAELXaU2XZsT77M")
+project = rf.workspace().project("biomedical-wastes")
+model = project.version(3).model
+count = 0;
+# infer on a local image
+json_response = model.predict("./syringe.jpg", confidence=40, overlap=30).json()
+threshold = 0.8
+for prediction in json_response["predictions"]:
+ if prediction["confidence"] > threshold:
+ # Do something specific
+ print("Syringe detected!")
+ break;
+# save the JSON response to a file
+with open('output.json', 'w') as f:
+ json.dump(json_response, f)
-# infer on a local image