Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HAL implementation hooks to cv::flip() and cv::rotate() functions from core module #24233

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

jvuillaumier
Copy link
Contributor

Hello,

This change proposes the addition of HAL hooks for cv::flip() and cv::rotate() functions from OpenCV core module.
Flip and rotation are functions commonly available from 2D hardware accelerators. This is convenient provision to enable custom optimized implementation of image flip/rotation on systems embedding such accelerator.

Thank you

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

@asmorkalov
Copy link
Contributor

@vpisarev @opencv-alalek could you take a look?

@jvuillaumier
Copy link
Contributor Author

Change seems to break videoio/VideoCaptureAPITests.mp4_orientation_meta_auto test.
My bad - I am looking at it and will update.

@asmorkalov
Copy link
Contributor

videoio/VideoCaptureAPITests.mp4_orientation_meta_auto uses cv::rotate internally.

@jvuillaumier
Copy link
Contributor Author

cv::rotate is used internally indeed, when a rotation meta is present in the stream:
https://github.com/opencv/opencv/blob/4.x/modules/videoio/src/cap_interface.hpp#L269

In place rotation is used, that may be a case where this change causes problem.
I will check what the actual issue is and update.

@jvuillaumier
Copy link
Contributor Author

Hello,

Change has been updated to take care of the in-place cv::rotate() case where same Mat is used for source and destination.

Test videoio/VideoCaptureAPITests.mp4_orientation_meta_auto is fixed.

Thanks

@jvuillaumier
Copy link
Contributor Author

Previous failure on videoio/VideoCaptureAPITests.mp4_orientation_meta_auto is confirmed to be fixed (in place case).

However CI suggests an abort was detected running stitchExposureCompMultiFeed_a123.a123/12 test on macOS-x64 - this test is passed on other platforms.

I will look at it and update.

@jvuillaumier
Copy link
Contributor Author

Hello,

I had a closer look to the abort issue reported by CI on stitchExposureCompMultiFeed_a123.a123/12 performance test on macOS-x64.

It is a bit puzzling me because:

  • Neither this test nor any other test from opencv_perf_stitching test suite is calling directly or indirectly a function changed by this patch (flip/rotate)
  • Test is passed on other platforms from CI
  • I could not repro the error locally neither on Yocto-ARM64 nor on Ubuntu-x64
  • Looking at recent PRs, I have not spotted such error so this test is presumably deemed stable

As I do not have access to a macOS-x64 platform, is it possible to restart CI on same change to confirm the issue and rule out a CI glitch?

Thanks

@jvuillaumier jvuillaumier changed the title Add HAL implementation hooks cv::flip() and cv::rotate() functions from core module Add HAL implementation hooks to cv::flip() and cv::rotate() functions from core module Sep 14, 2023
Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@asmorkalov asmorkalov added this to the 4.9.0 milestone Sep 21, 2023
@@ -201,6 +201,9 @@ CV_EXPORTS void cvt32f16f( const float* src, float16_t* dst, int len );
CV_EXPORTS void addRNGBias32f( float* arr, const float* scaleBiasPairs, int len );
CV_EXPORTS void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len );

CV_EXPORTS void flip( int src_type, const uchar* src_data, size_t src_step, int src_width, int src_height, uchar* dst_data, size_t dst_step, int flip_mode );
CV_EXPORTS void rotate( int src_type, const uchar* src_data, size_t src_step, int src_width, int src_height, uchar* dst_data, size_t dst_step, int angle );
Copy link
Contributor

@opencv-alalek opencv-alalek Sep 21, 2023

Choose a reason for hiding this comment

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

All functions from this file are defined somewhere in OpenCV codebase.
Added functions are not implemented. So they should not be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lines removed in updated version of the patch
Thanks

@@ -1097,4 +1101,50 @@ void rotate(InputArray _src, OutputArray _dst, int rotateMode)
}
}

void rotate(InputArray _src, OutputArray _dst, int rotateMode)
{
int angle;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing checks of input parameters constraints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check present in initial version of cv::rotate() is now present in the updated patch.
Thanks

@param dst_step destination image step
@param angle clockwise angle for rotation in degrees from set [90, 180, 270]
*/
inline int hal_ni_rotate(int src_type, const uchar* src_data, size_t src_step, int src_width, int src_height,
Copy link
Contributor

Choose a reason for hiding this comment

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

rotate => rotate90

To avoid confusion with generic rotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Functions renamed accordingly in updated version of the patch:
hal_ni_rotate => hal_ni_rotate90
cv_hal_rotate => cv_hal_rotate90

Thanks

This change is adding a HAL hook for custom cv::flip()
implementation.

Prototype of the HAL override function is:

/**
   @brief hal_flip
   @param src_type source and destination image type
   @param src_data source image data
   @param src_step source image step
   @param src_width source and destination image width
   @param src_height source and destination image height
   @param dst_data destination image data
   @param dst_step destination image step
   @param flip_mode 0 flips around x-axis, positive around y-axis, negative both

void flip(int src_type, const uchar* src_data, size_t src_step,
          int src_width, int src_height,
          uchar* dst_data, size_t dst_step,
          int flip_mode);
This change is adding a HAL hook for custom cv::rotate()
implementation.

Rotate operation is currently implemented as a composition of
cv::transpose() and cv::flip(), which makes some operations
a 2-steps process.

2D accelerators are usually capable of applying rotation in a
single step. Therefore, HAL function is hooked in the cv::rotate()
function rather than in the cv::transpose() and cv::flip() ones.

Prototype of the HAL override function is:

/**
   @brief rotate90
   @param src_type source and destination image type
   @param src_data source image data
   @param src_step source image step
   @param src_width source image width
   If angle has value [180] it is also destination image width
   If angle has values [90, 270] it is also destination image height
   @param src_height source and destination image height (destination image width for angles [90, 270])
   If angle has value [180] it is also destination image height
   If angle has values [90, 270] it is also destination image width
   @param dst_data destination image data
   @param dst_step destination image step
   @param angle clockwise angle for rotation in degrees from set [90, 180, 270]
*/

void rotate90( int src_type, const uchar* src_data, size_t src_step,
               int src_width, int src_height,
               uchar* dst_data, size_t dst_step,
               int angle);
@jvuillaumier
Copy link
Contributor Author

CI reports test failures in DNN module for multiple platforms.
Updates in last patch version consist in cleanup, function/macro renaming and additional input parameter check in cv::rotate() - mostly non functional changes.

As CI status for the previous version of the patch was green, I presume present CI test failures are not related to this patch version.

@jvuillaumier
Copy link
Contributor Author

CI errors for the DNN Einsum tests are likely related to #24311

@asmorkalov asmorkalov merged commit 24fd395 into opencv:4.x Oct 6, 2023
23 checks passed
hanliutong pushed a commit to hanliutong/opencv that referenced this pull request Oct 7, 2023
Add HAL implementation hooks to cv::flip() and cv::rotate() functions from core module opencv#24233

Hello,

This change proposes the addition of HAL hooks for cv::flip() and cv::rotate() functions from OpenCV core module.
Flip and rotation are functions commonly available from 2D hardware accelerators. This is convenient provision to enable custom optimized implementation of image flip/rotation on systems embedding such accelerator.

Thank you

### Pull Request Readiness Checklist

See details at https://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
@asmorkalov asmorkalov mentioned this pull request Oct 17, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Add HAL implementation hooks to cv::flip() and cv::rotate() functions from core module opencv#24233

Hello,

This change proposes the addition of HAL hooks for cv::flip() and cv::rotate() functions from OpenCV core module.
Flip and rotation are functions commonly available from 2D hardware accelerators. This is convenient provision to enable custom optimized implementation of image flip/rotation on systems embedding such accelerator.

Thank you

### Pull Request Readiness Checklist

See details at https://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 request May 29, 2024
Add HAL implementation hooks to cv::flip() and cv::rotate() functions from core module opencv#24233

Hello,

This change proposes the addition of HAL hooks for cv::flip() and cv::rotate() functions from OpenCV core module.
Flip and rotation are functions commonly available from 2D hardware accelerators. This is convenient provision to enable custom optimized implementation of image flip/rotation on systems embedding such accelerator.

Thank you

### Pull Request Readiness Checklist

See details at https://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 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.

None yet

4 participants