Relatively recently I started writing a project in which faces are detected through raspicam in python using opencv, but the result disappoints me, I get literally 5 fps, but if you remove face detection, then the fps becomes 30 fps, that is, the problem is specifically in the cascades apparently.
Sorry for such a translation, I do not communicate in English and use a translator.
I'm using raspberry pi 3b. Here is the code I am using:
import io
import picamera
import cv2
import numpy as np
stream = io.BytesIO()
cv2.namedWindow("Camera Feed")
face_cascade =cv2.CascadeClassifier('/home/pi/haarcascade_frontalface_default.xml')
with picamera.PiCamera() as camera:
camera.resolution = (420, 320)
camera.framerate = 24
for _ in camera.capture_continuous(stream, format='jpeg', use_video_port=True):
buff = np.frombuffer(stream.getvalue(), dtype=np.uint8)
image = cv2.imdecode(buff, 1)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255),
text = "FINDED"
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 0.7
font_thickness = 1
text_size = cv2.getTextSize(text, font, font_scale, font_thickness)[0]
text_x = x + (w - text_size[0]) // 2
text_y = y + h + text_size[1] + 10
cv2.putText(image, text, (text_x, text_y), font, font_scale, (0, 0, 255), font_thickness)
cv2.imshow("Camera Feed", image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
stream.seek(0)
stream.truncate()
cv2.destroyAllWindows()
i think problem in bad processor in raspberry pi
then nothing will help