I am trying to do object detection from raspberry pi by getting frames from three webcam camera's attached to raspberry. currently I have three types of objects which I want to detect so I trained three cascade classifiers as following .
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
I am getting the frames from three cameras in a loop and passing each frame to Detection class .
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
in ObjectDetection class
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)
The problem is that i am getting 4-5 frames per second after detection but I need at least 10 frames per second. Is there anything I can try to speed up the detection ?? Any help would be highly appreciated .
NOTE I have also tried Using LBP features while training but that didnt helped .
You are trying to do alot on very little
A few points to answer the question of "How can I try and speed up detection", these are all opinion but based on experience
A couple of other notes: