【发布时间】:2014-08-25 19:30:57
【问题描述】:
我正在尝试开发一个用作自拍相机的代码。视频将在窗口中显示,并且将不断检测人的面部和眼睛,一旦用户选择特定时间,就会捕获该时间点的帧。我可以使用时间模块中的睡眠功能在一段时间后捕获帧,但视频帧似乎冻结了。是否有任何解决方案可以让我继续观看视频,并且视频捕获会在一段时间后自动进行。
我正在使用代码-
import numpy as np
import cv2
import time
import cv2.cv as cv
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',frame)
#time.sleep(01)
Capture = cv.CaptureFromCAM(0)
time.sleep(5)
ret, frame = cap.read()
image = cv.QueryFrame(Capture) #here you have an IplImage
imgarray = np.asarray(image[:,:]) #this is the way I use to convert it to numpy array
cv2.imshow('capImage', imgarray)
cv2.waitKey(0)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
有人可以推荐我吗?任何形式的帮助将不胜感激。
【问题讨论】:
-
请删除帖子中所有不必要的代码
-
我删除了代码的人脸检测部分。只剩下必要的部分了
-
为什么它对同一个 id 使用 2 个视频捕获?
Capture = cv.CaptureFromCAM(0)将失败,因为它已经在使用中。请坚持使用 cv2 api,旧的 cv 不应该再使用了
标签: python opencv python-3.x video-capture face-detection