Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@savuor
Copy link
Contributor

@savuor savuor commented May 29, 2024

Related to #25563 discussion

  • HAL call added with a name minMaxOffset which now returns value offsets instead of indices
  • test for non-continuous matrices added
  • minor refactoring to make code more logical

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

@savuor
Copy link
Contributor Author

savuor commented May 29, 2024

@mplatings please take a look

Copy link

@mplatings mplatings left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple of very minor points for your consideration. Fine if you disregard either or both.

@asmorkalov asmorkalov added this to the 4.10.0 milestone May 29, 2024
@asmorkalov asmorkalov self-assigned this May 29, 2024
@asmorkalov asmorkalov self-requested a review May 29, 2024 17:35
@asmorkalov
Copy link
Contributor

C:\GHA-OCV-4\_work\opencv\opencv\opencv\modules\core\src\minmax.cpp(1518): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data

C:\GHA-OCV-4\_work\opencv\opencv\opencv\modules\core\test\test_arithm.cpp(2897): warning C4244: 'argument': conversion from 'double' to 'RawType', possible loss of data

C:\GHA-OCV-4\_work\opencv\opencv\opencv\modules\core\test\test_arithm.cpp(2898): warning C4244: 'argument': conversion from 'double' to 'RawType', possible loss of data

@asmorkalov
Copy link
Contributor

@vpisarev @opencv-alalek could you take a look on the proposal?

}

size_t minOffset = SIZE_MAX, maxOffset = SIZE_MAX;
int res = cv_hal_minMaxIdx(src.data, srcHalStep, srcHalWidth, srcHalHeight, src.depth(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to ignore CALL_HAL* macro approach?

Copy link
Contributor Author

@savuor savuor May 31, 2024

Choose a reason for hiding this comment

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

  1. We want HAL function to return offsets instead of indices because HAL function:
  • does not need to know the source matrix shape
  • does not support more than 2 dimensions, so in ND case resulting indices should be fixed anyway
  1. Therefore we need to convert offsets to indices
  2. CALL_HAL macro does not support that, it returns immediately after the call, so it was expanded

@param mask_data Mask data pointer
*/
inline int hal_ni_minMaxIdx(const uchar* src_data, size_t src_step, int width, int height, int depth, double* minVal, double* maxVal,
int* minIdx, int* maxIdx, uchar* mask) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should add a new interface instead of trying to fix/change existed due to compatibility reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, added it as minMaxOffset along with existing one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just not sure what to do with existing HAL which is not called anymore.
This can be discussed; I'm ready to roll the previous code back.

else // pass it like one continuous row
{
srcHalStep = 0;
srcHalWidth = (int)src.total()*cn;
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid overflow processing should be limited by tensor size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry but I don't understand the issue
HAL function gets continuous array having a size of dim1 * dim2 * ... * dimN * channels which is what exactly calculated in this line.


size_t minOffset = SIZE_MAX, maxOffset = SIZE_MAX;
int res = cv_hal_minMaxOffset(src.data, srcHalStep, srcHalWidth, srcHalHeight, src.depth(),
minVal, maxVal, &minOffset, &maxOffset, mask.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

where is mask.step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was (implicitly) assumed to be the same as the step of source image
Fixed by adding a new argument to HAL call

@savuor savuor force-pushed the rv/hal_minMaxIdx_fix branch from 9db389f to 8e75b5a Compare June 1, 2024 00:07
@asmorkalov asmorkalov marked this pull request as draft June 11, 2024 08:11
@asmorkalov asmorkalov closed this Jul 12, 2024
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