Read frames from UVC camera

1.7k views Asked by At

My camera is sporting 'GREY' and 'Y16' formats.

the output of v4l2-ctl --list-formats -d 0 # 0 is video0 is:

ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'GREY' (8-bit Greyscale)
    [1]: 'Y16 ' (16-bit Greyscale)

now if i use basic code of video streaming

import numpy as np
import cv2 as cv

cap = cv.VideoCapture('/dev/video0')

if not cap.isOpened():
    print("Cannot open camera")
    exit()
while True:
    # Capture frame-by-frame
    ret, frame = cap.read()
    # if frame is read correctly ret is True
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
   
    cv.imshow('frame', frame)
    if cv.waitKey(1) == ord('q'):
        break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()

it is returning black imageenter image description here

1

There are 1 answers

0
Maharshi Oza On
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('G','R','E','Y'))

by setting the property of the camera, now i am able to get the frame. enter image description here