From d1ff87d94d9307b63276233fea2dcaf21d8e5c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20O=C5=BCa=C5=84ski?= Date: Tue, 20 Jul 2021 13:49:40 +0200 Subject: [PATCH 1/3] Bugfix for solvePnPRansac with SOLVEPNP_ITERATIVE The current implementation overwrites the result rotation and translation in every iteration. If SOLVEPNP_ITERATIVE was run as a refinement it will start from the incorrect initial transformation thus degrading the final outcome. --- modules/calib3d/src/solvepnp.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index ad5c85b222..21a260f720 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -149,12 +149,13 @@ public: int runKernel( InputArray _m1, InputArray _m2, OutputArray _model ) const CV_OVERRIDE { Mat opoints = _m1.getMat(), ipoints = _m2.getMat(); - + Mat iter_rvec = rvec.clone(); + Mat iter_tvec = tvec.clone(); bool correspondence = solvePnP( _m1, _m2, cameraMatrix, distCoeffs, - rvec, tvec, useExtrinsicGuess, flags ); + iter_rvec, iter_tvec, useExtrinsicGuess, flags ); Mat _local_model; - hconcat(rvec, tvec, _local_model); + hconcat(iter_rvec, iter_tvec, _local_model); _local_model.copyTo(_model); return correspondence; @@ -313,7 +314,13 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, ipoints_inliers.resize(npoints1); try { - result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, + if (flags == SOLVEPNP_ITERATIVE && !useExtrinsicGuess) + { + rvec = _local_model.col(0).clone(); + tvec = _local_model.col(1).clone(); + useExtrinsicGuess = true; + } + result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, distCoeffs, rvec, tvec, useExtrinsicGuess, (flags == SOLVEPNP_P3P || flags == SOLVEPNP_AP3P) ? SOLVEPNP_EPNP : flags) ? 1 : -1; } From 7463e9b8bb5004b046a98a219852d53456b7ee02 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Mon, 19 Dec 2022 14:15:34 +0100 Subject: [PATCH 2/3] Even faster CV_PAUSE on SkyLake and above. No need to loop as RDTSC is 3/4 times faster than _mm_pause. --- modules/core/src/parallel_impl.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/core/src/parallel_impl.cpp b/modules/core/src/parallel_impl.cpp index 087b41233b..18667905e2 100644 --- a/modules/core/src/parallel_impl.cpp +++ b/modules/core/src/parallel_impl.cpp @@ -57,9 +57,8 @@ DECLARE_CV_PAUSE static inline void cv_non_sse_mm_pause() { __asm__ __volatile__ ("rep; nop"); } # define _mm_pause cv_non_sse_mm_pause # endif -// 5 * v is meants for backward compatibility: with pre-Skylake CPUs, _mm_pause took 4 or 5 cycles. -// With post-Skylake CPUs, _mm_pause takes 140 cycles. -# define CV_PAUSE(v) do { const uint64_t __delay = 5 * v; uint64_t __init = __rdtsc(); do { _mm_pause(); } while ((__rdtsc() - __init) < __delay); } while (0) +// With Skylake CPUs and above, _mm_pause takes 140 cycles so no need for a loop. +# define CV_PAUSE(v) do { (void)v; _mm_pause(); } while (0) # elif defined __GNUC__ && defined __aarch64__ # define CV_PAUSE(v) do { for (int __delay = (v); __delay > 0; --__delay) { asm volatile("yield" ::: "memory"); } } while (0) # elif defined __GNUC__ && defined __arm__ From 1339c7f30c40f2f480da78d82d5e7c58fddec797 Mon Sep 17 00:00:00 2001 From: Sergei Shutov Date: Wed, 14 Dec 2022 23:28:43 +0200 Subject: [PATCH 3/3] Define the number of dstChannels for Lab, Luv, YCrCb and XYZ conversions --- modules/imgproc/src/color.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/imgproc/src/color.hpp b/modules/imgproc/src/color.hpp index e3c25f08d9..abbd65ec06 100644 --- a/modules/imgproc/src/color.hpp +++ b/modules/imgproc/src/color.hpp @@ -115,6 +115,12 @@ inline int dstChannels(int code) case COLOR_YUV2BGR_YV12: case COLOR_YUV2RGB_YV12: case COLOR_YUV2BGR_IYUV: case COLOR_YUV2RGB_IYUV: case COLOR_YUV2RGB_UYVY: case COLOR_YUV2BGR_UYVY: case COLOR_YUV2RGB_YVYU: case COLOR_YUV2BGR_YVYU: case COLOR_YUV2RGB_YUY2: case COLOR_YUV2BGR_YUY2: + case COLOR_Lab2BGR: case COLOR_Lab2RGB: case COLOR_BGR2Lab: case COLOR_RGB2Lab: + case COLOR_Lab2LBGR: case COLOR_Lab2LRGB: + case COLOR_Luv2BGR: case COLOR_Luv2RGB: case COLOR_BGR2Luv: case COLOR_RGB2Luv: + case COLOR_Luv2LBGR: case COLOR_Luv2LRGB: + case COLOR_YCrCb2BGR: case COLOR_YCrCb2RGB: case COLOR_BGR2YCrCb: case COLOR_RGB2YCrCb: + case COLOR_XYZ2BGR: case COLOR_XYZ2RGB: case COLOR_BGR2XYZ: case COLOR_RGB2XYZ: return 3;