Ask Your Question

CaribeGirl's profile - activity

2016-09-28 12:23:07 -0600 asked a question Videiwriter create an avi with broken ot missing AVI Index

I'm using videoWriter to create a video. I'm using VS 2012 in windows. The idea of the code is to : 1. create a VideoWriter object 2. open a pre-existent image (a set of them inside a for loop) 3. add some boxes 4. save it to the video

The code works. But when it creates the video files and I try to open it with VLC I get the following error VLC Error Box

If I open it windows media player take a bit but it opens. I wonder if somebody can help me to figure out what's going on I need to use a video player more advanced than WMP

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include "opencv2/videoio/videoio.hpp"

double frameRate = 30.0;
cv::Size frameSize( 640, 512 );
std::string const videoPath ="E://videos//"
std::string const framePath ="E://frame//"
cv::Mat imToShow;
int main( void )
{

   std::string videoFile = videoPath +"video_test.avi"
   cv::VideoWriter videoObj( videoFile, CV_FOURCC_DEFAULT, frameRate, frameSize );
   if ( !videoObj.isOpened() )
   {
      std::cout << "ERROR: Failed to write the video" << std::endl;
      std::cin.get();
      return -1;
   }

    for ( int ifrm = 0ifrm < 301; ++ifrm )
     {
        std::string imFullName = framePath + "//frame_" + std::to_string( ifrm ) + ".tif";
        imToShow = cv::imread( imFullName, CV_8UC3 );
        cv::imshow( result_window, imToShow );
        cv::waitKey( 35 );
        //do some processing that adds a box to the image 
        drawBox( imToShow, corrDet, message, fontDefault );

        videoObj.write( imToShow );
     }
}