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

爷,独闯天下 提交于 2019-12-01 06:41:24
Sebastian Schmitz

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;
}

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!