Ask Your Question
0

Slow processing on Raspberry Pi using Python

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

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

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)

while(True):
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = detector.detectMultiScale(gray, 1.3, 5)
    for (x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(254,0,0),2)
    cv2.imshow('frame',img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

1

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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

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

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

Stats

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

Seen: 2,851 times

Last updated: Oct 30 '17