【问题标题】:Face recognition using raspberry pi, pi camera,python and Open Cv使用树莓派、pi 相机、python 和 Open Cv 进行人脸识别
【发布时间】:2016-09-20 06:10:42
【问题描述】:

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

你的程序有一个错误:预期是一个预期的块。

我尽力解决它,但没有任何效果。

由于我是 raspberry pi 和 python 的新手,任何帮助将不胜感激。

提前致谢。

【问题讨论】:

  • 这个问题的范围很广,可能不太适合 Stack Overflow。对于您实现的代码对您不起作用的地方,您是否有任何具体问题?你能发布你的代码吗?
  • @PaulRooney 感谢您的回答。我已对问题进行了编辑。请检查。希望现在有意义。
  • 你能发布语法错误吗?请记住,那篇文章中的某些代码不是 python。
  • @PaulRooney 请查看我编辑的问题。如果您仍然觉得它不完整,请帮助改进这个问题。谢谢
  • 根据错误消息,您的所有代码都错误地缩进了。原始帖子的代码块格式不正确也无济于事。您对 python 的了解还不够,无法正确缩进该代码吗?实际上不可能知道作者想要的缩进是什么,您可能需要尝试几种不同的可能性。您应该在他的博客上留言以整理出他的代码示例:)

标签: python python-2.7 opencv raspberry-pi2 raspberry-pi3


【解决方案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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-17
    • 2013-07-04
    • 2020-06-21
    • 2017-07-08
    • 2014-08-26
    • 2020-12-24
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多