Ask Your Question
0

2 dim matrix, how can it be

asked 2018-01-23 18:16:25 -0600

julian403 gravatar image

Hello. I hope you all are fine.

Im new with this API and as every newbie I need a little help here. I'm using a banana pi m2 and a usb cam (a genius one). First of all I want to check the camera paramters, so:

    #include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argc,char ** argv)
{
  VideoCapture cap(0);
  if (!cap.isOpened()) {
    cerr << "ERROR: Unable to open the camera" << endl;
    return 0;
  }
  Mat frame1, frame;
  cout << "Start grabbing, press a key on Live window to terminate" << endl;

        cap >> frame1;
        if (frame1.empty())
                {
                cerr << "ERROR: Unable to grab from the"<<endl;
                }
        int i, j, k,z;
i=frame1.dims;
j=frame1.cols;
k=frame1.rows;
z=frame1.type();

        printf("%d dim\n  %d col \n  %d row\n %d type\n", i, j, k, z);

return 1;
}

And this is what a I got:

Start grabbing, press a key on Live window to terminate
2 dim
640 col
480 row
16 type

How can be a matrix 2 dimension??? So, thats means that it has just 2 colors? its a two channel?

Also, a 16 type means CV_8U. So there is 8 bits per color(R G or B)? because VGA use 6bits per color Thanks in advance.

edit retag flag offensive close merge delete

Comments

the dimension you're missing is in frame.channels() (3) and it is BGR ordered

(but it is not really a "dimension", since the pixels are interleaved)

berak gravatar imageberak ( 2018-01-24 00:21:22 -0600 )edit

Thanks.

But, what do you means when you said "the pixels are interleaved"? Thats ones question that I still have because there is 8bits per color (RGB) on CV_8U and every matrix element (pixel) has 32 bits?? and thats pixel with RGB color are consecutive?

julian403 gravatar imagejulian403 ( 2018-01-24 08:55:55 -0600 )edit

again it is BGR, not RGB in opencv (and also numpy). like b g r b g r b g r .... (so yes, consecutive, not in seperate color planes (like it is in matlab)

also, that would make 24bits per pixel, not 32 (alpha has no real use in computer-vision)

berak gravatar imageberak ( 2018-01-24 09:05:37 -0600 )edit

Thanks a lot and the last one:

So if CV_8U has a deep pixel of 24bits that implies that CV_32F has 96 bits?

julian403 gravatar imagejulian403 ( 2018-01-24 09:27:57 -0600 )edit

CV_8U == a single channel (grayscale, 8 bit image)

CV_8UC3 == 3 8bit channels (bgr, hsv, yuv, etc.)

CV_32F == a single channel 32bit float image

CV_32FC3 == 3 32bit float channels

CV_64FC2 == .... you'll get the picture, i hope ..

berak gravatar imageberak ( 2018-01-24 09:31:32 -0600 )edit

But

CV_32FC3 == 3 32bit float channels. There is 32 bits per color (B G R) and thats 96 bits deep pixel which gives 2^96 total color. For what I know the human can see 2^24 color and the alpha is just the transparency. Its not too much 96 bits? for what I know all camera works with 32 bits including alpha.

julian403 gravatar imagejulian403 ( 2018-01-24 09:36:48 -0600 )edit

"There is 32 bits per color (B G R) and thats 96 bits deep pixel" -- exactly.

" For what I know the human can see 2^24 color " -- this is computer-vision , humans don't count ;)

also, there are a lot of Mat's that do not contain images per se, like transformations, neural network layers, distance tables, and whatnot.

" for what I know all camera works with 32 bits including alpha." -- no. cameras do not know anything about alpha. (and again, alpha is almost never used here)

berak gravatar imageberak ( 2018-01-24 09:45:34 -0600 )edit

Thank you very much.

julian403 gravatar imagejulian403 ( 2018-01-24 12:17:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-01-24 08:11:01 -0600

Soarez gravatar image

Can you see the image? probably you have a monochromatic image in gray scale. Dim = 2, means that you dont have a x,y matrix with 1 channel .

edit flag offensive delete link more

Comments

Yes I can see the image and its colored

julian403 gravatar imagejulian403 ( 2018-01-24 08:56:58 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-01-23 18:16:25 -0600

Seen: 284 times

Last updated: Jan 24 '18