我正试图通过从三个摄像头相机附加到覆盆子的镜架来对覆盆子pi进行物体检测。 目前我有三种类型的对象我想要检测,所以我训练了三个级联分类器如下。
opencv_traincascade -data data -vec positives.vec -bg bg.txt -numPos 1200 -numNeg 1000 -numStages 11 -minHitRate 0.999 -maxFalseAlarmRate 0.2 -w 24 -h 24
我从循环中的三个摄像头获取帧并将每个帧传递给Detection类。
obj_detection= ObjectDetection()
for name in camera_names:
if name not in self.cv2_window_name:
self.cv2_window_name.append(name)
frame = datavector[name]
width, height, channel = frame.shape
frame=cv2.resize(frame,(int(width/1),int(height/2)),interpolation=cv2.INTER_AREA) #resizing image helped a little but didnt helped much
frame = obj_detection.detect(frame)
print(time.time()) #to check frame rate currently showing 4 frames per second
cv2.imshow(name, frame)
cv2.waitKey(1) # CV2 Devil
ObjectDetection 类中的
self.objs['Traffic light']= cv2.CascadeClassifier("../1.xml")
self.objs['Stop']= cv2.CascadeClassifier("../2.xml")
self.objs['No Left'] = cv2.CascadeClassifier("../3.xml")
def detect(self,image):
self.image=image
objects = [key for key in self.objs]
t={}
for type in objects:
t[type]=Thread(target = self.detect_obj,args=(self.objs[type],self.image,type))
t[type].start()
[t[type].join() for type in objects]
return self.image
def detect_obj(self,classifier,image,type=""):
self.image=image
gray_image = cv2.cvtColor(self.image , cv2.COLOR_BGR2GRAY)
obj=classifier.detectMultiScale(
gray_image,
scaleFactor=1.02,
minNeighbors=2,
minSize=(50,50),
flags=cv2.CASCADE_SCALE_IMAGE
)
for (x,y,w,h) in obj:
cv2.rectangle(self.image,(x,y),(x+w,y+h),(255,219,0),2)
问题是我在检测后每秒获得4-5帧,但我需要每秒至少10帧。有什么我可以尝试加快检测?任何帮助将受到高度赞赏。
注意我在训练时也尝试过使用LBP功能,但这并没有帮助。
答案 0 :(得分:2)
您正试图在很少上
有几点可以回答“如何尝试和加快检测速度”的问题,这些都是基于经验的意见
其他几点说明: