python - Error printing image with Raspberry Pi and OpenCV face detection (imshow function) -


i'm trying build simple surveillance program raspberry pi camera, using opencv face detection. code:

# -*- coding: utf-8 -*-  picamera.array import pirgbarray picamera import picamera import time import cv2  #setting camera  camera = picamera() camera.resolution = (320, 240) camera.framerate = 30 rawcapture = pirgbarray(camera, size=(320, 240))  #basic cascade classifier face_cascade = cv2.cascadeclassifier('haarcascade_frontalface_default.xml') #0.1 sec warmup  time.sleep(0.1)  # capture frames camera frame in camera.capture_continuous(rawcapture, format="bgr", use_video_port=true):       image = frame.array     gray = cv2.cvtcolor(image, cv2.color_bgr2gray)     faces = face_cascade.detectmultiscale(gray, 1.3, 5)      #rectangle  loop     for(x, y, w, h) in faces:         image = cv2.rectangle(image,(x, y), (x+w, y+h), (255, 0, 0), 2)      # show frame [here comes problem]     cv2.imshow("frame", image)     #   cv2.imshow("gray", gray     key = cv2.waitkey(100) & 0xff  # clear stream in preparation next frame rawcapture.truncate(0) # if `q` key pressed, break loop if key == ord("q"):     break 

the point that, when draw rectangle in image, comes error:

opencv error: assertion failed (size.width>0 && size.height>0) in imshow, file /home/pi/opencv-2.4.10/modules/highgui/src/window.cpp, line 261 traceback (most recent call last): file "camera2.py", line 36, in cv2.imshow("frame", image) cv2.error: /home/pi/opencv-2.4.10/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

if put cv2.imshow right before rectangle loop, works perfectly. also, printing faces object shows detectmultiscale recognizing faces. should do?

thanks.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

android - MPAndroidChart - How to add Annotations or images to the chart -