face_detection.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:smart-cam 作者: smart-cam 项目源码 文件源码
def __get_uniq_faces_curr_frame(self, frame_id, faces_roi_hists_prev, faces_roi_hists):
        faces_prev = len(faces_roi_hists_prev)
        faces_curr = len(faces_roi_hists)
        logger.info("[{0}] Face Similarity: Prev: {1}, Curr: {2}".format(frame_id,
                                                                         faces_prev,
                                                                         faces_curr))
        # First Time
        if faces_prev == 0:
            return faces_curr

        # Current frame has more faces than prev frame
        #if faces_curr > faces_prev:
        #    return faces_curr - faces_prev

        uniq_faces_curr_frame = 0

        # Perform Image Histogram Similarity
        # For each histogram in current frame
        for rh1 in faces_roi_hists:
            match_found = False
            # For each histogram in previous frame
            for rh2 in faces_roi_hists_prev:
                #print "\nrh1 {0}: {1}".format(type(rh1),np.shape(rh1))
                #print "\nrh2 {0}: {1}".format(type(rh2),np.shape(rh2))
                corr = cv2.compareHist(rh1, rh2, cv2.HISTCMP_CORREL)
                logger.info("[{0}] Similarity Metrics: {1}".format(frame_id, corr))
                if corr >= 0.35:
                    # Match Found, can break the loop for this histogram in current frame
                    match_found = True
                    break;
            # Add to unique face count, if no match found for this histogram in current frame
            if not match_found:
                uniq_faces_curr_frame += 1

        logger.info("[{0}] Total Unique Faces in Current Frame: {1}".format(frame_id, uniq_faces_curr_frame))
        return uniq_faces_curr_frame
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号