Skip to content

G-API: Extend MediaFrame to be able to extract additional info besides access#20151

Merged
alalek merged 3 commits intoopencv:masterfrom
smirnov-alexey:as/extend_media_frame
Jun 8, 2021
Merged

G-API: Extend MediaFrame to be able to extract additional info besides access#20151
alalek merged 3 commits intoopencv:masterfrom
smirnov-alexey:as/extend_media_frame

Conversation

@smirnov-alexey
Copy link
Copy Markdown
Contributor

@smirnov-alexey smirnov-alexey commented May 24, 2021

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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
force_builders=Custom,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
build_image:Custom Win=openvino-2021.3.0
build_image:Custom Mac=openvino-2021.3.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
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@dmatveev @TolyaTalamanov @rgarnov please, review

Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov left a comment

Choose a reason for hiding this comment

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

Great! 🔥

Only cosmetic fixes are required

cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
return cv::MediaFrame::View(std::move(pp), std::move(ss));
}
cv::util::any blobParams() const override {
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.

Every MediaFrame and Adapter must implement this ? No default implementation by default ?

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.

Agreed. Provided a default implementation and removed all the overloads

cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
return cv::MediaFrame::View(std::move(pp), std::move(ss), Cb{m_cb});
}
cv::util::any blobParams() const override {
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.

Is it really needed to define this default behavior manually ?

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.

Answered above

cv::Mat bgr = cv::Mat::eye(240, 320, CV_8UC3);
cv::MediaFrame frame = cv::MediaFrame::Create<TestMediaBGR>(bgr);

cv::util::any any_params = frame.blobParams();
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 not just params

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.

Ok, but you don't need to store it in separate variable

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.

Done

InferenceEngine::ParamMap pmap({{"HELLO", 42},
{"COLOR_FORMAT",
InferenceEngine::ColorFormat::NV12}});
InferenceEngine::TensorDesc tdesc;
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.

So, maybe it makes sense to test with non-empty TensorDesc

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.

Done

auto params = cv::util::any_cast<std::pair<InferenceEngine::TensorDesc,
InferenceEngine::ParamMap>>(any_params);

InferenceEngine::ParamMap pmap({{"HELLO", 42},
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.

I would make it like this:

auto expected = std::make_pair(IE::TensorDesc{IE::Precision::U8, {1, 3, 300, 300}, IE::Layout::NCHW},     
                               IE::ParamMap{{"HELLO", 42}, {"COLOR_FORMAT", IE::ColorFormat::NV12}});

auto actual = cv::util::any_cast<decltype(expected)>>(frame.params());

EXPECT_EQ(expected, actual);

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.

Done, thanks for the example

@dmatveev dmatveev self-assigned this May 31, 2021
@dmatveev dmatveev added this to the 4.5.3 milestone May 31, 2021
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.

This PR can be simplified dramatically :)

virtual ~IAdapter() = 0;
virtual cv::GFrameDesc meta() const = 0;
virtual MediaFrame::View access(MediaFrame::Access) = 0;
virtual cv::util::any blobParams() const = 0;
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.

No as it breaks all the existing adapters. Please supply a default implementation instead (and make it safe enough to call by default - so no asserts/exceptions here if this default implementation is used).

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.

Got you, fixed

}
cv::util::any blobParams() const override {
return std::make_pair<std::string, int>("hello", 42);
}
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.

Please drop these changes after you introduce a default implementation

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.

Done

cv::util::any blobParams() const override {
GAPI_Assert(false && "Not implemented");
return {};
}
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.

Please drop these changes after you introduce a default implementation

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.

Done

cv::util::any blobParams() const override {
GAPI_Assert(false && "Not implemented");
return {};
}
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.

Drop

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.

Done

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@dmatveev @TolyaTalamanov please, review the changes

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@alalek How can I fix CN checks (do I need to)?

[Pipeline] sh
+ curl -s https://api.github.com/repos/smirnov-alexey/opencv_extra/branches
[Pipeline] }
ERROR: script returned exit code 7

I believe I got no branches in opencv_extra

@alalek
Copy link
Copy Markdown
Member

alalek commented May 31, 2021

CN checks

Ignore. These failures are infrastructure-related.

Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov left a comment

Choose a reason for hiding this comment

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

LGTM 👍

return cv::MediaFrame::View(std::move(pp), std::move(ss), Cb{m_cb});
}
cv::util::any blobParams() const override {
return std::make_pair<InferenceEngine::TensorDesc,
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.

I believe you don't have to specify template manually, make_pair(...) would be enough

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.

It seems I commented on these parts in another review, #20156 -- please incorporate the relevant review comments here and I think it can be merged.

Thanks!

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@alalek can we merge this?

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.

@alalek can you please merge this one before the freeze? Thanks

@alalek alalek merged commit d9ed9a9 into opencv:master Jun 8, 2021
@alalek alalek mentioned this pull request Jun 13, 2021
@alalek alalek mentioned this pull request Oct 15, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…rame

G-API: Extend MediaFrame to be able to extract additional info besides access

* Extend MediaFrame to be able to extract additional info besides access

* Add default implementation for blobParams()

* Add comment on the default blobParams()
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.

5 participants