【发布时间】:2022-07-08 23:05:42
【问题描述】:
所以我试图从 yt 做一个对象检测教程。我找到了一个叫 murtaza 的人,我想试试他的代码。这是视频; https://www.youtube.com/watch?v=diWDgKcH3E0 ; 没有错;它有效,但我想知道我是否只能检测框架中的某个对象而不是各种对象;所以就像我不希望它检测“coco.names”文件中的各种东西,但只有一个;知道我该怎么做吗?我正在使用 pycharm;而且因为他使用的编码策略非常先进;我不知道如何让代码做到这一点;所以: . 只检测一个对象,而不是视频流中的所有对象(网络摄像头) 。文件: https://github.com/sidpro-hash/Object-Detection - 仅下载: -“可可名称” -“frozen_inference_graph.pb” -“ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt” 这是代码:
import cv2
import cvzone
thres = 0.5 #to detect objects
#img = cv2.imread('cat3.jpg')
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
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'
weigthsPath = 'frozen_inference_graph.pb'
net = cv2.dnn_DetectionModel(weigthsPath,configPath)
net.setInputSize(320,320)
net.setInputScale(1.0/127.5)
net.setInputMean((127.5, 127.5, 127.5))
net.setInputSwapRB(True)
while True:
_, img = cap.read()
classIds, confs, bbox = net.detect(img, confThreshold=0.5)
print(classIds, bbox)
if len(classIds) != 0:
for classId, confidence, box in zip(classIds.flatten(), confs.flatten(), bbox):
#cv2.rectangle(img, box, color=(0,0,255), thickness=3)
cvzone.cornerRect(img, box)
cv2.putText(img, classNames[classId-1].upper(), (box[0]+10,box[1]+30),
cv2.FONT_HERSHEY_COMPLEX,1,(0,0,0), 2)
cv2.putText(img, str(round(confidence*100, 2)), (box[0]+200,box[1]+30),
cv2.FONT_HERSHEY_COMPLEX,1,(0,0,0), 2)
cv2.imshow("output", img)
cv2.waitKey(1)
【问题讨论】:
-
请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。