I want to save every single frame of a real time video in .pgm format. I am working with opencv 2.4.8 in c++. My problem is that despite all frames are saved and phenomenically in the right format (for example as frame_1.pgm) , when I open them they are not in grayscale, as a .pgm photo should be. Moreover I opened the images with a hexeditor and compared them with a correct pgm photo and there are obvious differences!Can somebody give any advice on what I am doing wrong??
here is the crucial part of my code:
//////////////////////////////////////////////////////////////
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_PXM_BINARY);
compression_params.push_back(0);
captureDevice1>> captureFrame1;
imwrite("frame_55.pgm",captureFrame1,compression_params);
//string imagename=argv[2];
string imagename="frame_";
//string imagename="frame_";
char numberfile[17];
sprintf_s(numberfile,17,"%u",im);
imagename+=numberfile;
imagename+=".pgm";
std::ifstream in( imagename.c_str(), std::ios::binary );
if ( !in )
{
std::cout << "Error in Image: " << imagename << std::endl;
continue;
}
in.close();
///////////////////////////////////////////////////////////////////////
Now if i try to load the image:frame_55.pgm I get an "Unsupported format" error while it works fine with other .pgm images!!
Thnx in advance guys for your time!!!