Grayscale avi to image
Hi :) I would like to convert a grayscale avi to images. I use the following code but the produced images are all black. When I use a colour avi, it does work perfect but it doesn't work for grayscale avi. How can I solve this problem? Thanks for your help. Best; Beldachi
int main (int argc, char **argv)
{
if (argc !=2)
{
std::cout << "USE: " << argv[0] << " <video-filename>" << std::endl;
return -1;
}
//Open the video that you pass from the command line
cv::VideoCapture cap(argv[1]);
if (!cap.isOpened())
{
std::cerr << "ERROR: Could not open video " << argv[1] << std::endl;
return -1;
}
int frame_count = 0;
bool should_stop = false;
while(!should_stop)
{
cv::Mat frame;
cap >> frame; //get a new frame from the video
if (frame.empty())
{
should_stop = true; //we arrived to the end of the video
continue;
}
char filename[128];
sprintf(filename, "frame_%06d.jpg", frame_count);
frame.convertTo(frame,CV_8U);
cv::imwrite(filename, frame);
frame_count++;
}
return 0;
}
I fixed the code, so that it highlights correctly :)
Could you show which type number you get for frame.type() after you read a frame?
Hi Moster;
In both cases (gray scale and colour), the captured frames are CV_8U.
Best, Beldachi
I'm actually interested in the number that you get from frame.type()
the number is 16 :)
I just wanted to make sure. So your grayscale avi also has 3 channels, since 16 = CV_8UC3. Did you also check this before you did frame.converTo()? Im going to post some code and you tell me how it looks like.
yes, I checked it before frame.converTo()