我正在尝试使用python和Open Cv实现面部识别。我已经使用python成功实现了面部检测,只需遵循一些可用的教程并且工作正常。
现在我要做的是做面部识别,我已经遵循了一些教程,但没有一个能为我工作。
我已经按照本教程进行了足够清楚,但代码中存在语法错误。
https://oscarliang.com/raspberry-pi-face-recognition-opencv/
我试图运行此代码
import cv
cv.NamedWindow(“w1”, cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
def repeat():
global capture #declare as globals since we are assigning to them now
global camera_index
frame = cv.QueryFrame(capture)
cv.ShowImage(“w1″, frame)
c = cv.WaitKey(10)
if(c==”n”): #in “n” key is pressed while the popup window is in focus
camera_index += 1 #try the next camera index
capture = cv.CaptureFromCAM(camera_index)
if not capture: #if the next camera index didn’t work, reset to 0.
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
while True:
repeat()
但我在第6行中遇到以下错误
程序中存在错误:预计会出现阻止。
我尽力解决它,但没有任何效果。
由于我是覆盆子pi和python的新手,所以我们将不胜感激。
提前致谢。
答案 0 :(得分:1)
您可以按照以下方式重新格式化,看看是否有任何帧。
import cv2.cv as cv
cv.NamedWindow('w1', cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
def repeat():
global capture #declare as globals since we are assigning to them now
global camera_index
frame = cv.QueryFrame(capture)
if frame:
cv.ShowImage('w1', frame)
c = cv.WaitKey(10)
if(c=='n'): #in “n” key is pressed while the popup window is in focus
camera_index += 1 #try the next camera index
capture = cv.CaptureFromCAM(camera_index)
if not capture: #if the next camera index didn’t work, reset to 0.
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
while True:
repeat()