OpenCV: can't set resolution of video capture

后端 未结 4 2087
离开以前
离开以前 2020-12-14 22:20

I am using OpenCV 2.4.5 on Ubuntu 12.04 64-bit. I would like to be able to set the resolution of the input from my Logitech C310 webcam. The camera supports up to 1280x960 a

相关标签:
4条回答
  • 2020-12-14 22:40

    You can use v4l2-ctl to set frame size of captured video like below.

    v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=1
    

    You can find more information at this link

    0 讨论(0)
  • 2020-12-14 22:41

    Just wanted to add my CMAKE options to build with Java on the Raspberry Pi 3 based on Ulrich's comprehensive answer for OpenCV 3.2.0. Make a /build folder a in the same folder as OpenCV CMakeList.txt and execute this script for the new /build folder:

    sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_OPENCL=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_SHARED_LIBS=OFF -D JAVA_INCLUDE_PATH=$JAVA_HOME/include -D JAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/arm/libawt.so -D JAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/arm/server/libjvm.so -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TESTS=OFF -D WITH_MATLAB=OFF -D WITH_CUFFT=OFF -D WITH_CUDA=OFF -D WITH_CUBLAS=OFF -D WITH_GTK=OFF -D WITH_WEBP=OFF -D BUILD_opencv_apps=OFF -D BUILD_PACKAGE=OFF -D WITH_LIBV4L=ON ..

    0 讨论(0)
  • 2020-12-14 22:42

    This is a bug in the v4l "version" (build) of OpenCV 2.4 (including 2.4.12), but the bug is not in the libv4l version. For OpenCV 3.1.0, neither the v4l nor the libv4l version has the bug.

    (Your error error message HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP indicates that you have the v4l version; the message is in cap_v4l.cpp, see code, but not in cap_libv4l.cpp.)

    A workaround to get the v4l version of OpenCV 2.4 to work at a fixed resolution other than 640x480 is changing the values for DEFAULT_V4L_WIDTH and DEFAULT_V4L_HEIGHT in modules/highgui/src/cap_v4l.cpp and re-building OpenCV, kudos to this answer.

    If you want to build the libv4l version instead, all you likely need to do is install libv4l-dev and rebuild OpenCV; WITH_LIBV4L was enabled by default for me. If it is not, your cmake command should contain

    -D WITH_LIBV4L=ON
    

    The cmake output (or version_string.tmp) for a libv4l build contains something like

      Video I/O:
        ...
        V4L/V4L2:   Using libv4l1 (ver 0.8.6) / libv4l2 (ver 0.8.6)
    

    (For a v4l build, it is just V4L/V4L2: NO/YES.)

    0 讨论(0)
  • 2020-12-14 22:42

    Maybe you can try this, but I am not sure if this is what you want:

    #include <X11/Xlib.h>
    
    Display* disp = XOpenDisplay(NULL);
    Screen*  scrn = DefaultScreenOfDisplay(disp);
    int height = scrn->height;
    int width  = scrn->width;
    
    //Create window for the ip cam video
    cv::namedWindow("Front", CV_WINDOW_NORMAL);
    
    cvSetWindowProperty( "Front", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN );
    
    //Position of the screen where the video is shows
    cvMoveWindow("Front", 0, 0);
    cvResizeWindow( "Front", width, height );
    

    Like this you get the full screen for any screen.

    0 讨论(0)
提交回复
热议问题