Ask Your Question
0

depth() and channel() function return incorrect values

asked 2016-01-25 04:55:44 -0600

acevans gravatar image

updated 2016-01-25 05:02:42 -0600

pklab gravatar image

Hi,

I am a newbie with opencv. I am using opencv3.1. I was reading the depth and channles of images but it returns weird values.

Here is my code:

string filepath = "C:/Users/studentlab/Desktop/koora/opencv-logo.png";
cv::Mat image_1= cv::imread(filepath.data(),CV_LOAD_IMAGE_UNCHANGED);
int DEPTH = image_1.depth();
int CHANNELS=image_1.channels();

The depth should be 4(CV_32U) but it reads 0(CV_8U). And the channels reads 4 for every image(i tried checking it for a greyscale image too). Can someone point out my mistake ?

I am using Qt Creator on Windows(64 bit) with MinGW(32 bit).

edit retag flag offensive close merge delete

Comments

Is there a CV_32U depth?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-01-25 05:24:11 -0600 )edit

Try a image_1.convertTo(floatImage, CV_32F);, then you can find another depth than 0...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-01-25 05:26:17 -0600 )edit

Sorry I meant CV_32S.... that would be a 4. I just wanted to read the depth so I code use it later in my code maybe.

acevans gravatar imageacevans ( 2016-01-25 05:34:28 -0600 )edit
1

Reading a PNG image he will have a GRAY or BGR or BGRA image. So DEPTH=>CV_8U and CHANNELS=>1 or 3 or 4. There are't incorrect values but there is incorrect undestanding :)

pklab gravatar imagepklab ( 2016-01-25 05:37:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-01-25 05:01:21 -0600

pklab gravatar image

updated 2016-01-25 05:05:21 -0600

Depth is byte per pixel and usually is unsigned char. Channel is the number of layers in your image. depth=1 and channel=4 is for a BGR+Alpha image. A gray scale image would have depth CV_8U and channels=1

edit flag offensive delete link more

Comments

Thanks. I got it now. I was just checking it against the properties window and it showed 'Bit Depth 32'. Now I get it that it meant 32 bits alltogether for all channels.

acevans gravatar imageacevans ( 2016-01-25 05:39:05 -0600 )edit

That's true ! Even if in OpenCV a BGR pixel is stored as 3 consecutive byte, pixel bit depth is 8 and channel is 3 so you should use depth*channel to know pixel memory size.

pklab gravatar imagepklab ( 2016-01-25 05:46:28 -0600 )edit

I do have one more question though... I loaded a greyscale image but it showed 3 channels. Why would a greyscale image need 3 channels ? I know this isnt connected to opencv... just curious.

acevans gravatar imageacevans ( 2016-01-25 11:05:38 -0600 )edit
1

use imread("file.png",CV_LOAD_IMAGE_GRAYSCALE) to load the image as greyscale

pklab gravatar imagepklab ( 2016-01-25 12:09:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-25 04:55:44 -0600

Seen: 2,828 times

Last updated: Jan 25 '16