4

我正在使用 Logitech C920 和 OpenCV 开发一个小型网络摄像头应用程序。

在给定的分辨率下,我实际上可以毫无问题地从相机获取图像。但除了帧的宽度和高度,我无法访问相机中的任何设置。我有以下代码。您可以猜到,代码生成了除前两行之外的所有零行。

难道我做错了什么?或者这是罗技的另一个专有 BS?如果这是 OpenCV 的限制,是否还有其他选项可以在 Windows 操作系统中为该网络摄像头开发应用程序?

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

2 回答 2

4

通过在安装 dshow 和 ffmpeg 后重建 OpenCV 解决了该问题。我现在什至可以设置一些值,例如帧速率,但是按规定工作的相机似乎是另一回事。在我的情况下,在不设置帧速率的情况下设置分辨率后,相机分辨率变为 640 x 480。虽然我的计算机安装了 H264 解码器,但 1920 x 1080 使用 OpenCV 可产生 5-7 fps。

于 2013-05-09T02:43:40.700 回答
2

在这篇文章中是一个示例代码,您可以如何以 30fps 的全高清速度访问您的相机。

编辑:

详细说明一下:

我还有罗技 c920、OpenCV 2.4.3、Windows 7 64bi。这是我可以使用下面的代码阅读的内容(我认为宽度和高度默认为 640*480)。

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

我使用的代码:

#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;
}
于 2014-02-04T09:48:29.373 回答