From 9c19a0cdba3e489b1944392028633ea8430d95eb Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Wed, 14 Aug 2024 16:57:44 +0800 Subject: [PATCH 01/19] Reinitialize divider matrix in DivRCPerfTest and DivPerfTest Cases. This patch reinitializes divider matrix without zero values in DivRCPerfTest and DivPerfTest test cases. --- modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp b/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp index 3a777cff3d..c5cf6c0ea9 100644 --- a/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp +++ b/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp @@ -438,7 +438,7 @@ PERF_TEST_P_(DivPerfTest, TestPerformance) //This condition need to workaround the #21044 issue in the OpenCV. //It reinitializes divider matrix without zero values for CV_16S DST type. - if (dtype == CV_16S && dtype != type) + if (dtype != type) cv::randu(in_mat2, cv::Scalar::all(1), cv::Scalar::all(255)); // OpenCV code /////////////////////////////////////////////////////////// @@ -530,8 +530,7 @@ PERF_TEST_P_(DivRCPerfTest, TestPerformance) initMatsRandU(type, sz, dtype, false); //This condition need to workaround the #21044 issue in the OpenCV. //It reinitializes divider matrix without zero values for CV_16S DST type. - if (dtype == CV_16S || (type == CV_16S && dtype == -1)) - cv::randu(in_mat1, cv::Scalar::all(1), cv::Scalar::all(255)); + cv::randu(in_mat1, cv::Scalar::all(1), cv::Scalar::all(255)); // OpenCV code /////////////////////////////////////////////////////////// cv::divide(sc, in_mat1, out_mat_ocv, scale, dtype); From 5638c38d530e2f524eeecbba80cf6deae2c0667a Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Thu, 4 Jul 2024 15:04:24 +0800 Subject: [PATCH 02/19] Resolve compilation bug Fixed a bug that occurred when compiling with the clang18 compiler. Signed-off-by: Hao Chen --- .../include/opencv2/core/hal/intrin_lasx.hpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/core/include/opencv2/core/hal/intrin_lasx.hpp b/modules/core/include/opencv2/core/hal/intrin_lasx.hpp index 4a98dbf96e..db491cc137 100644 --- a/modules/core/include/opencv2/core/hal/intrin_lasx.hpp +++ b/modules/core/include/opencv2/core/hal/intrin_lasx.hpp @@ -650,16 +650,18 @@ inline v_float32x8 v256_shuffle(const v_float32x8 &a) template inline v_float64x4 v256_shuffle(const v_float64x4 &a) { - int imm8 = m & 0b0001; //0 or 1 - if (m & 0x0b0010) imm8 |= 0b0100; - //else imm8 |= 0b0000; - if (m & 0x0b0100) imm8 |= 0b110000; //2 or 3 - else imm8 |= 0b100000; - if (m & 0x0b1000) imm8 |= 0b11000000; - else imm8 |= 0b10000000; + const int m1 = m & 0b1; + const int m2 = m & 0b10; + const int m3 = m & 0b100; + const int m4 = m & 0b1000; + const int m5 = m2 << 1; + const int m6 = m3 << 2; + const int m7 = m4 << 3; + const int m8 = m1 & m5 & m6 & m7; - return v_float64x4(__lasx_xvpermi_d(*((__m256i*)&a.val), imm8)); + return v_float64x4(__lasx_xvshuf4i_d(*((__m256i*)&a.val), *((__m256i*)&a.val), m8)); } + template inline void v256_zip(const _Tpvec& a, const _Tpvec& b, _Tpvec& ab0, _Tpvec& ab1) { @@ -1100,7 +1102,7 @@ inline v_uint8x32 v_rotate_right(const v_uint8x32& a, const v_uint8x32& b) template inline v_uint8x32 v_rotate_left(const v_uint8x32& a) { - enum {IMM_L = (imm - 16) & 0xFF}; + enum {IMM_L = ((imm - 16) & 0xFF) > 31 ? 31 : ((imm - 16) & 0xFF)}; enum {IMM_R = (16 - imm) & 0xFF}; if (imm == 0) return a; @@ -1117,7 +1119,7 @@ inline v_uint8x32 v_rotate_left(const v_uint8x32& a) template inline v_uint8x32 v_rotate_right(const v_uint8x32& a) { - enum {IMM_L = (imm - 16) & 0xFF}; + enum {IMM_L = ((imm - 16) & 0xFF) > 31 ? 31 : ((imm - 16) & 0xFF)}; if (imm == 0) return a; if (imm > 32) return v_uint8x32(); From a17fafc3afe1019ebee46c03b149fa8ad8f82a15 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Wed, 28 Aug 2024 11:49:27 +0200 Subject: [PATCH 03/19] Disable strict mode when reading avif files This fixes https://github.com/opencv/opencv/issues/26011 --- modules/imgcodecs/src/grfmt_avif.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/imgcodecs/src/grfmt_avif.cpp b/modules/imgcodecs/src/grfmt_avif.cpp index c1d3682d0c..98ddb73362 100644 --- a/modules/imgcodecs/src/grfmt_avif.cpp +++ b/modules/imgcodecs/src/grfmt_avif.cpp @@ -143,6 +143,7 @@ AvifDecoder::AvifDecoder() { m_buf_supported = true; channels_ = 0; decoder_ = avifDecoderCreate(); + decoder_->strictFlags = AVIF_STRICT_DISABLED; } AvifDecoder::~AvifDecoder() { @@ -166,6 +167,7 @@ bool AvifDecoder::checkSignature(const String &signature) const { std::unique_ptr decoder( avifDecoderCreate(), avifDecoderDestroy); if (!decoder) return false; + decoder->strictFlags = AVIF_STRICT_DISABLED; OPENCV_AVIF_CHECK_STATUS( avifDecoderSetIOMemory( decoder.get(), reinterpret_cast(signature.c_str()), From 61f6b6d773fe18cb39554bae0b0f4d619bfb20a3 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 21 Aug 2024 18:57:50 +0300 Subject: [PATCH 04/19] videoio: fix V4L backend with NV12 input format --- modules/videoio/src/cap_v4l.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index 531af03d1a..9baa9983de 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -1538,11 +1538,11 @@ void CvCaptureCAM_V4L::convertToRgb(const Buffer ¤tBuffer) return; case V4L2_PIX_FMT_NV12: cv::cvtColor(cv::Mat(imageSize.height * 3 / 2, imageSize.width, CV_8U, start), destination, - COLOR_YUV2RGB_NV12); + COLOR_YUV2BGR_NV12); return; case V4L2_PIX_FMT_NV21: cv::cvtColor(cv::Mat(imageSize.height * 3 / 2, imageSize.width, CV_8U, start), destination, - COLOR_YUV2RGB_NV21); + COLOR_YUV2BGR_NV21); return; #ifdef HAVE_JPEG case V4L2_PIX_FMT_MJPEG: From a905526f71a48dc8fb227a5aba28322d2683c451 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 30 Aug 2024 12:09:04 +0300 Subject: [PATCH 05/19] Got rid of CAROTENE_NEON_ARCH and use standard __ARM_ARCH check. --- 3rdparty/carotene/CMakeLists.txt | 10 +--------- 3rdparty/carotene/hal/tegra_hal.hpp | 4 ++-- 3rdparty/carotene/src/common.hpp | 11 ----------- 3rdparty/carotene/src/vround_helper.hpp | 8 ++++---- CMakeLists.txt | 10 +--------- .../config_reference/config_reference.markdown | 1 - 6 files changed, 8 insertions(+), 36 deletions(-) diff --git a/3rdparty/carotene/CMakeLists.txt b/3rdparty/carotene/CMakeLists.txt index dc780fd645..e229cbc022 100644 --- a/3rdparty/carotene/CMakeLists.txt +++ b/3rdparty/carotene/CMakeLists.txt @@ -42,17 +42,9 @@ endif() if(WITH_NEON) target_compile_definitions(carotene_objs PRIVATE "-DWITH_NEON") - if(NOT DEFINED CAROTENE_NEON_ARCH ) - elseif(CAROTENE_NEON_ARCH EQUAL 8) - target_compile_definitions(carotene_objs PRIVATE "-DCAROTENE_NEON_ARCH=8") - elseif(CAROTENE_NEON_ARCH EQUAL 7) - target_compile_definitions(carotene_objs PRIVATE "-DCAROTENE_NEON_ARCH=7") - else() - target_compile_definitions(carotene_objs PRIVATE "-DCAROTENE_NEON_ARCH=0") - endif() endif() - if(MINGW) + if(MINGW) target_compile_definitions(carotene_objs PRIVATE "-D_USE_MATH_DEFINES=1") endif() diff --git a/3rdparty/carotene/hal/tegra_hal.hpp b/3rdparty/carotene/hal/tegra_hal.hpp index 7f67ecf1a3..cb658e8af0 100644 --- a/3rdparty/carotene/hal/tegra_hal.hpp +++ b/3rdparty/carotene/hal/tegra_hal.hpp @@ -1857,7 +1857,7 @@ TegraCvtColor_Invoker(bgrx2hsvf, bgrx2hsv, src_data + static_cast(range. #endif // The optimized branch was developed for old armv7 processors and leads to perf degradation on armv8 -#if defined(DCAROTENE_NEON_ARCH) && (DCAROTENE_NEON_ARCH == 7) +#if defined(__ARM_ARCH) && (__ARM_ARCH == 7) inline CAROTENE_NS::BORDER_MODE borderCV2Carotene(int borderType) { switch(borderType) @@ -1928,7 +1928,7 @@ inline int TEGRA_GaussianBlurBinomial(const uchar* src_data, size_t src_step, uc #undef cv_hal_gaussianBlurBinomial #define cv_hal_gaussianBlurBinomial TEGRA_GaussianBlurBinomial -#endif // DCAROTENE_NEON_ARCH=7 +#endif // __ARM_ARCH=7 #endif // OPENCV_IMGPROC_HAL_INTERFACE_H diff --git a/3rdparty/carotene/src/common.hpp b/3rdparty/carotene/src/common.hpp index b9de371a6a..823ddf1ccf 100644 --- a/3rdparty/carotene/src/common.hpp +++ b/3rdparty/carotene/src/common.hpp @@ -58,17 +58,6 @@ namespace CAROTENE_NS { namespace internal { -#ifndef CAROTENE_NEON_ARCH -# if defined(__aarch64__) || defined(__aarch32__) -# define CAROTENE_NEON_ARCH 8 -# else -# define CAROTENE_NEON_ARCH 7 -# endif -#endif -#if ( !defined(__aarch64__) && !defined(__aarch32__) ) && (CAROTENE_NEON_ARCH == 8 ) -# error("ARMv7 doen't support A32/A64 Neon instructions") -#endif - inline void prefetch(const void *ptr, size_t offset = 32*10) { #if defined __GNUC__ diff --git a/3rdparty/carotene/src/vround_helper.hpp b/3rdparty/carotene/src/vround_helper.hpp index 89a6254510..f931a20984 100644 --- a/3rdparty/carotene/src/vround_helper.hpp +++ b/3rdparty/carotene/src/vround_helper.hpp @@ -57,7 +57,7 @@ namespace CAROTENE_NS { namespace internal { inline uint32x4_t vroundq_u32_f32(const float32x4_t val) { -#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */ +#if defined(__ARM_ARCH) && (__ARM_ARCH >= 8) return vcvtnq_u32_f32(val); #else const float32x4_t delta = vdupq_n_f32(CAROTENE_ROUND_DELTA); @@ -67,7 +67,7 @@ inline uint32x4_t vroundq_u32_f32(const float32x4_t val) inline uint32x2_t vround_u32_f32(const float32x2_t val) { -#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */ +#if defined(__ARM_ARCH) && (__ARM_ARCH >= 8) return vcvtn_u32_f32(val); #else const float32x2_t delta = vdup_n_f32(CAROTENE_ROUND_DELTA); @@ -77,7 +77,7 @@ inline uint32x2_t vround_u32_f32(const float32x2_t val) inline int32x4_t vroundq_s32_f32(const float32x4_t val) { -#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */ +#if defined(__ARM_ARCH) && (__ARM_ARCH >= 8) return vcvtnq_s32_f32(val); #else const float32x4_t delta = vdupq_n_f32(CAROTENE_ROUND_DELTA); @@ -87,7 +87,7 @@ inline int32x4_t vroundq_s32_f32(const float32x4_t val) inline int32x2_t vround_s32_f32(const float32x2_t val) { -#if CAROTENE_NEON_ARCH >= 8 /* get ready for ARMv9 */ +#if defined(__ARM_ARCH) && (__ARM_ARCH >= 8) return vcvtn_s32_f32(val); #else const float32x2_t delta = vdup_n_f32(CAROTENE_ROUND_DELTA); diff --git a/CMakeLists.txt b/CMakeLists.txt index ecc56e547a..e4ea325d69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1018,15 +1018,7 @@ foreach(hal ${OpenCV_HAL}) if(";${CPU_BASELINE_FINAL};" MATCHES ";NEON;") add_subdirectory(3rdparty/carotene/hal) ocv_hal_register(CAROTENE_HAL_LIBRARIES CAROTENE_HAL_HEADERS CAROTENE_HAL_INCLUDE_DIRS) - - if( NOT DEFINED CAROTENE_NEON_ARCH) - set(CAROTENE_NEON_MSG "Auto detected") - elseif( CAROTENE_NEON_ARCH GREATER 7) - set(CAROTENE_NEON_MSG "Force ARMv8+") - else() - set(CAROTENE_NEON_MSG "Force ARMv7") - endif() - list(APPEND OpenCV_USED_HAL "carotene (ver ${CAROTENE_HAL_VERSION}, ${CAROTENE_NEON_MSG})") + list(APPEND OpenCV_USED_HAL "carotene (ver ${CAROTENE_HAL_VERSION})") else() message(STATUS "Carotene: NEON is not available, disabling carotene...") endif() diff --git a/doc/tutorials/introduction/config_reference/config_reference.markdown b/doc/tutorials/introduction/config_reference/config_reference.markdown index 6beee31201..ab8bdee229 100644 --- a/doc/tutorials/introduction/config_reference/config_reference.markdown +++ b/doc/tutorials/introduction/config_reference/config_reference.markdown @@ -588,7 +588,6 @@ Following options can be used to change installation layout for common scenarios | `BUILD_FAT_JAVA_LIB` | _ON_ (for static Android builds) | Build single _opencv_java_ dynamic library containing all library functionality bundled with Java bindings. | | `BUILD_opencv_python2` | _ON_ | Build python2 bindings (deprecated). Python with development files and numpy must be installed. | | `BUILD_opencv_python3` | _ON_ | Build python3 bindings. Python with development files and numpy must be installed. | -| `CAROTENE_NEON_ARCH` | '(auto)' | Switch NEON Arch for Carotene. If it sets nothing, it will be auto-detected. If it sets 8, ARMv8(and later) is used. Otherwise, ARMv7 is used. | TODO: need separate tutorials covering bindings builds From 5b4d1ce6a09747c9bcaeab97f11aa410e9bcd398 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov <2536374+asmorkalov@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:10:24 +0300 Subject: [PATCH 06/19] Merge pull request #26080 from asmorkalov:as/HAL_minMaxIdx_ND_offset Added offset for HAL as ofs2idx expects 1-based index #26080 ### 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 --- modules/core/src/minmax.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/core/src/minmax.cpp b/modules/core/src/minmax.cpp index 8c6d8ad9a9..8a4a54522f 100644 --- a/modules/core/src/minmax.cpp +++ b/modules/core/src/minmax.cpp @@ -846,6 +846,8 @@ static MinMaxIdxFunc getMinmaxTab(int depth) return minmaxTab[depth]; } +// The function expects 1-based indexing for ofs +// Zero is treated as invalid offset (not found) static void ofs2idx(const Mat& a, size_t ofs, int* idx) { int i, d = a.dims; @@ -1524,9 +1526,9 @@ void cv::minMaxIdx(InputArray _src, double* minVal, { // minIdx[0] and minIdx[0] are always 0 for "flatten" version if (minIdx) - ofs2idx(src, minIdx[1], minIdx); + ofs2idx(src, minIdx[1]+1, minIdx); if (maxIdx) - ofs2idx(src, maxIdx[1], maxIdx); + ofs2idx(src, maxIdx[1]+1, maxIdx); return; } else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED) From 165bf25c46cdbb6d098c6f724d770c95072dbb78 Mon Sep 17 00:00:00 2001 From: catree Date: Sun, 1 Sep 2024 00:59:17 +0200 Subject: [PATCH 07/19] Fix typo with cameramatrix command for documentation. Fix link for "RANSAC for Dummies" tutorial. --- doc/opencv.bib | 2 +- modules/calib3d/include/opencv2/calib3d.hpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/opencv.bib b/doc/opencv.bib index 5531bb6dd5..e3363a181c 100644 --- a/doc/opencv.bib +++ b/doc/opencv.bib @@ -1310,7 +1310,7 @@ title={RANSAC for Dummies With examples using the RANSAC toolbox for Matlab \& Octave and more...}, author={Marco Zuliani}, year={2014}, - url = {https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.475.1243&rep=rep1&type=pdf} + url = {http://www.marcozuliani.com/docs/RANSAC4Dummies.pdf} } @inproceedings{forstner1987fast, title={A fast operator for detection and precise location of distincs points, corners and center of circular features}, diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index 9fc6773450..f44dacbedf 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -3805,7 +3805,7 @@ namespace fisheye @param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or vector\. @param affine - @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. + @param K Camera intrinsic matrix \f$\cameramatrix{K}\f$. @param D Input vector of distortion coefficients \f$\distcoeffsfisheye\f$. @param alpha The skew coefficient. @param jacobian Optional output 2Nx15 jacobian matrix of derivatives of image points with respect @@ -3829,7 +3829,7 @@ namespace fisheye @param undistorted Array of object points, 1xN/Nx1 2-channel (or vector\ ), where N is the number of points in the view. - @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. + @param K Camera intrinsic matrix \f$\cameramatrix{K}\f$. @param D Input vector of distortion coefficients \f$\distcoeffsfisheye\f$. @param alpha The skew coefficient. @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector\ . @@ -3841,12 +3841,12 @@ namespace fisheye CV_EXPORTS_W void distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0); /** @overload - Overload of distortPoints function to handle cases when undistorted points are got with non-identity + Overload of distortPoints function to handle cases when undistorted points are obtained with non-identity camera matrix, e.g. output of #estimateNewCameraMatrixForUndistortRectify. @param undistorted Array of object points, 1xN/Nx1 2-channel (or vector\ ), where N is the number of points in the view. @param Kundistorted Camera intrinsic matrix used as new camera matrix for undistortion. - @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. + @param K Camera intrinsic matrix \f$\cameramatrix{K}\f$. @param D Input vector of distortion coefficients \f$\distcoeffsfisheye\f$. @param alpha The skew coefficient. @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector\ . @@ -3858,7 +3858,7 @@ namespace fisheye @param distorted Array of object points, 1xN/Nx1 2-channel (or vector\ ), where N is the number of points in the view. - @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. + @param K Camera intrinsic matrix \f$\cameramatrix{K}\f$. @param D Input vector of distortion coefficients \f$\distcoeffsfisheye\f$. @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel @@ -3873,7 +3873,7 @@ namespace fisheye /** @brief Computes undistortion and rectification maps for image transform by #remap. If D is empty zero distortion is used, if R or P is empty identity matrixes are used. - @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. + @param K Camera intrinsic matrix \f$\cameramatrix{K}\f$. @param D Input vector of distortion coefficients \f$\distcoeffsfisheye\f$. @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel @@ -3891,7 +3891,7 @@ namespace fisheye @param distorted image with fisheye lens distortion. @param undistorted Output image with compensated fisheye lens distortion. - @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. + @param K Camera intrinsic matrix \f$\cameramatrix{K}\f$. @param D Input vector of distortion coefficients \f$\distcoeffsfisheye\f$. @param Knew Camera intrinsic matrix of the distorted image. By default, it is the identity matrix but you may additionally scale and shift the result by using a different matrix. @@ -3920,7 +3920,7 @@ namespace fisheye /** @brief Estimates new camera intrinsic matrix for undistortion or rectification. - @param K Camera intrinsic matrix \f$cameramatrix{K}\f$. + @param K Camera intrinsic matrix \f$\cameramatrix{K}\f$. @param image_size Size of the image @param D Input vector of distortion coefficients \f$\distcoeffsfisheye\f$. @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 @@ -3947,7 +3947,7 @@ namespace fisheye @ref fisheye::CALIB_USE_INTRINSIC_GUESS is specified, some or all of fx, fy, cx, cy must be initialized before calling the function. @param D Output vector of distortion coefficients \f$\distcoeffsfisheye\f$. - @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view. + @param rvecs Output vector of rotation vectors (see @ref Rodrigues ) estimated for each pattern view. That is, each k-th rotation vector together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern from the model coordinate space (in which object points are specified) to the world coordinate space, that is, a real @@ -4088,7 +4088,7 @@ optimization. It is the \f$max(width,height)/\pi\f$ or the provided \f$f_x\f$, \ - for all the other flags, number of input points must be >= 4 and object points can be in any configuration. @param criteria Termination criteria for internal undistortPoints call. The function interally undistorts points with @ref undistortPoints and call @ref cv::solvePnP, - thus the input are very similar. Check there and Perspective-n-Points is described in @ref calib3d_solvePnP + thus the input are very similar. More information about Perspective-n-Points is described in @ref calib3d_solvePnP for more information. */ CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints, From e2ba36bf9c071debcd318b9065e46efc73a7b3c1 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Mon, 2 Sep 2024 15:26:24 +0300 Subject: [PATCH 08/19] Merge pull request #26093 from sturkmen72:related_issue_22090 Update test_tiff.cpp #26093 related #22090 ### 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. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/imgcodecs/test/test_tiff.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/imgcodecs/test/test_tiff.cpp b/modules/imgcodecs/test/test_tiff.cpp index fb607bf18f..f9b4edaa10 100644 --- a/modules/imgcodecs/test/test_tiff.cpp +++ b/modules/imgcodecs/test/test_tiff.cpp @@ -1096,7 +1096,6 @@ INSTANTIATE_TEST_CASE_P(AllModes, Imgcodecs_Tiff_Modes, testing::ValuesIn(all_mo TEST(Imgcodecs_Tiff_Modes, write_multipage) { const string root = cvtest::TS::ptr()->get_data_path(); - const string filename = root + "readwrite/multipage.tif"; const string page_files[] = { "readwrite/multipage_p1.tif", "readwrite/multipage_p2.tif", @@ -1109,7 +1108,7 @@ TEST(Imgcodecs_Tiff_Modes, write_multipage) vector pages; for (size_t i = 0; i < page_count; i++) { - const Mat page = imread(root + page_files[i]); + const Mat page = imread(root + page_files[i], IMREAD_REDUCED_GRAYSCALE_8 + (int)i); pages.push_back(page); } From 3995ad8458df5a2f4cbc8de355d516eb5ad86e84 Mon Sep 17 00:00:00 2001 From: Letu Ren Date: Tue, 3 Sep 2024 10:54:10 +0800 Subject: [PATCH 09/19] Make T a math symbol --- doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.markdown b/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.markdown index df6df1afc5..656343446d 100644 --- a/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.markdown +++ b/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.markdown @@ -72,7 +72,7 @@ Theory -# We mentioned that an Affine Transformation is basically a **relation** between two images. The information about this relation can come, roughly, in two ways: - -# We know both \f$X\f$ and T and we also know that they are related. Then our task is to find \f$M\f$ + -# We know both \f$X\f$ and \f$T\f$ and we also know that they are related. Then our task is to find \f$M\f$ -# We know \f$M\f$ and \f$X\f$. To obtain \f$T\f$ we only need to apply \f$T = M \cdot X\f$. Our information for \f$M\f$ may be explicit (i.e. have the 2-by-3 matrix) or it can come as a geometric relation between points. From 88f99edc65b45d69492fa38ae31e3db3f446b3a8 Mon Sep 17 00:00:00 2001 From: tingboliao <33657473+tingboliao@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:56:37 +0800 Subject: [PATCH 10/19] Merge pull request #26071 from tingboliao:4.x Remove the redundant codes of cv::convertMaps and mRGBA2RGBA #26071 (1) cv::convertMaps: the branch [else if( m1type == CV_32FC2 && dstm1type == CV_16SC2 ) if( nninterpolate )] is unreachable, as the condition is satisfied in lines 1959 to 1961, calculated in advance and return directly. (2) mRGBA2RGBA: dst[0], dst[1], dst[2] and dst[3] is calculated repeatedly. Introduced in https://github.com/opencv/opencv/pull/13440 ### 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 --- modules/imgproc/src/color_rgb.simd.hpp | 5 -- modules/imgproc/src/imgwarp.cpp | 85 ++++++++++---------------- 2 files changed, 33 insertions(+), 57 deletions(-) diff --git a/modules/imgproc/src/color_rgb.simd.hpp b/modules/imgproc/src/color_rgb.simd.hpp index ca39d8a908..40e3854460 100644 --- a/modules/imgproc/src/color_rgb.simd.hpp +++ b/modules/imgproc/src/color_rgb.simd.hpp @@ -1088,11 +1088,6 @@ struct mRGBA2RGBA uchar v3_half = v3 / 2; - dst[0] = (v3==0)? 0 : (v0 * max_val + v3_half) / v3; - dst[1] = (v3==0)? 0 : (v1 * max_val + v3_half) / v3; - dst[2] = (v3==0)? 0 : (v2 * max_val + v3_half) / v3; - dst[3] = v3; - dst[0] = (v3==0)? 0 : saturate_cast((v0 * max_val + v3_half) / v3); dst[1] = (v3==0)? 0 : saturate_cast((v1 * max_val + v3_half) / v3); dst[2] = (v3==0)? 0 : saturate_cast((v2 * max_val + v3_half) / v3); diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index 4e4d718da3..289d09febd 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -2082,65 +2082,46 @@ void cv::convertMaps( InputArray _map1, InputArray _map2, } else if( m1type == CV_32FC2 && dstm1type == CV_16SC2 ) { - if( nninterpolate ) + #if CV_TRY_SSE4_1 + if( useSSE4_1 ) + opt_SSE4_1::convertMaps_32f2c16s_SSE41(src1f, dst1, dst2, size.width); + else + #endif { #if CV_SIMD128 - int span = VTraits::vlanes(); { - for( ; x <= (size.width << 1) - span * 2; x += span * 2 ) - v_store(dst1 + x, v_pack(v_round(v_load(src1f + x)), - v_round(v_load(src1f + x + span)))); + v_float32x4 v_scale = v_setall_f32((float)INTER_TAB_SIZE); + v_int32x4 v_mask = v_setall_s32(INTER_TAB_SIZE - 1); + v_int32x4 v_scale3 = v_setall_s32(INTER_TAB_SIZE); + int span = VTraits::vlanes(); + for (; x <= size.width - span; x += span ) + { + v_float32x4 v_src0[2], v_src1[2]; + v_load_deinterleave(src1f + (x << 1), v_src0[0], v_src0[1]); + v_load_deinterleave(src1f + (x << 1) + span, v_src1[0], v_src1[1]); + v_int32x4 v_ix0 = v_round(v_mul(v_src0[0], v_scale)); + v_int32x4 v_ix1 = v_round(v_mul(v_src1[0], v_scale)); + v_int32x4 v_iy0 = v_round(v_mul(v_src0[1], v_scale)); + v_int32x4 v_iy1 = v_round(v_mul(v_src1[1], v_scale)); + + v_int16x8 v_dst[2]; + v_dst[0] = v_pack(v_shr(v_ix0), v_shr(v_ix1)); + v_dst[1] = v_pack(v_shr(v_iy0), v_shr(v_iy1)); + v_store_interleave(dst1 + (x << 1), v_dst[0], v_dst[1]); + + v_store(dst2 + x, v_pack_u( + v_muladd(v_scale3, (v_and(v_iy0, v_mask)), (v_and(v_ix0, v_mask))), + v_muladd(v_scale3, (v_and(v_iy1, v_mask)), (v_and(v_ix1, v_mask))))); + } } #endif for( ; x < size.width; x++ ) { - dst1[x*2] = saturate_cast(src1f[x*2]); - dst1[x*2+1] = saturate_cast(src1f[x*2+1]); - } - } - else - { - #if CV_TRY_SSE4_1 - if( useSSE4_1 ) - opt_SSE4_1::convertMaps_32f2c16s_SSE41(src1f, dst1, dst2, size.width); - else - #endif - { - #if CV_SIMD128 - { - v_float32x4 v_scale = v_setall_f32((float)INTER_TAB_SIZE); - v_int32x4 v_mask = v_setall_s32(INTER_TAB_SIZE - 1); - v_int32x4 v_scale3 = v_setall_s32(INTER_TAB_SIZE); - int span = VTraits::vlanes(); - for (; x <= size.width - span; x += span ) - { - v_float32x4 v_src0[2], v_src1[2]; - v_load_deinterleave(src1f + (x << 1), v_src0[0], v_src0[1]); - v_load_deinterleave(src1f + (x << 1) + span, v_src1[0], v_src1[1]); - v_int32x4 v_ix0 = v_round(v_mul(v_src0[0], v_scale)); - v_int32x4 v_ix1 = v_round(v_mul(v_src1[0], v_scale)); - v_int32x4 v_iy0 = v_round(v_mul(v_src0[1], v_scale)); - v_int32x4 v_iy1 = v_round(v_mul(v_src1[1], v_scale)); - - v_int16x8 v_dst[2]; - v_dst[0] = v_pack(v_shr(v_ix0), v_shr(v_ix1)); - v_dst[1] = v_pack(v_shr(v_iy0), v_shr(v_iy1)); - v_store_interleave(dst1 + (x << 1), v_dst[0], v_dst[1]); - - v_store(dst2 + x, v_pack_u( - v_muladd(v_scale3, (v_and(v_iy0, v_mask)), (v_and(v_ix0, v_mask))), - v_muladd(v_scale3, (v_and(v_iy1, v_mask)), (v_and(v_ix1, v_mask))))); - } - } - #endif - for( ; x < size.width; x++ ) - { - int ix = saturate_cast(src1f[x*2]*INTER_TAB_SIZE); - int iy = saturate_cast(src1f[x*2+1]*INTER_TAB_SIZE); - dst1[x*2] = saturate_cast(ix >> INTER_BITS); - dst1[x*2+1] = saturate_cast(iy >> INTER_BITS); - dst2[x] = (ushort)((iy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (ix & (INTER_TAB_SIZE-1))); - } + int ix = saturate_cast(src1f[x*2]*INTER_TAB_SIZE); + int iy = saturate_cast(src1f[x*2+1]*INTER_TAB_SIZE); + dst1[x*2] = saturate_cast(ix >> INTER_BITS); + dst1[x*2+1] = saturate_cast(iy >> INTER_BITS); + dst2[x] = (ushort)((iy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (ix & (INTER_TAB_SIZE-1))); } } } From 8561f45c2a36f6d3cdda41844c389b59445d0b22 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Tue, 3 Sep 2024 14:16:22 +0200 Subject: [PATCH 11/19] Merge pull request #26084 from vrabaud:avif_check Avoid uninitialized value read in resize. #26084 When there is no point falling right, an hypothetical value is computed (but unused) using an uninitialized ofst. This triggers warnings in the sanitizers. Including those values in the for loops is also possible but messy when SIMD is involved. ### 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 --- modules/imgproc/src/resize.cpp | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp index 7e45f1e0f4..229b7f3ca5 100644 --- a/modules/imgproc/src/resize.cpp +++ b/modules/imgproc/src/resize.cpp @@ -95,6 +95,10 @@ static void hlineResize(ET* src, int cn, int *ofst, FT* m, FT* dst, int dst_min, } } } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } ET* src_last = src + cn*ofst[dst_width - 1]; for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point { @@ -126,6 +130,10 @@ template struct hline ET* px = src + ofst[i]; *(dst++) = m[0] * px[0] + m[1] * px[1]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + ofst[dst_width - 1])[0]; for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point { @@ -150,6 +158,10 @@ template struct hline *(dst++) = m[0] * px[0] + m[1] * px[2]; *(dst++) = m[0] * px[1] + m[1] * px[3]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + 2*ofst[dst_width - 1])[0]; src1 = (src + 2*ofst[dst_width - 1])[1]; for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point @@ -178,6 +190,10 @@ template struct hline *(dst++) = m[0] * px[1] + m[1] * px[4]; *(dst++) = m[0] * px[2] + m[1] * px[5]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + 3*ofst[dst_width - 1])[0]; src1 = (src + 3*ofst[dst_width - 1])[1]; src2 = (src + 3*ofst[dst_width - 1])[2]; @@ -210,6 +226,10 @@ template struct hline *(dst++) = m[0] * px[2] + m[1] * px[6]; *(dst++) = m[0] * px[3] + m[1] * px[7]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + 4*ofst[dst_width - 1])[0]; src1 = (src + 4*ofst[dst_width - 1])[1]; src2 = (src + 4*ofst[dst_width - 1])[2]; @@ -238,6 +258,10 @@ template struct hline ET* px = src + ofst[i]; *(dst++) = m[0] * src[0] + m[1] * src[1] + m[2] * src[2] + m[3] * src[3]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + ofst[dst_width - 1])[0]; for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point { @@ -262,6 +286,10 @@ template struct hline *(dst++) = m[0] * src[0] + m[1] * src[2] + m[2] * src[4] + m[3] * src[6]; *(dst++) = m[0] * src[1] + m[1] * src[3] + m[2] * src[5] + m[3] * src[7]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + 2*ofst[dst_width - 1])[0]; src1 = (src + 2*ofst[dst_width - 1])[1]; for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point @@ -290,6 +318,10 @@ template struct hline *(dst++) = m[0] * src[1] + m[1] * src[4] + m[2] * src[7] + m[3] * src[10]; *(dst++) = m[0] * src[2] + m[1] * src[5] + m[2] * src[8] + m[3] * src[11]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + 3*ofst[dst_width - 1])[0]; src1 = (src + 3*ofst[dst_width - 1])[1]; src2 = (src + 3*ofst[dst_width - 1])[2]; @@ -322,6 +354,10 @@ template struct hline *(dst++) = m[0] * src[2] + m[1] * src[6] + m[2] * src[10] + m[3] * src[14]; *(dst++) = m[0] * src[3] + m[1] * src[7] + m[2] * src[11] + m[3] * src[15]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src0 = (src + 4*ofst[dst_width - 1])[0]; src1 = (src + 4*ofst[dst_width - 1])[1]; src2 = (src + 4*ofst[dst_width - 1])[2]; @@ -383,6 +419,10 @@ void hlineResizeCn(uint8_t* src, int, int *o uint8_t* px = src + ofst[i]; *(dst++) = m[0] * px[0] + m[1] * px[1]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src_0 = (src + ofst[dst_width - 1])[0]; #if (CV_SIMD || CV_SIMD_SCALABLE) v_src_0 = vx_setall_u16(*((uint16_t*)&src_0)); @@ -439,6 +479,10 @@ void hlineResizeCn(uint8_t* src, int, int *o *(dst++) = m[0] * px[0] + m[1] * px[2]; *(dst++) = m[0] * px[1] + m[1] * px[3]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } ((ufixedpoint16*)(srccn.w))[0] = (src + 2 * ofst[dst_width - 1])[0]; ((ufixedpoint16*)(srccn.w))[1] = (src + 2 * ofst[dst_width - 1])[1]; #if (CV_SIMD || CV_SIMD_SCALABLE) v_srccn = v_reinterpret_as_u16(vx_setall_u32(srccn.d)); @@ -511,6 +555,10 @@ void hlineResizeCn(uint8_t* src, int, int *o *(dst++) = m[0] * px[1] + m[1] * px[4]; *(dst++) = m[0] * px[2] + m[1] * px[5]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } ((ufixedpoint16*)(srccn.w))[0] = (src + 3*ofst[dst_width - 1])[0]; ((ufixedpoint16*)(srccn.w))[1] = (src + 3*ofst[dst_width - 1])[1]; ((ufixedpoint16*)(srccn.w))[2] = (src + 3*ofst[dst_width - 1])[2]; @@ -584,6 +632,10 @@ void hlineResizeCn(uint8_t* src, int, int *o *(dst++) = m[0] * px[2] + m[1] * px[6]; *(dst++) = m[0] * px[3] + m[1] * px[7]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } ((ufixedpoint16*)(srccn.w))[0] = (src + 4 * ofst[dst_width - 1])[0]; ((ufixedpoint16*)(srccn.w))[1] = (src + 4 * ofst[dst_width - 1])[1]; ((ufixedpoint16*)(srccn.w))[2] = (src + 4 * ofst[dst_width - 1])[2]; ((ufixedpoint16*)(srccn.w))[3] = (src + 4 * ofst[dst_width - 1])[3]; #if (CV_SIMD || CV_SIMD_SCALABLE) @@ -635,6 +687,10 @@ void hlineResizeCn(uint16_t* src, int, int uint16_t* px = src + ofst[i]; *(dst++) = m[0] * px[0] + m[1] * px[1]; } + // Avoid reading a potentially unset ofst, leading to a random memory read. + if (i >= dst_width) { + return; + } src_0 = (src + ofst[dst_width - 1])[0]; #if (CV_SIMD || CV_SIMD_SCALABLE) v_src_0 = vx_setall_u32(*((uint32_t*)&src_0)); From 32d3d6fa9745d76a2dba2524151f4beb8e45174e Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Tue, 3 Sep 2024 16:30:49 +0300 Subject: [PATCH 12/19] build: minor changes for cmake 3.30 and some cleanup --- CMakeLists.txt | 87 ++++++----------------------- cmake/OpenCVDetectCXXCompiler.cmake | 8 ++- cmake/OpenCVDownload.cmake | 5 +- 3 files changed, 29 insertions(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4ea325d69..623c2b9540 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,14 +121,20 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIC}) ocv_cmake_hook(PRE_CMAKE_BOOTSTRAP) # Bootstrap CMake system: setup CMAKE_SYSTEM_NAME and other vars + +# workaround: https://gitlab.kitware.com/cmake/cmake/-/issues/20989 if(OPENCV_WORKAROUND_CMAKE_20989) set(CMAKE_SYSTEM_PROCESSOR_BACKUP ${CMAKE_SYSTEM_PROCESSOR}) endif() -enable_language(CXX C) + +project(OpenCV CXX C) + if(OPENCV_WORKAROUND_CMAKE_20989) set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR_BACKUP}) endif() +enable_testing() + ocv_cmake_hook(POST_CMAKE_BOOTSTRAP) if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE) @@ -151,10 +157,6 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # https://cmake.org/cmake/help/ endif() endif() -enable_testing() - -project(OpenCV CXX C) - if(MSVC) set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE) endif() @@ -163,70 +165,30 @@ ocv_cmake_eval(DEBUG_PRE ONCE) ocv_clear_vars(OpenCVModules_TARGETS) -include(cmake/OpenCVDownload.cmake) - -set(BUILD_LIST "" CACHE STRING "Build only listed modules (comma-separated, e.g. 'videoio,dnn,ts')") - # ---------------------------------------------------------------------------- -# Break in case of popular CMake configuration mistakes +# Autodetect if we are in a GIT repository # ---------------------------------------------------------------------------- -if(NOT CMAKE_SIZEOF_VOID_P GREATER 0) - message(FATAL_ERROR "CMake fails to determine the bitness of the target platform. - Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.") +find_host_package(Git QUIET) + +if(NOT DEFINED OPENCV_VCSVERSION AND GIT_FOUND) + ocv_git_describe(OPENCV_VCSVERSION "${OpenCV_SOURCE_DIR}") +elseif(NOT DEFINED OPENCV_VCSVERSION) + # We don't have git: + set(OPENCV_VCSVERSION "unknown") endif() +include(cmake/OpenCVDownload.cmake) + # ---------------------------------------------------------------------------- # Detect compiler and target platform architecture # ---------------------------------------------------------------------------- include(cmake/OpenCVDetectCXXCompiler.cmake) ocv_cmake_hook(POST_DETECT_COMPILER) -# Add these standard paths to the search paths for FIND_LIBRARY -# to find libraries from these locations first -if(UNIX AND NOT ANDROID) - if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8) - if(EXISTS /lib64) - list(APPEND CMAKE_LIBRARY_PATH /lib64) - else() - list(APPEND CMAKE_LIBRARY_PATH /lib) - endif() - if(EXISTS /usr/lib64) - list(APPEND CMAKE_LIBRARY_PATH /usr/lib64) - else() - list(APPEND CMAKE_LIBRARY_PATH /usr/lib) - endif() - elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4) - if(EXISTS /lib32) - list(APPEND CMAKE_LIBRARY_PATH /lib32) - else() - list(APPEND CMAKE_LIBRARY_PATH /lib) - endif() - if(EXISTS /usr/lib32) - list(APPEND CMAKE_LIBRARY_PATH /usr/lib32) - else() - list(APPEND CMAKE_LIBRARY_PATH /usr/lib) - endif() - endif() -endif() - -# Add these standard paths to the search paths for FIND_PATH -# to find include files from these locations first -if(MINGW) - if(EXISTS /mingw) - list(APPEND CMAKE_INCLUDE_PATH /mingw) - endif() - if(EXISTS /mingw32) - list(APPEND CMAKE_INCLUDE_PATH /mingw32) - endif() - if(EXISTS /mingw64) - list(APPEND CMAKE_INCLUDE_PATH /mingw64) - endif() -endif() - # ---------------------------------------------------------------------------- # OpenCV cmake options # ---------------------------------------------------------------------------- - +set(BUILD_LIST "" CACHE STRING "Build only listed modules (comma-separated, e.g. 'videoio,dnn,ts')") OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" OFF) # 3rd party libs @@ -660,19 +622,6 @@ ocv_include_directories(${OPENCV_CONFIG_FILE_INCLUDE_DIR}) # ---------------------------------------------------------------------------- set(OPENCV_EXTRA_MODULES_PATH "" CACHE PATH "Where to look for additional OpenCV modules (can be ;-separated list of paths)") -# ---------------------------------------------------------------------------- -# Autodetect if we are in a GIT repository -# ---------------------------------------------------------------------------- -find_host_package(Git QUIET) - -if(NOT DEFINED OPENCV_VCSVERSION AND GIT_FOUND) - ocv_git_describe(OPENCV_VCSVERSION "${OpenCV_SOURCE_DIR}") -elseif(NOT DEFINED OPENCV_VCSVERSION) - # We don't have git: - set(OPENCV_VCSVERSION "unknown") -endif() - - # ---------------------------------------------------------------------------- # OpenCV compiler and linker options # ---------------------------------------------------------------------------- diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake index 448afd46ea..77c9e5c985 100644 --- a/cmake/OpenCVDetectCXXCompiler.cmake +++ b/cmake/OpenCVDetectCXXCompiler.cmake @@ -83,6 +83,10 @@ if(NOT DEFINED CMAKE_SIZEOF_VOID_P AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SIZEOF_VOID_P) message(WARNING "OpenCV: CMAKE_SIZEOF_VOID_P is not defined. Perhaps CMake toolchain is broken") endif() +if(NOT CMAKE_SIZEOF_VOID_P GREATER 0) + message(FATAL_ERROR "CMake fails to determine the bitness of the target platform. + Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.") +endif() message(STATUS "Detected processor: ${CMAKE_SYSTEM_PROCESSOR}") if(OPENCV_SKIP_SYSTEM_PROCESSOR_DETECTION) @@ -156,8 +160,10 @@ elseif(MSVC) set(OpenCV_ARCH "ARM") elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") set(OpenCV_ARCH "x64") + elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") + set(OpenCV_ARCH "x86") else() - set(OpenCV_ARCH x86) + message(FATAL_ERROR "Failed to determine system architecture") endif() if(MSVC_VERSION EQUAL 1400) diff --git a/cmake/OpenCVDownload.cmake b/cmake/OpenCVDownload.cmake index 3e46515537..40e48d7465 100644 --- a/cmake/OpenCVDownload.cmake +++ b/cmake/OpenCVDownload.cmake @@ -40,11 +40,14 @@ file(REMOVE "${OPENCV_DOWNLOAD_WITH_WGET}") ocv_check_environment_variables(OPENCV_DOWNLOAD_MIRROR_ID) function(ocv_init_download_mirror) + if(NOT GIT_FOUND) + return() + endif() if(NOT DEFINED OPENCV_DOWNLOAD_MIRROR_ID) # Run `git remote get-url origin` to get remote source execute_process( COMMAND - git remote get-url origin + ${GIT_EXECUTABLE} remote get-url origin WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} RESULT_VARIABLE From 9ef574a213796e24116a8ee5c864ac7f6e562db5 Mon Sep 17 00:00:00 2001 From: Rostislav Vasilikhin Date: Thu, 5 Sep 2024 03:34:35 +0200 Subject: [PATCH 13/19] added bit-exact tests for RGB2Gray --- modules/imgproc/test/test_color.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/test/test_color.cpp b/modules/imgproc/test/test_color.cpp index 3bebb563de..a1f70103be 100644 --- a/modules/imgproc/test/test_color.cpp +++ b/modules/imgproc/test/test_color.cpp @@ -455,7 +455,7 @@ void CV_ColorGrayTest::get_test_array_types_and_sizes( int test_case_idx, vector double CV_ColorGrayTest::get_success_error_level( int /*test_case_idx*/, int i, int j ) { int depth = test_mat[i][j].depth(); - return depth == CV_8U ? 2 : depth == CV_16U ? 16 : 1e-5; + return depth == CV_8U ? 1 : depth == CV_16U ? 2 : 1e-5; } @@ -2844,6 +2844,11 @@ void runCvtColorBitExactCheck(ColorConversionCodes code, int inputType, uint32_t } } +TEST(Imgproc_cvtColor_BE, COLOR_RGB2GRAY) { runCvtColorBitExactCheck(COLOR_RGB2GRAY, CV_8UC3, 0x416bd44a); } +TEST(Imgproc_cvtColor_BE, COLOR_RGBA2GRAY) { runCvtColorBitExactCheck(COLOR_RGBA2GRAY, CV_8UC3, 0x416bd44a); } +TEST(Imgproc_cvtColor_BE, COLOR_BGR2GRAY) { runCvtColorBitExactCheck(COLOR_BGR2GRAY, CV_8UC3, 0x3008c6b8); } +TEST(Imgproc_cvtColor_BE, COLOR_BGRA2GRAY) { runCvtColorBitExactCheck(COLOR_BGRA2GRAY, CV_8UC3, 0x3008c6b8); } + TEST(Imgproc_cvtColor_BE, COLOR_BGR2YUV) { runCvtColorBitExactCheck(COLOR_BGR2YUV, CV_8UC3, 0xc2cbcfda); } TEST(Imgproc_cvtColor_BE, COLOR_RGB2YUV) { runCvtColorBitExactCheck(COLOR_RGB2YUV, CV_8UC3, 0x4e98e757); } TEST(Imgproc_cvtColor_BE, COLOR_YUV2BGR) { runCvtColorBitExactCheck(COLOR_YUV2BGR, CV_8UC3, 0xb2c62a3f); } From c0a0852f053cee5e30c6fd6ba3779d4b7d490716 Mon Sep 17 00:00:00 2001 From: Rostislav Vasilikhin Date: Thu, 5 Sep 2024 05:46:17 +0200 Subject: [PATCH 14/19] added more data types for warpAffine() perf tests --- modules/imgproc/perf/perf_warp.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/modules/imgproc/perf/perf_warp.cpp b/modules/imgproc/perf/perf_warp.cpp index 688d449a55..cb4c32c905 100644 --- a/modules/imgproc/perf/perf_warp.cpp +++ b/modules/imgproc/perf/perf_warp.cpp @@ -12,7 +12,7 @@ CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR) CV_ENUM(InterTypeExtended, INTER_NEAREST, INTER_LINEAR, WARP_RELATIVE_MAP) CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH) -typedef TestBaseWithParam< tuple > TestWarpAffine; +typedef TestBaseWithParam< tuple > TestWarpAffine; typedef TestBaseWithParam< tuple > TestWarpPerspective; typedef TestBaseWithParam< tuple > TestWarpPerspectiveNear_t; typedef TestBaseWithParam< tuple > TestRemap; @@ -21,6 +21,7 @@ void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode, boo PERF_TEST_P( TestWarpAffine, WarpAffine, Combine( + Values(CV_8UC1, CV_8UC4), Values( szVGA, sz720p, sz1080p ), InterType::all(), BorderMode::all() @@ -28,13 +29,14 @@ PERF_TEST_P( TestWarpAffine, WarpAffine, ) { Size sz, szSrc(512, 512); - int borderMode, interType; - sz = get<0>(GetParam()); - interType = get<1>(GetParam()); - borderMode = get<2>(GetParam()); + int borderMode, interType, dataType; + dataType = get<0>(GetParam()); + sz = get<1>(GetParam()); + interType = get<2>(GetParam()); + borderMode = get<3>(GetParam()); Scalar borderColor = Scalar::all(150); - Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4); + Mat src(szSrc, dataType), dst(sz, dataType); cvtest::fillGradient(src); if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1); Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2); @@ -47,6 +49,7 @@ PERF_TEST_P( TestWarpAffine, WarpAffine, PERF_TEST_P(TestWarpAffine, DISABLED_WarpAffine_ovx, Combine( + Values(CV_8UC1, CV_8UC4), Values(szVGA, sz720p, sz1080p), InterType::all(), BorderMode::all() @@ -54,13 +57,16 @@ PERF_TEST_P(TestWarpAffine, DISABLED_WarpAffine_ovx, ) { Size sz, szSrc(512, 512); - int borderMode, interType; - sz = get<0>(GetParam()); - interType = get<1>(GetParam()); - borderMode = get<2>(GetParam()); + int borderMode, interType, dataType; + + dataType = get<0>(GetParam()); + sz = get<1>(GetParam()); + interType = get<2>(GetParam()); + borderMode = get<3>(GetParam()); + Scalar borderColor = Scalar::all(150); - Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1); + Mat src(szSrc, dataType), dst(sz, dataType); cvtest::fillGradient(src); if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1); Mat warpMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2); From b743edd466dd47878a60a749b608fad5e34632cf Mon Sep 17 00:00:00 2001 From: Letu Ren Date: Thu, 5 Sep 2024 16:54:32 +0800 Subject: [PATCH 15/19] Update remap tutorial - Make x a math symbol - Fix a typo --- doc/tutorials/imgproc/imgtrans/remap/remap.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/tutorials/imgproc/imgtrans/remap/remap.markdown b/doc/tutorials/imgproc/imgtrans/remap/remap.markdown index fa6825f791..21547b7311 100644 --- a/doc/tutorials/imgproc/imgtrans/remap/remap.markdown +++ b/doc/tutorials/imgproc/imgtrans/remap/remap.markdown @@ -45,7 +45,7 @@ Theory ![](images/Remap_Tutorial_Theory_0.jpg) - observe how the red circle changes positions with respect to x (considering \f$x\f$ the horizontal + observe how the red circle changes positions with respect to \f$x\f$ (considering \f$x\f$ the horizontal direction): ![](images/Remap_Tutorial_Theory_1.jpg) @@ -62,19 +62,19 @@ Code - Wait for the user to exit the program @add_toggle_cpp -- The tutorial code's is shown lines below. You can also download it from +- The tutorial code is shown lines below. You can also download it from [here](https://github.com/opencv/opencv/tree/4.x/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp) @include samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp @end_toggle @add_toggle_java -- The tutorial code's is shown lines below. You can also download it from +- The tutorial code is shown lines below. You can also download it from [here](https://github.com/opencv/opencv/tree/4.x/samples/java/tutorial_code/ImgTrans/remap/RemapDemo.java) @include samples/java/tutorial_code/ImgTrans/remap/RemapDemo.java @end_toggle @add_toggle_python -- The tutorial code's is shown lines below. You can also download it from +- The tutorial code is shown lines below. You can also download it from [here](https://github.com/opencv/opencv/tree/4.x/samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py) @include samples/python/tutorial_code/ImgTrans/remap/Remap_Demo.py @end_toggle From dbd53fe89ad0b92fecdef2c1ee5ac51195cfa929 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Thu, 5 Sep 2024 19:49:50 +0300 Subject: [PATCH 16/19] RISC-V: remove statically initialized global RVV variables --- .../opencv2/core/hal/intrin_rvv_scalable.hpp | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/modules/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp b/modules/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp index c8d4ec37b5..28b0ad8a82 100644 --- a/modules/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp +++ b/modules/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp @@ -52,22 +52,6 @@ using uint = unsigned int; using uint64 = unsigned long int; using int64 = long int; -static const int __cv_rvv_e8m1_nlanes = __riscv_vsetvlmax_e8m1(); -static const int __cv_rvv_e16m1_nlanes = __riscv_vsetvlmax_e16m1(); -static const int __cv_rvv_e32m1_nlanes = __riscv_vsetvlmax_e32m1(); -static const int __cv_rvv_e64m1_nlanes = __riscv_vsetvlmax_e64m1(); -static const int __cv_rvv_e8m2_nlanes = __riscv_vsetvlmax_e8m2(); -static const int __cv_rvv_e16m2_nlanes = __riscv_vsetvlmax_e16m2(); -static const int __cv_rvv_e32m2_nlanes = __riscv_vsetvlmax_e32m2(); -static const int __cv_rvv_e64m2_nlanes = __riscv_vsetvlmax_e64m2(); -static const int __cv_rvv_e8m4_nlanes = __riscv_vsetvlmax_e8m4(); -static const int __cv_rvv_e16m4_nlanes = __riscv_vsetvlmax_e16m4(); -static const int __cv_rvv_e32m4_nlanes = __riscv_vsetvlmax_e32m4(); -static const int __cv_rvv_e64m4_nlanes = __riscv_vsetvlmax_e64m4(); -static const int __cv_rvv_e8m8_nlanes = __riscv_vsetvlmax_e8m8(); -static const int __cv_rvv_e16m8_nlanes = __riscv_vsetvlmax_e16m8(); -static const int __cv_rvv_e32m8_nlanes = __riscv_vsetvlmax_e32m8(); -static const int __cv_rvv_e64m8_nlanes = __riscv_vsetvlmax_e64m8(); template struct VTraits; @@ -76,7 +60,7 @@ struct VTraits; template <> \ struct VTraits \ { \ - static inline int vlanes() { return __cv_rvv_##SUF##_nlanes; } \ + static inline int vlanes() { return __riscv_vsetvlmax_##SUF(); } \ using lane_type = TYP; \ static const int max_nlanes = CV_RVV_MAX_VLEN/SZ; \ }; @@ -1813,8 +1797,8 @@ inline int v_scan_forward(const v_float64& a) // mask: {0,0,0,1, ...} -> {T,T,T,F, ...} #define OPENCV_HAL_IMPL_RVV_PACK_TRIPLETS(_Tpvec, v_trunc) \ inline _Tpvec v_pack_triplets(const _Tpvec& vec) { \ - size_t vl = __cv_rvv_e8m1_nlanes; \ - vuint32m1_t one = __riscv_vmv_v_x_u32m1(1, __cv_rvv_e32m1_nlanes); \ + size_t vl = VTraits::vlanes(); \ + vuint32m1_t one = __riscv_vmv_v_x_u32m1(1, VTraits::vlanes()); \ vuint8m1_t zero = __riscv_vmv_v_x_u8m1(0, vl); \ vuint8m1_t mask = __riscv_vreinterpret_u8m1(one); \ return __riscv_vcompress(vec, __riscv_vmseq(v_trunc(__riscv_vslideup(zero, mask, 3, vl)), 0, vl), VTraits<_Tpvec>::vlanes()); \ From 7590813b693e94ca608185320bde1493ccc0abfc Mon Sep 17 00:00:00 2001 From: Rostislav Vasilikhin Date: Fri, 6 Sep 2024 07:26:00 +0200 Subject: [PATCH 17/19] Merge pull request #26115 from savuor:rv/flip_ocl_dtypes Added more data types to OCL flip() and rotate() perf tests #26115 Connected PR with updated sanity data: https://github.com/opencv/opencv_extra/pull/1206 ### 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 - [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 --- modules/core/perf/opencl/perf_arithm.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/core/perf/opencl/perf_arithm.cpp b/modules/core/perf/opencl/perf_arithm.cpp index cb14aa92b1..42f5244b7f 100644 --- a/modules/core/perf/opencl/perf_arithm.cpp +++ b/modules/core/perf/opencl/perf_arithm.cpp @@ -357,7 +357,8 @@ typedef TestBaseWithParam FlipFixture; OCL_PERF_TEST_P(FlipFixture, Flip, ::testing::Combine(OCL_TEST_SIZES, - OCL_TEST_TYPES, FlipType::all())) + ::testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_32FC1, CV_32FC4), + FlipType::all())) { const FlipParams params = GetParam(); const Size srcSize = get<0>(params); @@ -387,7 +388,9 @@ typedef tuple RotateParams; typedef TestBaseWithParam RotateFixture; OCL_PERF_TEST_P(RotateFixture, rotate, - ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, RotateType::all())) + ::testing::Combine(OCL_TEST_SIZES, + ::testing::Values(CV_8UC1, CV_8UC2, CV_8UC4, CV_32FC1, CV_32FC4), + RotateType::all())) { const RotateParams params = GetParam(); const Size srcSize = get<0>(params); From 307dc2a298e7a53d2e852dc14fd6bac036961f39 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 6 Sep 2024 15:13:55 +0300 Subject: [PATCH 18/19] Excluded nullptr leak to arithmetic HAL got from empty Mat. --- modules/core/src/arithm.cpp | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 08e1f613ef..72d5806ebb 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -997,6 +997,13 @@ void cv::add( InputArray src1, InputArray src2, OutputArray dst, { CV_INSTRUMENT_REGION(); + CV_Assert(src1.empty() == src2.empty()); + if (src1.empty() && src2.empty()) + { + dst.release(); + return; + } + arithm_op(src1, src2, dst, mask, dtype, getAddTab(), false, 0, OCL_OP_ADD ); } @@ -1005,6 +1012,13 @@ void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst, { CV_INSTRUMENT_REGION(); + CV_Assert(_src1.empty() == _src2.empty()); + if (_src1.empty() && _src2.empty()) + { + _dst.release(); + return; + } + ExtendedTypeFunc subExtFunc = getSubExtFunc(_src1.depth(), _src2.depth(), dtype < 0 ? _dst.depth() : dtype); arithm_op(_src1, _src2, _dst, mask, dtype, getSubTab(), false, 0, OCL_OP_SUB, /* extendedFunc */ subExtFunc); @@ -1014,6 +1028,13 @@ void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst ) { CV_INSTRUMENT_REGION(); + CV_Assert(src1.empty() == src2.empty()); + if (src1.empty() && src2.empty()) + { + dst.release(); + return; + } + arithm_op(src1, src2, dst, noArray(), -1, getAbsDiffTab(), false, 0, OCL_OP_ABSDIFF); } @@ -1131,6 +1152,13 @@ void divide(InputArray src1, InputArray src2, { CV_INSTRUMENT_REGION(); + CV_Assert(src1.empty() == src2.empty()); + if (src1.empty() && src2.empty()) + { + dst.release(); + return; + } + arithm_op(src1, src2, dst, noArray(), dtype, getDivTab(), true, &scale, OCL_OP_DIV_SCALE); } @@ -1139,6 +1167,12 @@ void divide(double scale, InputArray src2, { CV_INSTRUMENT_REGION(); + if (src2.empty()) + { + dst.release(); + return; + } + arithm_op(src2, src2, dst, noArray(), dtype, getRecipTab(), true, &scale, OCL_OP_RECIP_SCALE); } @@ -1172,6 +1206,13 @@ void cv::addWeighted( InputArray src1, double alpha, InputArray src2, { CV_INSTRUMENT_REGION(); + CV_Assert(src1.empty() == src2.empty()); + if (src1.empty() && src2.empty()) + { + dst.release(); + return; + } + double scalars[] = {alpha, beta, gamma}; arithm_op(src1, src2, dst, noArray(), dtype, getAddWeightedTab(), true, scalars, OCL_OP_ADDW); } From 79faf857d988bcbfc993f0a17cd38835d9d243d9 Mon Sep 17 00:00:00 2001 From: pasbi Date: Mon, 9 Sep 2024 07:47:26 +0200 Subject: [PATCH 19/19] Merge pull request #26042 from pasbi:add-PtrStepSz_size Add size() to CUDA PtrStepSz #26042 According to [cppreference.com compiler support table](https://en.cppreference.com/w/cpp/compiler_support/17), `nvcc` supports `[[nodiscard]]` from version 11. ### 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 Related: https://github.com/opencv/opencv/pull/25659 --- modules/core/include/opencv2/core/cuda_types.hpp | 8 ++++++++ modules/core/include/opencv2/core/cvdef.h | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/cuda_types.hpp b/modules/core/include/opencv2/core/cuda_types.hpp index b33f06179d..ddee2f3d59 100644 --- a/modules/core/include/opencv2/core/cuda_types.hpp +++ b/modules/core/include/opencv2/core/cuda_types.hpp @@ -66,6 +66,9 @@ #define __CV_CUDA_HOST_DEVICE__ #endif +#include "opencv2/core/cvdef.h" +#include "opencv2/core.hpp" + namespace cv { namespace cuda @@ -124,6 +127,11 @@ namespace cv int cols; int rows; + + CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ Size size() const { return {cols, rows}; } + CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ T& operator ()(const Point &pos) { return (*this)(pos.y, pos.x); } + CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ const T& operator ()(const Point &pos) const { return (*this)(pos.y, pos.x); } + using PtrStep::operator(); }; typedef PtrStepSz PtrStepSzb; diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index ff1a3d7a5f..a2154b2df2 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -747,7 +747,11 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType) # define __has_cpp_attribute(__x) 0 # endif # if __has_cpp_attribute(nodiscard) -# define CV_NODISCARD_STD [[nodiscard]] +# if defined(__NVCC__) && __CUDACC_VER_MAJOR__ < 12 +# define CV_NODISCARD_STD +# else +# define CV_NODISCARD_STD [[nodiscard]] +# endif # elif __cplusplus >= 201703L // available when compiler is C++17 compliant # define CV_NODISCARD_STD [[nodiscard]]