使用OpenCV的摄像头捕获的灰屏 [英] Capturing grey screen from camera using OpenCV

查看:745
本文介绍了使用OpenCV的摄像头捕获的灰屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从我的网络摄像头(内置HP DV5)捕捉图像的问题。唯一的结果是灰色的屏幕。这里的code:

I have a problem with capturing image from my web cam (built in hp dv5). The only result is grey screen. Here's the code:

#include "StdAfx.h"
#include "cv.h"
#include "highgui.h"
#include <stdio.h>  // A Simple Camera Capture Framework
int main() { 
    CvCapture* capture;
    for (int i = -1;i < 100;i++) {
        capture = cvCaptureFromCAM( i );   
        if( !capture ) {
            fprintf( stderr, "ERROR: capture is NULL \n" ); 

        } else {
            break;
        }
    }
    //cvSetCaptureProperty( capture, CV_CAP_PROP_FPS,15);
    //cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 160 );
    //cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 120 );
    // Create a window in which the captured images will be presented   
    cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );    // Show the image captured from the camera in the window and repeat   
    while( 1 ) {     // Get one frame     
        IplImage* frame = cvQueryFrame( capture );
        cvGrabFrame(capture);
        frame = cvRetrieveFrame(capture);

        if( !frame ) {
            fprintf( stderr, "ERROR: frame is null...\n" );
            getchar();
            break;
        } else {
            fprintf( stderr, "OK\n" );  
        }
        cvShowImage( "mywindow", frame );     // Do not release the frame!      
        //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),     //remove higher bits using AND operator     
        int c = cvWaitKey(100);
    }    // Release the capture device housekeeping   
    cvReleaseCapture( &capture );   
    cvDestroyWindow( "mywindow" );   
    return 0; 
}

它修改code从OpenCV中的维基。我知道,找到相机这样的疯了,但它并没有使用-1或0工作,我增加了一些额外的属性(已经评论),但它并没有反正工作。提前致谢 :)
问候,
克里斯

It's modified code from OpenCV's wiki. I know that finding the camera in this way its crazy but it didn't work with -1 or 0. I added some additional properties (commented already) but it didn't work anyway. Thanks in advance :) Greetings, Chris

推荐答案

我正在尝试使用相机时,灰色的屏幕和OpenCV的Windows内部的Python包装。

I was getting a grey screen when trying to use the camera and the Python wrapper for OpenCV inside Windows.

与我发现它被察觉2称为谷歌相机适配器0和谷歌相机适配器1。

Tracing through with the debugger I found that it was spotting 2 camera interfaces called "Google Camera Adapter 0" and "Google Camera Adapter 1".

我能够通过固定摄像机输入:

I was able to fix the camera input by:


  1. 将添加/删除程序和卸载谷歌Talk插件

  2. 拔掉摄像头和重新插回,这样安装了新的驱动程序。

现在工作正常,我。

(请注意,我不知道第1步是否是重要的,它可能会导致其他的东西打破,所以我会建议你尝试第2步先......)

(Note that I do not know whether step 1 was important, and it may cause other things to break, so I would recommend you try step 2 first...)

这篇关于使用OpenCV的摄像头捕获的灰屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆