我正在从事一个计算机视觉项目,下面是我的代码应该如何工作: 在 while 循环中,代码应该运行一个函数,该函数为前 5 帧返回一个字符串。如果该函数返回一个我正在寻找的输出,那么它应该继续运行其余的代码。剩下的代码涉及两个函数,主要执行人脸检测和识别任务。我希望这些任务仅以每秒 1 或 2 帧的速度执行。问题是我的代码没有执行检测和识别部分。
frame_id = 0
while True:
frame = video_capture.read()
frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5) #resize frame (optional)
height, width = frame.shape[:2]
frame_id += 1
# Selecting 5 frames per second to
flag = False
if frame_id <= 5:
event = Bodyevent(frame)
if event is None:
continue
if "1" in event or "2" in event:
cv2.putText(frame, "DETECTED", (100, height - 20),
cv2.FONT_HERSHEY_COMPLEX_SMALL, 1,
(255, 255, 255), 1, cv2.LINE_AA)
flag = True
if flag == True:
# Now run the tasks
if frame_id % 6 == 0:
print("frame: ", frame_id)
# detect object #1
detect(frame)
find_results = []
if frame.ndim == 2:
frame = facenet.to_rgb(frame)
frame = frame[:, :, 0:3]
bounding_boxes, _ = detect_face.detect_face(frame, minsize, pnet, rnet, onet, threshold, factor)
# detect number of faces and store in nrof_faces
nrof_faces = bounding_boxes.shape[0]
if nrof_faces > 0:
label = classify_face(frame)
# recognition task #
else:
print('Unable to align')