▼OpenCV-Python操作UBS摄像头“pipeline”

  1. import numpy as np
    import cv2 as cv
    cap = cv.VideoCapture(0)
    if not cap.isOpened():
        print("Cannot open camera")
        exit()
    cap.set(cv.CAP_PROP_FRAME_HEIGHT,240)
    cap.set(cv.CAP_PROP_FRAME_WIDTH,320)
    '''使用cv.VideoCapture.set设置摄像头分辨率是出现错误'''
    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
        # Our operations on the frame come here
        gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        # Display the resulting frame
        cv.imshow('frame', gray)
        if cv.waitKey(1) == ord('q'):
            break
    # When everything done, release the capture
    cap.release()
    cv.destroyAllWindows()
    

    问题:

在执行的时候出现:

[ WARN:0] global /root/opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
[ WARN:0] global /root/opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data flow error.
[ WARN:0] global /root/opencv/modules/videoio/src/cap_gstreamer.cpp (515) startPipeline OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /root/opencv/modules/videoio/src/cap_gstreamer.cpp (1055) setProperty OpenCV | GStreamer warning: no pipeline
Can't receive frame (stream end?). Exiting ...
[ WARN:0] global /root/opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

 

解决方式:原因是摄像头不支持set的分辨率,查看摄像头的相关说明,修改设置的分辨率为允许设置的分辨率

你可能感兴趣的:(▼OpenCV-Python操作UBS摄像头“pipeline”)