4
votes

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 except for frame width and height, I can't access any setting in the camera. I have following code. As you can guess, the code produced all zero lines except for the first two.

Am I doing something wrong? or Is this another proprietary BS from Logitech? If this is limitation of OpenCV, is there any other option to develop an application for this webcam in Windows OS?

    m_cam.open(0);
    if(!m_cam.isOpened() )  // check if we succeeded
    {
        std::cerr << "ERROR: Could not open cameras." << std::endl;
        return;
    }

    int ex = static_cast<int>(m_cam.get(CV_CAP_PROP_FOURCC));
    char EXT[] = {ex & 0XFF , (ex & 0XFF00) >> 8,(ex & 0XFF0000) >> 16,(ex & 0XFF000000) >> 24, 0};
    m_cam.set(CV_CAP_PROP_FOURCC,CV_FOURCC('H','2','6','4')); 
    m_cam.set(CV_CAP_PROP_FRAME_WIDTH,1280);//2304);//1829//1200//800
    m_cam.set(CV_CAP_PROP_FRAME_HEIGHT,720);//1536); //1080//800//600   
    m_cam.set(CV_CAP_PROP_FPS, 30);
    //m_cam.set(CV_CAP_PROP_EXPOSURE,0);
    std::cout<< m_cam.get(CV_CAP_PROP_FRAME_WIDTH) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_FRAME_HEIGHT) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_FPS) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_EXPOSURE) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_FORMAT) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_CONTRAST) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_BRIGHTNESS) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_SATURATION) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_HUE) << std::endl; 
    std::cout<< m_cam.get(CV_CAP_PROP_POS_FRAMES) << std::endl; 
2

2 Answers

2
votes

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

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.