bmp to pgm conversion
I've 1000 .bmp files that should be converted into .pgm format in order to run m rest of the program. How can we do that in opencv?
I've 1000 .bmp files that should be converted into .pgm format in order to run m rest of the program. How can we do that in opencv?
please try the code below
note : it finds all the files having "bmp" extension at the working directory and loads as gray-scale then saves as "original-image-name + pgm"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
using namespace std;
int main()
{
vector<String> filenames;
String folder = "*.bmp";
glob(folder, filenames);
for(size_t i = 0; i < filenames.size(); ++i)
{
Mat src = imread(filenames[i],0); // open image as gray
if(src.data)
{
imwrite( filenames[i]+".pgm", src );
}
}
return 0;
}
You might want to define compression parameters, in order to loose as less information as possible!
@StevenPuttemans he wants to convert images to "pgm". afaik saving as pgm is lossless
Asked: 2015-12-07 00:47:31 -0600
Seen: 62,279 times
Last updated: Dec 07 '15
if filename are indexed you can use videocapture to read image and after use imwrite with pgm extension
Thank you.
@LBerger Can you please help me here link text