from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import imutils
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640,480))
time.sleep(0.1)
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
image = frame.array
#cv2.imshow("frame", image)
gray = cv2.cvtColor(frame.array, cv2.COLOR_BGR2GRAY)[1]
#cv2.imshow("Gray", gray)
thresh = cv2.threshold(gray, 225, 255, cv2.THRESH_BINARY)[1]
#cv2.imshow("Thresh", thresh)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
output = thresh.copy()
cv2.imshow("frame", image)
cv2.imshow("Gray", gray)
cv2.imshow("Thresh", thresh)
key = cv2.waitKey(1) & 0xFF
rawCapture.truncate(0)
if key == ord("q"):
break
Hey guys I am running opencv 3.3.0 on python 3.5.3 on a raspberry pi 3 b+ running raspbian when I run the above code in a virtual environment with opencv it compiles and runs but does not work as intended. The frame window shows up and updates fine but the gray and thresh frames open and then the width become close to 0. I attached a photo of it If anyone has any insight that would be great.desktop
Try changing
gray = cv2.cvtColor(frame.array, cv2.COLOR_BGR2GRAY)[1]
to simply
gray = cv2.cvtColor(frame.array, cv2.COLOR_BGR2GRAY)