mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #26259 from Kumataro:fix26258
core: C-API cleanup: RNG algorithms in core(4.x) #26259 - replace CV_RAND_UNI and NORMAL to cv::RNG::UNIFORM and cv::RNG::NORMAL. ### 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 - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -409,7 +409,7 @@ void RNG::fill( InputOutputArray _mat, int disttype,
|
||||
(((_param2.rows == 1 || _param2.cols == 1) &&
|
||||
(_param2.rows + _param2.cols - 1 == cn || _param2.rows + _param2.cols - 1 == 1 ||
|
||||
(_param1.size() == Size(1, 4) && _param1.type() == CV_64F && cn <= 4))) ||
|
||||
(_param2.rows == cn && _param2.cols == cn && disttype == NORMAL)));
|
||||
(_param2.rows == cn && _param2.cols == cn && disttype == RNG::NORMAL)));
|
||||
|
||||
Vec2i* ip = 0;
|
||||
Vec2d* dp = 0;
|
||||
@@ -421,7 +421,7 @@ void RNG::fill( InputOutputArray _mat, int disttype,
|
||||
int n1 = (int)_param1.total();
|
||||
int n2 = (int)_param2.total();
|
||||
|
||||
if( disttype == UNIFORM )
|
||||
if( disttype == RNG::UNIFORM )
|
||||
{
|
||||
_parambuf.allocate(cn*8 + n1 + n2);
|
||||
double* parambuf = _parambuf.data();
|
||||
@@ -535,7 +535,7 @@ void RNG::fill( InputOutputArray _mat, int disttype,
|
||||
}
|
||||
CV_Assert( func != 0 );
|
||||
}
|
||||
else if( disttype == CV_RAND_NORMAL )
|
||||
else if( disttype == RNG::NORMAL )
|
||||
{
|
||||
_parambuf.allocate(MAX(n1, cn) + MAX(n2, cn));
|
||||
double* parambuf = _parambuf.data();
|
||||
@@ -586,7 +586,7 @@ void RNG::fill( InputOutputArray _mat, int disttype,
|
||||
float* nbuf = 0;
|
||||
float* tmpbuf = 0;
|
||||
|
||||
if( disttype == UNIFORM )
|
||||
if( disttype == RNG::UNIFORM )
|
||||
{
|
||||
buf.allocate(blockSize*cn*4);
|
||||
param = (uchar*)(double*)buf.data();
|
||||
@@ -637,7 +637,7 @@ void RNG::fill( InputOutputArray _mat, int disttype,
|
||||
{
|
||||
int len = std::min(total - j, blockSize);
|
||||
|
||||
if( disttype == CV_RAND_UNI )
|
||||
if( disttype == RNG::UNIFORM )
|
||||
func( ptr, len*cn, &state, param, tmpbuf, smallFlag );
|
||||
else
|
||||
{
|
||||
@@ -753,12 +753,31 @@ void cv::randShuffle( InputOutputArray _dst, double iterFactor, RNG* _rng )
|
||||
|
||||
#ifndef OPENCV_EXCLUDE_C_API
|
||||
|
||||
// Related with https://github.com/opencv/opencv/issues/26258
|
||||
// To suppress cast-user-defined warning for casting CvRNG to cv::RNG& with GCC14.
|
||||
// ( CvRNG is uint64, and cv::RNG has only status member which is uint64. )
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 14
|
||||
#define CV_IGNORE_CAST_USER_DEFINED_WARNING
|
||||
#endif
|
||||
|
||||
CV_IMPL void
|
||||
cvRandArr( CvRNG* _rng, CvArr* arr, int disttype, CvScalar param1, CvScalar param2 )
|
||||
{
|
||||
cv::Mat mat = cv::cvarrToMat(arr);
|
||||
|
||||
#ifdef CV_IGNORE_CAST_USER_DEFINED_WARNING
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-user-defined"
|
||||
#endif
|
||||
|
||||
// !!! this will only work for current 64-bit MWC RNG !!!
|
||||
cv::RNG& rng = _rng ? (cv::RNG&)*_rng : cv::theRNG();
|
||||
|
||||
#ifdef CV_IGNORE_CAST_USER_DEFINED_WARNING
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
rng.fill(mat, disttype == CV_RAND_NORMAL ?
|
||||
cv::RNG::NORMAL : cv::RNG::UNIFORM, cv::Scalar(param1), cv::Scalar(param2) );
|
||||
}
|
||||
@@ -766,10 +785,25 @@ cvRandArr( CvRNG* _rng, CvArr* arr, int disttype, CvScalar param1, CvScalar para
|
||||
CV_IMPL void cvRandShuffle( CvArr* arr, CvRNG* _rng, double iter_factor )
|
||||
{
|
||||
cv::Mat dst = cv::cvarrToMat(arr);
|
||||
|
||||
#ifdef CV_IGNORE_CAST_USER_DEFINED_WARNING
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-user-defined"
|
||||
#endif
|
||||
|
||||
cv::RNG& rng = _rng ? (cv::RNG&)*_rng : cv::theRNG();
|
||||
|
||||
#ifdef CV_IGNORE_CAST_USER_DEFINED_WARNING
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
cv::randShuffle( dst, iter_factor, &rng );
|
||||
}
|
||||
|
||||
#ifdef CV_IGNORE_CAST_USER_DEFINED_WARNING
|
||||
#undef CV_IGNORE_CAST_USER_DEFINED_WARNING
|
||||
#endif
|
||||
|
||||
#endif // OPENCV_EXCLUDE_C_API
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user