Can't access properties of cv::VideoCapture with Logitech C920

后端 未结 2 1442
误落风尘
误落风尘 2021-01-13 16:40

I am developing a small webcam application with Logitech C920 and OpenCV.

I can actually get images from camera without any problem with given resolution. But excep

相关标签:
2条回答
  • 2021-01-13 17:12

    In this post is an example code how you can access your camera at 30fps in full hd.

    Edit:

    To elaborate a bit:

    I also have the Logitech c920, OpenCV 2.4.3, Windows 7 64bi. This are the things i can read with the code below (width and height is by default on 640*480 i think).

    CV_CAP_PROP_FRAME_WIDTH 1920
    CV_CAP_PROP_FRAME_HEIGHT 1080
    CV_CAP_PROP_FPS 0
    CV_CAP_PROP_EXPOSURE -5
    CV_CAP_PROP_FORMAT -1
    CV_CAP_PROP_CONTRAST 128
    CV_CAP_PROP_BRIGHTNESS 128
    CV_CAP_PROP_SATURATION 128
    CV_CAP_PROP_HUE -8.58993e+008
    CV_CAP_PROP_POS_FRAMES -1
    CV_CAP_PROP_FOURCC -4.66163e+008
    Input codec type: }Ù6õ //Obviously wrong
    

    The Code i used:

    #include <iostream> // for standard I/O
    #include <string>   // for strings
    #include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat)
    #include <opencv2/highgui/highgui.hpp>  // Video write
    #include "opencv2/opencv.hpp"
    using namespace cv; using namespace std;
    
    void getCameraInfo(VideoCapture m_cam){
        std::cout<<"CV_CAP_PROP_FRAME_WIDTH " << m_cam.get(CV_CAP_PROP_FRAME_WIDTH) << std::endl; 
        std::cout<<"CV_CAP_PROP_FRAME_HEIGHT " << m_cam.get(CV_CAP_PROP_FRAME_HEIGHT) << std::endl; 
        std::cout<<"CV_CAP_PROP_FPS " << m_cam.get(CV_CAP_PROP_FPS) << std::endl; 
        std::cout<<"CV_CAP_PROP_EXPOSURE " << m_cam.get(CV_CAP_PROP_EXPOSURE) << std::endl; 
        std::cout<<"CV_CAP_PROP_FORMAT " << m_cam.get(CV_CAP_PROP_FORMAT) << std::endl; //deafult CV_8UC3?!
        std::cout<<"CV_CAP_PROP_CONTRAST " << m_cam.get(CV_CAP_PROP_CONTRAST) << std::endl; 
        std::cout<<"CV_CAP_PROP_BRIGHTNESS "<< m_cam.get(CV_CAP_PROP_BRIGHTNESS) << std::endl; 
        std::cout<<"CV_CAP_PROP_SATURATION "<< m_cam.get(CV_CAP_PROP_SATURATION) << std::endl; 
        std::cout<<"CV_CAP_PROP_HUE "<< m_cam.get(CV_CAP_PROP_HUE) << std::endl; 
        std::cout<<"CV_CAP_PROP_POS_FRAMES "<< m_cam.get(CV_CAP_PROP_POS_FRAMES) << std::endl; 
        std::cout<<"CV_CAP_PROP_FOURCC "<< m_cam.get(CV_CAP_PROP_FOURCC) << std::endl; 
    
        int ex = static_cast<int>(m_cam.get(CV_CAP_PROP_FOURCC));     // Get Codec Type- Int form
        char EXT[] = {(char)(ex & 255) , (char)((ex & 0XFF00) >> 8),(char)((ex & 0XFF0000) >> 16),(char)((ex & 0XFF000000) >> 24), 0};
        cout << "Input codec type: " << EXT << endl;
    }
    
    int main(int, char**){
        string resVideoPath = "C:\\yourPath\\video.avi";
        VideoCapture vidSource;
        double fps=10;
        vidSource = VideoCapture(0); // open the default camera
        vidSource.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
        vidSource.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
    
        if(!vidSource.isOpened()){
            cout  << "Could not open the input video to read"<< endl;
            return -1;
        }
        getCameraInfo(vidSource);
    
        namedWindow("Capture", CV_WINDOW_AUTOSIZE);
        while(true){
    
            Mat frame;
            vidSource >> frame;
            if(!frame.data){
                cerr << "Could not retrieve frame.";
                return -1;}
    
            imshow("Capture", frame);
            if(waitKey(1) == 27)
                break;
        }
        return 0;
    }
    
    0 讨论(0)
  • 2021-01-13 17:14

    Fixed the problem by rebuilding OpenCV after getting dshow and ffmpeg installed. I can even set some of the values such as frame rate now, but the camera working as specified seems to be a separate matter. In my case, after setting resolution without setting frame rate, camera resolution goes to 640 x 480. Although my computer has H264 decoder installed, 1920 x 1080 produces 5-7 fps with OpenCV.

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