-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8%cpuusageopencv.py
More file actions
50 lines (45 loc) · 1.7 KB
/
8%cpuusageopencv.py
File metadata and controls
50 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import cv2
#img = cv2.imread("lena.PNG")
cap = cv2.VideoCapture(0)
cap.set(3,240)
cap.set(4,180)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 240)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
cap.set(cv2.CAP_PROP_FPS, 10)
classNames = []
classFile = "coco.names"
with open(classFile,"rt") as f:
classNames = f.read().rstrip("\n").split("\n")
configPath = "ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt"
weightsPath = "frozen_inference_graph.pb"
net = cv2.dnn_DetectionModel(weightsPath,configPath)
net.setInputSize(320,320)
net.setInputScale(1.0/ 127.5)
net.setInputMean((127.5,127.5,127.5))
net.setInputSwapRB(True)
while True:
success,img = cap.read()
classIds,confs,bbox = net.detect(img,confThreshold=0.55)
if len(classIds) != 0:
for classId,confidence,box in zip(classIds.flatten(),confs.flatten(),bbox):
can = classNames[classId-1]
if can == "cup":
print("I found something useful")
print(can)
cv2.rectangle(img,box,color=(0,255,0),thickness = 2)
elif can == "bowl":
print("I found something useful")
print(can)
cv2.rectangle(img,box,color=(0,255,0),thickness = 2)
elif can == "bottle":
print("I found something useful")
print(can)
cv2.rectangle(img,box,color=(0,255,0),thickness = 2)
elif can == "cell phone":
print("I found something useful")
print(can)
cv2.rectangle(img,box,color=(0,255,0),thickness = 2)
else:
pass
cv2.imshow("Bottle Detector",img)
cv2.waitKey(300)