Ask Your Question

Slow processing on Raspberry Pi using Python

asked 2017-04-27 08:20:47 -0500

updated 2017-04-27 10:25:10 -0500

kbarni gravatar image

hi i am using raspberry pi for my final year project. i wrote some scripts for face detection, training and face recognition all are working fine but its very slow. it shows only single frame per second because of processing of each frame. i have to extend this work upto emotion detection as well hence i want to make it faster. i also ran same codes on my pc it was pretty fast which means my scripts are good but i would want it to be faster on my pi. Please HELP !!!

this is my face detection code

import numpy as np
import cv2

detector= cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)

    ret, img =
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = detector.detectMultiScale(gray, 1.3, 5)
    for (x,y,w,h) in faces:
    if cv2.waitKey(1) & 0xFF == ord('q'):
edit retag flag offensive close merge delete



well, Raspberry Pis are quite slow... A 1.2GHz ARM processor is in fact much weaker than a similar speed desktop processor.

Some tricks to speed up processing:

  • check if it's working in parallel: does it use all four cores (assuming you have a Raspberry Pi model 2 or 3). On single core processors (Raspberry Pi Zero or A+) it will always be slow. If it uses only one core, check if you can recompile it with parallelisation flags (with TBB).

  • reduce the image size

kbarni gravatar imagekbarni ( 2017-04-27 10:23:13 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-30 20:57:50 -0500

supra56 gravatar image

For Rpi 2 use picamera for faster. The webcam si too slowly. For Rpi 3 can use either picamera or webcam

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-04-27 08:20:47 -0500

Seen: 2,204 times

Last updated: Oct 30 '17