ochornenko / Camera2GLPreview

Android camera preview application using Camera2 API and OpenGL ES/Vulkan
174 stars 53 forks source link

Why the byte[] have three channels but not the same lengths as an CV8_UC3 Matrix Opencv ? #4

Closed simonprovost closed 5 years ago

simonprovost commented 5 years ago

Hello,

You have earn one star by me because your project seems very well !

We can see the byte[] have this :

  • byte[] lenght : 1382400 octets.

I have a matrix in opencv which have multiple things on it but his value ( my_mat.step[0] * my_mat.rows) :

  • my_mat calcul result : 3840 * 720 = 2764800 Then, this result divide by two equal : 1382400, same as byte[]

Why, byte[] have this value ?

I want to copy my_mat data into your byte[] but it is really weird.. If you have somethings and some idea's, I will be very wonderful.

Regards.

ochornenko commented 5 years ago

In ::draw you can get YUV_420_888 buffer with actual length of the buffer and width, height of the image. Convertion from YUV420 to RGBA is happening in GL shaders. Check GLShaders.h file.

simonprovost commented 5 years ago

Okay thank you for these informations but it didn't say anything because i am on this function :

void VideoRendererContext::draw(uint8_t *buffer, size_t length, size_t width, size_t height, int rotation)

And this buffer have a weird length, this is normal ? this is because it is happening in GL ? sorry but i didn't understand at all

Regars.

ochornenko commented 5 years ago

I don't see anything wrong with length. I checked 640x480 resolution.

length = 460800

m_sizeY = width height; m_sizeU = width height / 4; m_sizeV = width * height / 4;

sizeYUV = m_sizeY + m_sizeU + m_sizeV; // 460800 the same as length

simonprovost commented 5 years ago

Oh great! thank you I've understood it more.

It works perfectly right now. CLOSED.