Dataset Viewer
Auto-converted to Parquet Duplicate
instruction
stringclasses
9 values
input
stringlengths
279
5.47k
output
stringlengths
6
9.58k
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
It's enough to specify 16-22
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
let's: 1. put a loop inside parallel_for to handle a range of rows: ``` int nstripes = Hout*C*N; parallel_for_(Range(0, nstripes), [&](const Range& range) { for (int row = range.start; row < range.end; row++) { int n = row/(Hout*C); int c = (row - n*Hout*C)/Hout; int y = row % Hout; if (type == CV_8U && interpolation == NN) { for (int x = 0; x < Wout; x++) { ... } } else if (type == CV_8U && interpolation == LINEAR) { for (int x = 0; x < Wout; x++) { } } ... }); ``` 2. instead of a single loop over x, have a multiple loops that should be put into a template function, depending on the input data type, interpolation method etc. 3. support different data types, at least, 8U, FP16, BF16, FP32. in total, you will have `4 {8U, FP16, BF16, FP32} * 3 {nearest neighbor, bilinear, bicubic} * 1 {2D} == 12` branches.
You are an expert OpenCV code reviewer specializing in performance optimization. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
Make normToPix branchless to facilitate auto vectorization: ``` static inline void normToPix(float nx, float ny, int W, int H, bool align_corners, float& x, float& y) { float delta = float(align_corners); x = ((nx + 1.f)*(W - delta) + (delta - 1.f))*0.5f; y = ((ny + 1.f)*(H - delta) + (delta - 1.f))*0.5f; } ``` basically, you can precompute constant xscale, xdelta, yscale, ydelta, so that the code above is equivalent to ``` static inline void normToPix(float nx, float ny, float xscale, float yscale, float xdelta, float ydelta, float& x, float& y) { x = nx*xscale + xdelta; y = ny*yscale + ydelta; } ``` compiler will _unlikely_ do this job for you, because it knows about machine arithmetic and rounding errors, so it will value accuracy over speed. You need to do this optimization manually.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
this code with nested lambda functions is not going to be fast. Please, rewrite this code without lambda functions that are called inside the innermost loop. Don't use `fetch()` blindly, 'cause it's very slow. Check that the whole 2x2 fetched neighborhood of the pixel is inside the image, in this case simply convert top-left corner to int's (without using `floor`, because of a non-negative number x we always have (int)std::floor(x) == (int)x).
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
use more correct `saturate_cast<int>(x);`
You are an expert OpenCV code reviewer specializing in performance optimization. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
Please, optimize it. Don't use loops here to compute coefficients. In OpenCV we have optimized bicubic intepolation in `cv::resize()`, take the code from there: https://github.com/opencv/opencv/blob/6d889ee74c94124f6492eb8f0d50946d9c31d8e9/modules/imgproc/src/resize.cpp#L964. Make sure that both variants produce the same results.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
compute the sumwx and sumwy analytically.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/gridsample_layer.cpp **Change Type:** added **Context:** PR #27700: Added gridsample layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,328 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> ```
don't use loops to do cubic interpolation
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp **Change Type:** modified **Context:** PR #27755: Optimize FFmpeg VideoCapture with swscale threads option **Code Changes:** ```diff @@ -607,6 +607,7 @@ struct CvCapture_FFMPEG int hw_device; int use_opencl; int extraDataIdx; + int requestedThreads; }; void CvCapture_FFMPEG::init() @@ -658,6 +659,7 @@ void CvCapture_FFMPEG::init() hw_device = -1; ```
OpenCV initializes threading for encoder in the following way: ``` if (!enc->thread_count) { int nCpus = cv::getNumberOfCPUs(); int requestedThreads = std::min(nCpus, 16); // [OPENCV:FFMPEG:24] Application has requested XX threads. Using a thread count greater than 16 is not recommended. std::string threads_option = utils::getConfigurationParameterString("OPENCV_FFMPEG_THREADS"); if (!threads_option.empty()) { requestedThreads = atoi(threads_option.c_str()); } enc->thread_count = requestedThreads; } ``` I propose to use `nCpus = cv::getNumberOfCPUs()` here too as initial value.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/bitshift_layer.cpp **Change Type:** added **Context:** PR #27666: Added bitshift layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,137 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" ```
no need to cast to U — shiftVal is already of U type.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/bitshift_layer.cpp **Change Type:** added **Context:** PR #27666: Added bitshift layer to new DNN engine **Review Line:** 13 **Code Changes:** ```diff +#include "../precomp.hpp" +#include "layers_common.hpp" + +// ONNX reference: BitShift operator +// Spec: https://onnx.ai/onnx/operators/onnx__BitShift.html +// Supported opsets: ai.onnx opset 11 and newer +// NOTE: Broadcasting is NOT fully supported. Only two cases are handled: +// 1) array (input[0]) shifted by array (input[1]) of the SAME SHAPE +// 2) array (input[0]) shifted by a SCALAR (0-D) shift amount + +namespace cv { ```
please, put a note here that broadcasting is not fully supported, only the same shapes (`array shift array`) or `array shift scalar`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/bitshift_layer.cpp **Change Type:** added **Context:** PR #27666: Added bitshift layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,137 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" ```
extra conversion into a temporary array is too big overhead for such a simple operation. Please, rewrite it to avoid the use of temporary array.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/bitshift_layer.cpp **Change Type:** added **Context:** PR #27666: Added bitshift layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,137 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" ```
check that inputs[1] == inputs[0] or inputs[1] has 0 dimensions.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/bitshift_layer.cpp **Change Type:** added **Context:** PR #27666: Added bitshift layer to new DNN engine **Review Line:** 90 **Code Changes:** ```diff + void getTypes(const std::vector<MatType>& in, const int reqOut, const int reqInt, + std::vector<MatType>& out, std::vector<MatType>& internals) const CV_OVERRIDE + { + CV_Assert(in.size() >= 2); + int t = in[0]; + CV_Assert(t == CV_8U || t == CV_16U || t == CV_32U || t == CV_64U); + CV_Assert(in[1] == in[0]); + out.assign(reqOut, MatType(t)); + internals.assign(reqInt, MatType(t)); + } + ```
according to ONNX specification, there must be `in[1] == in[0]`. Please, check it.
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/misc/java/gen_dict.json **Change Type:** modified **Context:** PR #27567: Enable Java wrapper generation for Vec4i **Code Changes:** ```diff @@ -648,6 +648,31 @@ "jni_var": "Vec3d %(n)s(%(n)s_val0, %(n)s_val1, %(n)s_val2)", "suffix": "DDD" }, + "Vec4i": { + "j_type": "int[]", + "jn_args": [ + [ + "int", + ".val[0]" ```
I propose to presume `.val` here and below for compatibility with existing code.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** doc/opencv.bib **Change Type:** modified **Context:** PR #27730: doc: fix doxygen warnings for imgcodecs, flann and objdetect **Review Line:** 1440 **Code Changes:** ```diff @@ -1431,14 +1431,6 @@ @article{Viola04 publisher = {Kluwer Academic Publishers}, url = {https://www.face-rec.org/algorithms/Boosting-Ensemble/16981346.pdf} } -@inproceedings{wang2016iros, - author = {John Wang and Edwin Olson}, - title = {{AprilTag} 2: Efficient and robust fiducial detection}, - booktitle = {Proceedings of the {IEEE/RSJ} International Conference on Intelligent Robots and Systems {(IROS)}}, - year = {2016}, - month = {October}, - url = {https://april.eecs.umich.edu/pdfs/wang2016iros.pdf} -} @misc{Welch95, author = {Welch, Greg and Bishop, Gary}, title = {An introduction to the Kalman filter}, ```
Can you add the url field in the other bibtex file?
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27537: Refactor Blackwell - In CUDA 13: - 10.0 is b100/b200 same for aarch64 (gb200) - 10.3 is GB300 - 11.0 is Thor with new OpenRm driver (moves ... **Code Changes:** ```diff @@ -109,7 +109,7 @@ macro(ocv_initialize_nvidia_device_generations) set(_arch_ampere "8.0;8.6") set(_arch_lovelace "8.9") set(_arch_hopper "9.0") - set(_arch_blackwell "10.0;12.0") + set(_arch_blackwell "10.0;10.3;11.0;12.0;12.1") if(NOT CMAKE_CROSSCOMPILING) list(APPEND _generations "Auto") endif() @@ -273,14 +273,15 @@ macro(ocv_set_cuda_arch_bin_and_ptx nvcc_executable) ```
Hm.. each option here is yet another kernel build. Longer build and fatter binary. I would say, that we do not need all possible combinations, if the target is defined by the arch name. "12.0;12.1" most probably should be just 12.1. The same for 10.x variations, if pure 10.0 devices do not exist and 10.3 is minimal production version.
You are an expert OpenCV code reviewer specializing in performance optimization. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27537: Refactor Blackwell - In CUDA 13: - 10.0 is b100/b200 same for aarch64 (gb200) - 10.3 is GB300 - 11.0 is Thor with new OpenRm driver (moves ... **Code Changes:** ```diff @@ -109,7 +109,7 @@ macro(ocv_initialize_nvidia_device_generations) set(_arch_ampere "8.0;8.6") set(_arch_lovelace "8.9") set(_arch_hopper "9.0") - set(_arch_blackwell "10.0;12.0") + set(_arch_blackwell "10.0;10.3;11.0;12.0;12.1") if(NOT CMAKE_CROSSCOMPILING) list(APPEND _generations "Auto") endif() @@ -273,14 +273,15 @@ macro(ocv_set_cuda_arch_bin_and_ptx nvcc_executable) ```
Hello, In CUDA 13 10.0 is b100/b200 same for aarch64 (gb200) 10.3 is GB300 11.0 is Thor with new OpenRm driver (moves to SBSA) 12.0 is RTX/RTX PRO 12.1 is Spark GB10 feel free to change it or recommend me the most optimized codegen there
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27537: Refactor Blackwell - In CUDA 13: - 10.0 is b100/b200 same for aarch64 (gb200) - 10.3 is GB300 - 11.0 is Thor with new OpenRm driver (moves ... **Code Changes:** ```diff @@ -109,7 +109,7 @@ macro(ocv_initialize_nvidia_device_generations) set(_arch_ampere "8.0;8.6") set(_arch_lovelace "8.9") set(_arch_hopper "9.0") - set(_arch_blackwell "10.0;12.0") + set(_arch_blackwell "10.0;10.3;11.0;12.0;12.1") if(NOT CMAKE_CROSSCOMPILING) list(APPEND _generations "Auto") endif() @@ -273,14 +273,15 @@ macro(ocv_set_cuda_arch_bin_and_ptx nvcc_executable) ```
Orin is moving to sbsa (deletes old nvgpu) in Q1 2026. I don’t if it will mantain the same codegen
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27537: Refactor Blackwell - In CUDA 13: - 10.0 is b100/b200 same for aarch64 (gb200) - 10.3 is GB300 - 11.0 is Thor with new OpenRm driver (moves ... **Code Changes:** ```diff @@ -109,7 +109,7 @@ macro(ocv_initialize_nvidia_device_generations) set(_arch_ampere "8.0;8.6") set(_arch_lovelace "8.9") set(_arch_hopper "9.0") - set(_arch_blackwell "10.0;12.0") + set(_arch_blackwell "10.0;10.3;11.0;12.0;12.1") if(NOT CMAKE_CROSSCOMPILING) list(APPEND _generations "Auto") endif() @@ -273,14 +273,15 @@ macro(ocv_set_cuda_arch_bin_and_ptx nvcc_executable) ```
There is new option that is putting f 10.0f and takes optimizarion for all blackwell family
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27537: Refactor Blackwell - In CUDA 13: - 10.0 is b100/b200 same for aarch64 (gb200) - 10.3 is GB300 - 11.0 is Thor with new OpenRm driver (moves ... **Code Changes:** ```diff @@ -109,7 +109,7 @@ macro(ocv_initialize_nvidia_device_generations) set(_arch_ampere "8.0;8.6") set(_arch_lovelace "8.9") set(_arch_hopper "9.0") - set(_arch_blackwell "10.0;12.0") + set(_arch_blackwell "10.0;10.3;11.0;12.0;12.1") if(NOT CMAKE_CROSSCOMPILING) list(APPEND _generations "Auto") endif() @@ -273,14 +273,15 @@ macro(ocv_set_cuda_arch_bin_and_ptx nvcc_executable) ```
Separator needs to be a `;` not a `,` in `...;10.3,11.0;...` for the compute capability autodetection to work.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27537: Refactor Blackwell - In CUDA 13: - 10.0 is b100/b200 same for aarch64 (gb200) - 10.3 is GB300 - 11.0 is Thor with new OpenRm driver (moves ... **Code Changes:** ```diff @@ -109,7 +109,7 @@ macro(ocv_initialize_nvidia_device_generations) set(_arch_ampere "8.0;8.6") set(_arch_lovelace "8.9") set(_arch_hopper "9.0") - set(_arch_blackwell "10.0;12.0") + set(_arch_blackwell "10.0;10.3;11.0;12.0;12.1") if(NOT CMAKE_CROSSCOMPILING) list(APPEND _generations "Auto") endif() @@ -273,14 +273,15 @@ macro(ocv_set_cuda_arch_bin_and_ptx nvcc_executable) ```
Yeah, good catch. Done!
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/cuda_info.cpp **Change Type:** modified **Context:** PR #27636: cuda 13.0 compatibility **Code Changes:** ```diff @@ -424,7 +424,9 @@ int cv::cuda::DeviceInfo::clockRate() const #ifndef HAVE_CUDA throw_no_cuda(); #else - return deviceProps().get(device_id_)->clockRate; + int clockRate; + cudaSafeCall(cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, device_id_)); + return clockRate; #endif } ```
> modules\core\src\cuda_info.cpp(951): error C2039: 'clockRate': is not a member of 'cudaDeviceProp'
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/cuda_info.cpp **Change Type:** modified **Context:** PR #27636: cuda 13.0 compatibility **Code Changes:** ```diff @@ -424,7 +424,9 @@ int cv::cuda::DeviceInfo::clockRate() const #ifndef HAVE_CUDA throw_no_cuda(); #else - return deviceProps().get(device_id_)->clockRate; + int clockRate; + cudaSafeCall(cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, device_id_)); + return clockRate; #endif } ```
`maxTexture1DLinear` has been depreciated not `maxTexture1D` See > opencv\modules\core\src\cuda_info.cpp(566): error C2039: 'maxTexture1DLinear': is not a member of 'cudaDeviceProp'
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_bmp.cpp **Change Type:** modified **Context:** PR #27559: imgcodecs: bmp: support to write 32bpp BMP with BI_BITFIELDS **Code Changes:** ```diff @@ -42,6 +42,7 @@ #include "precomp.hpp" #include "grfmt_bmp.hpp" +#include "opencv2/core/utils/logger.hpp" namespace cv { @@ -603,6 +604,7 @@ BmpEncoder::BmpEncoder() { ```
According to the documentation (32-bit section of the table): > The bitmap has a maximum of 2^32 colors. If the bV5Compression member of the BITMAPV5HEADER is BI_RGB, the bmiColors member of [BITMAPINFO](https://learn.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-bitmapinfo) is NULL. Each DWORD in the bitmap array represents the relative intensities of blue, green, and red for a pixel. The value for blue is in the least significant 8 bits, followed by 8 bits each for green and red. The high byte in each DWORD is not used. The bmiColors color table is used for optimizing colors used on palette-based devices, and must contain the number of entries specified by the bV5ClrUsed member of the BITMAPV5HEADER.If the bV5Compression member of the BITMAPV5HEADER is BI_BITFIELDS, the bmiColors member contains three DWORD color masks that specify the red, green, and blue components of each pixel. Each DWORD in the bitmap array represents a single pixel. The bitmap with BMP_RGB flag and 32-bit per channel is 3 channel image. The high byte is not used. I propose to revert imread changes and corresponding test. Images with BI_RBG/BMP_RGB should be 3 channel images. Images with BI_BITFIELD/RGB_BITFIELD - 4 channel images.
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_bmp.cpp **Change Type:** modified **Context:** PR #27559: imgcodecs: bmp: support to write 32bpp BMP with BI_BITFIELDS **Code Changes:** ```diff @@ -42,6 +42,7 @@ #include "precomp.hpp" #include "grfmt_bmp.hpp" +#include "opencv2/core/utils/logger.hpp" namespace cv { @@ -603,6 +604,7 @@ BmpEncoder::BmpEncoder() { ```
In case if BI_RGB format is set in header it's not RGBX, it's RGB according to the documentation. Need to understand how the user generated it.
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_bmp.cpp **Change Type:** modified **Context:** PR #27559: imgcodecs: bmp: support to write 32bpp BMP with BI_BITFIELDS **Code Changes:** ```diff @@ -42,6 +42,7 @@ #include "precomp.hpp" #include "grfmt_bmp.hpp" +#include "opencv2/core/utils/logger.hpp" namespace cv { @@ -603,6 +604,7 @@ BmpEncoder::BmpEncoder() { ```
OK, I revert to support reading. With ffmpeg , Windows Bitmap files saved in AV_PIX_FMT_BGRA format seems not able to read after this fix. - BITMAPINFOHEADER - biBitCount = 32 - biCompression = BI_RGB - BGRA data is stored. https://github.com/FFmpeg/FFmpeg/blob/2fffa01ddb777871cd53ef6c92f5c19cae8afe16/libavcodec/bmpenc.c#L119-L135 ||OpenCV v4.12.0(Before) | After| |:-|-|-| |Read RGBA BMP with BI_RGB | Not supported | Not supported (Only handled as RGB) | |Read RGBA BMP with BI_BITFIELDS | Supported | Supported | |Write RGBA BMP with BI_RGB | Supported (Default) |Supported | |Write RGBA BMP with BI_BITFIELDS| Not supported|Supported (Default) |
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp **Change Type:** modified **Context:** PR #27691: FFmpeg 8.0 support. **Review Line:** 690 **Code Changes:** ```diff if( video_st ) { #ifdef CV_FFMPEG_CODECPAR +// avcodec_close removed in FFmpeg release 8.0 +# if (LIBAVCODEC_BUILD < CALC_FFMPEG_VERSION(62, 11, 100)) avcodec_close( context ); +# endif #endif video_st = NULL; } @@ -2005,7 +2008,18 @@ void CvCapture_FFMPEG::get_rotation_angle() ```
avcodec_free_context in the `#else`?
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp **Change Type:** modified **Context:** PR #27691: FFmpeg 8.0 support. **Review Line:** 690 **Code Changes:** ```diff if( video_st ) { #ifdef CV_FFMPEG_CODECPAR +// avcodec_close removed in FFmpeg release 8.0 +# if (LIBAVCODEC_BUILD < CALC_FFMPEG_VERSION(62, 11, 100)) avcodec_close( context ); +# endif #endif video_st = NULL; } @@ -2005,7 +2008,18 @@ void CvCapture_FFMPEG::get_rotation_angle() ```
I think it should be `avcodec_free_context(&context);` for any version
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp **Change Type:** modified **Context:** PR #27691: FFmpeg 8.0 support. **Review Line:** 690 **Code Changes:** ```diff if( video_st ) { #ifdef CV_FFMPEG_CODECPAR +// avcodec_close removed in FFmpeg release 8.0 +# if (LIBAVCODEC_BUILD < CALC_FFMPEG_VERSION(62, 11, 100)) avcodec_close( context ); +# endif #endif video_st = NULL; } @@ -2005,7 +2008,18 @@ void CvCapture_FFMPEG::get_rotation_angle() ```
There is avcodec_free_context at line 699. Is not it enough?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_ffmpeg_impl.hpp **Change Type:** modified **Context:** PR #27691: FFmpeg 8.0 support. **Review Line:** 2020 **Code Changes:** ```diff + AVPacketSideData* sd = video_st->codecpar->coded_side_data; + int nb_sd = video_st->codecpar->nb_coded_side_data; + if (sd && nb_sd > 0) + { + const AVPacketSideData* mtx = av_packet_side_data_get(sd, nb_sd, AV_PKT_DATA_DISPLAYMATRIX); + data = mtx->data; + } +# endif if (data) { rotation_angle = -cvRound(av_display_rotation_get((const int32_t*)data)); ```
This segfaults if `av_packet_side_data_get` returns NULL. Which is does if there is no side data present. See https://ffmpeg.org/doxygen/8.0/group__lavc__packet__side__data.html#ga61a3a0fba92a308208c8ab957472d23c. This showed up in `videoio_encapsulate.write/7` of `opencv_test_videoio`.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/python/multiview_calibration.py **Change Type:** modified **Context:** PR #27651: fix empty intrinsics handling and minor calibration improvements **Code Changes:** ```diff @@ -18,9 +18,10 @@ import numpy as np import yaml import math +import warnings def insideImageMask(pts, w, h): - return np.logical_and(np.logical_and(pts[0] < w, pts[1] < h), np.logical_and(pts[0] > 0, pts[1] > 0)) + return (pts[0] >= 0) & (pts[0] <= w - 1) & (pts[1] >= 0) & (pts[1] <= h - 1) ```
I propose to print a message that the same K and distortion is applied for all cameras.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nary_eltwise_layers.cpp **Change Type:** modified **Context:** PR #27710: Added Pow layer to new DNN engine **Review Line:** 792 **Code Changes:** ```diff } - int type_for_dispatch = op == OPERATION::WHERE ? outputs.front().type() : inputs.front().type(); - typeDispatch(type_for_dispatch, inputs.size(), inputs, outputs); + std::vector<Mat> used_inputs = inputs; + if (op == OPERATION::POW) { + CV_Assert(used_inputs.size() == 2); + const int out_type = outputs[0].type(); + if (used_inputs[0].type() != out_type || used_inputs[1].type() != out_type) { + Mat a_conv, b_conv; + used_inputs[0].convertTo(a_conv, out_type); ```
why Pow does not use the broadcasting mechanism of all other binary operations (such as SUB or DIV)?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/is_inf_layer.cpp **Change Type:** added **Context:** PR #27660: Added IsInf layer to new DNN engine **Review Line:** 7 **Code Changes:** ```diff +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include "opencv2/core/fast_math.hpp" // for cvIsInf + +namespace cv { +namespace dnn { ```
please, put the link to description of the operation at onnx.ai and also specify, which opsets are supported.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/is_inf_layer.cpp **Change Type:** added **Context:** PR #27660: Added IsInf layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,122 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include "opencv2/core/fast_math.hpp" // for cvIsInf ```
I would split this into different loops: ``` if (detectPositive && detectNegative) { for (...) ... // just check for cvIsInf() } else if (detectPositive) { for (...) ... // cvIsInf(v) && v > 0 } else if (detectNegative) { for (...) ... // cvIsInf(v) && v < 0 } else { // report error? } ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/is_inf_layer.cpp **Change Type:** added **Context:** PR #27660: Added IsInf layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,122 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include "opencv2/core/fast_math.hpp" // for cvIsInf ```
it would be nice to make this loop parallel just to eliminate possible bottlenecks when everything else in the model graph is parallel
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/is_inf_layer.cpp **Change Type:** added **Context:** PR #27660: Added IsInf layer to new DNN engine **Review Line:** 112 **Code Changes:** ```diff + const size_t total = X.total(); + uchar* dst = Y.ptr<uchar>(); + + switch (depth) { + case CV_32F: computeIsInfMask<float>(X.ptr<float>(), dst, total, detect_pos, detect_neg); break; + case CV_64F: computeIsInfMask<double>(X.ptr<double>(), dst, total, detect_pos, detect_neg); break; + case CV_16F: computeIsInfMask<hfloat, float>(X.ptr<hfloat>(), dst, total, detect_pos, detect_neg); break; + case CV_16BF: computeIsInfMask<bfloat, float>(X.ptr<bfloat>(), dst, total, detect_pos, detect_neg); break; + default: CV_Error_(Error::StsError, ("IsInf: Unsupported type depth=%d", depth)); + } + } ```
bfloat and hfloat should be supported as well. 1) Add optional WT=T parameter to computeIsInfMask. 2) Change `T v = src[i];` to `WT v = WT(src[i]);`. 3) use WT=float for hfloat and bfloat
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp **Change Type:** renamed **Context:** PR #23192: DNN: Refactor the fast conv structure **Code Changes:** ```diff @@ -10,11 +10,19 @@ */ #include "../../precomp.hpp" -#include "fast_convolution.hpp" -#include "fast_convolution.simd.hpp" +#include "convolution.hpp" + +#include "conv_block.simd.hpp" +#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content ```
Calling NEON code through `opt_NEON::` requires the support of complete NEON dispatch. Using the `cpu_baseline` namespace is a temporary solution.
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp **Change Type:** renamed **Context:** PR #23192: DNN: Refactor the fast conv structure **Code Changes:** ```diff @@ -10,11 +10,19 @@ */ #include "../../precomp.hpp" -#include "fast_convolution.hpp" -#include "fast_convolution.simd.hpp" +#include "convolution.hpp" + +#include "conv_block.simd.hpp" +#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content ```
AFAIK, NEON could be enabled as a baseline only. Dispatching of NEON is not supported due to issues with ABI. Ref: https://developer.arm.com/documentation/den0018/a/Compiling-NEON-Instructions/GCC-command-line-options/Option-to-enable-use-of-NEON-and-floating-point-instructions --- > convBlock_NEON in general we should not have such function names.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp **Change Type:** renamed **Context:** PR #23192: DNN: Refactor the fast conv structure **Code Changes:** ```diff @@ -10,11 +10,19 @@ */ #include "../../precomp.hpp" -#include "fast_convolution.hpp" -#include "fast_convolution.simd.hpp" +#include "convolution.hpp" + +#include "conv_block.simd.hpp" +#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content ```
How about leaving the NEON code in a separated file with `neon.hpp` suffix and `opt_NEON` namespace?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/cpu_kernels/convolution.cpp **Change Type:** renamed **Context:** PR #23192: DNN: Refactor the fast conv structure **Code Changes:** ```diff @@ -10,11 +10,19 @@ */ #include "../../precomp.hpp" -#include "fast_convolution.hpp" -#include "fast_convolution.simd.hpp" +#include "convolution.hpp" + +#include "conv_block.simd.hpp" +#include "layers/cpu_kernels/conv_block.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content ```
> separated file with `neon.hpp` suffix With `.neon.cpp` suffix. Take a look how it is done here: https://github.com/opencv/opencv/blob/4.7.0/modules/imgproc/src/resize.avx2.cpp
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/cpu_kernels/conv_block.simd.hpp **Change Type:** added **Context:** PR #23192: DNN: Refactor the fast conv structure **Code Changes:** ```diff @@ -0,0 +1,259 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "opencv2/core/hal/intrin.hpp" + +namespace cv { +namespace dnn { +CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN ```
Line 11 should do the same. Code from `conv_block.neon.cpp` should be moved here as there is "no difference" against AVX+ code above.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_spng.cpp **Change Type:** modified **Context:** PR #27621: Add strict validation for encoding parameters **Code Changes:** ```diff @@ -482,6 +482,7 @@ SPngEncoder::SPngEncoder() m_support_metadata[IMAGE_METADATA_EXIF] = true; m_support_metadata[IMAGE_METADATA_XMP] = true; m_support_metadata[IMAGE_METADATA_ICCP] = true; + m_supported_encode_key = {IMWRITE_PNG_COMPRESSION, IMWRITE_PNG_STRATEGY, IMWRITE_PNG_BILEVEL, IMWRITE_PNG_FILTER, IMWRITE_PNG_ZLIBBUFFER_SIZE}; } SPngEncoder::~SPngEncoder() @@ -534,25 +535,56 @@ bool SPngEncoder::write(const Mat &img, const std::vector<int> &params) ```
todo: replace from early return to break
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27621: Add strict validation for encoding parameters **Code Changes:** ```diff @@ -913,6 +913,7 @@ PngEncoder::PngEncoder() memset(palette, 0, sizeof(palette)); memset(trns, 0, sizeof(trns)); memset(op, 0, sizeof(op)); + m_supported_encode_key = {IMWRITE_PNG_COMPRESSION, IMWRITE_PNG_STRATEGY, IMWRITE_PNG_BILEVEL, IMWRITE_PNG_FILTER, IMWRITE_PNG_ZLIBBUFFER_SIZE}; } PngEncoder::~PngEncoder() @@ -983,26 +984,61 @@ bool PngEncoder::write( const Mat& img, const std::vector<int>& params ) ```
todo: replace from early return to break
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/fast.cpp **Change Type:** modified **Context:** PR #27657: Added heuristic to allocate buffer for FAST features depending on input image resolution **Code Changes:** ```diff @@ -429,8 +429,10 @@ void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool { CV_INSTRUMENT_REGION(); + const size_t max_fast_features = std::max(_img.total()/100, size_t(1000)); // Simple heuristic that depends on resolution. + CV_OCL_RUN(_img.isUMat() && type == FastFeatureDetector::TYPE_9_16, - ocl_FAST(_img, keypoints, threshold, nonmax_suppression, 10000)); + ocl_FAST(_img, keypoints, threshold, nonmax_suppression, (int)max_fast_features)); ```
there are a few typos: 1) resoption => resolution, 2) propably => probably. recommended comment: "Use a simple heuristic depending on the image resolution; can probably be reduced even further". also, sizeof(KeyPoint) is 28 bytes. If, say, image has a modest (by modern standards) resolution of 24Mpix, the buffer will have size 168Mb, which is rather big and allocation of such a buffer may slowdown the function. I suggest to reduce `max_fast_features` to `std::max(_img.total()/100, (size_t)1000);` that will give at max 10K features for 1000x1000 image and 240K features for 24Mpix image — more than enough for any kind of registration/scene recognition/loop closure algorithm.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/models.yml **Change Type:** modified **Context:** PR #27592: Added image super-resolution samples using seemoredetails model **Review Line:** 532 **Code Changes:** ```diff +################################################################################ + +seemoredetails: + load_info: + url: "https://github.com/Naresh-19/opencv-superres-models/raw/main/seemore_x4v2_static512.onnx" + sha1: "584467bd36f5715aa12c3203bba16e4de6392034" + model: "seemore_x4v2_static512.onnx" + mean: [0.0, 0.0, 0.0] + scale: 0.00392 + rgb: true + width: 512 ```
Could you add link to the original repo with the model, rather than own fork? If it's not possible, please extend your repo with: - Link to the original model and/or paper. - Command line / pre-requsites to export ONNX - License information and credits.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/models.yml **Change Type:** modified **Context:** PR #27592: Added image super-resolution samples using seemoredetails model **Review Line:** 532 **Code Changes:** ```diff +################################################################################ + +seemoredetails: + load_info: + url: "https://github.com/Naresh-19/opencv-superres-models/raw/main/seemore_x4v2_static512.onnx" + sha1: "584467bd36f5715aa12c3203bba16e4de6392034" + model: "seemore_x4v2_static512.onnx" + mean: [0.0, 0.0, 0.0] + scale: 0.00392 + rgb: true + width: 512 ```
Addressed 👍 : [Github](https://github.com/Naresh-19/opencv-superres-models)
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
maybe we can avoid a special branch just for rank == 0 case?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
hfloat/bfloat should be handled with custom implementations of isNonZero: they should just check for 0x0/0x8000 case (one function is enough for both hfloat and bfloat): ``` static inline isNonZeroF16(uint16_t val) { return (val&0x7fff) != 0; } ... X.type() == CV_16F || X.type() == CV_16BF ? isNonZeroF16(*X.ptr<uint16_t>()) ``` Since hfloat/bfloat is the only case that requires `WT!=T` and this case can be solved as shown above, WT parameter in isNonZero is not needed anymore. Maybe the whole function is not needed either, just put the expression (`x!=0`) in-place. also, all other types: uint8/int8, uint16/int16, uint32/int32, uint64/int64 must be supported. It's enough to have 1
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Review Line:** 169 **Code Changes:** ```diff + + const int depth = CV_MAT_DEPTH(X.type()); + std::vector<size_t> nzcounts; + std::vector<size_t> nzstart; + size_t nnz = 0; + switch (depth) + { + case CV_Bool: + case CV_8U: + case CV_8S: { nnz = computeNonZeroCountsPerStripe<uchar>(X.ptr<uchar>(), total, nstripes, nzcounts); break; } + case CV_16U: ```
put this into a template function with parallel loop inside. Compute number of non-zero elements for each stripe. After you computed number of non-zero elements in each stripe, compute cumsum: ``` constexpr int nstripes = 16; std::vector<size_t> nzcounts(nstripes, 0); std::vector<size_t> nzstart(nstripes+1, 0); parallel_for_(Range(0, nstripes), [&](const Range& range) { size_t i0 = total*range.start/nstripes; size_t i1 = total*range.end/nstripes; size_t nz = 0; for (...) { nz += ... } nzcounts[range.start] = nz; }); // nzstart = { 0, nzcounts[0], nzcounts[0] + nzcounts[1], nzcounts[0] + ... + nzcounts[2], ... } for (int i = 1; i <= nstripes; i++) { nzstart[i] = nzstart[i-1] + nzcounts[i-1]; } // allocate output of shape nzstart[nstripes] = nzcounts[0] + ... + nzcounts[nstripes-1] ... parallel_for_(Range(0, nstripes), [&](const Range& range) { size_t i0 = total*range.start/nstripes; size_t i1 = total*range.end/nstripes; size_t nzcurrstart = nzstart[range.start]; for (...) { if (nonZero(inp[i]) { outarray[nzcurrstart] = <index>; nzcurrstart++;} } });
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
this function is too expensive. Replace it with a nested loop, say, 3D loop: outermost iteration will cover all dimensions but the last two, the pre-last dimension and then the innermost one. or at least 2D loop: all dimensions but the last one and the innermost dimension.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
again, cover all types, not just a few selected types. Put implementation into a template function
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
pass nstripes as function parameter, to make sure that all stages of the algorithm use exactly the same number of stripes.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
why do we have this complex nested loop? Can we have a simple loop where we check inside when the last coordinate reaches the maximum possible value and then we recompute ND index (from the raw index). We can put this check before emitting next ND index, and then we don't need the initialization loop before the main loop
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
we don't need separate versions for CV_8U and CV_8S. we don't need separate versions for CV_16U and CV_16S. we don't need separate versions for CV_32U and CV_32S. we don't need separate versions for CV_64U and CV_64S.
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
can we retain only a single switch statement? All the memory allocation logic can be put into helper methods, that we will call from each branch of this switch.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
use `std::array<int, CV_MAX_DIM>`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
do something like this: ``` coord[rank-1] = lastDimSize - 1; for (;i < i1; i++) { if (++coord[rank-1] >= lastDimSize) { // recompute all coordinates (coord) from 'i' int idxLinear = i; for (int d = rank-1; d >= 0; d--) { coord[d] = idxLinear % shape[d]; idxLinear /= shape[d]; } } if (isNonZero(data[i])) { for (int d = 0; d < rank; d++) { y[(size_t)d * nnz_total + col] = (int64_t)coord[d]; // should it be y[col*nnz_total + d]? } col++; } } ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Review Line:** 197 **Code Changes:** ```diff + MatShape outShape = shape(rank, (int)nnz); + auto kind = out_arr.kind(); + std::vector<Mat>* out_mats = nullptr; + std::vector<UMat>* out_umats = nullptr; + Mat Y; + if (kind == _InputArray::STD_VECTOR_MAT) { + out_mats = &out_arr.getMatVecRef(); + out_mats->resize(1); + out_mats->at(0).fit(outShape, CV_64S); + Y = out_mats->at(0); + } else { ```
``` std::vector<Mat>* out_mats = nullptr; std::vector<UMat>* out_umats = nullptr; Mat Y; if (kind == _InputArray::STD_VECTOR_MAT) { out_mats = &out_arr.getMatVecRef(); out_mats->resize(1); out_mats->at(0).fit(outShape, CV_64S); Y = out_mats->at(0); } else { CV_Assert(kind == _InputArray::STD_VECTOR_UMAT); out_umats = &out_arr.getUMatVecRef(); out_umats->resize(1); out_umats->at(0).fit(outShape, CV_64S); Y = Mat(outShape, CV_64S); } int64* y = Y.ptr<int64>(); switch (depth) { .... } if (kind == _InputArray::STD_VECTOR_UMAT) { Y.copyTo(out_umats->at(0)); } ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
`std::fill`?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/nonzero_layer.cpp **Change Type:** added **Context:** PR #27701: Added nonzero layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,243 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the +// top-level directory of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include <opencv2/dnn/shape_utils.hpp> +#include <cstdint> +#include <array> ```
same thing, reduce the number of branches
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/is_nan_layer.cpp **Change Type:** added **Context:** PR #27661: Added IsNan layer to new DNN engine **Code Changes:** ```diff @@ -0,0 +1,91 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// Copyright (C) 2025, BigVision LLC, all rights reserved. +// Third party copyrights are property of their respective owners. + +#include "../precomp.hpp" +#include "layers_common.hpp" +#include "opencv2/core/fast_math.hpp" // for cvIsNaN ```
please, make this loop parallel
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/is_nan_layer.cpp **Change Type:** added **Context:** PR #27661: Added IsNan layer to new DNN engine **Review Line:** 80 **Code Changes:** ```diff + const int depth = CV_MAT_DEPTH(X.type()); + const size_t total = X.total(); + uchar* dst = Y.ptr<uchar>(); + + switch (depth) { + case CV_32F: computeIsNaNMask<float>(X.ptr<float>(), dst, total); break; + case CV_64F: computeIsNaNMask<double>(X.ptr<double>(), dst, total); break; + case CV_16F: computeIsNaNMask<hfloat, float>(X.ptr<hfloat>(), dst, total); break; + case CV_16BF: computeIsNaNMask<bfloat, float>(X.ptr<bfloat>(), dst, total); break; + default: CV_Error_(Error::StsError, ("IsNaN: Unsupported type depth=%d", depth)); + } ```
hfloat and bfloat should be supported as well
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/perf/perf_decode_encode.cpp **Change Type:** modified **Context:** PR #27605: Performance tests for writing and reading animations **Code Changes:** ```diff @@ -7,10 +7,82 @@ namespace opencv_test { -#ifdef HAVE_PNG - using namespace perf; +static Animation makeCirclesAnimation(Size size = Size(320, 240), int type = CV_8UC4, int nbits = 8, int frameCount = 40) +{ ```
Img is local variable inside for loop body and re-created on each loop iteration. No need to call clone for it.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/perf/perf_decode_encode.cpp **Change Type:** modified **Context:** PR #27605: Performance tests for writing and reading animations **Code Changes:** ```diff @@ -7,10 +7,82 @@ namespace opencv_test { -#ifdef HAVE_PNG - using namespace perf; +static Animation makeCirclesAnimation(Size size = Size(320, 240), int type = CV_8UC4, int nbits = 8, int frameCount = 40) +{ ```
As soon as it's perf test, I propose to exclude file i/o from scope and use in-memory encoding with imencodeanimation
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/include/opencv2/3d/mst.hpp **Change Type:** added **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -0,0 +1,65 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_3D_MST_HPP +#define OPENCV_3D_MST_HPP + +#include <vector> + ```
remove _DETAIL
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/include/opencv2/3d/mst.hpp **Change Type:** added **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -0,0 +1,65 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_3D_MST_HPP +#define OPENCV_3D_MST_HPP + +#include <vector> + ```
Please use doxygen notation for the documentation.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/include/opencv2/3d/mst.hpp **Change Type:** added **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -0,0 +1,65 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_3D_MST_HPP +#define OPENCV_3D_MST_HPP + +#include <vector> + ```
The graph may have 2 or more isolated pieces. I propose the following: 1. return status, e.g. bool 2. add `CV_OUT std::vector<MSTEdge>&` parameter for result. Also the solution will be more friendly solution for Python and Java bindings.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/src/mst.cpp **Change Type:** added **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Review Line:** 148 **Code Changes:** ```diff + resultingEdges.clear(); + if (numNodes <= 0 || inputEdges.empty() || root < 0 || root >= numNodes) + return false; + + bool result = false; + switch (algorithm) + { + case MST_PRIM: + result = buildMSTPrim(numNodes, inputEdges, resultingEdges, root); + break; + case MST_KRUSKAL: ```
Please use `CV_TRACE_FUNCTION();` as the first statement of exported function.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/src/mst.cpp **Change Type:** added **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -0,0 +1,163 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include <opencv2/3d/mst.hpp> +#include <queue> +#include <tuple> + ```
It's definitely invalid user input. It should not be just ignored. We use CV_Assert / CV_Error and throw exception with it.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/src/mst.cpp **Change Type:** added **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -0,0 +1,163 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include <opencv2/3d/mst.hpp> +#include <queue> +#include <tuple> + ```
It's the only place where false is returned, besides the obvious one. What happens if the MST cannot be built, e.g. the graph consists of 2 split sub-graphs? I would say, it should return false too.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/src/rgbd/pose_graph.cpp **Change Type:** modified **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -3,8 +3,9 @@ // of this distribution and at http://opencv.org/license.html #include "../precomp.hpp" -#include "sparse_block_matrix.hpp" #include "opencv2/3d/detail/optimizer.hpp" +#include <opencv2/3d/mst.hpp> +#include "sparse_block_matrix.hpp" namespace cv ```
Looks like some data specific parameter. I propose to add lambda parameter with default value 0.485 to `initializePosesWithMST` to have opportunity to change it without OpenCV modification and rebuild. The value may be promoted to the weight calculator as parameter too.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/test/test_mst.cpp **Change Type:** added **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Review Line:** 271 **Code Changes:** ```diff + << "Prim's MST size incorrect for large graph: expected " + << (numNodes - 1) << " edges, got " << primMST.size() << "."; + EXPECT_EQ(kruskalMST.size(), static_cast<size_t>(numNodes - 1)) + << "Kruskal's MST size incorrect for large graph: expected " + << (numNodes - 1) << " edges, got " << kruskalMST.size() << "."; +} + +typedef tuple<int /*numNodes*/, + std::vector<MSTEdge>/*edges*/ + > MSTNegativeParamType; +typedef testing::TestWithParam<MSTNegativeParamType> MSTNegative; ```
Please add a couple of tests with negative scenarios: - split graph of 2-3 sub-graphs - one isolated node in the graph
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/test/test_pose_graph.cpp **Change Type:** modified **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -155,6 +155,119 @@ TEST(PoseGraph, sphereG2O) } } +TEST(PoseGraphMST, optimization) +{ + applyTestTag(CV_TEST_TAG_LONG, CV_TEST_TAG_DEBUG_VERYLONG); + + // The dataset was taken from here: https://lucacarlone.mit.edu/datasets/ + // Connected paper: ```
We have saveMesh / savePointCloud for obj and ply i/o. Please use it: https://docs.opencv.org/5.x/da/d35/group____3d.html#gad565f2878b3d8c3f959ae7967a520bb2
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/3d/test/test_pose_graph.cpp **Change Type:** modified **Context:** PR #27423: Feat #25150: Pose Graph MST initialization **Code Changes:** ```diff @@ -155,6 +155,119 @@ TEST(PoseGraph, sphereG2O) } } +TEST(PoseGraphMST, optimization) +{ + applyTestTag(CV_TEST_TAG_LONG, CV_TEST_TAG_DEBUG_VERYLONG); + + // The dataset was taken from here: https://lucacarlone.mit.edu/datasets/ + // Connected paper: ```
Looks like this code is not needed any more, as you added implementation with `saveMesh` below.
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
I propose to not touch the constructor, but add `setLegacyFlag()` method. It's easier to remove legacy method in future than break compatibility for all code that uses Charuco.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
I believe we should minimize or do not bring code with legacy/buggy behavior from `opencv_contrib` into the main repository (as we don't really want to support/maintain that). If `setLegacyFlag()` doesn't work, then I propose to create `CharucoBoardLegacy` or `cv::aruco::legacy::CharucoBoard` in `opencv_contrib/modules/aruco` for this purpose. There is inheritance with `Board` base class and Pimpl design, but some trick is required to expose `Board::Impl` to `opencv_contrib` (we don't need that in public OpenCV headers).
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/src/aruco/aruco_board.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -229,7 +229,8 @@ struct GridBoardImpl : public Board::Impl { Board::Impl(_dictionary), size(_size), markerLength(_markerLength), - markerSeparation(_markerSeparation) + markerSeparation(_markerSeparation), + legacyPattern(false) { CV_Assert(size.width*size.height > 0 && markerLength > 0 && markerSeparation > 0); } ```
actually, this is the only important bit. Generating board images in the legacy format is nice for consistency with the flag, but not really desirable. Could we introduce a function that shuffles `impl->objPoints` from new to old layout? This would fix detection of existing boards which is the main issue here.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
> Deciding otherwise will inevitably lead to systems version upgrades silently failing without an evident explanation. one way or another, mentioning this change in the release notes would have been nice..
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/src/aruco/aruco_board.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -229,7 +229,8 @@ struct GridBoardImpl : public Board::Impl { Board::Impl(_dictionary), size(_size), markerLength(_markerLength), - markerSeparation(_markerSeparation) + markerSeparation(_markerSeparation), + legacyPattern(false) { CV_Assert(size.width*size.height > 0 && markerLength > 0 && markerSeparation > 0); } ```
```impl->objPoints``` is also used further down in the constructor in ```calcNearestMarkerCorners()```. So reshuffling also needs to include to clear whatever is going on there and execute it again. This is what I meant before with clearing and recreating the board again. Sure it's possible to do, but not really elegant imho. But I will check and make a proposal.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
> I believe we should minimize or do not bring code with legacy/buggy behavior from `opencv_contrib` into the main repository (as we don't really want to support/maintain that). > > If `setLegacyFlag()` doesn't work, then I propose to create `CharucoBoardLegacy` or `cv::aruco::legacy::CharucoBoard` in `opencv_contrib/modules/aruco` for this purpose. There is inheritance with `Board` base class and Pimpl design, but some trick is required to expose `Board::Impl` to `opencv_contrib` (we don't need that in public OpenCV headers). I don't mean that `setLegacyFlag()` does not work - just that it involves a bit more code changes and is not as elegant imho. But if this is the preferred option over adding a flag to the constructor, then I'll try to make a proposal. I'd like to avoid maintaining something in opencv_contrib in parallel. The old behavior is not "buggy", it's just a slightly different board design, a variant. I still don't get why the board design had to change in the first place. There is no advantage, no reuse of existing code or something like that, but that's a different discussion. Now there are two versions out in the world. Maybe "legacy" is the wrong word for it. Maybe calling it "even"/"odd", or "A"/"B" order. Or "WBF" (white-box-first). Does not matter much as long as it works. I'll make a proposal for a setLegacyFlag() implementation.
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
The insistence on the black-box-first design is admittedly baffling. I've had a custom WBF aruco slide made for microscopy calibration with chrome deposition on glass that cost hundreds of dollars, and now I can't upgrade opencv beyond 4.5.5 without my calibration code breaking completely.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
probably it makes sense to dub the BBF order (i.e. 4.6, 4.7 behavior) "legacy" and hence set the flag to false by default. I doubt that with that many WBF patterns in the wild and WBF effectively being the default from 4.8 on BBF will be anything but legacy.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
Resolved: constructor is not being touched. Different board layouts are supported by `setBBF(bool)` method.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/src/aruco/aruco_board.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -229,7 +229,8 @@ struct GridBoardImpl : public Board::Impl { Board::Impl(_dictionary), size(_size), markerLength(_markerLength), - markerSeparation(_markerSeparation) + markerSeparation(_markerSeparation), + legacyPattern(false) { CV_Assert(size.width*size.height > 0 && markerLength > 0 && markerSeparation > 0); } ```
Added `setBBF()` method to switch between layouts without modifying the constructor.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/src/aruco/aruco_board.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -229,7 +229,8 @@ struct GridBoardImpl : public Board::Impl { Board::Impl(_dictionary), size(_size), markerLength(_markerLength), - markerSeparation(_markerSeparation) + markerSeparation(_markerSeparation), + legacyPattern(false) { CV_Assert(size.width*size.height > 0 && markerLength > 0 && markerSeparation > 0); } ```
Default value is not initialized in constructor (must be set to `false`).
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/src/aruco/aruco_board.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -229,7 +229,8 @@ struct GridBoardImpl : public Board::Impl { Board::Impl(_dictionary), size(_size), markerLength(_markerLength), - markerSeparation(_markerSeparation) + markerSeparation(_markerSeparation), + legacyPattern(false) { CV_Assert(size.width*size.height > 0 && markerLength > 0 && markerSeparation > 0); } ```
Default value is not initialized in constructor (must be set to `false`).
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -12,15 +12,19 @@ namespace opencv_test { namespace { * @brief Get a synthetic image of Chessboard in perspective */ static Mat projectChessboard(int squaresX, int squaresY, float squareSize, Size imageSize, - Mat cameraMatrix, Mat rvec, Mat tvec) { + Mat cameraMatrix, Mat rvec, Mat tvec, bool legacyPattern) { Mat img(imageSize, CV_8UC1, Scalar::all(255)); Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); ```
Avoid `for loops` over parameters in test bodies. In case of failure there would be unclear message without information about used parameters. Also due to `for loops` it is hard to debug/reproduce the problem. It is better to add parameter and/or separate test case.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -12,15 +12,19 @@ namespace opencv_test { namespace { * @brief Get a synthetic image of Chessboard in perspective */ static Mat projectChessboard(int squaresX, int squaresY, float squareSize, Size imageSize, - Mat cameraMatrix, Mat rvec, Mat tvec) { + Mat cameraMatrix, Mat rvec, Mat tvec, bool legacyPattern) { Mat img(imageSize, CV_8UC1, Scalar::all(255)); Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); ```
I see the point, and I suppose the point is equaly valid for the already existing `for loops` over `distance`/`yaw`/`pitch` to which I only extended a `BFF` loop. To get a real improvement here, all the `for loops` should be unraveled. I can try to make a proposal. But I must say the intention of the pull request is to add compatibility, fix a specific issue. It is not to re-work all of the Aruco/Charuco test cases. `For loops` are all over the place in the aruco module to cover different poses and parameters. For the sake of making progress efficiently: Wouldn't it make more sense to create another PR with the goal of test cases clean-up?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -12,15 +12,19 @@ namespace opencv_test { namespace { * @brief Get a synthetic image of Chessboard in perspective */ static Mat projectChessboard(int squaresX, int squaresY, float squareSize, Size imageSize, - Mat cameraMatrix, Mat rvec, Mat tvec) { + Mat cameraMatrix, Mat rvec, Mat tvec, bool legacyPattern) { Mat img(imageSize, CV_8UC1, Scalar::all(255)); Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); ```
Resolved: I removed the for-loop over BBF by splitting the test case into black-box-first and white-box-first.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/src/aruco/aruco_board.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -229,7 +229,8 @@ struct GridBoardImpl : public Board::Impl { Board::Impl(_dictionary), size(_size), markerLength(_markerLength), - markerSeparation(_markerSeparation) + markerSeparation(_markerSeparation), + legacyPattern(false) { CV_Assert(size.width*size.height > 0 && markerLength > 0 && markerSeparation > 0); } ```
Name must be `legacyPattern`, value is `false`
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 194 **Code Changes:** ```diff void CV_CharucoPoseEstimation::run(int) { int iter = 0; Mat cameraMatrix = Mat::eye(3, 3, CV_64FC1); - Size imgSize(500, 500); + Size imgSize(750, 750); aruco::DetectorParameters params; params.minDistanceToBorder = 3; aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250)); + board.setLegacyPattern(legacyPattern); aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params); ```
Why are test parameters changed?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 201 **Code Changes:** ```diff aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250)); + board.setLegacyPattern(legacyPattern); aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params); - cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 650; + cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 1000; cameraMatrix.at<double>(0, 2) = imgSize.width / 2; cameraMatrix.at<double>(1, 2) = imgSize.height / 2; Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); + ```
Why are test parameters changed?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 201 **Code Changes:** ```diff aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250)); + board.setLegacyPattern(legacyPattern); aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params); - cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 650; + cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 1000; cameraMatrix.at<double>(0, 2) = imgSize.width / 2; cameraMatrix.at<double>(1, 2) = imgSize.height / 2; Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); + ```
> Why are test parameters changed? Test parameter change was required in `CV_CharucoPoseEstimation` because the aruco detection had trouble to detect the all aruco code in the low resolution test image at maximum angle. The pose estimation test fails if not all codes are properly detected. But the failure is not actually due to charuco pose estimation which is under test here. Root cause for the test failure was the too small artifical image with too low resolution. Some aruco codes were indistinguishable, depending on the order and exact position on the projected board, so the detection issue is not real a failure of the aruco detection. The code is truely not recognizable with these generation parameters, so it's correct behavior not to detect it. Increasing the cameraMatrix and thus the resolution of the artifical image yields more clear aruco codes for all poses tested in the pose estimation test procedure.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 194 **Code Changes:** ```diff void CV_CharucoPoseEstimation::run(int) { int iter = 0; Mat cameraMatrix = Mat::eye(3, 3, CV_64FC1); - Size imgSize(500, 500); + Size imgSize(750, 750); aruco::DetectorParameters params; params.minDistanceToBorder = 3; aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250)); + board.setLegacyPattern(legacyPattern); aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params); ```
See answer below regarding focal length in the camera matrix. The artifically projected board was too small for all codes to be recognizable.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 201 **Code Changes:** ```diff aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250)); + board.setLegacyPattern(legacyPattern); aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params); - cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 650; + cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 1000; cameraMatrix.at<double>(0, 2) = imgSize.width / 2; cameraMatrix.at<double>(1, 2) = imgSize.height / 2; Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); + ```
See attached some debug images of the test (required some additional code to create debug output). The aruco detection simply fails with the smaller original settings. Aruco id=1 is not recognized. My guess is due to the low resolution and the aliased artifical image, but I did not dig deeper as I understood this test case as not meant for aruco tests but for the charuco pose accuracy, and it's clear that aruco works better at higher resolution (second image) so it's due to image quality, not the pose. I do wonder a bit why the same aruco pattern is detected at the original resolution with the other chessboard pattern (black box in upper left, new variant) at the same settings although the aruco code is even smaller - see the third image. My guess is that it's just random chance that it works here and not in the other image due it being an aliased artifical image. ![original_legacy_d0 200000y-55p-30](https://user-images.githubusercontent.com/108057787/217106183-ced1eb1c-0921-464a-8d29-9be4d3ea3e2a.png) ![legacy_d0 200000y-55p-30](https://user-images.githubusercontent.com/108057787/217106330-7bb7b6f0-53a7-4ffe-8459-008d8a1decd0.png) ![original_d0 200000y-55p-30](https://user-images.githubusercontent.com/108057787/217107365-3d61ff65-93e5-4aef-aada-167ab7b830c2.png)
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 201 **Code Changes:** ```diff aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250)); + board.setLegacyPattern(legacyPattern); aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params); - cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 650; + cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 1000; cameraMatrix.at<double>(0, 2) = imgSize.width / 2; cameraMatrix.at<double>(1, 2) = imgSize.height / 2; Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); + ```
Here zoomed into both versions, old test settings vs. new test settings, showing the difference a bit more clearly. ![image](https://user-images.githubusercontent.com/108057787/217169867-29ca2b53-87aa-4f8e-93f4-58dbff8f83ea.png)
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/test/test_charucodetection.cpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -12,15 +12,19 @@ namespace opencv_test { namespace { * @brief Get a synthetic image of Chessboard in perspective */ static Mat projectChessboard(int squaresX, int squaresY, float squareSize, Size imageSize, - Mat cameraMatrix, Mat rvec, Mat tvec) { + Mat cameraMatrix, Mat rvec, Mat tvec, bool legacyPattern) { Mat img(imageSize, CV_8UC1, Scalar::all(255)); Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0)); ```
I do have a small patch ready and working for the three relevant loops in `test_charucodetection.cpp`. It also requires to increase the virtual image resolution for the distance in `CV_CharucoDiamondDetection` which is otherwise unaffected by this PR. Debug image output code would also be included (but disabled) in the patch. Please advise if I should include it here or not.
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner + * if there is an even row count of chessboard boxes, otherwise it starts with a black box. + * This setting ensures compatibility to patterns created with OpenCV versions prior OpenCV 4.6.0. + * See https://github.com/opencv/opencv/issues/23152. ```
Documentation/comments should be more clear now. I had the parameter change to `legacyParamter` per directions in the other comment, but I am happy to change it again to anything else like `chessboardPatternCompatibility` if this would be the accepted name?
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/objdetect/include/opencv2/objdetect/aruco_board.hpp **Change Type:** modified **Context:** PR #23153: ChArUco pre460 pattern support **Review Line:** 146 **Code Changes:** ```diff @@ -146,6 +146,18 @@ class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board { CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength, const Dictionary &dictionary, InputArray ids = noArray()); + /** @brief set legacy chessboard pattern. + * + * Legacy setting creates chessboard patterns starting with a white box in the upper left corner ```
Sorry, there is useful information for discussion here. Please don't mark as resolved for now.
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
15