The code below only runs at 1-2FPS. Need help making the necessary changes to improve the frame rate to about 10fps. The code is implemented on the jetson nano.
importface_recognitionimportcv2importosimportdlibimportpickleimporttimeprint(cv2.__version__)fpsReport=0scaleFactor=.25Encodings=[]Names=[]withopen('train.pkl','rb')asf:Names=pickle.load(f)Encodings=pickle.load(f)font=cv2.FONT_HERSHEY_SIMPLEXcam=cv2.VideoCapture(0)timeStamp=time.time()whileTrue:_,frame=cam.read()frameSmall=cv2.resize(frame,(0,0),fx=scaleFactor,fy=scaleFactor)frameRGB=cv2.cvtColor(frameSmall,cv2.COLOR_BGR2RGB)facePositions=face_recognition.face_locations(frameRGB,model='CNN')allEncodings=face_recognition.face_encodings(frameRGB,facePositions)for(top,right,bottom,left),face_encodinginzip(facePositions,allEncodings):name='Unknown Person'matches=face_recognition.compare_faces(Encodings,face_encoding)ifTrueinmatches:first_match_index=matches.index(True)name=Names[first_match_index]top=int(top/scaleFactor)right=int(right/scaleFactor)bottom=int(bottom/scaleFactor)left=int(left/scaleFactor)cv2.rectangle(frame,(left,top),(right,bottom),(0,0,255),2)cv2.putText(frame,name,(left,top-6),font,.75,(0,0,255),2)dt=time.time()-timeStampfps=1/dtfpsReport=0.90*fps+0.1*fps#print('fps is: ',round(fpsReport,2))timeStamp=time.time()cv2.rectangle(frame,(0,0),(100,40),(0,0,255),-1)cv2.putText(frame,str(round(fpsReport,1))+'fps',(0,25),font,.75,(0,255,255,2))cv2.imshow('Picture',frame)cv2.moveWindow('Picture',0,0)ifcv2.waitKey(1)==ord('q'):breakcam.release()cv2.destroyAllWindows()
Kindly please help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The code below only runs at 1-2FPS. Need help making the necessary changes
to improve the frame rate to about 10fps. The code is implemented on the
jetson nano.
~~~
import face_recognition
import cv2
import os
import dlib
import pickle
import time
print(cv2.version)
fpsReport=0
scaleFactor=.25
Encodings=[]
Names=[]
with open('train.pkl','rb') as f:
Names=pickle.load(f)
Encodings=pickle.load(f)
The code below only runs at 1-2FPS. Need help making the necessary changes to improve the frame rate to about 10fps. The code is implemented on the jetson nano.
Kindly please help.
Aside from making sure compiler optimizations are on, use smaller images.
See also http://dlib.net/faq.html#Whyisdlibslow
On Thu, Nov 16, 2023 at 6:33 AM Nikhil B bwajster@users.sourceforge.net
wrote: