Commit 15f161fe authored by jack's avatar jack

update

parent 843d9c7c
......@@ -27,7 +27,7 @@ class DarknetYolo:
self.COLORS=COLORS
def getdetresults(self, frame, hasdraw):
def getdetresults(self, frame):
netMain, metaMain, thresh, COLORS = self.netMain, self.metaMain, self.thresh, self.COLORS
# Create a 4D blob from a frame.
......@@ -65,19 +65,25 @@ class DarknetYolo:
# lower confidences.
idxs = cv2.dnn.NMSBoxes(boxes, confidences, thresh, 0.3)
if len(idxs) > 0:
if not hasdraw:
return idxs, boxes, confidences, classIDs, metaMain;
lists = [[0 for i in range(0)] for i in range( len(idxs.flatten()) )]
k=0
for i in idxs.flatten():
# get x,y,w,h
(x, y) = (boxes[i][0], boxes[i][1])
(w, h) = (boxes[i][2], boxes[i][3])
# draw rectangle
x2 = x + w
y2 = y + h
lists[k].append(x)
lists[k].append(y)
lists[k].append(x2)
lists[k].append(y2)
label = metaMain[classIDs[i]]
confidence = confidences[i]
color = [int(c) for c in COLORS[classIDs[i]]]
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 1, lineType=cv2.LINE_AA)
text = "{}: {:.4f}".format(metaMain[classIDs[i]], confidences[i])
cv2.putText(frame, text, (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX,
0.5, color, 1, lineType=cv2.LINE_AA)
cv2.imshow("Tag", frame)
#cv2.waitKey(0)
lists[k].append(label)
lists[k].append(confidence)
lists[k].append(color)
k=k+1
return lists
else:
print("Cann't detect objects,please check image!")
......@@ -53,14 +53,23 @@ while cv.waitKey(1) < 0:
# Release device
cap.release()
break
detections_lists = []
detections_lists = yolo.getdetresults(frame)
print(len(detections_lists ))
idxs, boxes, confidences, classIDs, metaMain = yolo.getdetresults(frame,False)
for i in idxs.flatten():
(x, y) = (boxes[i][0], boxes[i][1])
(w, h) = (boxes[i][2], boxes[i][3])
cv.rectangle(frame, (x, y), (x + w, y + h), (255, 255, 255), 1, lineType=cv.LINE_AA)
text = "{}: {:.4f}".format(metaMain[classIDs[i]], confidences[i])
cv.putText(frame, text, (x, y - 5), cv.FONT_HERSHEY_SIMPLEX,
0.5, (255, 255, 255), 1, lineType=cv.LINE_AA)
cv.imshow("Tag", frame)
for i in range( len(detections_lists) ):
# get x,y,w,h
x1 = detections_lists[i][0]
y1 = detections_lists[i][1]
x2 = detections_lists[i][2]
y2 = detections_lists[i][3]
label = detections_lists[i][4]
confidence = detections_lists[i][5]
color = detections_lists[i][6]
cv.rectangle(frame, (x1, y1), (x2, y2), color, 1, lineType=cv.LINE_AA)
text = "{}: {:.4f}".format(label, confidence )
cv.putText(frame, text, (x1, y1 - 5), cv.FONT_HERSHEY_SIMPLEX,
0.5, color, 1, lineType=cv.LINE_AA)
cv.imshow("Tag", frame)
#print(detections_lists)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment