Moataz Elmasry
Moataz Elmasry

Reputation: 2519

weird behaviour saving image in opencv

After doing some opencv operation, I initialize a new image that I'd like to use. Saving this empty image gives a weird result

enter image description here

The lines I use to save this image are:

Mat dst2 (Size (320, 240), CV_8UC3);
imwrite("bla.jpg", dst2);

I should get a black image, but this is what I get. Moving these two lines to the start of the program everything wordks fine Anyone had this problem before?

I just noticed that these white lines contain portions from other images I'm processing in the same program

Regards

Upvotes: 2

Views: 160

Answers (1)

Rui Marques
Rui Marques

Reputation: 8904

Because you did not initialize the image with any values, you just defined the size and type, you will get random pixels (or not so random, it is probably showing pieces of pixels in memory).

It is the same concept of using/accessing an uninitialized variable.

To paint the image black you can use Mat::setTo, docs here:

http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-setto

Upvotes: 1

Related Questions