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/calib3d/src/solvepnp.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Code Changes:** ```diff @@ -311,18 +311,42 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, opoints_inliers.resize(npoints1); ipoints_inliers.resize(npoints1); - result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, - distCoeffs, rvec, tvec, useExtrinsicGuess, - (flags == SOLVEPNP_P3P || flags == SOLVEPNP_AP3P) ? SOLVEPNP_EPNP : flags) ? 1 : -1; + try + { + result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, ```
I'm not quite sure about this, but I have seen same usage in [calibinit.cpp](https://github.com/opencv/opencv/blob/cac5b0fe5a3e06718a6cb408d6468ff87428ef2a/modules/calib3d/src/calibinit.cpp#L2261-L2266). Maybe in Release build, `CV_LOG_DEBUG` doesn't use `e`, then `CV_UNUSED` can supress the warning?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/test/test_solvepnp_ransac.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Code Changes:** ```diff @@ -837,6 +837,43 @@ TEST(Calib3d_SolvePnPRansac, double_support) EXPECT_LE(cvtest::norm(t, Mat_<double>(tF), NORM_INF), 1e-3); } +TEST(Calib3d_SolvePnPRansac, bad_input_points_19253) +{ + // with this specific data + // when computing the final pose using points in the consensus set with SOLVEPNP_ITERATIVE and solvePnP() + // an exception is thrown from solvePnP because there are 5 non-coplanar 3D points and the DLT algorithm needs at least 6 non-coplanar 3D points + // with PR #19253 we choose to return true, with the pose estimated from the MSS stage instead of throwing the exception ```
In my test data, the 2D points are from the normalized image coordiante system, that's why the camera matrix is `Mat::eye(3, 3, CV_64FC1)`. So, the reprojection error here is not in pixel unit. As you can see, the focal length of my camera is about 460.0, and the tolerance of reprojection error is set to 4 pixels. It should be fine.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/test/test_solvepnp_ransac.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Code Changes:** ```diff @@ -837,6 +837,43 @@ TEST(Calib3d_SolvePnPRansac, double_support) EXPECT_LE(cvtest::norm(t, Mat_<double>(tF), NORM_INF), 1e-3); } +TEST(Calib3d_SolvePnPRansac, bad_input_points_19253) +{ + // with this specific data + // when computing the final pose using points in the consensus set with SOLVEPNP_ITERATIVE and solvePnP() + // an exception is thrown from solvePnP because there are 5 non-coplanar 3D points and the DLT algorithm needs at least 6 non-coplanar 3D points + // with PR #19253 we choose to return true, with the pose estimated from the MSS stage instead of throwing the exception ```
Fixed now.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/test/test_solvepnp_ransac.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Code Changes:** ```diff @@ -837,6 +837,43 @@ TEST(Calib3d_SolvePnPRansac, double_support) EXPECT_LE(cvtest::norm(t, Mat_<double>(tF), NORM_INF), 1e-3); } +TEST(Calib3d_SolvePnPRansac, bad_input_points_19253) +{ + // with this specific data + // when computing the final pose using points in the consensus set with SOLVEPNP_ITERATIVE and solvePnP() + // an exception is thrown from solvePnP because there are 5 non-coplanar 3D points and the DLT algorithm needs at least 6 non-coplanar 3D points + // with PR #19253 we choose to return true, with the pose estimated from the MSS stage instead of throwing the exception ```
You are right. I did not see that the camera matrix is identity.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/solvepnp.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Code Changes:** ```diff @@ -311,18 +311,42 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, opoints_inliers.resize(npoints1); ipoints_inliers.resize(npoints1); - result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, - distCoeffs, rvec, tvec, useExtrinsicGuess, - (flags == SOLVEPNP_P3P || flags == SOLVEPNP_AP3P) ? SOLVEPNP_EPNP : flags) ? 1 : -1; + try + { + result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, ```
Yes, I think that it is to probably suppress warning in release mode.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/solvepnp.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Code Changes:** ```diff @@ -311,18 +311,42 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, opoints_inliers.resize(npoints1); ipoints_inliers.resize(npoints1); - result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, - distCoeffs, rvec, tvec, useExtrinsicGuess, - (flags == SOLVEPNP_P3P || flags == SOLVEPNP_AP3P) ? SOLVEPNP_EPNP : flags) ? 1 : -1; + try + { + result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, ```
Maybe something like this? This is to explain to the user that everything went fine (consensus set was found that agree with the hypothesis), but issue occurs when computing the final pose using all the points in the consensus set. ```suggestion CV_LOG_DEBUG(NULL, "solvePnPRansac(): solvePnP stage to compute the final pose using points in the consensus set failed, use result from MSS (Minimal Sample Sets) stage instead:\n" << e.what()); ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/test/test_solvepnp_ransac.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Code Changes:** ```diff @@ -837,6 +837,43 @@ TEST(Calib3d_SolvePnPRansac, double_support) EXPECT_LE(cvtest::norm(t, Mat_<double>(tF), NORM_INF), 1e-3); } +TEST(Calib3d_SolvePnPRansac, bad_input_points_19253) +{ + // with this specific data + // when computing the final pose using points in the consensus set with SOLVEPNP_ITERATIVE and solvePnP() + // an exception is thrown from solvePnP because there are 5 non-coplanar 3D points and the DLT algorithm needs at least 6 non-coplanar 3D points + // with PR #19253 we choose to return true, with the pose estimated from the MSS stage instead of throwing the exception ```
I would add some comments before this line to explain this test: - with this specific data - when computing the final pose using points in the consensus set with `SOLVEPNP_ITERATIVE` and `solvePnP()` - an exception is thrown from `solvePnP` because there are 5 non-coplanar 3D points and the DLT algorithm needs at least 6 non-coplanar 3D points - with PR #19253 we choose to return `true`, with the pose estimated from the MSS stage instead of throwing the exception
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/solvepnp.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Review Line:** 326 **Code Changes:** ```diff + { + if (flags == SOLVEPNP_ITERATIVE && + npoints1 == 5 && + e.what() && + std::string(e.what()).find("DLT algorithm needs at least 6 points") != std::string::npos + ) + { + CV_LOG_INFO(NULL, "solvePnPRansac(): solvePnP stage to compute the final pose using points " + "in the consensus set raised DLT 6 points exception, use result from MSS (Minimal Sample Sets) stage instead."); + rvec = _local_model.col(0); // output rotation vector + tvec = _local_model.col(1); // output translation vector ```
This part changes behavior of the case which is not covered by PR's description: - `result = solvePnP()` doesn't throw exception - it returns `result <= 0` Alternative #19492 preserves behavior of non-exception case. --- > When I call solvePnPRansac with 69 points (data I provided above), then I should get a result (even if it's false) rather than an Exception. `false` code path is changed. > solvePnPRansac returns true even if the solvePnP stage failed. In this case, result from MSS stage is taken, and the exception content from solvePnP is put into log. Only exception's case is logged, but returned value is forced "true" for other cases too.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/solvepnp.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Review Line:** 326 **Code Changes:** ```diff + { + if (flags == SOLVEPNP_ITERATIVE && + npoints1 == 5 && + e.what() && + std::string(e.what()).find("DLT algorithm needs at least 6 points") != std::string::npos + ) + { + CV_LOG_INFO(NULL, "solvePnPRansac(): solvePnP stage to compute the final pose using points " + "in the consensus set raised DLT 6 points exception, use result from MSS (Minimal Sample Sets) stage instead."); + rvec = _local_model.col(0); // output rotation vector + tvec = _local_model.col(1); // output translation vector ```
You are right, the logging strategy here is problematic.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/solvepnp.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Review Line:** 326 **Code Changes:** ```diff + { + if (flags == SOLVEPNP_ITERATIVE && + npoints1 == 5 && + e.what() && + std::string(e.what()).find("DLT algorithm needs at least 6 points") != std::string::npos + ) + { + CV_LOG_INFO(NULL, "solvePnPRansac(): solvePnP stage to compute the final pose using points " + "in the consensus set raised DLT 6 points exception, use result from MSS (Minimal Sample Sets) stage instead."); + rvec = _local_model.col(0); // output rotation vector + tvec = _local_model.col(1); // output translation vector ```
Main question is about the final returned value. |result = solvePnP|(1) existed code|(2) This PR| (3) PR 19492|case4(no PR) |---|---|---|---|---| |result > 0|true|true|true|true| |result<=0|false|true (&#x2753;) |false|false| |exception|exception|true (&#x2753;)|true (&#x2753;)| false|
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/solvepnp.cpp **Change Type:** modified **Context:** PR #19253: Unexpected exception in solvePnPRansac caused by input points **Review Line:** 326 **Code Changes:** ```diff + { + if (flags == SOLVEPNP_ITERATIVE && + npoints1 == 5 && + e.what() && + std::string(e.what()).find("DLT algorithm needs at least 6 points") != std::string::npos + ) + { + CV_LOG_INFO(NULL, "solvePnPRansac(): solvePnP stage to compute the final pose using points " + "in the consensus set raised DLT 6 points exception, use result from MSS (Minimal Sample Sets) stage instead."); + rvec = _local_model.col(0); // output rotation vector + tvec = _local_model.col(1); // output translation vector ```
I think you meant to @ someone else (not me)?
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/matrix_sparse.cpp **Change Type:** modified **Context:** PR #26590: support C++20 standard **Review Line:** 174 **Code Changes:** ```diff @@ -171,7 +171,14 @@ void SparseMat::Hdr::clear() hashtab.clear(); hashtab.resize(HASH_SIZE0); pool.clear(); +#if defined(__GNUC__) && (__GNUC__ == 13) && !defined(__clang__) && (__cplusplus >= 202002L) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif pool.resize(nodeSize); +#if defined(__GNUC__) && (__GNUC__ == 13) && !defined(__clang__) && (__cplusplus >= 202002L) ```
It's not safe replacement. Pool elements cannot be used after it, but they could be before.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/test/test_filter.cpp **Change Type:** modified **Context:** PR #26590: support C++20 standard **Code Changes:** ```diff @@ -1865,107 +1865,65 @@ TEST(Imgproc_PreCornerDetect, accuracy) { CV_PreCornerDetectTest test; test.safe TEST(Imgproc_Integral, accuracy) { CV_IntegralTest test; test.safe_run(); } ////////////////////////////////////////////////////////////////////////////////// - -class CV_FilterSupportedFormatsTest : public cvtest::BaseTest -{ -public: - CV_FilterSupportedFormatsTest() {} - ~CV_FilterSupportedFormatsTest() {} ```
What issue does it solve? I prefer the original version.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/test/test_filter.cpp **Change Type:** modified **Context:** PR #26590: support C++20 standard **Code Changes:** ```diff @@ -1865,107 +1865,65 @@ TEST(Imgproc_PreCornerDetect, accuracy) { CV_PreCornerDetectTest test; test.safe TEST(Imgproc_Integral, accuracy) { CV_IntegralTest test; test.safe_run(); } ////////////////////////////////////////////////////////////////////////////////// - -class CV_FilterSupportedFormatsTest : public cvtest::BaseTest -{ -public: - CV_FilterSupportedFormatsTest() {} - ~CV_FilterSupportedFormatsTest() {} ```
Perhaps this test should be rewritten using `ASSERT/EXPECT_NO_THROW` and `SCOPED_TRACE` :slightly_smiling_face:
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/generalized_hough.cpp **Change Type:** modified **Context:** PR #26590: support C++20 standard **Code Changes:** ```diff @@ -692,7 +692,11 @@ namespace getContourPoints(edges, dx, dy, points); features.resize(levels_ + 1); - std::for_each(features.begin(), features.end(), [=](std::vector<Feature>& e) { e.clear(); e.reserve(maxBufferSize_); }); + const size_t maxBufferSize = maxBufferSize_; + std::for_each(features.begin(), features.end(), [maxBufferSize](std::vector<Feature>& e) { + e.clear(); + e.reserve(maxBufferSize); + }); ```
I think lambda capture list should be kept as small as possible. If compatibility with C++11 should be preserved, then ```suggestion const size_t maxBufferSize = maxBufferSize_; std::for_each(features.begin(), features.end(), [maxBufferSize](std::vector<Feature>& e) { e.clear(); e.reserve(maxBufferSize); }); ``` otherwise for C++14 ```c++ std::for_each(features.begin(), features.end(), [maxBufferSize = maxBufferSize_](std::vector<Feature>& e) { e.clear(); e.reserve(maxBufferSize); }); ```
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/gpt2_inference.py **Change Type:** modified **Context:** PR #26584: Update printingin GPT2 sample **Code Changes:** ```diff @@ -30,21 +30,17 @@ python gpt2_inference.py --model=<path-to-onnx-model> --prompt=<use-promt-of-the-same-length-used-while-exporting> ''' - - import numpy as np import tiktoken import argparse import cv2 as cv ```
I propose to raise the limitation up to 1000 tockens or more.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/object_tracker.cpp **Change Type:** added **Context:** PR #26202: Improved Tracker Samples **Code Changes:** ```diff @@ -0,0 +1,309 @@ +#include <iostream> +#include <cmath> + +#include <opencv2/dnn.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/highgui.hpp> +#include <opencv2/video.hpp> +#include "common.hpp" + ```
The path of the models are confusing. Warning messages require setting `OPENCV_SAMPLES_DATA_PATH` or `OPENCV_DOWNLOAD_CACHE_DIR`; when `OPENCV_SAMPLES_DATA_PATH` is set, another warning appear: FileNotFoundError: File xxxx not found! Please specify the path to /opencv/samples/data in the OPENCV_SAMPLES_DATA_PATH environment variable, or specify the path to opencv_extra/testdata in the OPENCV_DNN_TEST_DATA_PATH environment variable, or specify the path to the model download cache directory in the OPENCV_DOWNLOAD_CACHE_DIR environment variable, or pass the full path to xxxx.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/object_tracker.cpp **Change Type:** added **Context:** PR #26202: Improved Tracker Samples **Code Changes:** ```diff @@ -0,0 +1,309 @@ +#include <iostream> +#include <cmath> + +#include <opencv2/dnn.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/highgui.hpp> +#include <opencv2/video.hpp> +#include "common.hpp" + ```
Such main does not make a lot of sense. I propose to rename "run" to "main" and remove it.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/object_tracker.cpp **Change Type:** added **Context:** PR #26202: Improved Tracker Samples **Code Changes:** ```diff @@ -0,0 +1,309 @@ +#include <iostream> +#include <cmath> + +#include <opencv2/dnn.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/highgui.hpp> +#include <opencv2/video.hpp> +#include "common.hpp" + ```
Why do you use 100 here?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/object_tracker.cpp **Change Type:** added **Context:** PR #26202: Improved Tracker Samples **Code Changes:** ```diff @@ -0,0 +1,309 @@ +#include <iostream> +#include <cmath> + +#include <opencv2/dnn.hpp> +#include <opencv2/imgproc.hpp> +#include <opencv2/highgui.hpp> +#include <opencv2/video.hpp> +#include "common.hpp" + ```
yes, 100ms is too long delay. Should be decreased to 10.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/ml/src/svm.cpp **Change Type:** modified **Context:** PR #26587: Fix #25812: Add error handling for invalid nu parameter in SVM NU_SVC **Review Line:** 1462 **Code Changes:** ```diff COPYRIGHT NOTICE ---------------- @@ -1458,9 +1460,10 @@ class SVMImpl CV_FINAL : public SVM for( j = i+1; j< class_count; j++ ) { int cj = class_ranges[j+1] - class_ranges[j]; - if( nu*(ci + cj)*0.5 > std::min( ci, cj ) ) - // TODO: add some diagnostic + if( nu*(ci + cj)*0.5 > std::min( ci, cj ) ) { + CV_LOG_ERROR(NULL, "Training cases incompatible with nu parameter—try a lower value."); return false; ```
CV_Error raises exception. The method would interrupt execution here instead of false result. Alternative solution is just log message like ``` CV_LOG_ERROR(NULL, "Training cases incompatible with nu parameter—try a lower value."); ```
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:** modules/core/misc/objc/common/CvTypeExt.swift **Change Type:** modified **Context:** PR #26559: Fixed cv::Mat type constants in ObjC and Swift. **Review Line:** 55 **Code Changes:** ```diff @@ -53,7 +53,7 @@ public extension CvType { static let CV_16FC4: Int32 = CV_16FC(4) static let CV_CN_MAX = 512 - static let CV_CN_SHIFT = 3 + static let CV_CN_SHIFT = 5 static let CV_DEPTH_MAX = 1 << CV_CN_SHIFT static func CV_8UC(_ channels:Int32) -> Int32 { ```
Still wrong outdated value.
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:** modules/highgui/CMakeLists.txt **Change Type:** modified **Context:** PR #26563: Missing include directories needed for wayland-util and xkbcommon **Code Changes:** ```diff @@ -83,6 +83,7 @@ if(WITH_WAYLAND AND HAVE_WAYLAND) endif() endif() + ocv_module_include_directories(${WAYLAND_CLIENT_INCLUDE_DIRS} ${XKBCOMMON_INCLUDE_DIRS}) elseif(HAVE_QT) set(OPENCV_HIGHGUI_BUILTIN_BACKEND "QT${QT_VERSION_MAJOR}") add_definitions(-DHAVE_QT) ```
I propose to add includes to line 85 into `if(WITH_WAYLAND AND HAVE_WAYLAND)` condition scope. and stay the line as is.
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/drawing.cpp **Change Type:** modified **Context:** PR #26513: Fix for issue 26264 **Code Changes:** ```diff @@ -2477,21 +2477,70 @@ void cv::drawContours( InputOutputArray _image, InputArrayOfArrays _contours, CV_Assert(ncontours <= (size_t)std::numeric_limits<int>::max()); if (lineType == cv::LINE_AA && _image.depth() != CV_8U) lineType = 8; - Mat image = _image.getMat(), hierarchy = _hierarchy.getMat(); + Mat image = _image.getMat(); + Mat_<Vec4i> hierarchy = _hierarchy.getMat(); - if (thickness >= 0) // contour lines + int i = 0, end = (int)ncontours; ```
Most likely faster because there is no dynamic re-allocation ```cpp indexesToFill.resize(end-i); indexesToFill = iota<int>(indexesToFill.begin(), indexesToFill.end(), i); ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/drawing.cpp **Change Type:** modified **Context:** PR #26513: Fix for issue 26264 **Code Changes:** ```diff @@ -2477,21 +2477,70 @@ void cv::drawContours( InputOutputArray _image, InputArrayOfArrays _contours, CV_Assert(ncontours <= (size_t)std::numeric_limits<int>::max()); if (lineType == cv::LINE_AA && _image.depth() != CV_8U) lineType = 8; - Mat image = _image.getMat(), hierarchy = _hierarchy.getMat(); + Mat image = _image.getMat(); + Mat_<Vec4i> hierarchy = _hierarchy.getMat(); - if (thickness >= 0) // contour lines + int i = 0, end = (int)ncontours; ```
Maybe initialize hierarchy as ```cpp Mat_<Vec4i> hierarchy = _hierarchy.getMat(); ``` so that you do not type `.at<Vec4i>` every time
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/drawing.cpp **Change Type:** modified **Context:** PR #26513: Fix for issue 26264 **Review Line:** 2531 **Code Changes:** ```diff + next = hierarchy(next)[0]; // next sibling + } } - for (; i < end; ++i) + } + std::vector<Mat> contoursToFill; + contoursToFill.reserve(indexesToFill.size()); + for (const int& idx : indexesToFill) + contoursToFill.emplace_back(_contours.getMat(idx)); + + if (thickness < 0) ```
```cpp contoursToFill.reserve(indexesToFill.size()); ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/test/test_contours.cpp **Change Type:** modified **Context:** PR #26513: Fix for issue 26264 **Code Changes:** ```diff @@ -446,9 +446,9 @@ static void d2xy(int n, int d, int *x, int *y) } } -TEST(Imgproc_FindContours, hilbert) +static Mat draw_hilbert(int n = 64, int scale = 10) { - int n = 64, n2 = n*n, scale = 10, w = (n + 2)*scale; + int n2 = n*n, w = (n + 2)*scale; Point ofs(scale, scale); ```
why not put it into for loop?
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/stitching/include/opencv2/stitching.hpp **Change Type:** modified **Context:** PR #26516: Document some stitching methods and enable bindings for them. **Review Line:** 308 **Code Changes:** ```diff + */ + CV_WRAP std::vector<int> component() const { return indices_; } + + /** Returns estimated camera parameters for all stitched images + */ + CV_WRAP std::vector<cv::detail::CameraParams> cameras() const { return cameras_; } CV_WRAP double workScale() const { return work_scale_; } /** @brief Return the mask of the panorama. ```
As I can see `setTransform` method is not wrapped, it seems that is not possible to set `cameras_` from Python.
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/stitching/include/opencv2/stitching.hpp **Change Type:** modified **Context:** PR #26516: Document some stitching methods and enable bindings for them. **Review Line:** 308 **Code Changes:** ```diff + */ + CV_WRAP std::vector<int> component() const { return indices_; } + + /** Returns estimated camera parameters for all stitched images + */ + CV_WRAP std::vector<cv::detail::CameraParams> cameras() const { return cameras_; } CV_WRAP double workScale() const { return work_scale_; } /** @brief Return the mask of the panorama. ```
There is issue in current generator implementation: ``` In file included from /mnt/Projects/Projects/opencv/modules/python/src2/cv2.cpp:88: /mnt/Projects/Projects/opencv-build/modules/python_bindings_generator/pyopencv_generated_types_content.h: In function ‘PyObject* pyopencv_cv_Stitcher_setTransform(PyObject*, PyObject*, PyObject*)’: /mnt/Projects/Projects/opencv-build/modules/python_bindings_generator/pyopencv_generated_types_content.h:21351:5: error: ‘vector_detail_CameraParams’ was not declared in this scope; did you mean ‘vector_CameraParams’? 21351 | vector_detail_CameraParams cameras; ``` Let's handle it separately.
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/tensorflow/tf_importer.cpp **Change Type:** modified **Context:** PR #26394: Modified tensorflow parser for the new dnn engine **Review Line:** 636 **Code Changes:** ```diff friend class TFLayerHandler; @@ -603,6 +633,80 @@ class TFImporter void parseCustomLayer (tensorflow::GraphDef& net, const tensorflow::NodeDef& layer, LayerParams& layerParams); }; +void TFImporter::addLayer(const std::string& name, const std::string& type, LayerParams& layerParams, std::vector<std::string> inputs, int numOutputs, int repeatInputs) +{ + if (repeatInputs != 0) + { + CV_CheckEQ(inputs.size(), 1u, ""); + for (int i = 0; i < repeatInputs; i++) ```
const std::vector<std::string>&
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/tensorflow/tf_importer.cpp **Change Type:** modified **Context:** PR #26394: Modified tensorflow parser for the new dnn engine **Code Changes:** ```diff @@ -10,9 +10,11 @@ Implementation of Tensorflow models parser */ #include "../precomp.hpp" +#include "../net_impl.hpp" #include <opencv2/core/utils/fp_control_utils.hpp> +#include <opencv2/core/utils/configuration.private.hpp> #include <opencv2/core/utils/logger.defines.hpp> ```
Please add meaningful error message.
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:** 3rdparty/clapack/runtime/cblas_wrap.c **Change Type:** added **Context:** PR #18571: Added clapack **Review Line:** 286 **Code Changes:** ```diff + } + if (info) + fprintf(stderr, "Parameter %d to routine %s was incorrect\n", info, rout); + vfprintf(stderr, form, argptr); + va_end(argptr); + if (info && !info) + xerbla_(empty, &info); /* Force link of our F77 error handler */ + exit(-1); +} ```
Looks like a bug: #26528 --- > `exit(-1)` Should not have that.
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/test/test_layers.cpp **Change Type:** modified **Context:** PR #26503: Fixed test LSTM warning. **Review Line:** 2745 **Code Changes:** ```diff @@ -2742,7 +2742,7 @@ INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionActivationEltwiseFusion, Com TEST(Layer_LSTM, repeatedInference) { - std::string onnx_file_path = findDataFile("dnn/onnx/models/onnxscript_lstm.onnx", false); + std::string onnx_file_path = findDataFile("dnn/onnx/models/onnxscript_lstm.onnx", true); // Test parameters const int batch_size = 1; ```
`true` value is a default, so it could be removed. Reproduce with `OPENCV_TEST_CHECK_OPTIONAL_DATA=1` environment variable.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers.cpp **Change Type:** modified **Context:** PR #26503: Fixed test LSTM warning. **Review Line:** 2745 **Code Changes:** ```diff @@ -2742,7 +2742,7 @@ INSTANTIATE_TEST_CASE_P(TestLayerFusion, ConvolutionActivationEltwiseFusion, Com TEST(Layer_LSTM, repeatedInference) { - std::string onnx_file_path = findDataFile("dnn/onnx/models/onnxscript_lstm.onnx", false); + std::string onnx_file_path = findDataFile("dnn/onnx/models/onnxscript_lstm.onnx", true); // Test parameters const int batch_size = 1; ```
Addressed in https://github.com/opencv/ci-gha-workflow/pull/198
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/core/src/hal_replacement.hpp **Change Type:** modified **Context:** PR #26459: HAL added for absdiff(array, scalar) + related fixes **Code Changes:** ```diff @@ -109,9 +109,10 @@ Add scalar: _dst[i] = src[i] + scalar @param width width of the images @param height height of the images @param scalar_data pointer to scalar value +@param nChannels number of channels per element */ -inline int hal_ni_addScalar32f32f(const float *src_data, size_t src_step, float *dst_data, size_t dst_step, int width, int height, const float* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } -inline int hal_ni_addScalar16s16s(const int16_t *src_data, size_t src_step, int16_t *dst_data, size_t dst_step, int width, int height, const int16_t* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_addScalar32f32f(const float* src_data, size_t src_step, float* dst_data, size_t dst_step, int width, int height, const float* scalar_data, int nChannels) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_addScalar16s16s(const int16_t* src_data, size_t src_step, int16_t* dst_data, size_t dst_step, int width, int height, const int16_t* scalar_data, int nChannels) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } ```
shall it be unsigned/uint32_t type for the output array?
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/core/src/hal_replacement.hpp **Change Type:** modified **Context:** PR #26459: HAL added for absdiff(array, scalar) + related fixes **Code Changes:** ```diff @@ -109,9 +109,10 @@ Add scalar: _dst[i] = src[i] + scalar @param width width of the images @param height height of the images @param scalar_data pointer to scalar value +@param nChannels number of channels per element */ -inline int hal_ni_addScalar32f32f(const float *src_data, size_t src_step, float *dst_data, size_t dst_step, int width, int height, const float* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } -inline int hal_ni_addScalar16s16s(const int16_t *src_data, size_t src_step, int16_t *dst_data, size_t dst_step, int width, int height, const int16_t* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_addScalar32f32f(const float* src_data, size_t src_step, float* dst_data, size_t dst_step, int width, int height, const float* scalar_data, int nChannels) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_addScalar16s16s(const int16_t* src_data, size_t src_step, int16_t* dst_data, size_t dst_step, int width, int height, const int16_t* scalar_data, int nChannels) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } ```
discussed, fixed
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/recurrent2_layers.cpp **Change Type:** added **Context:** PR #26391: LSTM layer for new graph engine. **Code Changes:** ```diff @@ -0,0 +1,605 @@ +// 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 <iostream> +#include <cmath> +#include <opencv2/dnn/shape_utils.hpp> +#include "layers_common.hpp" ```
Please use modern license header, e.g. https://github.com/opencv/opencv/blob/4.x/modules/dnn/src/backend.cpp
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/recurrent2_layers.cpp **Change Type:** added **Context:** PR #26391: LSTM layer for new graph engine. **Code Changes:** ```diff @@ -0,0 +1,605 @@ +// 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 <iostream> +#include <cmath> +#include <opencv2/dnn/shape_utils.hpp> +#include "layers_common.hpp" ```
Please remove if not relevant.
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/test/test_onnx_importer.cpp **Change Type:** modified **Context:** PR #26391: LSTM layer for new graph engine. **Review Line:** 1331 **Code Changes:** ```diff #endif testONNXModels("split_max"); } - +// Fails with the new engine. Output shape [?, N, OutputSize] not supported by new graph engine TEST_P(Test_ONNX_layers, LSTM_Activations) { if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) @@ -1497,15 +1497,21 @@ TEST_P(Test_ONNX_layers, LSTM_init_h0_c0) applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); testONNXModels("lstm_init_h0_c0", npy, 0, 0, false, false, 3); ```
Please add note why the test is disabled. Here and bellow.
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/recurrent2_layers.cpp **Change Type:** added **Context:** PR #26391: LSTM layer for new graph engine. **Review Line:** 194 **Code Changes:** ```diff + std::vector<MatType>& outputs, + std::vector<MatType>& internals) const CV_OVERRIDE + { + CV_Assert(inputs[0] == CV_32F || inputs[0] == CV_64F); // Only floating-point types are supported currently + outputs.assign(requiredOutputs, inputs[0]); + internals.assign(4, inputs[0]); + } + + + void forward(InputArrayOfArrays inputs_arr, + OutputArrayOfArrays outputs_arr, ```
According to implementation, only fp32 and m.b. fp64 are supported. Need ti add check/assert here.
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/recurrent2_layers.cpp **Change Type:** added **Context:** PR #26391: LSTM layer for new graph engine. **Code Changes:** ```diff @@ -0,0 +1,605 @@ +// 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 <iostream> +#include <cmath> +#include <opencv2/dnn/shape_utils.hpp> +#include "layers_common.hpp" ```
Please add check that the layer got enough inputs.
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/recurrent2_layers.cpp **Change Type:** added **Context:** PR #26391: LSTM layer for new graph engine. **Review Line:** 467 **Code Changes:** ```diff + + vconcat(part1, part2, dst); + + int finalShape[] = {2, batchSize, numHidden}; + dst = dst.reshape(1, sizeof(finalShape)/sizeof(finalShape[0]), finalShape); + + if (layout == BATCH_SEQ_HID){ + cv::transposeND(dst, {1, 0, 2}, dst); + } + } + } ```
redundant space line.
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/init.cpp **Change Type:** modified **Context:** PR #26391: LSTM layer for new graph engine. **Review Line:** 212 **Code Changes:** ```diff @@ -209,6 +209,7 @@ void initializeLayerFactory() CV_DNN_REGISTER_LAYER_CLASS(FlowWarp, FlowWarpLayer); CV_DNN_REGISTER_LAYER_CLASS(LSTM, LSTMLayer); + CV_DNN_REGISTER_LAYER_CLASS(LSTM2, LSTM2Layer); CV_DNN_REGISTER_LAYER_CLASS(GRU, GRULayer); CV_DNN_REGISTER_LAYER_CLASS(CumSum, CumSumLayer); CV_DNN_REGISTER_LAYER_CLASS(Einsum, EinsumLayer); ```
That is the first layer named in such a way. I think that layer name should remain the same while `Impl` class should be different for different versions of the engine
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/init.cpp **Change Type:** modified **Context:** PR #26391: LSTM layer for new graph engine. **Review Line:** 212 **Code Changes:** ```diff @@ -209,6 +209,7 @@ void initializeLayerFactory() CV_DNN_REGISTER_LAYER_CLASS(FlowWarp, FlowWarpLayer); CV_DNN_REGISTER_LAYER_CLASS(LSTM, LSTMLayer); + CV_DNN_REGISTER_LAYER_CLASS(LSTM2, LSTM2Layer); CV_DNN_REGISTER_LAYER_CLASS(GRU, GRULayer); CV_DNN_REGISTER_LAYER_CLASS(CumSum, CumSumLayer); CV_DNN_REGISTER_LAYER_CLASS(Einsum, EinsumLayer); ```
Not first. Here are some examples [[1](https://github.com/opencv/opencv/blob/979428d5908b5396237b18cbd50d0b18265e2463/modules/dnn/src/init.cpp#L92)], [[2](https://github.com/opencv/opencv/blob/979428d5908b5396237b18cbd50d0b18265e2463/modules/dnn/src/init.cpp#L88)], [[3](https://github.com/opencv/opencv/blob/979428d5908b5396237b18cbd50d0b18265e2463/modules/dnn/src/init.cpp#L107)]
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/test/test_onnx_importer.cpp **Change Type:** modified **Context:** PR #26391: LSTM layer for new graph engine. **Review Line:** 1331 **Code Changes:** ```diff #endif testONNXModels("split_max"); } - +// Fails with the new engine. Output shape [?, N, OutputSize] not supported by new graph engine TEST_P(Test_ONNX_layers, LSTM_Activations) { if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) @@ -1497,15 +1497,21 @@ TEST_P(Test_ONNX_layers, LSTM_init_h0_c0) applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); testONNXModels("lstm_init_h0_c0", npy, 0, 0, false, false, 3); ```
Is that comment still actual? To understand why working tests have been disabled and no new alternatives added.
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/test/test_layers.cpp **Change Type:** modified **Context:** PR #26391: LSTM layer for new graph engine. **Review Line:** 2745 **Code Changes:** ```diff TestLayerFusion::dnnBackendsAndTargetsForFusionTests() )); +TEST(Layer_LSTM, repeatedInference) +{ + std::string onnx_file_path = findDataFile("dnn/onnx/models/onnxscript_lstm.onnx", false); + + // Test parameters + const int batch_size = 1; + const int seq_length = 5; + const int input_size = 6; ```
Merged against RED CI: ``` [----------] 1 test from Layer_LSTM [ RUN ] Layer_LSTM.repeatedInference TEST ERROR: Don't use 'optional' findData() for dnn/onnx/models/onnxscript_lstm.onnx unknown file: Failure C++ exception with description "OpenCV(5.0.0-pre) /build/precommit_linux64/5.x/opencv/modules/ts/src/ts.cpp:969: error: (-215:Assertion failed) required || result_.empty() in function 'findData' " thrown in the test body. [ FAILED ] Layer_LSTM.repeatedInference (0 ms) ```
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/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp **Change Type:** modified **Context:** PR #26454: imgproc: fix perf regressions on the c4 kernels of warpAffine / warpPerspective / remap **Code Changes:** ```diff @@ -543,6 +543,40 @@ OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float32, vfloat32m2_t, float, VTraits<v_float OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float64, vfloat64m2_t, double, VTraits<v_float64>::vlanes() / 2, VTraits<v_float64>::vlanes(), 64, f64) #endif +template <int N = VTraits<v_uint16>::max_nlanes> +inline void v_store(ushort* ptr, const v_uint16& a) +{ + ushort buf[VTraits<v_uint16>::max_nlanes]; + v_store(buf, a); + for (int i = 0; i < N; i++) { ```
why `n` parameter is passed? Let's get rid of it.
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/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp **Change Type:** modified **Context:** PR #26454: imgproc: fix perf regressions on the c4 kernels of warpAffine / warpPerspective / remap **Code Changes:** ```diff @@ -543,6 +543,40 @@ OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float32, vfloat32m2_t, float, VTraits<v_float OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float64, vfloat64m2_t, double, VTraits<v_float64>::vlanes() / 2, VTraits<v_float64>::vlanes(), 64, f64) #endif +template <int N = VTraits<v_uint16>::max_nlanes> +inline void v_store(ushort* ptr, const v_uint16& a) +{ + ushort buf[VTraits<v_uint16>::max_nlanes]; + v_store(buf, a); + for (int i = 0; i < N; i++) { ```
let's get rid of 'n' parameter in the newly added intrinsics.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp **Change Type:** modified **Context:** PR #26454: imgproc: fix perf regressions on the c4 kernels of warpAffine / warpPerspective / remap **Code Changes:** ```diff @@ -543,6 +543,40 @@ OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float32, vfloat32m2_t, float, VTraits<v_float OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float64, vfloat64m2_t, double, VTraits<v_float64>::vlanes() / 2, VTraits<v_float64>::vlanes(), 64, f64) #endif +template <int N = VTraits<v_uint16>::max_nlanes> +inline void v_store(ushort* ptr, const v_uint16& a) +{ + ushort buf[VTraits<v_uint16>::max_nlanes]; + v_store(buf, a); + for (int i = 0; i < N; i++) { ```
~I am afraid that we cannot, since `v_store` is already defined.~ Ok, never mind. Tested and it can work without `n`.
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/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp **Change Type:** modified **Context:** PR #26454: imgproc: fix perf regressions on the c4 kernels of warpAffine / warpPerspective / remap **Code Changes:** ```diff @@ -543,6 +543,40 @@ OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float32, vfloat32m2_t, float, VTraits<v_float OPENCV_HAL_IMPL_RVV_LOADSTORE_OP(v_float64, vfloat64m2_t, double, VTraits<v_float64>::vlanes() / 2, VTraits<v_float64>::vlanes(), 64, f64) #endif +template <int N = VTraits<v_uint16>::max_nlanes> +inline void v_store(ushort* ptr, const v_uint16& a) +{ + ushort buf[VTraits<v_uint16>::max_nlanes]; + v_store(buf, a); + for (int i = 0; i < N; i++) { ```
Done. Also removed `n` parameter from last PR.
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/arithm.cpp **Change Type:** modified **Context:** PR #25624: HAL added for add(array, scalar) **Review Line:** 590 **Code Changes:** ```diff #endif +typedef int (*ScalarFunc)(const uchar* src, size_t step_src, + uchar* dst, size_t step_dst, int width, int height, + void* scalar, bool scalarIsFirst); + typedef int (*ExtendedTypeFunc)(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void*); ```
`usrdata` is not supported, this should be fixed for more common cases
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/core/src/hal_replacement.hpp **Change Type:** modified **Context:** PR #25624: HAL added for add(array, scalar) **Review Line:** 113 **Code Changes:** ```diff +@param dst_step destination image step +@param width width of the images +@param height height of the images +@param scalar_data pointer to scalar value +*/ +inline int hal_ni_addScalar32f32f(const float *src_data, size_t src_step, float *dst_data, size_t dst_step, int width, int height, const float* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_addScalar16s16s(const int16_t *src_data, size_t src_step, int16_t *dst_data, size_t dst_step, int width, int height, const int16_t* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } //! @} /** @@ -192,6 +206,8 @@ inline int hal_ni_not8u(const uchar *src_data, size_t src_step, uchar *dst_data, ```
if we want to support C1, C3 etc. scalars, we need to add `int nchannels` (check that the name is consistent with other HAL entries)
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/core/src/hal_replacement.hpp **Change Type:** modified **Context:** PR #25624: HAL added for add(array, scalar) **Review Line:** 113 **Code Changes:** ```diff +@param dst_step destination image step +@param width width of the images +@param height height of the images +@param scalar_data pointer to scalar value +*/ +inline int hal_ni_addScalar32f32f(const float *src_data, size_t src_step, float *dst_data, size_t dst_step, int width, int height, const float* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_addScalar16s16s(const int16_t *src_data, size_t src_step, int16_t *dst_data, size_t dst_step, int width, int height, const int16_t* scalar_data) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } //! @} /** @@ -192,6 +206,8 @@ inline int hal_ni_not8u(const uchar *src_data, size_t src_step, uchar *dst_data, ```
Probably we will add support for more channels in later PRs For now we leave it just for 1 channel
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:** CMakeLists.txt **Change Type:** modified **Context:** PR #26303: Skip KleidiCV in offline build **Code Changes:** ```diff @@ -935,7 +935,7 @@ if(HAVE_OPENVX) endif() endif() -if(WITH_KLEIDICV) +if(HAVE_KLEIDICV) ocv_debug_message(STATUS "Enable KleidiCV acceleration") if(NOT ";${OpenCV_HAL};" MATCHES ";kleidicv;") set(OpenCV_HAL "kleidicv;${OpenCV_HAL}") ```
This skips `add_subdirectory()` call if user specifies `cmake -DOpenCV_HAL=kleidicv ...`.
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:** CMakeLists.txt **Change Type:** modified **Context:** PR #26303: Skip KleidiCV in offline build **Code Changes:** ```diff @@ -935,7 +935,7 @@ if(HAVE_OPENVX) endif() endif() -if(WITH_KLEIDICV) +if(HAVE_KLEIDICV) ocv_debug_message(STATUS "Enable KleidiCV acceleration") if(NOT ";${OpenCV_HAL};" MATCHES ";kleidicv;") set(OpenCV_HAL "kleidicv;${OpenCV_HAL}") ```
What is the problem to follow carotene design?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/test/test_io.cpp **Change Type:** modified **Context:** PR #26420: Support 0d/1d Mat in FileStorage **Review Line:** 2054 **Code Changes:** ```diff + EXPECT_EQ(src.size, dst.size); + EXPECT_EQ(cv::norm(src, dst, NORM_INF), 0.0); +} + +typedef testing::TestWithParam<const char*> FileStorage_exact_type; +TEST_P(FileStorage_exact_type, empty_mat) +{ + testExactMat(Mat(), GetParam()); +} + +TEST_P(FileStorage_exact_type, mat_0d) ```
This test raises debug assertion ``` [ RUN ] Core_InputOutput/FileStorage_exact_type.empty_mat/0, where GetParam() = ".yml" unknown file: Failure C++ exception with description "OpenCV(5.0.0-pre) /work/opencv/modules/core/include/opencv2/core/mat.inl.hpp:1349: error: (-215:Assertion failed) i < dims() in function 'operator[]' " thrown in the test body. [ FAILED ] Core_InputOutput/FileStorage_exact_type.empty_mat/0, where GetParam() = ".yml" (1 ms) ``` Here: https://github.com/opencv/opencv/blob/979428d5908b5396237b18cbd50d0b18265e2463/modules/core/include/opencv2/core/mat.inl.hpp#L1346-L1354
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/test/test_io.cpp **Change Type:** modified **Context:** PR #26420: Support 0d/1d Mat in FileStorage **Review Line:** 2054 **Code Changes:** ```diff + EXPECT_EQ(src.size, dst.size); + EXPECT_EQ(cv::norm(src, dst, NORM_INF), 0.0); +} + +typedef testing::TestWithParam<const char*> FileStorage_exact_type; +TEST_P(FileStorage_exact_type, empty_mat) +{ + testExactMat(Mat(), GetParam()); +} + +TEST_P(FileStorage_exact_type, mat_0d) ```
Please take a look at https://github.com/opencv/opencv/pull/26444
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/calib3d/src/undistort.dispatch.cpp **Change Type:** modified **Context:** PR #26437: backport C++ stereo/stereo_geom.cpp:5.x to calib3d/stereo_geom.cpp:4.x **Review Line:** 511 **Code Changes:** ```diff - cvUndistortPointsInternal(_src, _dst, _cameraMatrix, _distCoeffs, matR, matP, - cv::TermCriteria(cv::TermCriteria::COUNT, 5, 0.01)); -} - namespace cv { void undistortPoints(InputArray _src, OutputArray _dst, ```
AFAIK these kind of functions were keeped in 4.x for compatibility as discussed in https://github.com/opencv/opencv/pull/26259
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/calib3d/src/undistort.dispatch.cpp **Change Type:** modified **Context:** PR #26437: backport C++ stereo/stereo_geom.cpp:5.x to calib3d/stereo_geom.cpp:4.x **Review Line:** 511 **Code Changes:** ```diff - cvUndistortPointsInternal(_src, _dst, _cameraMatrix, _distCoeffs, matR, matP, - cv::TermCriteria(cv::TermCriteria::COUNT, 5, 0.01)); -} - namespace cv { void undistortPoints(InputArray _src, OutputArray _dst, ```
Currently, this is only used internally, it is not part of the public C API (which does not have much in calib3d, cf https://github.com/opencv/opencv/blob/4.x/modules/calib3d/include/opencv2/calib3d/calib3d_c.h). This PR switches the C code that uses it to C++, so there is no need for that function anymore.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/undistort.dispatch.cpp **Change Type:** modified **Context:** PR #26437: backport C++ stereo/stereo_geom.cpp:5.x to calib3d/stereo_geom.cpp:4.x **Review Line:** 511 **Code Changes:** ```diff - cvUndistortPointsInternal(_src, _dst, _cameraMatrix, _distCoeffs, matR, matP, - cv::TermCriteria(cv::TermCriteria::COUNT, 5, 0.01)); -} - namespace cv { void undistortPoints(InputArray _src, OutputArray _dst, ```
for example https://github.com/shimat/opencvsharp uses cvUndistortPoints. shouldn't this be preserved?
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/calib3d/src/undistort.dispatch.cpp **Change Type:** modified **Context:** PR #26437: backport C++ stereo/stereo_geom.cpp:5.x to calib3d/stereo_geom.cpp:4.x **Review Line:** 511 **Code Changes:** ```diff - cvUndistortPointsInternal(_src, _dst, _cameraMatrix, _distCoeffs, matR, matP, - cv::TermCriteria(cv::TermCriteria::COUNT, 5, 0.01)); -} - namespace cv { void undistortPoints(InputArray _src, OutputArray _dst, ```
``` git grep cvUndistortPoints ``` dies not return anything in their repo, where do they use it? They use `cv::undistortPoints` which is the C++ API. `modules/calib3d/src/calib3d_c_api.h` is an internal header so modifying it fine, other projects cannot use the API it offers.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/undistort.dispatch.cpp **Change Type:** modified **Context:** PR #26437: backport C++ stereo/stereo_geom.cpp:5.x to calib3d/stereo_geom.cpp:4.x **Review Line:** 511 **Code Changes:** ```diff - cvUndistortPointsInternal(_src, _dst, _cameraMatrix, _distCoeffs, matR, matP, - cv::TermCriteria(cv::TermCriteria::COUNT, 5, 0.01)); -} - namespace cv { void undistortPoints(InputArray _src, OutputArray _dst, ```
sorry let me check again
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/calib3d/src/undistort.dispatch.cpp **Change Type:** modified **Context:** PR #26437: backport C++ stereo/stereo_geom.cpp:5.x to calib3d/stereo_geom.cpp:4.x **Review Line:** 511 **Code Changes:** ```diff - cvUndistortPointsInternal(_src, _dst, _cameraMatrix, _distCoeffs, matR, matP, - cv::TermCriteria(cv::TermCriteria::COUNT, 5, 0.01)); -} - namespace cv { void undistortPoints(InputArray _src, OutputArray _dst, ```
I agree, the C API is till used, but the API removed in this PR is INTERNAL to OpenCV, nobody outside of OpenCV is using it because they cannot use it: the header that declares it is not public, it is in `src`, not in `include`. `cvUndistortPoints` was removed from the public C API 6 years ago in https://github.com/opencv/opencv/commit/8f15a609afc3c08ea0a5561ca26f1cf182414ca2#diff-7ae6742689a7ee66932275c29e27989687a7b9e6ca2549a765f5b27414c753daR53 The link you just sent me is from a different repo, the last commit on that file is "[support 2.4.10](https://github.com/imclab/opencvsharp/commit/f55344d7c5d93838206c9a55153be4636fa99734)" which is a very old OpenCV that is not supported anymore.
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/OpenCVMinDepVersions.cmake **Change Type:** modified **Context:** PR #26287: build: transition to C++17, minor changes in documentation - * Raise C++ standard to C++17 * Show warnings for possible configuration issue... **Review Line:** 3 **Code Changes:** ```diff @@ -1,5 +1,6 @@ if(NOT DEFINED MIN_VER_CMAKE) - set(MIN_VER_CMAKE 3.7) + set(MIN_VER_CMAKE 3.13) # Debian 10 + # set(MIN_VER_CMAKE 3.10) # Visual Studio 2017 15.7 endif() set(MIN_VER_CUDA 6.5) set(MIN_VER_CUDNN 7.5) ```
Let's use the lowest possible version.
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/OpenCVDetectCXXCompiler.cmake **Change Type:** modified **Context:** PR #26287: build: transition to C++17, minor changes in documentation - * Raise C++ standard to C++17 * Show warnings for possible configuration issue... **Review Line:** 212 **Code Changes:** ```diff + if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + set(HAVE_CXX17 ON) endif() endif() if(NOT HAVE_CXX11) - message(FATAL_ERROR "OpenCV 4.x requires C++11") + message(WARNING "OpenCV 5.x requires C++11 support, but it was not detected. Your compilation may fail.") +endif() +if(NOT HAVE_CXX17) + message(WARNING "OpenCV 5.x requires C++17 support, but it was not detected. Your compilation may fail.") ```
C++11 support is implied by C++17 support - so i presume `HAVE_CXX11` could be removed completely?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/calibration.cpp **Change Type:** modified **Context:** PR #26414: backport C++ 3d/calibration_base.cpp:5.x to calib3d/calibration_base.cpp:4.x **Code Changes:** ```diff @@ -42,7 +42,6 @@ #include "precomp.hpp" #include "hal_replacement.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "distortion_model.hpp" #include "calib3d_c_api.h" #include <stdio.h> @@ -58,1316 +57,7 @@ ```
`dABdA` and `dABdB` are optional. `cvarrToMat` returns empty Mat if the pointer is nullptr. Empty Mat is not equal to `cv::NoArray()`. You have to check pointers on wrapper side and put `cv::noArray` for optional outputs.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/calibration.cpp **Change Type:** modified **Context:** PR #26414: backport C++ 3d/calibration_base.cpp:5.x to calib3d/calibration_base.cpp:4.x **Code Changes:** ```diff @@ -42,7 +42,6 @@ #include "precomp.hpp" #include "hal_replacement.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "distortion_model.hpp" #include "calib3d_c_api.h" #include <stdio.h> @@ -58,1316 +57,7 @@ ```
The same for optional params.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/calibration.cpp **Change Type:** modified **Context:** PR #26414: backport C++ 3d/calibration_base.cpp:5.x to calib3d/calibration_base.cpp:4.x **Code Changes:** ```diff @@ -42,7 +42,6 @@ #include "precomp.hpp" #include "hal_replacement.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "distortion_model.hpp" #include "calib3d_c_api.h" #include <stdio.h> @@ -58,1316 +57,7 @@ ```
I actually removed the function
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/calib3d/src/calibration.cpp **Change Type:** modified **Context:** PR #26414: backport C++ 3d/calibration_base.cpp:5.x to calib3d/calibration_base.cpp:4.x **Code Changes:** ```diff @@ -42,7 +42,6 @@ #include "precomp.hpp" #include "hal_replacement.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "distortion_model.hpp" #include "calib3d_c_api.h" #include <stdio.h> @@ -58,1316 +57,7 @@ ```
I actually removed the function
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/ocl.cpp **Change Type:** modified **Context:** PR #26331: build: made environment access a separate feature - - changed second argument of the `getConfigurationParameterString` to `std::string` fro... **Review Line:** 2127 **Code Changes:** ```diff std::string platform, deviceName; std::vector<std::string> deviceTypes; - if (!configuration) - configuration = getenv("OPENCV_OPENCL_DEVICE"); + std::string configuration(configuration_); + if (configuration.empty()) + configuration = utils::getConfigurationParameterString("OPENCV_OPENCL_DEVICE"); - if (configuration && - (strcmp(configuration, "disabled") == 0 || ```
NULL can't be handled
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/highgui/src/window.cpp **Change Type:** modified **Context:** PR #26331: build: made environment access a separate feature - - changed second argument of the `getConfigurationParameterString` to `std::string` fro... **Review Line:** 665 **Code Changes:** ```diff @@ -662,7 +662,7 @@ int cv::waitKey(int delay) static int use_legacy = -1; if (use_legacy < 0) { - use_legacy = getenv("OPENCV_LEGACY_WAITKEY") != NULL ? 1 : 0; + use_legacy = utils::getConfigurationParameterBool("OPENCV_LEGACY_WAITKEY"); } if (use_legacy > 0) return code; ```
I propose to drop it in 5.x
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_dshow.cpp **Change Type:** modified **Context:** PR #26331: build: made environment access a separate feature - - changed second argument of the `getConfigurationParameterString` to `std::string` fro... **Review Line:** 306 **Code Changes:** ```diff - const char* s = getenv("OPENCV_DSHOW_DEBUG"); - gs_verbose = s != NULL && atoi(s) != 0; - } - - + static const bool gs_verbose = utils::getConfigurationParameterBool("OPENCV_DSHOW_DEBUG"); if (gs_verbose) { va_list args; @@ -2982,18 +2974,18 @@ int videoInput::start(int deviceID, videoDevice *VD){ VD->readyToCapture = true; ```
I propose to use generic logging here with default environment variables.
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 #26331: build: made environment access a separate feature - - changed second argument of the `getConfigurationParameterString` to `std::string` fro... **Review Line:** 932 **Code Changes:** ```diff { -#ifndef NO_GETENV - char* debug_option = getenv("OPENCV_FFMPEG_DEBUG"); - char* level_option = getenv("OPENCV_FFMPEG_LOGLEVEL"); + const bool debug_option = utils::getConfigurationParameterBool("OPENCV_FFMPEG_DEBUG"); + std::string level_option = utils::getConfigurationParameterString("OPENCV_FFMPEG_LOGLEVEL"); int level = AV_LOG_VERBOSE; - if (level_option != NULL) + if (!level_option.empty()) { - level = atoi(level_option); ```
I propose to use generic logging here with default environment variables.
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:** CMakeLists.txt **Change Type:** modified **Context:** PR #26331: build: made environment access a separate feature - - changed second argument of the `getConfigurationParameterString` to `std::string` fro... **Review Line:** 539 **Code Changes:** ```diff @@ -536,6 +536,7 @@ OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn' OCV_OPTION(OPENCV_ENABLE_MEMALIGN "Enable posix_memalign or memalign usage" ON) OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF) OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF) +OCV_OPTION(OPENCV_DISABLE_ENV_SUPPORT "Disable environment variables access (getenv)" (CMAKE_SYSTEM_NAME MATCHES "Windows(CE|Phone|Store)")) OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target (Arm). See https://developer.arm.com/documentation/100863/latest." OFF) OCV_OPTION(ENABLE_CUDA_FIRST_CLASS_LANGUAGE "Enable CUDA as a first class language, if enabled dependant projects will need to use CMake >= 3.18" OFF VISIBLE_IF (WITH_CUDA AND NOT CMAKE_VERSION VERSION_LESS 3.18) ```
iOS and derivatives?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/highgui/src/window.cpp **Change Type:** modified **Context:** PR #26331: build: made environment access a separate feature - - changed second argument of the `getConfigurationParameterString` to `std::string` fro... **Review Line:** 665 **Code Changes:** ```diff @@ -662,7 +662,7 @@ int cv::waitKey(int delay) static int use_legacy = -1; if (use_legacy < 0) { - use_legacy = getenv("OPENCV_LEGACY_WAITKEY") != NULL ? 1 : 0; + use_legacy = utils::getConfigurationParameterBool("OPENCV_LEGACY_WAITKEY"); } if (use_legacy > 0) return code; ```
OK, but this PR is for 4.x, so we'll need to remove it after these changes make their way to 5.x.
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:** CMakeLists.txt **Change Type:** modified **Context:** PR #26331: build: made environment access a separate feature - - changed second argument of the `getConfigurationParameterString` to `std::string` fro... **Review Line:** 539 **Code Changes:** ```diff @@ -536,6 +536,7 @@ OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn' OCV_OPTION(OPENCV_ENABLE_MEMALIGN "Enable posix_memalign or memalign usage" ON) OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF) OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF) +OCV_OPTION(OPENCV_DISABLE_ENV_SUPPORT "Disable environment variables access (getenv)" (CMAKE_SYSTEM_NAME MATCHES "Windows(CE|Phone|Store)")) OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target (Arm). See https://developer.arm.com/documentation/100863/latest." OFF) OCV_OPTION(ENABLE_CUDA_FIRST_CLASS_LANGUAGE "Enable CUDA as a first class language, if enabled dependant projects will need to use CMake >= 3.18" OFF VISIBLE_IF (WITH_CUDA AND NOT CMAKE_VERSION VERSION_LESS 3.18) ```
I'm not sure, it seems that we have no any specific handling for iOS. Perhaps this platform supports environment variables. If Apple compiler defines `NO_GETENV`, then it would automatically disable our getenv support even if cmake option is turned OFF.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/segmentation.cpp **Change Type:** modified **Context:** PR #26347: Updated segmentation sample as per current update usage and engine **Code Changes:** ```diff @@ -12,81 +12,176 @@ using namespace cv; using namespace std; using namespace dnn; +const string about = + "Use this script to run semantic segmentation deep learning networks using OpenCV.\n\n" + "Firstly, download required models using `download_models.py` (if not already done). Set environment variable OPENCV_DOWNLOAD_CACHE_DIR to specify where models should be downloaded. Also, point OPENCV_SAMPLES_DATA_PATH to opencv/samples/data.\n" + "To run:\n" + "\t ./example_dnn_classification modelName(e.g. u2netp) --input=$OPENCV_SAMPLES_DATA_PATH/butterfly.jpg (or ignore this argument to use device camera)\n" + "Model path can also be specified using --model argument."; ```
Please add fallback to ENGINE_CLASSIC, if device/target is not OCV/CPU.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/segmentation.cpp **Change Type:** modified **Context:** PR #26347: Updated segmentation sample as per current update usage and engine **Code Changes:** ```diff @@ -12,81 +12,176 @@ using namespace cv; using namespace std; using namespace dnn; +const string about = + "Use this script to run semantic segmentation deep learning networks using OpenCV.\n\n" + "Firstly, download required models using `download_models.py` (if not already done). Set environment variable OPENCV_DOWNLOAD_CACHE_DIR to specify where models should be downloaded. Also, point OPENCV_SAMPLES_DATA_PATH to opencv/samples/data.\n" + "To run:\n" + "\t ./example_dnn_classification modelName(e.g. u2netp) --input=$OPENCV_SAMPLES_DATA_PATH/butterfly.jpg (or ignore this argument to use device camera)\n" + "Model path can also be specified using --model argument."; ```
It does not print command line options. The command line parser may add custom test to printMessage with ::about(): https://docs.opencv.org/5.x/d0/d2e/classcv_1_1CommandLineParser.html#a2e11e779047efded23f75d9c5c5dd82e
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/segmentation.py **Change Type:** modified **Context:** PR #26347: Updated segmentation sample as per current update usage and engine **Code Changes:** ```diff @@ -1,140 +1,176 @@ import cv2 as cv import argparse import numpy as np -import sys from common import * -backends = (cv.dnn.DNN_BACKEND_DEFAULT, cv.dnn.DNN_BACKEND_INFERENCE_ENGINE, cv.dnn.DNN_BACKEND_OPENCV, - cv.dnn.DNN_BACKEND_VKCOM, cv.dnn.DNN_BACKEND_CUDA) ```
The same idea for fallback.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/ndsrvp/src/bilateralFilter.cpp **Change Type:** added **Context:** PR #26364: 3rdparty: NDSRVP - Part 2.1: Filter-Related Functions **Code Changes:** ```diff @@ -0,0 +1,270 @@ +// 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 "ndsrvp_hal.hpp" +#include "opencv2/imgproc/hal/interface.h" +#include "cvutils.hpp" + +namespace cv { ```
I propose to return `CV_HAL_ERROR_NOT_IMPLEMENTED` instead of assert. Just in case if some branches are added to main OpenCV.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** 3rdparty/ndsrvp/src/bilateralFilter.cpp **Change Type:** added **Context:** PR #26364: 3rdparty: NDSRVP - Part 2.1: Filter-Related Functions **Code Changes:** ```diff @@ -0,0 +1,270 @@ +// 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 "ndsrvp_hal.hpp" +#include "opencv2/imgproc/hal/interface.h" +#include "cvutils.hpp" + +namespace cv { ```
lrint behaviour depends on external state defined by `fesetround`. Do you have alternative for it?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** samples/dnn/classification.cpp **Change Type:** modified **Context:** PR #26334: Modify DNN Samples to use ENGINE_CLASSIC for Non-Default Back-end or Target **Code Changes:** ```diff @@ -143,7 +143,11 @@ int main(int argc, char** argv) } CV_Assert(!model.empty()); //! [Read and initialize network] - Net net = readNetFromONNX(model); + EngineType engine = ENGINE_AUTO; + if (backend != "default" || target != "cpu"){ + engine = ENGINE_CLASSIC; + } + Net net = readNetFromONNX(model, engine); ```
Let it be `ENGINE_AUTO`. It fails back to classic in case of issues.
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:** 3rdparty/kleidicv/CMakeLists.txt **Change Type:** modified **Context:** PR #26390: Disable SME2 branches in KleidiCV as it's incompatible with some CLang versions, e.g. NDK 28b1 **Review Line:** 23 **Code Changes:** ```diff @@ -20,4 +20,5 @@ else() set(THE_ROOT "${OpenCV_BINARY_DIR}/3rdparty/kleidicv/kleidicv-${KLEIDICV_SRC_COMMIT}") endif() +option(KLEIDICV_ENABLE_SME2 "" OFF) # not compatible with some CLang versions in NDK include("${THE_ROOT}/adapters/opencv/CMakeLists.txt") ```
`if(ANDRROID)` ?
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:** 3rdparty/kleidicv/CMakeLists.txt **Change Type:** modified **Context:** PR #26390: Disable SME2 branches in KleidiCV as it's incompatible with some CLang versions, e.g. NDK 28b1 **Review Line:** 23 **Code Changes:** ```diff @@ -20,4 +20,5 @@ else() set(THE_ROOT "${OpenCV_BINARY_DIR}/3rdparty/kleidicv/kleidicv-${KLEIDICV_SRC_COMMIT}") endif() +option(KLEIDICV_ENABLE_SME2 "" OFF) # not compatible with some CLang versions in NDK include("${THE_ROOT}/adapters/opencv/CMakeLists.txt") ```
It's not specific to Android, it's clang side effect.
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/caffe/caffe_importer.cpp **Change Type:** modified **Context:** PR #26208: Modified Caffe parser to support the new dnn engine **Code Changes:** ```diff @@ -40,6 +40,7 @@ //M*/ #include "../precomp.hpp" +#include "../net_impl.hpp" #ifdef HAVE_PROTOBUF #include <iostream> @@ -53,8 +54,10 @@ #include "caffe_io.hpp" ```
`const &`?
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/caffe/caffe_importer.cpp **Change Type:** modified **Context:** PR #26208: Modified Caffe parser to support the new dnn engine **Code Changes:** ```diff @@ -40,6 +40,7 @@ //M*/ #include "../precomp.hpp" +#include "../net_impl.hpp" #ifdef HAVE_PROTOBUF #include <iostream> @@ -53,8 +54,10 @@ #include "caffe_io.hpp" ```
``` if(!newEngine) { addedBlobs.clear(); addedBlobs.reserve(layersSize + 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/caffe/caffe_importer.cpp **Change Type:** modified **Context:** PR #26208: Modified Caffe parser to support the new dnn engine **Review Line:** 758 **Code Changes:** ```diff + engine = engine_forced; + CaffeImporter caffeImporter(prototxt.c_str(), caffeModel.c_str()); Net net; - caffeImporter.populateNet(net); + caffeImporter.populateNet(net, engine == ENGINE_NEW || engine == ENGINE_AUTO); return net; } Net readNetFromCaffe(const char *bufferProto, size_t lenProto, - const char *bufferModel, size_t lenModel) ```
What about fallback, if the new engine cannot handle the model?
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/caffe/caffe_importer.cpp **Change Type:** modified **Context:** PR #26208: Modified Caffe parser to support the new dnn engine **Review Line:** 758 **Code Changes:** ```diff + engine = engine_forced; + CaffeImporter caffeImporter(prototxt.c_str(), caffeModel.c_str()); Net net; - caffeImporter.populateNet(net); + caffeImporter.populateNet(net, engine == ENGINE_NEW || engine == ENGINE_AUTO); return net; } Net readNetFromCaffe(const char *bufferProto, size_t lenProto, - const char *bufferModel, size_t lenModel) ```
Look like it is unnecessary. The parser doesn't fall in tests
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/features2d/include/opencv2/features2d.hpp **Change Type:** modified **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -70,6 +70,13 @@ @{ @defgroup features2d_hal_interface Interface @} + + @defgroup features2d_annoy Approximate Nearest Neighbors Search in Multi-Dimensional Spaces + + This section documents OpenCV's interface to the Annoy. Annoy (Approximate Nearest Neighbors Oh Yeah) + is a library to search for points in space that are close to a given query point. It also creates + large read-only file-based data structures that are mmapped into memory so that many processes may ```
ANNOY_DIST is inside AnnoyIndex, don't duplicate prefix => ANNIndex::DIST_EUCLIDEAN.
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/features2d/include/opencv2/features2d.hpp **Change Type:** modified **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -70,6 +70,13 @@ @{ @defgroup features2d_hal_interface Interface @} + + @defgroup features2d_annoy Approximate Nearest Neighbors Search in Multi-Dimensional Spaces + + This section documents OpenCV's interface to the Annoy. Annoy (Approximate Nearest Neighbors Oh Yeah) + is a library to search for points in space that are close to a given query point. It also creates + large read-only file-based data structures that are mmapped into memory so that many processes may ```
use 'Approximate Nearest Neighbor Search' instead of 'Annoy' here
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/test/test_nearestneighbors.cpp **Change Type:** modified **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -330,4 +330,55 @@ TEST(Features2d_FLANN_Saved, regression) { CV_FlannSavedIndexTest test; test.saf #endif +class CV_AnnoyTest : public NearestNeighborTest +{ +public: + CV_AnnoyTest() : NearestNeighborTest(), index(NULL) {} + +protected: ```
The function should return void, if you want to use EXPECT_ macro. https://google.github.io/googletest/advanced.html#using-assertions-in-sub-routines
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -0,0 +1,264 @@ +// 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 "../3rdparty/annoy/annoylib.h" +#include <opencv2/core/utils/logger.hpp> + + ```
Let's use seed from OpenCV RNG.
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/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -0,0 +1,264 @@ +// 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 "../3rdparty/annoy/annoylib.h" +#include <opencv2/core/utils/logger.hpp> + + ```
It's not safe solution. errorMsg is empty and msg will be nullptr or the allocated buffer size is unpredictable. In case of error it leads to extra memory corruption.
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/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -0,0 +1,264 @@ +// 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 "../3rdparty/annoy/annoylib.h" +#include <opencv2/core/utils/logger.hpp> + + ```
The same issue with memory corruption.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -0,0 +1,264 @@ +// 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 "../3rdparty/annoy/annoylib.h" +#include <opencv2/core/utils/logger.hpp> + + ```
The same error.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -0,0 +1,264 @@ +// 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 "../3rdparty/annoy/annoylib.h" +#include <opencv2/core/utils/logger.hpp> + + ```
The same error.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -0,0 +1,264 @@ +// 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 "../3rdparty/annoy/annoylib.h" +#include <opencv2/core/utils/logger.hpp> + + ```
Why do you introduce seed range limitation?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -0,0 +1,264 @@ +// 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 "../3rdparty/annoy/annoylib.h" +#include <opencv2/core/utils/logger.hpp> + + ```
you can easily get rid of memcpy if create `std::vector` from `indices.ptr<int>(i)` and `dists.ptr<DataType>(i)`.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/features2d/src/annoy.cpp **Change Type:** added **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Review Line:** 54 **Code Changes:** ```diff + ANNIndexImpl(int dimension) : dim(dimension) + { + index = makePtr<::cvannoy::AnnoyIndex<int, DataType, DistanceType, Random, ::cvannoy::AnnoyIndexSingleThreadedBuildPolicy>>(dimension); + } + + void addItems(InputArray _dataset) CV_OVERRIDE + { + CV_Assert(!_dataset.empty()); + + Mat features = _dataset.getMat(); + CV_Assert(features.cols == dim); ```
I propose to return bool and print error to log, but not throw exception, if `addItems` was not successful.
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/features2d/include/opencv2/features2d.hpp **Change Type:** modified **Context:** PR #25708: Add interface to Annoy which will replace the FLANN **Code Changes:** ```diff @@ -70,6 +70,13 @@ @{ @defgroup features2d_hal_interface Interface @} + + @defgroup features2d_annoy Approximate Nearest Neighbors Search in Multi-Dimensional Spaces + + This section documents OpenCV's interface to the Annoy. Annoy (Approximate Nearest Neighbors Oh Yeah) + is a library to search for points in space that are close to a given query point. It also creates + large read-only file-based data structures that are mmapped into memory so that many processes may ```
The description does not match implementation. 1. The both outputs are optional. 2. The output is re-created, if it has unexpected size or type.