nareshmlx/opencv-pr huggingface dataset:
**File:** modules/imgproc/src/lsd.cpp
**Change Type:** added
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -0,0 +1,1249 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                           License Agreement
```

Review comment:
it's more safe for the further possible refactorings to put everything into namespace cv { }
**File:** modules/imgproc/src/lsd.cpp
**Change Type:** added
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -0,0 +1,1249 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                           License Agreement
```

Review comment:
let's do text replacement M_PI=>CV_PI
**File:** modules/imgproc/src/lsd.cpp
**Change Type:** added
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -0,0 +1,1249 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                           License Agreement
```

Review comment:
It's duplication of the standard OpenCV ROI support. Let's remove roi parameter from API. User may call <pre> lsd_ptr-&gt;detect(image(roi), ..., lines); lines += Scalar(roi.x, roi.y, roi.x, roi.y); </pre> if needed
**File:** modules/imgproc/src/lsd.cpp
**Change Type:** added
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -0,0 +1,1249 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                           License Agreement
```

Review comment:
this is quite error prone code. If an error happens somewhere in the middle of function and exception is thrown, the memory is leaked. The solution would be to have simple vectors "w, p, n" instead of pointers or use smart pointer Ptr&lt;&gt;
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -191,6 +191,12 @@ enum { HOUGH_STANDARD      = 0,
        HOUGH_GRADIENT      = 3
      };
 
+//! Variants of Line Segment Detector
+enum { LSD_REFINE_NONE = 0,
+       LSD_REFINE_STD  = 1,
+       LSD_REFINE_ADV  = 2
+     };
+
```

Review comment:
destructor should be made virtual
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -191,6 +191,12 @@ enum { HOUGH_STANDARD      = 0,
        HOUGH_GRADIENT      = 3
      };
 
+//! Variants of Line Segment Detector
+enum { LSD_REFINE_NONE = 0,
+       LSD_REFINE_STD  = 1,
+       LSD_REFINE_ADV  = 2
+     };
+
```

Review comment:
I'd suggest we remove this protected constructor and find some other way to solve compiler warnings; this looks ugly and we somehow manage to avoid such things and many other classes that use Algorithm-based design.
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -191,6 +191,12 @@ enum { HOUGH_STANDARD      = 0,
        HOUGH_GRADIENT      = 3
      };
 
+//! Variants of Line Segment Detector
+enum { LSD_REFINE_NONE = 0,
+       LSD_REFINE_STD  = 1,
+       LSD_REFINE_ADV  = 2
+     };
+
```

Review comment:
this should be removed
**File:** modules/imgproc/test/test_lsd.cpp
**Change Type:** added
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -0,0 +1,265 @@
+#include "test_precomp.hpp"
+
+#include <vector>
+
+using namespace cv;
+using namespace std;
+
+const Size img_size(640, 480);
+const int LSD_TEST_SEED = 0x134679;
```

Review comment:
unfortunately, this is very bad practice. First of all, if test crashes, it's difficult to reproduce. Secondly, as we found with other non-deterministic tests, sometimes they generate such tests that the algorithm fails. So, please, declare some constant on top of the file, e.g. <pre>static int LSD_TEST_SEED = 0x12345;</pre> and use it instead getTickCount().
**File:** modules/imgproc/test/test_lsd.cpp
**Change Type:** added
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -0,0 +1,265 @@
+#include "test_precomp.hpp"
+
+#include <vector>
+
+using namespace cv;
+using namespace std;
+
+const Size img_size(640, 480);
+const int LSD_TEST_SEED = 0x134679;
```

Review comment:
just one run of the test is not enough. Run 100-1000 test cases (but initialize RNG only once!!! otherwise all the test cases will be the same)
**File:** samples/cpp/lsd_lines.cpp
**Change Type:** added
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.
**Review Line:** 1

**Code Changes:**
```diff
@@ -0,0 +1,54 @@
+#include <iostream>
+#include <string>
+
+#include "opencv2/core/core.hpp"
+#include "opencv2/core/utility.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
```

Review comment:
please, take a look at opencv/samples/cpp/houghlines.cpp sample. It's your primary competitor. E.g. load building.jpg, apply canny edge detector to it and then apply your line detector. If you want, please, add an option to your sample to run canny edge detector before LSD. This way you can pass building.jpg right into your sample without preprocessing the image.
**File:** modules/imgproc/include/opencv2/imgproc.hpp
**Change Type:** modified
**Context:** PR #1119: LSD (Line Segment Detector) - The pull request includes the LSD class, accuracy tests and a sample program.

**Code Changes:**
```diff
@@ -191,6 +191,12 @@ enum { HOUGH_STANDARD      = 0,
        HOUGH_GRADIENT      = 3
      };
 
+//! Variants of Line Segment Detector
+enum { LSD_REFINE_NONE = 0,
+       LSD_REFINE_STD  = 1,
+       LSD_REFINE_ADV  = 2
+     };
+
```

Review comment:
Yes, actually it's no longer needed. I didn't delete it when I was done with my tests.
**File:** modules/ocl/include/opencv2/ocl/ocl.hpp
**Change Type:** modified
**Context:** PR #1489: 2 4 knearest neighbor - Added knearest neighbor of OpenCL version. It includes the accuracy/performance test and the implementation of KNN.
**Review Line:** 1912

**Code Changes:**
```diff
+            void clear();
+
+            void find_nearest(const oclMat& samples, int k, oclMat& lables);
+
+        private:
+            oclMat samples_ocl;
+        };
     }
 }
 #if defined _MSC_VER && _MSC_VER >= 1200
```

Review comment:
I believe you can use these fields from the base class: ``` int max_k, var_count; int total; bool regression; ```
**File:** modules/ocl/src/knearest.cpp
**Change Type:** added
**Context:** PR #1489: 2 4 knearest neighbor - Added knearest neighbor of OpenCL version. It includes the accuracy/performance test and the implementation of KNN.

**Code Changes:**
```diff
@@ -0,0 +1,157 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
this->max_k = max_k if needed (base class can do something)
**File:** modules/ocl/src/knearest.cpp
**Change Type:** added
**Context:** PR #1489: 2 4 knearest neighbor - Added knearest neighbor of OpenCL version. It includes the accuracy/performance test and the implementation of KNN.

**Code Changes:**
```diff
@@ -0,0 +1,157 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
What is about KNearestNeighbour::train(...)?
**File:** modules/ocl/src/knearest.cpp
**Change Type:** added
**Context:** PR #1489: 2 4 knearest neighbor - Added knearest neighbor of OpenCL version. It includes the accuracy/performance test and the implementation of KNN.
**Review Line:** 71

**Code Changes:**
```diff
+    samples_ocl.release();
+}
+
+void KNearestNeighbour::clear()
+{
+    CvKNearest::clear();
+}
+
+bool KNearestNeighbour::train(const Mat& trainData, Mat& labels, Mat& sampleIdx,
+                              bool isRegression, int _max_k, bool updateBase)
+{
```

Review comment:
Clear oclMat also.
**File:** modules/features2d/src/freak.cpp
**Change Type:** modified
**Context:** PR #1932: Updating STAR detector and FREAK descriptor to work with large and/or 16-bit images - A project that I've been working with involves large, ...
**Review Line:** 244

**Code Changes:**
```diff
 
     ((FREAK*)this)->buildPattern();
 
+    // Convert to gray if not already
+    Mat grayImage = image;
+//    if( image.channels() > 1 )
+//        cvtColor( image, grayImage, COLOR_BGR2GRAY );
+
+    // Use 32-bit integers if we won't overflow in the integral image
+    if ((image.depth() == CV_8U || image.depth() == CV_8S) &&
+        (image.rows * image.cols) < 8388608 ) // 8388608 = 2 ^ (32 - 8(bit depth) - 1(sign bit))
```

Review comment:
Why these lines are commented?
**File:** modules/features2d/src/freak.cpp
**Change Type:** modified
**Context:** PR #1932: Updating STAR detector and FREAK descriptor to work with large and/or 16-bit images - A project that I've been working with involves large, ...
**Review Line:** 244

**Code Changes:**
```diff
 
     ((FREAK*)this)->buildPattern();
 
+    // Convert to gray if not already
+    Mat grayImage = image;
+//    if( image.channels() > 1 )
+//        cvtColor( image, grayImage, COLOR_BGR2GRAY );
+
+    // Use 32-bit integers if we won't overflow in the integral image
+    if ((image.depth() == CV_8U || image.depth() == CV_8S) &&
+        (image.rows * image.cols) < 8388608 ) // 8388608 = 2 ^ (32 - 8(bit depth) - 1(sign bit))
```

Review comment:
Because they were causing one of the tests to fail. It's mentioned in here: https://github.com/Itseez/opencv/pull/1654
**File:** modules/features2d/src/freak.cpp
**Change Type:** modified
**Context:** PR #1932: Updating STAR detector and FREAK descriptor to work with large and/or 16-bit images - A project that I've been working with involves large, ...
**Review Line:** 244

**Code Changes:**
```diff
 
     ((FREAK*)this)->buildPattern();
 
+    // Convert to gray if not already
+    Mat grayImage = image;
+//    if( image.channels() > 1 )
+//        cvtColor( image, grayImage, COLOR_BGR2GRAY );
+
+    // Use 32-bit integers if we won't overflow in the integral image
+    if ((image.depth() == CV_8U || image.depth() == CV_8S) &&
+        (image.rows * image.cols) < 8388608 ) // 8388608 = 2 ^ (32 - 8(bit depth) - 1(sign bit))
```

Review comment:
So, may be they should be deleted or there should be some notes, why they are still be in request?
**File:** modules/features2d/src/freak.cpp
**Change Type:** modified
**Context:** PR #1932: Updating STAR detector and FREAK descriptor to work with large and/or 16-bit images - A project that I've been working with involves large, ...
**Review Line:** 244

**Code Changes:**
```diff
 
     ((FREAK*)this)->buildPattern();
 
+    // Convert to gray if not already
+    Mat grayImage = image;
+//    if( image.channels() > 1 )
+//        cvtColor( image, grayImage, COLOR_BGR2GRAY );
+
+    // Use 32-bit integers if we won't overflow in the integral image
+    if ((image.depth() == CV_8U || image.depth() == CV_8S) &&
+        (image.rows * image.cols) < 8388608 ) // 8388608 = 2 ^ (32 - 8(bit depth) - 1(sign bit))
```

Review comment:
There really wasn't any conclusion (or response) in #1654, so I just commented in order to pass the tests. However, keeping the lines in strikes me as correct behavior. So, the code is currently in logic purgatory.
**File:** modules/ocl/include/opencv2/ocl/ocl.hpp
**Change Type:** modified
**Context:** PR #1077: Add ocl::kmeans and ocl::distanceToCenters functions

**Code Changes:**
```diff
@@ -834,6 +834,18 @@ namespace cv
         CV_EXPORTS void cornerMinEigenVal_dxdy(const oclMat &src, oclMat &dst, oclMat &Dx, oclMat &Dy,
             int blockSize, int ksize, int bordertype = cv::BORDER_DEFAULT);
 
+        /////////////////////////////////// ML ///////////////////////////////////////////
+
+        //! Compute closest centers for each lines in source and lable it after center's index
+        // supports CV_32FC1/CV_32FC2/CV_32FC4 data type
+        CV_EXPORTS void distanceToCenters(oclMat &dists, oclMat &labels, const oclMat &src, const oclMat &centers);
+
```

Review comment:
CV_EXPORTS is missing. This function name should renamed to 1) start with a small leter; 2) do not include word computer, since it's not a class. Probably, distanceToCenters will be better.
**File:** modules/core/src/umatrix.cpp
**Change Type:** modified
**Context:** PR #2326: [T-API] 3-channel support in OpenCL kernels for some OpenCV functions - add, subtract, bitwise__, resize, warpAffine, warpPerspective. check...
**Review Line:** 754

**Code Changes:**
```diff
         CV_Assert( checkScalar(value, type(), _value.kind(), _InputArray::UMAT) );
-        double buf[4];
+        double buf[4]={0,0,0,0};
         convertAndUnrollScalar(value, tp, (uchar*)buf, 1);
 
+        int scalarcn = cn == 3 ? 4 : cn;
         char opts[1024];
-        sprintf(opts, "-D dstT=%s", ocl::memopTypeToStr(tp));
+        sprintf(opts, "-D dstT=%s -D dstST=%s -D dstT1=%s -D cn=%d", ocl::memopTypeToStr(tp),
+                ocl::memopTypeToStr(CV_MAKETYPE(tp,scalarcn)),
+                ocl::memopTypeToStr(CV_MAT_DEPTH(tp)), cn);
```

Review comment:
I don't see any reason why in case of `cn=3` `scalarcn` should be `4`. Your solution works, but it looks worse in terms of code readability
**File:** modules/imgproc/src/imgwarp.cpp
**Change Type:** modified
**Context:** PR #2326: [T-API] 3-channel support in OpenCL kernels for some OpenCV functions - add, subtract, bitwise__, resize, warpAffine, warpPerspective. check...

**Code Changes:**
```diff
@@ -1957,7 +1957,7 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize,
     double inv_fx = 1. / fx, inv_fy = 1. / fy;
     float inv_fxf = (float)inv_fx, inv_fyf = (float)inv_fy;
 
-    if( cn == 3 || !(cn <= 4 &&
+    if( !(cn <= 4 &&
            (interpolation == INTER_NEAREST || interpolation == INTER_LINEAR ||
             (interpolation == INTER_AREA && inv_fx >= 1 && inv_fy >= 1) )) )
         return false;
@@ -1975,15 +1975,18 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize,
```

Review comment:
missed `-D` before `cn=%d`
**File:** modules/core/src/umatrix.cpp
**Change Type:** modified
**Context:** PR #2326: [T-API] 3-channel support in OpenCL kernels for some OpenCV functions - add, subtract, bitwise__, resize, warpAffine, warpPerspective. check...
**Review Line:** 754

**Code Changes:**
```diff
         CV_Assert( checkScalar(value, type(), _value.kind(), _InputArray::UMAT) );
-        double buf[4];
+        double buf[4]={0,0,0,0};
         convertAndUnrollScalar(value, tp, (uchar*)buf, 1);
 
+        int scalarcn = cn == 3 ? 4 : cn;
         char opts[1024];
-        sprintf(opts, "-D dstT=%s", ocl::memopTypeToStr(tp));
+        sprintf(opts, "-D dstT=%s -D dstST=%s -D dstT1=%s -D cn=%d", ocl::memopTypeToStr(tp),
+                ocl::memopTypeToStr(CV_MAKETYPE(tp,scalarcn)),
+                ocl::memopTypeToStr(CV_MAT_DEPTH(tp)), cn);
```

Review comment:
tests on CV_16UC3 images fail without such a change, unfortunately.
**File:** doc/tutorials/core/adding_images/adding_images.rst
**Change Type:** modified
**Context:** PR #2423: I thing, that it's will be better - I thing, that it's will be better

**Code Changes:**
```diff
@@ -6,12 +6,12 @@ Adding (blending) two images using OpenCV
 Goal
 =====
 
-In this tutorial you will learn how to:
+In this tutorial you will learn:
 
 .. container:: enumeratevisibleitemswithsquare
 
-   * What is *linear blending* and why it is useful.
```

Review comment:
You can try to use another editor (vim, gedit, sublime, ...) and make these changes. To rollback these changes, type in repo root: 1. `git reset --hard HEAD~1` - this will erase latest commit, 2. Improve tutorial without redundant changes and make a commit, 3. `git push origin bugfix_5:bugfix_5 -f`.
**File:** doc/tutorials/core/adding_images/adding_images.rst
**Change Type:** modified
**Context:** PR #2423: I thing, that it's will be better - I thing, that it's will be better

**Code Changes:**
```diff
@@ -6,12 +6,12 @@ Adding (blending) two images using OpenCV
 Goal
 =====
 
-In this tutorial you will learn how to:
+In this tutorial you will learn:
 
 .. container:: enumeratevisibleitemswithsquare
 
-   * What is *linear blending* and why it is useful.
```

Review comment:
I meant change directory to OpenCV's repository root in Terminal or Git bash (e.g. `cd <path to OpenCV repo>`).
**File:** doc/tutorials/core/adding_images/adding_images.rst
**Change Type:** modified
**Context:** PR #2423: I thing, that it's will be better - I thing, that it's will be better

**Code Changes:**
```diff
@@ -6,12 +6,12 @@ Adding (blending) two images using OpenCV
 Goal
 =====
 
-In this tutorial you will learn how to:
+In this tutorial you will learn:
 
 .. container:: enumeratevisibleitemswithsquare
 
-   * What is *linear blending* and why it is useful.
```

Review comment:
You need to push with `-f` (`--force`) since it's rewriting history.
**File:** doc/tutorials/core/adding_images/adding_images.rst
**Change Type:** modified
**Context:** PR #2423: I thing, that it's will be better - I thing, that it's will be better

**Code Changes:**
```diff
@@ -6,12 +6,12 @@ Adding (blending) two images using OpenCV
 Goal
 =====
 
-In this tutorial you will learn how to:
+In this tutorial you will learn:
 
 .. container:: enumeratevisibleitemswithsquare
 
-   * What is *linear blending* and why it is useful.
```

Review comment:
Great (you can check this videos: https://tutsplus.com/course/improve-workflow-in-sublime-text-2/ to be a sublime's Jedi)! Don't forget to update others request.
**File:** modules/objdetect/include/opencv2/objdetect/erfilter.hpp
**Change Type:** added
**Context:** PR #1159: Class-specific Extremal Region Filter algorithm as proposed in : - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, ...

**Code Changes:**
```diff
@@ -0,0 +1,197 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
let's make 2 constructors: ERStat(); and ERStat(level, pixel, x, y) without optional parameters. it will be much more safe construction, since in the current form C++ compiler may silently cast an integer into ERStat() structure using the ERStat(your_integer, 0, 0, 0) constructor.
**File:** modules/objdetect/include/opencv2/objdetect/erfilter.hpp
**Change Type:** added
**Context:** PR #1159: Class-specific Extremal Region Filter algorithm as proposed in : - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, ...

**Code Changes:**
```diff
@@ -0,0 +1,197 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
I suggest to store the bounding box in Rect structure. That's what we use in OpenCV all the time
**File:** modules/objdetect/include/opencv2/objdetect/erfilter.hpp
**Change Type:** added
**Context:** PR #1159: Class-specific Extremal Region Filter algorithm as proposed in : - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, ...

**Code Changes:**
```diff
@@ -0,0 +1,197 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
we will have many, many ER regions during the algorithm run. Let's not to store the derived (secondary) features. Everything that can be computed easily from the basic (primary) features such as area, perimeter, bbox etc. should not be stored. It should be computed inside the first stage classifier callback on-fly and then immediately discarded after classification is done.
**File:** modules/objdetect/include/opencv2/objdetect/erfilter.hpp
**Change Type:** added
**Context:** PR #1159: Class-specific Extremal Region Filter algorithm as proposed in : - Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, ...

**Code Changes:**
```diff
@@ -0,0 +1,197 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
```

Review comment:
we are already inside cv namespace. Please, remove all the extra cv:: for the sake of better readability.