我试图用raspberryPi进行人脸识别,我使用Raspi 3b,使用pi相机和python2.7。我仍然在处理数据集代码,其捕获图片以便稍后可以被训练和识别,(数据集代码>训练代码>识别代码)。
这是我的数据集代码
#ncclib
import cv2
cv2.__version__
import os
from picamera import PiCamera
from picamera.array import PiRGBArray
import numpy
import time
#strtprvw
camera = PiCamera()
camera.resolution = (640, 480)
rawCapture = PiRGBArray(camera, size=(640, 480))
display_window = cv2.namedWindow("Faces")
camera.start_preview()
#deteksi
cascadepath = my cacscade path(im using default.xml)
face_dtct = cv2.CascadeClassifier(cascadepath)
#id
face_id = input("enter id number : ")
#incr
count = 0
#gambar
while(True):
time.sleep(0.1)
rawCapture.truncate()
camera.capture(rawCapture, format="bgr") #ambilgambar
img = rawCapture.array
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #ubahgrayscale
faces = face_dtct.detectMultiScale(gray, 1.3, 5) #deteksiwajah gray
for (x,y,w,h) in faces:
cv2.rectangle(img, (x,y), (x+w,y+h), (255,0,0), 2) #cropdetectedface
count += 1
cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", gray[y:y+h,x:x+w]) #saving
cv2.imshow("faces", img)#nampilin gambar di screen
if cv2.waitKey(100) & 0xFF == ord('q'):
break
elif count >20:
break
camera.stop.preview()
cv2.destroyAllWindows()
我得到了这个
文件" new.py",第30行,in camera.capture(rawCapture,format =" bgr")#ambilgambar
文件" /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/picamera/camera.py" ;,第1421行,捕获 如果不是encoder.wait(self.CAPTURE_TIMEOUT):
文件" /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/picamera/encoders.py" ;,第395行,等待 self.stop的()
文件" /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/picamera/encoders.py" ;,第419行,停止 self._close_output()
文件" /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/picamera/encoders.py" ;,第349行,在_close_output中 mo.close_stream(输出,打开)
文件" /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/picamera/mmalobj.py",第371行,在close_stream stream.flush()
文件" /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/picamera/array.py" ;,第238行,同花顺 self.array = bytes_to_rgb(self.getvalue(),self.size或self.camera.resolution)
文件" /home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/picamera/array.py" ;,第127行,以bytes_to_rgb为单位 '分辨率%dx%d'的缓冲区长度不正确%(宽度,高度))
picamera.exc.PiCameraValueError:分辨率640x480的缓冲区长度不正确
我做了数据集文件夹,有没有人面临同样的问题,或者知道解决方案,请帮忙,分享。我真的很感激你的帮助,谢谢你