Alperen AYDIN
Alperen AYDIN

Reputation: 567

Is it normal that Opencv's imread is giving me a 2-D Mat when I ask for a color image?

So I have an .bmp image file in my folder.

I load it using imread:

  cv::Mat image = cv::imread( imageName, CV_LOAD_IMAGE_COLOR );

After that I look at the dimensions of it with:

std::cout<<"Rows: "<<image.rows <<"  Cols:"<<image.cols<<" Dims:"<<image.dims<<std::endl;

This gives me :

Rows: 480 Cols:640 Dims:2

But given that I had RGB image, shouldn't it also be 3D Mat?

Upvotes: 2

Views: 1463

Answers (1)

Miki
Miki

Reputation: 41765

Yes, it's normal.

dims is defined as (from the doc):

int dims; //! the array dimensionality, >= 2

You should look at the number of channels instead:

std:cout << "Channels: " << image.channels() << std::endl;

Upvotes: 4

Related Questions