Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DNN: Add New API blobFromImageParam#22750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
asmorkalov merged 2 commits intoopencv:4.xfromzihaomu:improve_blobFromImage
Apr 21, 2023

Conversation

@zihaomu
Copy link
Member

@zihaomuzihaomu commentedNov 4, 2022
edited
Loading

The purpose of this PR:

  1. Add new APIblobFromImageParam to extendblobFromImage API. It can support the different datalayout (NCHW or NHWC), and letter_box.
  2. blobFromImage can outputCV_16F

Pull Request Readiness Checklist

See details athttps://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

@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch 2 times, most recently from7b47836 toe4abcecCompareNovember 4, 2022 05:53
@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch 5 times, most recently from60209c1 tod280eabCompareNovember 24, 2022 08:25
@zihaomu
Copy link
MemberAuthor

zihaomu commentedNov 24, 2022
edited
Loading

Hi, the updated code has re-used old blobFromImage API, only change is convert scalefactor fromdouble toScalar. And this change brokes the java binding, shown as follows:

    [mkdir] Created dir: /home/ci/build/java_test/build/classes    [javac] Compiling 58 source files to /home/ci/build/java_test/build/classes    [javac] /home/ci/build/java_test/src/org/opencv/test/dnn/DnnListRegressionTest.java:69: error: incompatible types: double cannot be converted to Scalar    [javac]         Mat inputBlob = Dnn.blobFromImage(image, 1.0, new Size(224, 224), new Scalar(0), true, true);    [javac]                                                  ^    [javac] /home/ci/build/java_test/src/org/opencv/test/dnn/DnnTensorFlowTest.java:98: error: incompatible types: double cannot be converted to Scalar    [javac]         Mat inputBlob = Dnn.blobFromImage(image, 1.0, new Size(224, 224), new Scalar(0), true, true);    [javac]                                                  ^    [javac] Note: /home/ci/build/java_test/src/org/opencv/test/dnn/DnnTensorFlowTest.java uses or overrides a deprecated API.    [javac] Note: Recompile with -Xlint:deprecation for details.    [javac] Note: Some input files use unchecked or unsafe operations.    [javac] Note: Recompile with -Xlint:unchecked for details.    [javac] Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output    [javac] 2 errors

Is there any solution?
Is it possible to map one cpp API ofblobFromImage into two java APi?

Copy link
Member

@alalekalalek left a comment

Choose a reason for hiding this comment

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

As we have a new version with "parameters" do we really need to update old versionsblobFromImage()? We could deprecate them and suggest using a new variant.

@asmorkalov
Copy link
Contributor

You can generate extra overloads in Java with ManualFuncs option of Java bindigs generator. See modules/core/misc/java/gen_dict.json as example. Java tests for all manual functions are required.

zihaomu reacted with thumbs up emoji

@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch 4 times, most recently fromb80264b to716ba23CompareNovember 30, 2022 03:54
@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch 2 times, most recently from972d8ce to12acf76CompareFebruary 15, 2023 08:29
@zihaomuzihaomu changed the titleDNN: improve blobFromImage APIDNN: ExtendingblobFromImage through New APIblobFromImageParamFeb 15, 2023
@zihaomuzihaomu changed the titleDNN: ExtendingblobFromImage through New APIblobFromImageParamDNN: Add New API blobFromImageParamFeb 15, 2023
@zihaomu
Copy link
MemberAuthor

As we have a new version with "parameters" do we really need to update old versionsblobFromImage()? We could deprecate them and suggest using a new variant.

Agree with@alalek. I propose that this PR only add new features to the new APIblobFromImageParam, without changing thescalefactor type at old API (blobFromImage). Since theblobFromImage has too many arguments, and the future new features will be added to theblobFromImageParam.

@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch fromedd832e tob8d1f84CompareMarch 1, 2023 03:48
@asmorkalov
Copy link
Contributor

@zihaomu@vpisarev friendly reminder.

@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch 3 times, most recently from6816dbd to5c0ed4fCompareApril 12, 2023 07:22
@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch 2 times, most recently fromb386d90 to957cd82CompareApril 17, 2023 03:35
@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch from957cd82 tob4f6383CompareApril 18, 2023 05:44
Copy link
Contributor

@asmorkalovasmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@vpisarevvpisarev self-requested a reviewApril 19, 2023 06:23
@vpisarev
Copy link
Contributor

@dkurt, can you please tell if "planar" layout used in TFLite importer is the same thing as "ND" layout used in other formats?

@dkurt
Copy link
Member

dkurt commentedApr 19, 2023
edited
Loading

Do we really need to introduce legacy TensorFlow NHWC data layout? I think it may introduce more confusion than strict NCHW input.

Also, I'm not sure about preserving ratio during scale (crop/letter_box). They are different in different applications. For example, EfficientDet from TensorFlow:

h,w=img.shape[0:2]# 1. Resize and keep aspect ratioassert(w>=h)h=int(h/w*args.height)inp=cv.resize(img.astype(np.float32), (args.width,h))# It's important to perform resize for fp32# 2. Zero padding to the bottominp=np.pad(inp, ((0,args.height-h), (0,0), (0,0)),'constant')inp=np.expand_dims(inp.transpose(2,0,1),axis=0)

source

@dkurt, can you please tell if "planar" layout used in TFLite importer is the same thing as "ND" layout used in other formats?

@vpisarev, TFLite's planar is the same as TensorFlow's planar. It's used in case of 4D->3D or 2D reshaping when OpenCV data layout matches TensorFlow during import.

@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch froma8c3f22 to30aeda5CompareApril 21, 2023 09:25
@asmorkalov
Copy link
Contributor

[  FAILED  ] blobFromImageWithParams_4ch.letter_box

@zihaomuzihaomuforce-pushed theimprove_blobFromImage branch from30aeda5 to9450d87CompareApril 21, 2023 14:57
@zihaomu
Copy link
MemberAuthor

Hi@asmorkalov, thanks for your reminder, updated.

@asmorkalovasmorkalov merged commit601778e intoopencv:4.xApr 21, 2023
@asmorkalovasmorkalov added this to the4.8.0 milestoneApr 21, 2023
@asmorkalovasmorkalov mentioned this pull requestMay 31, 2023
@asmorkalovasmorkalov mentioned this pull requestOct 30, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull requestJan 4, 2024
DNN: Add New API blobFromImageParamopencv#22750The purpose of this PR:1. Add new API `blobFromImageParam` to extend `blobFromImage` API. It can support the different data layout (NCHW or NHWC), and letter_box.2. ~~`blobFromImage` can output `CV_16F`~~### Pull Request Readiness ChecklistSee details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request- [x] I agree to contribute to the project under Apache 2 License.- [x] 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- [x] 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
thewoz pushed a commit to thewoz/opencv that referenced this pull requestMay 29, 2024
DNN: Add New API blobFromImageParamopencv#22750The purpose of this PR:1. Add new API `blobFromImageParam` to extend `blobFromImage` API. It can support the different data layout (NCHW or NHWC), and letter_box.2. ~~`blobFromImage` can output `CV_16F`~~### Pull Request Readiness ChecklistSee details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request- [x] I agree to contribute to the project under Apache 2 License.- [x] 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- [x] 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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vpisarevvpisarevvpisarev approved these changes

@asmorkalovasmorkalovasmorkalov approved these changes

@alalekalalekalalek left review comments

Assignees

@vpisarevvpisarev

Projects

None yet

Milestone

4.8.0

Development

Successfully merging this pull request may close these issues.

5 participants

@zihaomu@asmorkalov@vpisarev@dkurt@alalek

[8]ページ先頭

©2009-2025 Movatter.jp