小编Mar*_*alm的帖子

从网络摄像头捕获图像并显示它 - OpenCV - Eclipse - Windows

我是OpenCV的新手,我想显示我的网络摄像头看到的OpenCV.我正在使用C编码语言.

我试过这段代码:

#include <stdio.h>

#include <cv.h> // Include the OpenCV library
#include <highgui.h> // Include interfaces for video capturing

int main()
{
    cvNamedWindow("Window", CV_WINDOW_AUTOSIZE);
    CvCapture* capture =cvCreateCameraCapture(-1);
    if (!capture){
        printf("Error. Cannot capture.");
    }
    else{
        cvNamedWindow("Window", CV_WINDOW_AUTOSIZE);

        while (1){
            IplImage* frame = cvQueryFrame(capture);
            if(!frame){
                printf("Error. Cannot get the frame.");
                break;
            }
        cvShowImage("Window",frame);
        }
        cvReleaseCapture(&capture);
        cvDestroyWindow("Window");
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的网络摄像头的指示灯亮起,但结果是一个完全灰色的窗口,没有图像.

你能帮助我吗?

c webcam opencv video-capture frame

1
推荐指数
1
解决办法
5940
查看次数

标签 统计

c ×1

frame ×1

opencv ×1

video-capture ×1

webcam ×1