【发布时间】:2021-09-28 16:10:04
【问题描述】:
有什么方法可以从我的脚本中自定义对象检测。如果是,该怎么做,我需要安装什么吗?请提供分步指南或视频指南。
无论如何,我正在使用 Raspberry Pi 来做这件事。所以它最好是免费的 GPU,并且能够在树莓派中做到这一点。
在这个脚本下面,它对我有用,只是我需要检测“coco.name”、“ssd_mobilenet”中未包含的特定内容。
示例:我想检测“SKII Toner”而不是“bottle”我希望它是“SKII Toner”
import cv2
import numpy as np
#Threshold setup
thres = 0.3 # Threshold to detect object
nms_threshold = 0.2
#camera setup
cap = cv2.VideoCapture(0)
#cap.set(3,1080)
#cap.set(4,1920)
#cap.set(10,300)
#standard configuration setting up
classFile = "coco.names"
classNames = []
with open(classFile,"rt") as f:
classNames = f.read().rstrip("\n").split("\n")
#print(classNames)
configPath = "/home/pi/darknet/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt"
weightPath = "/home/pi/darknet/frozen_inference_graph.pb"
net = cv2.dnn_DetectionModel(configPath,weightPath)
net.setInputSize(320,320)
net.setInputScale(1.0/ 120)
net.setInputMean((120, 120, 120))
net.setInputSwapRB(True)
while True:
success,img = cap.read()
img = cv2.flip(img, 0)
classIds, confs, bbox = net.detect(img,confThreshold=thres)
bbox = list(bbox)
confs = list(np.array(confs).reshape(1,-1)[0])
confs = list(map(float,confs))
#print(type(confs[0]))
#print(confs)
indices = cv2.dnn.NMSBoxes(bbox,confs,thres,nms_threshold)
#print(indices)
for i in indices:
i = i[0]
box = bbox[i]
x,y,w,h = box[0], box[1], box[2], box[3]
cv2.rectangle(img, (x,y),(x+w,h+y), color=(0,255,0),thickness=1)
cv2.putText(img,classNames[classIds[i][0]-1].upper(),(box[0]+10,box[1]+30),
cv2.FONT_HERSHEY_COMPLEX,1,(0,255,0),1)
cv2.imshow("Output",img)
cv2.waitKey(1)
【问题讨论】:
-
我不完全理解你的问题..你想检测一个新的类“SKII Toner”(我什至不知道它是什么)?
-
@rok 早安,是的,我想检测新的类,而不是使用 coco.names。
标签: raspberry-pi python-3.7 object-detection cv2