dariodip
dariodip

Reputation: 228

C++ OpenCV imread with CV_8UC4 halved size

We are trying to read a PNG image of size 400x400 using OpenCV 4.1.0 calling:

*image = imread( filepath, CV_8UC4 );

When I print both cols and rows of the mat calling:

printf("col: %d , rows: %d \n", image->cols, image->rows);

it shows

col: 200, rows: 200

But calling file on the picture it shows:

PNG image data, 400 x 400, 8-bit/color RGBA, non-interlaced.

When I try to put the pic on a second one, it shows that the size is of the picture wrong indeed.

How can I force the reading of the picture giving a 400x400 Mat of Vec4b.

Upvotes: 0

Views: 592

Answers (1)

Oliort UA
Oliort UA

Reputation: 1647

The second argument of imread is flags argument, which expects some color loading flags but not pixel type as you provide. Read possible flags values and their meaning here.

Instead load the image as is, and if it does not contain 4 channels or the type is not what you want, recombine channels (with OpenCV split(), merge(), mixChannels() etc.) and convert it to needed pixel type with cv::Mat::convertTo(). Or use legal imread flags if any of them suits your needs.

Upvotes: 2

Related Questions