Skip to content

G-API: Add ROI processing in VPP preproc#21658

Merged
alalek merged 2 commits intoopencv:4.xfrom
sivanov-work:vpp_core_add_roi
Mar 5, 2022
Merged

G-API: Add ROI processing in VPP preproc#21658
alalek merged 2 commits intoopencv:4.xfrom
sivanov-work:vpp_core_add_roi

Conversation

@sivanov-work
Copy link
Copy Markdown
Contributor

@sivanov-work sivanov-work commented Feb 24, 2022

Add ROI processing for core part of VPP preproc which is essential from #21554

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Build Configuration

force_builders=XCustom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2021.3.0:20.04
Xbuild_image:Custom Win=openvino-2021.2.0
build_image:Custom Mac=openvino-2021.2.0

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

buildworker:Custom=linux-1
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

build_image:Custom Win=gapi-onevpl-2021.6.0
buildworker:Custom Win=windows-3
build_contrib:Custom Win=OFF

decoded_frame = cv::MediaFrame();
preproc_number++;
}
} catch (...) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's the reason to have catch here? Normally if ASSERT_TRUE fails you may catch it (I believe those macros throw exceptions in gtest as the overall test suite execution continues after that)

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.

i don't exactly remember reasons why it was done as throwing exception (this code copy-pasted from older and older PR):
Maybe, I don't want to wrap each function in NO_THROW macro (3 at least), because as far i remember, some pp_* have no default ctors. Also in any tests throwing exception and breaking while-loop is expected behavior

Copy link
Copy Markdown
Contributor

@OrestChura OrestChura left a comment

Choose a reason for hiding this comment

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

some cosmetic-rearranging comments

testing::ValuesIn(files));

using roi_t = cv::Rect;
using roi_t = cv::util::optional<cv::Rect>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this using can be declared at :183 and be used instead of all cv::util::optional<cv::Rect> usages

MFX_CODEC_HEVC, MFX_ACCEL_MODE_VIA_D3D11,
out_frame_info_t{cv::GFrameDesc {cv::MediaFormat::NV12, {1920, 1280}}},
roi_t{0,0,100,100}},
roi_t{}},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can use empty_roi variable here? (and on :455)

@dmatveev dmatveev self-assigned this Mar 1, 2022
@dmatveev dmatveev added this to the 4.6.0 milestone Mar 1, 2022
Copy link
Copy Markdown
Contributor

@rgarnov rgarnov left a comment

Choose a reason for hiding this comment

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

Looks good

using out_frame_info_t = cv::GFrameDesc;
using preproc_args_t = std::tuple<source_t, decoder_t, acceleration_t, out_frame_info_t>;

static cv::util::optional<cv::Rect> empty_roi;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why it's needed?
Does it make sense to just pass cv::optional<cv::Rect>{} ?

pp_session sess = preproc_engine.initialize_preproc(param.value(),
required_frame_param);
(void)preproc_engine.run_sync(sess, frame);
(void)preproc_engine.run_sync(sess, frame, empty_roi);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Honestly, I didn't understand how it works
Does it do crop if roi is passed and doesn't do crop otherwise.

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.

optinal cv::Rect passed through engine and falls in pipeline execution, please check apply_roi:
https://github.com/opencv/opencv/pull/21658/files#diff-d281efabce2ff069582bd99d9c40e910c4386b65d60010ed9e4b106f4f2b237bR39

If no roi stored in optional then no crop operation would happen

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

Comment on lines +76 to +77
memcpy(&(original_surface_ptr->Info),
&original_frame_info, sizeof(Surface::info_t));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may be way to C-ish, and unsafe for C++ data types if any. Would operator= work better where? Just wondering

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.

It is packed C-structure in VPL/MFX without operator=. I didn't implement our custom operator= because it doesn't protect us from VPL API changes ( when new fields will added in such c-structure from vpl side)

@sivanov-work
Copy link
Copy Markdown
Contributor Author

@alalek Could you merge it please? Minor comments elapsed which may be implemented in the next PRs

@alalek alalek merged commit 44c2c77 into opencv:4.x Mar 5, 2022
@opencv-pushbot opencv-pushbot mentioned this pull request Apr 23, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
 G-API: Add ROI processing in VPP preproc

* Add ROI in VPP prepro

* Apply comments
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.

6 participants