簡體   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