0
votes

I was trying to write an image to a folder using OpenCV imwrite function. The code compiles and runs successfully but the image is not saving in the folder/path.I am getting output from 'imshow' and my image is in CV_8UC1 format.

find the code below

    Mat reflection = function which computes image
    imshow("output image", reflection);
    imwrite("E:/New folder/img.bmp", reflection);

so I checked current folder writing and modified code like this

bool check = imwrite("./img.bmp", reflection);

this 'bool check' status is 'false' and not writing the image.

I've also checked folder permission with guidelines from microsoft help my "E/New Folder/" is permitted to write. still, the image is not saving. I am okay with any image format .jpg, .png and .bmp. I am using windows 7, OpenCV 3.0, visual studio 2017.

Please help me and thanks for reading it

2
Have you tried without the path? Saving into current working dir or something... like imwrite("img.bmp", reflection); ?Aleksei Maide
Have you tried to convert the image to CV_8UC3? I doubt 1-channel image can be stored in bmp file.James Dong
does it work if you choose imwrite("E:/New folder/img.png", reflection); instead?Micka
are all the necessary dll's available to the application? For videowriter for example, no frames are written, if the opencv_ffmpeg dll is missing, but the program does run (and isn't complaining about a missing dll or something). Maybe there is some similar dependency for imwrite, too.Micka
@Micka imwrite must has the -highugi flag for the linker, but it will throw a linker error if it is not availableKev1n91

2 Answers

2
votes

Opencv doesn't seem to support saving BMP files check the imwrite docs. Changing the filename to img.png should work. Also using ./ in windows is not valid, this is used in unix systems to represent the current working directory see Windows current directory. Updating it to

bool check = imwrite(".\img.png", reflection);

or

bool check = imwrite("img.png", reflection);

Should work

0
votes

OpenCV do support bmp, just use as follows.

bool check = imwrite("img.bmp", reflection);