ochornenko / Camera2GLPreview

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

Conversion in CPU is full useless ? How could I convert in GPU ? #5

Closed simonprovost closed 6 years ago

simonprovost commented 6 years ago

Hello Again,

In VideoRendererContext::draw I've added to it some things which is great for my application, but I have a question:

Without my modification we can see that the CPU is used at 15%, 20% in general, then we can note that your application is very good in performance in 720P.

However, if I write theses lines:

  cv::Mat mat_yuv(static_cast<int>(height * 1.5), width, CV_8UC1, buffer);
  cv::Mat rgb_mat;
  cv::cvtColor(mat_yuv, rgb_mat, CV_YUV2RGB_I420);

It will grow up to 80 % of my CPU, it is too weird ? Now I think that the conversion is not good for CPU. Do you know how can I decrease this grew up?

Could I make this on the GPU? I do not know anything, that's why I tell you my request. Thank you advance Dude. Regards.

ochornenko commented 6 years ago

Not sure what conversion you are trying to do. In my sample app it converts YUV420 to RGBA in GL shader. If you want to render directly RGB frame (or RGBA) you need to create you own OpenGL renderer and GL shaders. If you need to convert some different format (not YUV420) to RGB in order to render frame you would need to modify GL renderer/shaders or create new one.

simonprovost commented 6 years ago

I have a function which have an algorithm and she must need an RGB buffer, then with you Draw function you received a YUV buffer, I'll convert it and play with it and reconvert it to send to your function which convert yuv to rgba and you'll draw..

It is too long because I don't a multi threading between my function which contain the algorithm and acquisitions and drawing, then I think about it and produce a multi threading and come back but I think that will be much better.

Thank you.

ochornenko commented 6 years ago

It will not work faster if you are going to use separate thread for conversion, it depends on your algorithm, but you can use GPU (GL shaders) for RGB conversion and processing video frame.

simonprovost commented 6 years ago

Oh really ? Ok ok thanks for it. Then :

first conversion (opencv native) (YUV TO RGB FOR MY ALGORITHM) take 11 ~ 18 ms . My algorithm take in general : 110 ~ 160 ms. And the last conversion (RGV TO YUV) and memcpy into final buffer take : 3 ~ 6 ms.

And next step is ->Draw(...)