ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
53.59k stars 13.51k forks source link

drop frame from 240~300 to 5~10 #1226

Open diamondbarcode opened 4 years ago

diamondbarcode commented 4 years ago

dlip : 19.21.0 cv2: 4.4.0 Cuda Support

Description

I just add this line to my python test code and my video out drop frame from 240~300 to 5~10 not sure what cause.

What I Did

add : faceLOC=face_recognition.face_locations(frame) to code

import cv2
import jetson.inference
import jetson.utils
import time
import numpy as np
import face_recognition

width=1280
height=720
#font=jetson.utils.cudaFont()

# create camera object
cam=jetson.utils.gstCamera(width,height,'/dev/video0')
# display object
#display=jetson.utils.glDisplay()
# nural network object referent : https://github.com/dusty-nv/jetson-inference 
net=jetson.inference.imageNet('googlenet')
#net=jetson.inference.detectNet('facenet-120')

#grab time clock to cal frame per sec
timeMark=time.time()
# frame per sec start 0
fpsFilter=0

#show view
#while display.IsOpen():
while True:
    # read frame
    frame,width,height=cam.CaptureRGBA(zeroCopy=1)
    # identify what it is and confidence of it by just return ID and confidence level
    #classID, confidence=net.Classify(frame,width,height)
    #classID, confidence=net.Detect(frame,width,height)
    # translate class id to description
    #item=net.GetClassDesc(classID)
    # call FPS

    dt=time.time()-timeMark
    fps=1/dt
    fpsFilter=0.95*fpsFilter+0.5*fps
    timeMark=time.time()
    # put text
    #font.OverlayText(frame,width,height,str(round(fpsFilter,1))+' FPS '+item,5,5,font.Magenta,font.Blue)
    # show frame
    #display.RenderOnce(frame,width,height)
    #try display with cv2 and see what it hit ...
    frame=jetson.utils.cudaToNumpy(frame,width,height,4)
    frame=cv2.cvtColor(frame,cv2.COLOR_RGBA2BGR).astype(np.uint8)
    faceLOC=face_recognition.face_locations(frame) # just this line drop from 240 FPS to just 10 ..
    #print(faceLOC)
    cv2.putText(frame,str(round(fpsFilter,1))+' FPS ',(0,30),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2)
    cv2.imshow("",frame)
    if cv2.waitKey(1)==ord('q'):
        break
cam.releast()
cv2.destroyAllWindows()
ageitgey commented 4 years ago

You are saying that you have a program that does nothing at 240fps and gets slower when you call face detection of every frame of video. I'm not sure what else you would expect to happen? It takes time to run a model on every frame of video and that particular model is not GPU accelerated by default.

You can try changing with the size of the image you pass to the function and whether or not you use the CNN model to see how that impacts the speed of face detection. Check out some of the various examples.

diamondbarcode commented 4 years ago

When I try an example from" https://github.com/dusty-nv/jetson-inference " to detect objects it stays around 300 to 240(u see I quote out the test). I think I may do it wrong or I do not know how to offload work to GPU.

I try the CNN model it performs worse then DNN(in other tests example). I am sorry I don't know how to approach this I just learning about this AI world in less than a month.