nareshmlx/opencv-pr huggingface dataset:
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #25703: imgproc: fixed imread with output image argument - Resolves #25694 Replaces #25695 * Moved `OutputArray` down the call stack * Allow output...
**Review Line:** 460

**Code Changes:**
```diff
+imread_( const String& filename, int flags, OutputArray mat )
 {
     /// Search for the relevant decoder to handle the imagery
     ImageDecoder decoder;
@@ -444,18 +460,7 @@ imread_( const String& filename, int flags, Mat& mat )
     Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
 
     // grab the decoded type
-    int type = decoder->type();
-    if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
-    {
```

Review comment:
`create` should not reallocate data if requested image size fits into existing Mat. ```.cpp Mat img(1000, 1000, CV_8UC3); imread(f, img); // should not reallocate data if image size is less than (1000, 1000) ``` Without this change it will not be possible to read multiple images of different sizes efficiently, because user would need to pass either empty Mat or a Mat with exact image dimensions on each iteration. I.e. with proposed change, following code should work and should perform reallocations only when necessary: ```.cpp Mat img; for (auto f : filenames) { imread(f, img); // will fail if images have different sizes } ```
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #25703: imgproc: fixed imread with output image argument - Resolves #25694 Replaces #25695 * Moved `OutputArray` down the call stack * Allow output...
**Review Line:** 460

**Code Changes:**
```diff
+imread_( const String& filename, int flags, OutputArray mat )
 {
     /// Search for the relevant decoder to handle the imagery
     ImageDecoder decoder;
@@ -444,18 +460,7 @@ imread_( const String& filename, int flags, Mat& mat )
     Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
 
     // grab the decoded type
-    int type = decoder->type();
-    if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
-    {
```

Review comment:
sorry you are right. `mat.create( size.height, size.width, type );` does the job.
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #25703: imgproc: fixed imread with output image argument - Resolves #25694 Replaces #25695 * Moved `OutputArray` down the call stack * Allow output...
**Review Line:** 460

**Code Changes:**
```diff
+imread_( const String& filename, int flags, OutputArray mat )
 {
     /// Search for the relevant decoder to handle the imagery
     ImageDecoder decoder;
@@ -444,18 +460,7 @@ imread_( const String& filename, int flags, Mat& mat )
     Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
 
     // grab the decoded type
-    int type = decoder->type();
-    if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
-    {
```

Review comment:
``` TickMeter tm; Mat im; for (int i = 0; i < 5; i++) { tm.reset(); tm.start(); imread("read.png", im); tm.stop(); printf("read time %f\n", tm.getTimeSec()); } imshow("read.png", im); waitKey(); ``` ``` read time 0.692092 read time 0.615938 read time 0.615163 read time 0.615883 read time 0.617650 ``` good job!
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #25703: imgproc: fixed imread with output image argument - Resolves #25694 Replaces #25695 * Moved `OutputArray` down the call stack * Allow output...
**Review Line:** 331

**Code Changes:**
```diff
@@ -81,6 +81,22 @@ static Size validateInputImageSize(const Size& size)
 }
 
 
+static inline int calcType(int type, int flags)
+{
+    if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
+    {
+        if( (flags & IMREAD_ANYDEPTH) == 0 )
+            type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
+
+        if( (flags & IMREAD_COLOR) != 0 ||
+           ((flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
+            type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
+        else
```

Review comment:
`InputOutputArray` is better. I know, that they are synonyms, but it's simpler for reader.
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #25703: imgproc: fixed imread with output image argument - Resolves #25694 Replaces #25695 * Moved `OutputArray` down the call stack * Allow output...
**Review Line:** 331

**Code Changes:**
```diff
@@ -81,6 +81,22 @@ static Size validateInputImageSize(const Size& size)
 }
 
 
+static inline int calcType(int type, int flags)
+{
+    if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
+    {
+        if( (flags & IMREAD_ANYDEPTH) == 0 )
+            type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
+
+        if( (flags & IMREAD_COLOR) != 0 ||
+           ((flags & IMREAD_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
+            type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
+        else
```

Review comment:
It seems that it won't work without changing public `imread` to accept `InputOutputArray` (https://docs.opencv.org/4.x/d0/d46/classcv_1_1__InputOutputArray.html). There is no obvious way to construct `InputOutputArray` from `OutputArray` (https://docs.opencv.org/4.x/d2/d9e/classcv_1_1__OutputArray.html).
**File:** modules/core/misc/python/package/mat_wrapper/__init__.py
**Change Type:** modified
**Context:** PR #25406: feat: use numeric dtype for MatLike instead of generic
**Review Line:** 9

**Code Changes:**
```diff
 
-# Same as cv2.typing.NumPyArrayGeneric, but avoids circular dependencies
+# Same as cv2.typing.NumPyArrayNumeric, but avoids circular dependencies
 if TYPE_CHECKING:
-    _NumPyArrayGeneric = np.ndarray[Any, np.dtype[np.generic]]
+    _NumPyArrayNumeric = np.ndarray[Any, np.dtype[np.integer[Any] | np.floating[Any]]]
 else:
-    _NumPyArrayGeneric = np.ndarray
+    _NumPyArrayNumeric = np.ndarray
 
 # NumPy documentation: https://numpy.org/doc/stable/user/basics.subclassing.html
```

Review comment:
Should this also include `np.unsignedinteger[Any]` ?
**File:** modules/core/misc/python/package/mat_wrapper/__init__.py
**Change Type:** modified
**Context:** PR #25406: feat: use numeric dtype for MatLike instead of generic
**Review Line:** 9

**Code Changes:**
```diff
 
-# Same as cv2.typing.NumPyArrayGeneric, but avoids circular dependencies
+# Same as cv2.typing.NumPyArrayNumeric, but avoids circular dependencies
 if TYPE_CHECKING:
-    _NumPyArrayGeneric = np.ndarray[Any, np.dtype[np.generic]]
+    _NumPyArrayNumeric = np.ndarray[Any, np.dtype[np.integer[Any] | np.floating[Any]]]
 else:
-    _NumPyArrayGeneric = np.ndarray
+    _NumPyArrayNumeric = np.ndarray
 
 # NumPy documentation: https://numpy.org/doc/stable/user/basics.subclassing.html
```

Review comment:
NumPy integer is a base class for all integer types. In my understanding for both signed and unsigned ones. Documentation: https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.integer
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -4040,6 +4040,19 @@ A program using pyramid scaling, Canny, contours and contour simplification to f
 squares in the input image.
 */
 
+//! @brief Find contours using link runs algorithm
+//!
+//! This function implements an algorithm different from cv::findContours:
+//! - doesn't allocate temporary image internally, thus it has reduced memory consumption
+//! - supports CV_8UC1 images only
+//! - outputs 2-level hierarhy only (RETR_CCOMP mode)
```

Review comment:
Why not CV_EXPORTS_W? What about documentation and reference to paper?
**File:** modules/imgproc/src/contours_common.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...
**Review Line:** 1

**Code Changes:**
```diff
@@ -0,0 +1,75 @@
+// 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 "contours_common.hpp"
```

Review comment:
The file is empty. Do we need it?
**File:** modules/imgproc/src/contours_common.hpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,219 @@
+// 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_CONTOURS_COMMON_HPP
+#define OPENCV_CONTOURS_COMMON_HPP
+
+#include "precomp.hpp"
+#include <stack>
```

Review comment:
Please remove unused methods.
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -4040,6 +4040,19 @@ A program using pyramid scaling, Canny, contours and contour simplification to f
 squares in the input image.
 */
 
+//! @brief Find contours using link runs algorithm
+//!
+//! This function implements an algorithm different from cv::findContours:
+//! - doesn't allocate temporary image internally, thus it has reduced memory consumption
+//! - supports CV_8UC1 images only
+//! - outputs 2-level hierarhy only (RETR_CCOMP mode)
```

Review comment:
I propose to move it to `opencv2/imgproc/imgproc_c.h` or some `details` header. In case, if we need to presume the implementation, it's less painful for 4.x->5.x merges. What about `findContoursLegacy` ?
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -4040,6 +4040,19 @@ A program using pyramid scaling, Canny, contours and contour simplification to f
 squares in the input image.
 */
 
+//! @brief Find contours using link runs algorithm
+//!
+//! This function implements an algorithm different from cv::findContours:
+//! - doesn't allocate temporary image internally, thus it has reduced memory consumption
+//! - supports CV_8UC1 images only
+//! - outputs 2-level hierarhy only (RETR_CCOMP mode)
```

Review comment:
Could you add documentation for the functions? Do we really need it in public API?
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -4040,6 +4040,19 @@ A program using pyramid scaling, Canny, contours and contour simplification to f
 squares in the input image.
 */
 
+//! @brief Find contours using link runs algorithm
+//!
+//! This function implements an algorithm different from cv::findContours:
+//! - doesn't allocate temporary image internally, thus it has reduced memory consumption
+//! - supports CV_8UC1 images only
+//! - outputs 2-level hierarhy only (RETR_CCOMP mode)
```

Review comment:
I exported this function to be able to test it (though I haven't make such tests yet), I'm not sure whether is it useful. It transforms chain code to vector of points using one of methods, but there are no other interfaces with chain codes. New findContours can return chain code, but without origin point it is not very useful. So export of this function is still in question. I wanted to get other opinions. Should we complete chain code output in `findContours` and expose `approximateChain` or hide these functionality?
**File:** modules/imgproc/src/contours_common.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...
**Review Line:** 1

**Code Changes:**
```diff
@@ -0,0 +1,75 @@
+// 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 "contours_common.hpp"
```

Review comment:
Yes, I've moved `contourTreeToResults` function there (it was original intention).
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -4040,6 +4040,19 @@ A program using pyramid scaling, Canny, contours and contour simplification to f
 squares in the input image.
 */
 
+//! @brief Find contours using link runs algorithm
+//!
+//! This function implements an algorithm different from cv::findContours:
+//! - doesn't allocate temporary image internally, thus it has reduced memory consumption
+//! - supports CV_8UC1 images only
+//! - outputs 2-level hierarhy only (RETR_CCOMP mode)
```

Review comment:
Moved to `imgproc/detail/legacy.hpp`, renamed to `findContours_legacy`.
**File:** modules/imgproc/src/contours_approx.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,354 @@
+// 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/base.hpp"
+#include "opencv2/core/types.hpp"
+#include "opencv2/imgproc.hpp"
+#include "contours_common.hpp"
+#include <vector>
```

Review comment:
What if add the check to for loop?
**File:** modules/imgproc/src/contours_approx.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,354 @@
+// 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/base.hpp"
+#include "opencv2/core/types.hpp"
+#include "opencv2/imgproc.hpp"
+#include "contours_common.hpp"
+#include <vector>
```

Review comment:
looks like if you replace indexes from int to `size_t` then all casts to int can be dropped. It's related to `pass_cleanup`, `clear_until`, `calc_dominance`, etc.
**File:** modules/imgproc/src/contours_link.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...
**Review Line:** 304

**Code Changes:**
```diff
+        if (j == sz.width)
+            break;
+
+        cur_point.x = j;
+
+        rns.push_back(LRP(cur_point));
+        rns[cur].next = (int)rns.size() - 1;
+        cur = rns[cur].next;
+
+        j = findEndContourPoint(image.ptr<uchar>(), sz, j + 1);
+
```

Review comment:
Looks like rns has predictable size. It makes sense to use reserve and emplace_back.
**File:** modules/imgproc/src/contours_approx.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,354 @@
+// 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/base.hpp"
+#include "opencv2/core/types.hpp"
+#include "opencv2/imgproc.hpp"
+#include "contours_common.hpp"
+#include <vector>
```

Review comment:
This was in the original code and, since this function isn't covered by tests, I tried to preserve this original behavior. As I understand, `k` should't exceed `len` (even `len/2` maybe) and if this happens then it means that input array was not valid, so exception might be more appropriate than continuing.
**File:** modules/imgproc/src/contours_common.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,75 @@
+// 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 "contours_common.hpp"
+#include <map>
+#include <limits>
+
```

Review comment:
Can I use this style (https://github.com/opencv/opencv/wiki/.clang_format) for formatting for all new files?
**File:** modules/imgproc/src/contours_link.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...
**Review Line:** 304

**Code Changes:**
```diff
+        if (j == sz.width)
+            break;
+
+        cur_point.x = j;
+
+        rns.push_back(LRP(cur_point));
+        rns[cur].next = (int)rns.size() - 1;
+        cur = rns[cur].next;
+
+        j = findEndContourPoint(image.ptr<uchar>(), sz, j + 1);
+
```

Review comment:
`rns` size is not predictable, it depends on number of contours on image and their shape. We can reserve some amount assuming there are at least some contours though.
**File:** modules/imgproc/src/contours_approx.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,354 @@
+// 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/base.hpp"
+#include "opencv2/core/types.hpp"
+#include "opencv2/imgproc.hpp"
+#include "contours_common.hpp"
+#include <vector>
```

Review comment:
Originally I tried to use `size_t`, but in some places arithmetics requires switching to signed type or comparing with signed values and VS doesn't like it. Also, perhaps 32-bit might be slightly faster or consume less memory? I've added debug assertion to check that main array size is less than max int for safety.
**File:** modules/imgproc/src/contours_approx.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,354 @@
+// 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/base.hpp"
+#include "opencv2/core/types.hpp"
+#include "opencv2/imgproc.hpp"
+#include "contours_common.hpp"
+#include <vector>
```

Review comment:
Made these changes too.
**File:** modules/imgproc/src/contours_approx.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,354 @@
+// 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/base.hpp"
+#include "opencv2/core/types.hpp"
+#include "opencv2/imgproc.hpp"
+#include "contours_common.hpp"
+#include <vector>
```

Review comment:
Use `Cv32suf`
**File:** modules/imgproc/src/contours_approx.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,354 @@
+// 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/base.hpp"
+#include "opencv2/core/types.hpp"
+#include "opencv2/imgproc.hpp"
+#include "contours_common.hpp"
+#include <vector>
```

Review comment:
Previous operands alignment is more readable,
**File:** modules/imgproc/src/contours_new.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,697 @@
+// 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/imgproc.hpp"
+#include "precomp.hpp"
+#include "opencv2/core/hal/intrin.hpp"
+#include "opencv2/core/check.hpp"
+#include "opencv2/core/utils/logger.hpp"
```

Review comment:
Is there clang-format option 'do not touch'?
**File:** modules/imgproc/src/contours_new.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,697 @@
+// 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/imgproc.hpp"
+#include "precomp.hpp"
+#include "opencv2/core/hal/intrin.hpp"
+#include "opencv2/core/check.hpp"
+#include "opencv2/core/utils/logger.hpp"
```

Review comment:
`do not touch` is preferable here too. 2 or more spaces before comment should help with reading code.
**File:** modules/imgproc/src/contours_new.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,697 @@
+// 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/imgproc.hpp"
+#include "precomp.hpp"
+#include "opencv2/core/hal/intrin.hpp"
+#include "opencv2/core/check.hpp"
+#include "opencv2/core/utils/logger.hpp"
```

Review comment:
previous variable is more readable.
**File:** modules/imgproc/src/contours_new.cpp
**Change Type:** added
**Context:** PR #25146: Reworked findContours to reduce C-API usage - What is done: * rewritten `findContours` and `icvApproximateChainTC89` using C++ data structu...

**Code Changes:**
```diff
@@ -0,0 +1,697 @@
+// 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/imgproc.hpp"
+#include "precomp.hpp"
+#include "opencv2/core/hal/intrin.hpp"
+#include "opencv2/core/check.hpp"
+#include "opencv2/core/utils/logger.hpp"
```

Review comment:
`_contours.kind()` should be aligned to have readable code.