繁体   English   中英

使用树莓派,Pi相机,Python和Open Cv进行人脸识别

[英]Face recognition using raspberry pi, pi camera,python and Open Cv

我正在尝试使用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行出现以下错误

您的程序中有一个错误:预期的块。

我尽力解决了这个问题,但没有任何效果。

因为我是树莓派和python的新手,所以我们将不胜感激。

提前致谢。

您可以按以下方式重新格式化它,看看是否有任何框架。

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM