【问题标题】:How to manipulate frame per second in face recognition?如何在人脸识别中操纵每秒帧数?
【发布时间】:2021-04-19 05:55:54
【问题描述】:

我正在研究涉及对象检测的人脸识别。我使用 Yolov5 进行对象检测,使用 Facenet 进行人脸识别。我的 fps (~0.400) 非常低,这使得任务变得迟缓。那么如何限制几个初步任务的前 N ​​帧的 fps,而不是每秒 30 帧,我只想每秒只用 1 帧进行识别任务?

我尝试使用 cap.set(cv2.CAP_PROP_FPS, 5),但收到一条错误消息,提示“无法抓取帧”。

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


【问题讨论】:

  • 能否请您提出其他解决方案?
  • 您系统的负载是多少?您确定您的系统能够产生超过 0.4 fps 的速度吗?
  • 我如何检查,对于 Windows?据我所知,我使用的是网络摄像头,它支持 30 fps。

标签: opencv machine-learning deep-learning computer-vision


【解决方案1】:

我尝试将此添加为评论,但它太长了。这不完全是您问题的答案,但它可能有助于一种方法。我将首先通过测量这些任务的毫秒数来确定延迟:DETECTION TASKOBJECT DETECTION TASKSRECOGNITION TASK 在上面的代码中。

您应该能够实时进行检测,或者至少 5-10 FPS 或更高,这可能适合您的需求。如果识别是你的瓶颈,我会在另一个线程上这样做。这很有效,因为您不需要一遍又一遍地检测同一张脸。如果帧中有 30 FPS 和同一张脸 5 秒,那么只对那张脸执行一次识别,而不是 5x30 次。

使用多对象跟踪跨帧跟踪对象(人脸),而无需对每个对象执行人脸识别。 This tracking algorithm 易于实现且运行迅速。因此,跨帧跟踪对象,然后每个轨道只提交一次以供识别 - 并在另一个线程上执行此操作。

【讨论】:

    猜你喜欢
    • 2018-11-26
    • 2020-10-12
    • 2011-12-11
    • 2012-07-18
    • 2021-09-08
    • 1970-01-01
    • 2020-11-02
    • 2011-12-14
    • 1970-01-01
    相关资源
    最近更新 更多