0

我正在尝试使用 opencv 编写一个非常基本的视频捕获程序,但是尽管我付出了所有努力,但什么也没写。我相当确定我正在关注所有关于该主题的教程。

这是我正在使用的代码:

#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <videoInput.h>
static const cv::Size _SIZE(640, 480);
static const int FPS = 20;
int webcam = 0;
std::auto_ptr<videoInput> VI(NULL);
std::auto_ptr<cv::VideoWriter> outputVideo(NULL);
cv::Mat frame(_SIZE.height, _SIZE.width, CV_8UC3);

// get device list create videoInput 
videoInput::listDevices();
VI.reset(new videoInput())

// choose first device
VI->setupDevice(webcam, _SIZE.width, _SIZE.height);

// always check
if(!VI->isDeviceSetup(webcam))
return -1;  //-->

// set device frame rate
VI->setIdealFramerate(webcam, FPS);

// create named window and image
cv::namedWindow("CAM");
do
if (VI->isFrameNew(webcam))
{
VI->getPixels(webcam, (unsigned char*)frame.data, false, true); // получение пикселей в BGR

if (outputVideo.get())
{
    (*outputVideo).write( frame);
}
char c = cv::waitKey(5);
if (!IsWindowVisible((HWND)cvGetWindowHandle("CAM")) || c==27)
{
    exit(0);
}
cv::imshow("CAM", frame);
} while(1);

我尝试了各种扩展和各种 Fourcc 值。通常,在除 avi 之外的任何扩展上,都会创建 writer 但不执行任何操作。相反,avi 文件编写器根本无法创建。

我已经读过可能缺少编解码器,但这意味着什么 - 我到底需要把它们放在哪里才能被opencv找到?

总而言之,我很困惑。这是教程代码,它应该可以工作。

4

0 回答 0