Skip to content

G-API planar kernels#14917

Merged
alalek merged 13 commits intoopencv:masterfrom
rgarnov:gapi_planar_kernels
Jul 4, 2019
Merged

G-API planar kernels#14917
alalek merged 13 commits intoopencv:masterfrom
rgarnov:gapi_planar_kernels

Conversation

@rgarnov
Copy link
Copy Markdown
Contributor

@rgarnov rgarnov commented Jun 27, 2019

build_gapi_standalone:Linux x64=ade-0.1.1d
build_gapi_standalone:Win64=ade-0.1.1d
build_gapi_standalone:Mac=ade-0.1.1d
build_gapi_standalone:Linux x64 Debug=ade-0.1.1d

@rgarnov
Copy link
Copy Markdown
Contributor Author

rgarnov commented Jun 27, 2019

@dbudniko please take a look

Dmitry Budnikov added 9 commits June 28, 2019 17:54
@dbudniko
Copy link
Copy Markdown

dbudniko commented Jul 2, 2019

@rgarnov @alalek , please review the latest fixes.

@rgarnov
Copy link
Copy Markdown
Contributor Author

rgarnov commented Jul 2, 2019

Looks good

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of playing with size, you can split planes completely:

planeB, planeG, planeR


@note Function textual ID is "org.opencv.core.transform.resizeP"

@param src input image, must be of @ref CV_8UC3 type;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

planar image
CV_8UC3

CV_8UC3 means interleaved image. So planar is source of confusion here.
planar is src1, src2 and src3 with CV_8UC1 type.

What is the main difference between resize and resizeP? Missing fx, fy?
Do we really need this entry point?


How do you want to downscale image by 2 with odd source size?
9x9 => 4.5 x 4.5 as 4x4 - is not 2x downscaling without extra information.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference is that resizeP has GMatP ("planar GMat") as input and as output so the engine can behave correctly.
This description definitely should be changed to reflect planar image memory layout (three planes laying in the memory contiguously), so the image height should be plane_height*plane_number, image type is CV_8UC1 and so on. Maybe planar images deserve some special chapter?

The function converts an input image from NV12 color space to RGB.
The conventional ranges for Y, U, and V channel values are 0 to 255.

Output image must be 8-bit unsigned planar 3-channel image @ref CV_8UC3.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

planar 3-channel

CV_8UC3 is interleaved 3-channel.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've upadted doxygen comments. I suggest to merge it as is to move forward.

@dmatveev
Copy link
Copy Markdown
Contributor

dmatveev commented Jul 2, 2019

Instead of playing with size, you can split planes completely:
planeB, planeG, planeR

For sure, and this is how our preprocessing works now on CPU. We do use a "split3" thing with its output Mats redirected properly to form a 3-channel buffer in the CHW layout.

split3 with three distinct outputs has both advantages (e.g. we can compose the output plane order for free in a way we need) and disadvantages (it doesn't put any restrictions on its output memory chunks - so those could be three different bufferfs).

On some platform which we currently enable with G-API, the operations like color conversions and resize operate with planar images natively. However, that operations assume only a single data pointer (with a fixed offset between the planes), not three different ones. So from the API perspective it is safer to introduce "planar" image type there rather than simulate it with three data objects pointing to the same memory chunk

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 2, 2019

3-channel color image:

  • interleaved: 2D matrix {height, width} with CV_8UC3 element type
  • your concatenated planar: 3D matrix {channels, height, width} with CV_8UC1 element type

Not sure why you need some strange GMatP workarounds with implicit number of channels (plane_height*plane_number).
Regular 3D matrix is able properly handle this layout with explicit number of channels in size[0].


Main problem of 3D approach is NV12 storage format, where planes are not "equal".

@dbudniko
Copy link
Copy Markdown

dbudniko commented Jul 4, 2019

@dmatveev please approve. @alalek is waiting for it to merge.

@dmatveev
Copy link
Copy Markdown
Contributor

dmatveev commented Jul 4, 2019

Not sure why you need some strange GMatP workarounds with implicit number of channels (plane_height*plane_number).

It is mainly an API contract. All our existing kernels which work with GMats in their API do not expect planar input, so we decided to forbid passing possibly-planar data there to avoid issues and confusion. GMat/GMatP clearly separates kernels on a type level.

@dmatveev
Copy link
Copy Markdown
Contributor

dmatveev commented Jul 4, 2019

Regular 3D matrix is able properly handle this layout with explicit number of channels in size[0].

This is a good point, BTW! Probably later we'll adjust API to use multi-dimensional matrices for the planar case.

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks!

@alalek alalek merged commit ad49138 into opencv:master Jul 4, 2019
@dmatveev
Copy link
Copy Markdown
Contributor

dmatveev commented Jul 6, 2019

Thanks!

AhiyaHiya added a commit to AhiyaHiya/opencv that referenced this pull request Jul 7, 2019
* master: (74 commits)
  Merge pull request opencv#14917 from rgarnov:gapi_planar_kernels
  Fixed initUndistortRectifyMap AVX2 implementation
  Merge pull request opencv#14959 from dvd42:onnx_clip
  videoio: eliminate build warnings (clang)
  ts: runtime check for misused 'optional' test data files
  3rdparty(itt): support AARCH64
  tensroflow support maxpoolgrad
  Fix blob detector insertion sort
  Fix crash, add assert and test
  Merge pull request opencv#14946 from andrey-golubev:obj_not_ref
  re-enable CPU_BASELINE=FP16 on Armv7 platform
  Merge pull request opencv#14828 from armenpoghosov:parmen_RANSACPointSetRegistrator_getSubset_disaster_cleanup
  Merge pull request opencv#14916 from terfendail:wsignmask_deprecated
  core: evaluate CV_Error() parameters during static scans
  dnn: fix build with Vulkan
  Merge pull request opencv#14936 from StefanBruens:crosscorr_cleanup
  Explicitly default operator= for Vec<T, n>
  Fix JS sample of dnn
  3rdparty: TBB version 2018u1 => 2019u8
  cmake: support rpath-link linker option
  ...
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
G-API planar kernels (opencv#14917)

* Added resizeP with tests

* NV12 planar filters

* fix warnings in ResizeP test

* fix out mat ocv warning

* sz_on - > sz rename

* cpu tests new signature

* try to fix resizeP test

* trailing spaces remove

* doxygen doc fixed

* doxygen minor fix

* more doxygen fixes

* Doxygen corrected and extended after review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants