Ask Your Question
0

bmp to pgm conversion

asked 2015-12-07 00:47:31 -0600

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?

edit retag flag offensive close merge delete

Comments

1

if filename are indexed you can use videocapture to read image and after use imwrite with pgm extension

LBerger gravatar imageLBerger ( 2015-12-07 01:31:51 -0600 )edit

Thank you.

Ayesha Siddique gravatar imageAyesha Siddique ( 2015-12-07 03:34:03 -0600 )edit

@LBerger Can you please help me here link text

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-06-10 02:58:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-12-07 08:22:37 -0600

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;
}
edit flag offensive delete link more

Comments

You might want to define compression parameters, in order to loose as less information as possible!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-08 04:09:04 -0600 )edit
1

@StevenPuttemans he wants to convert images to "pgm". afaik saving as pgm is lossless

sturkmen gravatar imagesturkmen ( 2015-12-08 11:35:17 -0600 )edit

True, apologies :)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-09 01:40:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-07 00:47:31 -0600

Seen: 62,279 times

Last updated: Dec 07 '15