OpenCV 3错误'CV_FOURCC':未找到标识符

8

我刚刚在使用Visual Studio 2013编译完成OpenCV 3后,尝试进行编码,但是遗憾的是,我无法确定问题出在哪里。

#include "opencv2/opencv.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main() {

    VideoCapture vcap(0);
    if (!vcap.isOpened()) {
        cout << "Error opening video stream or file" << endl;
        return -1;
    }

    int frame_width = vcap.get(cv::CAP_PROP_FRAME_WIDTH);
    int frame_height = vcap.get(cv::CAP_PROP_FRAME_HEIGHT);
    VideoWriter video("out.avi", CV_FOURCC('M', 'J', 'P', 'G'), 10, Size(frame_width, frame_height), true);

    for (;;) {

        Mat frame;
        vcap >> frame;
        video.write(frame);
        imshow("Frame", frame);
        char c = (char)waitKey(33);
        if (c == 27) break;
    }
    return 0;


1>------ Build started: Project: ConsoleApplication12, Configuration: Release x64 ------
1>  Source.cpp
1>Source.cpp(21): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>Source.cpp(22): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>Source.cpp(23): error C3861: 'CV_FOURCC': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我不知道该用什么替换“CV_FOURCC”。

编辑后:

int frame_width = vcap.get(cv::CAP_PROP_FRAME_WIDTH);
    int frame_height = vcap.get(cv::CAP_PROP_FRAME_HEIGHT);
    int codec = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
    VideoWriter video("out.avi", codec, 10, Size(frame_width, frame_height), true);

我已经编辑并成功编译了下面的代码,但是它不起作用。它没有创建“out.avi”文件。然而,这段代码在All-in-one版本上是有效的。 - Pranciskus
2个回答

17

-4

我使用了糟糕的OpenCV源代码来构建我的库。


1
这不是解决方案,事实上,这甚至不应该是一个有效的答案,很抱歉要说:yano的才是解决方案。 - xCovelus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接