7

Just built OpenCV 3 on PC with Visual Studio 2013 and now I'm trying code but sadly I can't figure out what's wrong?

#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 ==========

Couldn't figure out with what I have to replace "CV_FOURCC".

edited:

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);
Pranciskus
  • 487
  • 1
  • 6
  • 17
  • I edited below and compiled successfully but code doesn't work. It doesn't create "out.avi" file. However, this code is working on All-in-one version – Pranciskus Aug 01 '18 at 02:24

2 Answers2

16

looks like this has changed in later versions of OpenCV to cv::VideoWriter::fourcc(...) where ... is the four-character-comma-separated list.

More information here for OpenCV 3.4: https://docs.opencv.org/3.4/dd/d9e/classcv_1_1VideoWriter.html#afec93f94dc6c0b3e28f4dd153bc5a7f0

yano
  • 4,827
  • 2
  • 23
  • 35
-4

I used bad OpenCV source to build my libraries.

Pranciskus
  • 487
  • 1
  • 6
  • 17
  • 1
    this is not the solution, indeed, this should not even be a valid answer, sorry to say: yano's one is the solution. – xCovelus Apr 17 '23 at 18:31