gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 17:45:09 24 4
gpt4 key购买 nike

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

There's an error in your program:expected an intended block.



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

由于我是树莓派和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()

关于python - 使用树莓派,Pi相机,Python和Open Cv进行人脸识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37389693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com