Slow processing on Raspberry Pi using Python
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()
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