Как исправить imshow (), показывающий серое изображение - PullRequest
0 голосов
/ 15 мая 2019

Я пытаюсь показать захват веб-камеры на экране в моем Raspberry Pi.Первый кадр отображается без проблем, но следующие отображаются серыми.

Работает на окнах, но не на малине.

import cv2 as cv

cap = cv.VideoCapture(0)
ret, frame = cap.read()
cv.imshow('frame0',frame)
while True:
    ret, frame = cap.read()
    cv.imshow('frame',frame)
    if cv.waitKey(1) == ord('q'):
        break
cap.release()
cv.destroyAllWindows()

1 Ответ

0 голосов
/ 15 мая 2019

Сначала установите модуль Picamera, а затем попробуйте:

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))

# allow the camera to warmup
time.sleep(0.1)

# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    image = frame.array

    # show the frame
    cv2.imshow("Frame", image)
    key = cv2.waitKey(1) & 0xFF

    # clear the stream in preparation for the next frame
    rawCapture.truncate(0)

    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break

Источник: https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...