Ask Your Question

mickael_biardeau's profile - activity

2016-03-22 15:16:56 -0600 commented question VideoWriter opencv3.0.0 only one image in movie

OK I will try to find another way. Thanks for your time.

2016-03-22 02:16:35 -0600 answered a question VideoWriter opencv3.0.0 only one image in movie

Thanks for your response. I avoid IplImage and use cv::Mat instead. But the result is the same. The first image is present during all the movie, whatever the duration. Here is my full code. What is wrong?

    cv::VideoWriter         iVideoWriter;
    bool color = true;  
    CvSize imgSize = cvSize(640, 480);

    int codec = CV_FOURCC('M', 'J', 'P', 'G');
    iVideoWriter.open("c:\\temp\\video.avi", codec, 1.0, imgSize, color);

    if (iVideoWriter.isOpened() )
    {
        cv::Mat matImg;

        int a = 20;
        int type = CV_LOAD_IMAGE_COLOR;
        while (a > 0) {
            switch (a % 4)
            {
            case 0:
                matImg = cv::imread("D:\\1nb.bmp", type);
                break;
            case 1:
                matImg = cv::imread("D:\\2nb.bmp", type);
                break;
            case 2:
                matImg = cv::imread("D:\\3nb.bmp", type);
                break;
            case 3:
                matImg = cv::imread("D:\\1nb_MB.bmp", type);
                break;
            }

            cout << "a=" << a << ".before convert:" << matImg.depth() << ", " << matImg.channels();

            if (color == false && matImg.channels() != 1)
            {
                cv::Mat colorMat = matImg;
                cv::Mat greyMat;
                cv::cvtColor(colorMat, greyMat, CV_BGR2GRAY);
                matImg = greyMat;
            }
            else if (color == true && matImg.channels() != 3)
            {
                cv::Mat colorMat;
                cv::Mat greyMat = matImg;
                cv::cvtColor(greyMat, colorMat, CV_GRAY2BGR);
                matImg = colorMat;
            }

            cout << ". after convert:" << matImg.depth() << ", " << matImg.channels() << ".";

            _tstring str;
            str = "Display window" + to_string(a);
            cv::namedWindow(str.c_str(), cv::WINDOW_AUTOSIZE);// Create a window for display.
            cv::imshow(str.c_str(), matImg);

            cv::waitKey(1000);

            iVideoWriter.write(matImg);

            a--;
            cout << endl;
        }
        iVideoWriter.release();
    }
2016-03-20 01:08:54 -0600 asked a question VideoWriter opencv3.0.0 only one image in movie

Hi,

I open a VideoWriter with fps=1, codec used ( 'X', 'V', 'I', 'D' or 'D','I','V','X' or 'M','J','P','G'). AVI created successfully. Then i push 20 differents color images. The result is a video of 20 s => OK. But the first image is displayed during all the movie. The 19 others are not present.

What do I have to do? Is there a specific settings missing?

pseudo-code:

cvSize = 640x480
iVideoWriter.open(filename.c_str(),CV_FOURCC('M','J','P','G'),fps=1,cvSize,color=true);=> return true
...
for (i=0; i<20; i++)
{
cv::Mat matImg;
...
IplImage *iplImg=NULL;     
matImg = cv::cvarrToMat(iplImg); // iplImg contains my image, with the right size
outStream.write(matImg);
cvReleaseImage(&iplImg);
...
}

a loop = 1 unique image

I am using opencv_world300.dll && opencv_ffmpeg300.dll

Thanks

[edit]:

Thanks for your response. I avoid IplImage and use cv::Mat instead. But the result is the same. The first image is present during all the movie, whatever the duration. Here is my full code. What is wrong?

    cv::VideoWriter         iVideoWriter;
    bool color = true;  
    CvSize imgSize = cvSize(640, 480);

    int codec = CV_FOURCC('M', 'J', 'P', 'G');
    iVideoWriter.open("c:\\temp\\video.avi", codec, 1.0, imgSize, color);

    if (iVideoWriter.isOpened() )
    {
        cv::Mat matImg;

        int a = 20;
        int type = CV_LOAD_IMAGE_COLOR;
        while (a > 0) {
            switch (a % 4)
            {
            case 0:
                matImg = cv::imread("D:\\1nb.bmp", type);
                break;
            case 1:
                matImg = cv::imread("D:\\2nb.bmp", type);
                break;
            case 2:
                matImg = cv::imread("D:\\3nb.bmp", type);
                break;
            case 3:
                matImg = cv::imread("D:\\1nb_MB.bmp", type);
                break;
            }

            cout << "a=" << a << ".before convert:" << matImg.depth() << ", " << matImg.channels();

            if (color == false && matImg.channels() != 1)
            {
                cv::Mat colorMat = matImg;
                cv::Mat greyMat;
                cv::cvtColor(colorMat, greyMat, CV_BGR2GRAY);
                matImg = greyMat;
            }
            else if (color == true && matImg.channels() != 3)
            {
                cv::Mat colorMat;
                cv::Mat greyMat = matImg;
                cv::cvtColor(greyMat, colorMat, CV_GRAY2BGR);
                matImg = colorMat;
            }

            cout << ". after convert:" << matImg.depth() << ", " << matImg.channels() << ".";

            _tstring str;
            str = "Display window" + to_string(a);
            cv::namedWindow(str.c_str(), cv::WINDOW_AUTOSIZE);// Create a window for display.
            cv::imshow(str.c_str(), matImg);

            cv::waitKey(1000);

            iVideoWriter.write(matImg);

            a--;
            cout << endl;
        }
        iVideoWriter.release();
    }