opencv imread changes image

51 Views Asked by At

I have a very basic test case:

#include <opencv2/opencv.hpp>
int main(){
auto image = cv::imread("input.bmp");
cv::imwrite("output.bmp");
}

input.bmp

input.bmp

output.bmp

output.bmp

As you can see, they look completely different. Whats happening here?

I tried with cv::imread("input.bmp", -1) to read the image unchanged but that doesn't help. I've tried with other bmp images and somtimes it works, weirdly enough. I haven't figured out when it works and when it doesn't.

EDIT: link to the original file: https://drive.google.com/file/d/1mG3I-G0sS0qi3QBuvQQK9Oa9yPq1Uoif/view?usp=sharing

1

There are 1 best solutions below

0
Lukas Gradl On

I was able to circumvent the problem by reading and writing the same image with the imagemagick library. I'm not doing anything in between, just reading and writing with imagemagick. Then I can read and write the image with opencv without it changing the image. This takes up to 200ms unfortunately, so I would rather have a better solution, but for now it works.