Python Picamera在使用树莓Pi进行人脸识别时不起作用
我是python和R-Pi的新手。所以在看了Adrian的教程之后,我想让面部识别开始工作。() 我的picamera通常可以正常工作,但当遵循上面的帖子时,我的picamera无法工作 以下是我的源代码:Python Picamera在使用树莓Pi进行人脸识别时不起作用,python,raspberry-pi,face-recognition,Python,Raspberry Pi,Face Recognition,我是python和R-Pi的新手。所以在看了Adrian的教程之后,我想让面部识别开始工作。() 我的picamera通常可以正常工作,但当遵循上面的帖子时,我的picamera无法工作 以下是我的源代码: from imutils.video import VideoStream import argparse import imutils import time import cv2 import os ap = argparse.ArgumentParser() ap.add_argum
from imutils.video import VideoStream
import argparse
import imutils
import time
import cv2
import os
ap = argparse.ArgumentParser()
ap.add_argument("-c", "--cascade", required=True,
help = "path to where the face cascade resides")
ap.add_argument("-o", "--output", required=True,
help="path to output directory")
args = vars(ap.parse_args())
detector = cv2.CascadeClassifier(args["cascade"])
print("[INFO] starting video stream...")
#vs = VideoStream(src=0).start()
vs = VideoStream(usePiCamera=True).start()
time.sleep(2.0)
total = 0
while True:
frame = vs.read()
orig = frame.copy()
frame = imutils.resize(frame, width=400)
rects = detector.detectMultiScale(
cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), scaleFactor=1.1,
minNeighbors=5, minSize=(30, 30))
for (x, y, w, h) in rects:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("k"):
p = os.path.sep.join([args["output"], "{}.png".format(
str(total).zfill(5))])
cv2.imwrite(p, orig)
total += 1
elif key == ord("q"):
break
print("[INFO] {} face images stored".format(total))
print("[INFO] cleaning up...")
cv2.destroyAllWindows()
vs.stop()
当我运行这个代码时
[INFO] starting video stream...
出现但相机不出现在树莓Pi上;当我面对镜头时
[INFO] {} face images stored
[INFO] cleaning up...
出现。您能试试这个吗
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
如果还没有完成,您可以让piCamera作为普通网络摄像头工作。因此,使用CV2更容易。您是否有/dev/video0?要启用/dev/video0:sudo modprobe bcm2835-v4l2或将bcm2835-v4l2添加到/etc/modulesIs-raspistill拍照?您是否在raspi配置中激活了网络摄像头?请解释为什么您的代码是问题的答案-OP的代码有什么问题?您是否尝试了我的代码?它有用吗?如果是这种情况,而您还没有使用bcm2835-v4l2,请尝试使用:vs=VideoStream(src=0).start()来查找发生了什么。您看到问题下面的注释了吗?谢谢您非常好的回答!多亏了你,我学会了用一种不同的方式来对待它。!