如何在人脸识别中处理每秒帧数?

我正在研究人脸识别,这也涉及到物体检测。我使用Yolov5进行对象检测,使用Facenet进行人脸识别。我得到了非常低的fps (~0.400),这使得任务滞后。那么,我如何限制几个初步任务的前N帧的fps,然后我希望识别任务每秒只有1帧,而不是每秒30帧?

我尝试使用cap.set(cv2.CAP_PROP_FPS, 5),但收到错误提示'Can't grab a frame.‘’。

代码语言:javascript运行复制with tf.Graph().as_default():

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.6)

sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))

with sess.as_default():

pnet, rnet, onet = detect_face.create_mtcnn(sess, './models/')

minsize = 20 # minimum size of face

threshold = [0.6, 0.7, 0.7] # three steps's threshold

factor = 0.709 # scale factor

margin = 44

frame_interval = 3

batch_size = 1000

image_size = 182

input_image_size = 160

print('Loading feature extraction model')

modeldir = './models/'

facenet.load_model(modeldir)

images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")

embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")

phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")

embedding_size = embeddings.get_shape()[1]

classifier_filename = './myclassifier/my_classifier.pkl'

classifier_filename_exp = os.path.expanduser(classifier_filename)

with open(classifier_filename_exp, 'rb') as infile:

(model, class_names) = pickle.load(infile)

print('load classifier file-> %s' % type(class_names))

HumanNames = class_names

video_capture = cv2.VideoCapture(0)

c = 0

print('Start!')

prevTime = 0

FPSLimit = 10

StartTime = time.time()

while True:

ret, frame = video_capture.read()

# frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5) #resize frame (optional)

curTime = time.time() # calcq fps

timeF = frame_interval

#if int(curTime - StartTime) > FPSLimit:

if (c % timeF == 0):

DETECTION TASK

if nrof_faces > 0:

OBJECT DETECTION TASKS

RECOGNITION TASK

战双帕弥什WIKI
岸田文雄谈日本足球队赢德国 日本网民:怎么不放假?