我训练了Darkflow来检测5个自定义objetcts,现在我想发出一个仅在检测到对象时发出蜂鸣声的警报(5类中的任何对象)。因此,我需要有关在暗流代码中进行更改的信息。如果您可以帮助一段示例代码,那将更有帮助。 从darkflow.net.build导入TFNet 导入cv2 将numpy导入为np 导入imutils cap = cv2.VideoCapture('rtsp:// admin:123456@192.168.226.201:554 / profile1')
options = {'model': 'cfg/tiny-yolo-voc-5c.cfg','load': 118800,
'threshold': 0.7, 'gpu': 1.0}
tfnet = TFNet(options)
while True:
ret, frame = cap.read()
#frame = cv2.resize(frame,(720,480))
frame = imutils.resize(frame, width=600)
#cv2.imshow('frame',frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
edges = cv2.Canny(blur,100,200)
th3 = cv2.adaptiveThreshold(edges,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINA RY,11,2)
contours,_ = cv2.findContours(th3, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
height, width = edges.shape
min_x, min_y = width, height
max_x = max_y = 0
for cnt in contours:
area = cv2.contourArea(cnt)
# if area < 10000 and area > 13000:
# continue
(x,y,w,h) = cv2.boundingRect(cnt)
min_x, max_x = min(x, min_x), max(x+w, max_x) #if (w< 400 and w>300) and (h<400 and w>300):
min_y, max_y = min(y, min_y), max(y+h, max_y)
#if (w< 670 and w>50) and (h <670 and w>50):
#roi = frame[y:y+h, x:x+w]
result = tfnet.return_predict(frame)
for elem in result:
top_x, top_y = elem["topleft"]["x"], elem["topleft"]["y"]
bot_x, bot_y = elem["bottomright"]["x"] , elem["bottomright"]["y"]
cv2.rectangle(frame,(top_x,top_y),(bot_x,bot_y),(0,0,255),2)
cv2.putText(frame, elem["label"], (top_x-10, top_y-
10),cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 1, cv2.LINE_AA)
cv2.imshow('roi',frame)
#cv2.imshow('frame',frame)
key = cv2.waitKey(30)
if key == ord('q'):
break
cap.release()
cv2.destroyAllWindows()