python face detection raspberry pi with picamera -


i newbie python , opencv trying build face detection project raspberry pi. getting error , here code

traceback (most recent call last):

 file "/home/pi/desktop/picamera-code/facedetection1.0", line 19, in <module> frame in      camera.capture_continuous(rawcapture, format="bgr", use_video_port=true): 

code:

import numpy np import cv2 picamera.array import pirgbarray picamera import picamera import time   camera = picamera() camera.resolution = (640, 480) camera.framerate = 32 rawcapture = pirgbarray(camera, size=(640, 480))  time.sleep(0.1)    face_cascade =  cv2.cascadeclassifier('/home/pi/downloads/haarcascade_frontalface_default.xml')  frame in camera.capture_continuous(rawcapture, format="bgr",  use_video_port=true):      img=np.asarray(frame.array)     gray = cv2.cvtcolor(img, cv2.color_bgr2gray)      faces = face_cascade.detectmultiscale(gray, 1.3, 5)     (x,y,w,h) in faces:         img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)         roi_gray = gray[y:y+h, x:x+w]         roi_color = img[y:y+h, x:x+w]   cv2.imshow('img',img) cv2.waitkey(0) cv2.destroyallwindows() 

the problem in camera.capture_continuos. first value, output, cannot array records infinite iteration docs says. instead of should put output file. if want stream capture can use io.bytes well.

in link explains examples on how tu use frame , should redirect output.

you can suggest on api docs. take stream , truncate image getting:

import io import time import picamera picamera.picamera() camera:     stream = io.bytesio()     foo in camera.capture_continuous(stream, format='jpeg'):     # yours:  frame in camera.capture_continuous(stream, format="bgr",  use_video_port=true):         # truncate stream current position (in case         # prior iterations output longer image)         stream.truncate()         stream.seek(0)         if process(stream):             break 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -