Reputation: 163
I have a problem with OpenCV VideoWriter.
Currently I have 2 projects: one in C# and one in C++.
C# project will read *.bmp file, create bitmap list then call writeVideo function in C++ project.
In C++ project, I am using VideoWriter with MJPG codec, read bitmap one by one from bitmap list, convert to mat, add to cv::VideoWriter object, then use video.release().
All *.bmp files are 101x76.
It works when the folder has 53 files. Otherwise, when the folder has less than 53 files, it doesn't work (output file cannot be opened).
Here is my code:
int s = bmList->Count;
int w = bmList[0]->Width;
int h = bmList[0]->Height;
cv::VideoWriter video(msclr::interop::marshal_as<std::string>(path), CV_FOURCC('M','J','P','G'), 10, cv::Size(w, h));
for (int i = 0; i < s; i++){
IplImage* temp;
System::Drawing::Imaging::BitmapData^ bitmapData = bmList[i]->LockBits(System::Drawing::Rectangle(0, 0, w, h), System::Drawing::Imaging::ImageLockMode::ReadWrite, bmList[i]->PixelFormat);
temp = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 4);
temp->imageData = (char*)bitmapData->Scan0.ToPointer();
bmList[i]->UnlockBits(bitmapData);
cv::Mat mat = cv::Mat();
cv::cvtColor(cv::Mat(temp), mat, CV_BGRA2BGR);
video << mat;
}
video.release();
Do you know about this problem? Please help me! Thank you.
Upvotes: 1
Views: 1063
Reputation: 163
I found same problem here: mjpeg @ 0x27ee9e0 buffer smaller than minimum size: How to create a video file with size less than the minimum buffer size?
It means input buffer is smaller than minimum size. I upgraded OpenCV to 3.1.0 and it worked.
Thank you, everyone, for your support!
Upvotes: 1