1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-18 08:44:11 +08:00

Merge pull request #3943 from troelsy:4.x

Add Otsu's method to cv::cuda::threshold #3943

I implemented Otsu's method in CUDA for a separate project and want to add it to cv::cuda::threshold

I have made an effort to use existing OpenCV functions in my code, but I had some trouble with `ThresholdTypes` and `cv::cuda::calcHist`. I couldn't figure out how to include `precomp.hpp` to get the definition of `ThresholdTypes`. For `cv::cuda::calcHist` I tried adding `opencv_cudaimgproc`, but it creates a circular dependency on `cudaarithm`. I have include a simple implementation of `calcHist` so the code runs, but I would like input on how to use `cv::cuda::calcHist` instead. 

### 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
- [ ] 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
This commit is contained in:
Troels Ynddal
2025-06-19 15:38:53 +02:00
committed by GitHub
parent edce692c7a
commit 6329974d4d
5 changed files with 289 additions and 5 deletions

View File

@@ -546,12 +546,16 @@ static inline void scaleAdd(InputArray src1, double alpha, InputArray src2, Outp
/** @brief Applies a fixed-level threshold to each array element.
The special value cv::THRESH_OTSU may be combined with one of the other types. In this case, the function determines the
optimal threshold value using the Otsu's and uses it instead of the specified threshold. The function returns the
computed threshold value in addititon to the thresholded matrix.
The Otsu's method is implemented only for 8-bit matrices.
@param src Source array (single-channel).
@param dst Destination array with the same size and type as src .
@param dst Destination array with the same size and type as src.
@param thresh Threshold value.
@param maxval Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV threshold types.
@param type Threshold type. For details, see threshold . The THRESH_OTSU and THRESH_TRIANGLE
threshold types are not supported.
@param type Threshold type. For details, see threshold. The THRESH_TRIANGLE threshold type is not supported.
@param stream Stream for the asynchronous version.
@sa threshold