0

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()
3
  • You should move to python3 with with picamera2.
    – Dougie
    Aug 7 at 13:35
  • @Dougie sorry, can you help me with that? I dont understand "You should move to python3 with with picamera2", i think problem in bad processor in raspberry pi, and problem with opencv
    – Lyricss
    Aug 9 at 18:36
  • i think problem in bad processor in raspberry pi then nothing will help Aug 11 at 8:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.