0

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

11
  • Have you tried without the path? Saving into current working dir or something... like imwrite("img.bmp", reflection); ? Commented Oct 10, 2017 at 6:28
  • Have you tried to convert the image to CV_8UC3? I doubt 1-channel image can be stored in bmp file. Commented Oct 10, 2017 at 7:11
  • does it work if you choose imwrite("E:/New folder/img.png", reflection); instead? Commented Oct 10, 2017 at 7:34
  • 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. Commented Oct 10, 2017 at 7:36
  • @Micka imwrite must has the -highugi flag for the linker, but it will throw a linker error if it is not available Commented Oct 10, 2017 at 7:44

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

I tried it still not saving the image bool check value is false
It seems opencv cant save BMP files, change the file to "img.png" Docs
0

OpenCV do support bmp, just use as follows.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.