raspberry pi opencv 视频 window 显示不正确

raspberry pi opencv video window dosen't show properly

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

大家好我在 运行ning opencv 3.3.0 on python 3.5.3 on a raspberry pi 3 b+ 运行ning raspbian 当我运行 上面的代码在带有 opencv 的虚拟环境中编译并且 运行s 但没有按预期工作。帧 window 显示并更新正常,但灰色和 thresh 帧打开,然后宽度接近 0。我附上了它的照片如果有人有任何见解会很棒。desktop

尝试改变

gray = cv2.cvtColor(frame.array, cv2.COLOR_BGR2GRAY)[1]

简单

gray = cv2.cvtColor(frame.array, cv2.COLOR_BGR2GRAY)