nareshmlx/opencv-pr huggingface dataset:
**File:** 3rdparty/openvx/src/openvx_hal.cpp
**Change Type:** added
**Context:** PR #7093: Initial version of OpenVX HAL - - added cmake support for OpenVX - added initial version of OpenVX HAL (immediate mode)

**Code Changes:**
```diff
@@ -0,0 +1,8 @@
+#include "openvx_hal.hpp"
+
+vxContext * vxContext::getContext()
+{
+    // not thread safe
+    static vxContext instance;
+    return &instance;
+}
```

Review comment:
We will rewrite this code after the PR is integrated, I've removed it for now.
**File:** 3rdparty/openvx/include/openvx_hal.hpp
**Change Type:** added
**Context:** PR #7093: Initial version of OpenVX HAL - - added cmake support for OpenVX - added initial version of OpenVX HAL (immediate mode)
**Review Line:** 121

**Code Changes:**
```diff
+
+
+struct vxContext
+{
+    vx_context ctx;
+    static vxContext * getContext();
+private:
+    vxContext()
+    {
+        ctx = vxCreateContext();
+        vxErr::check(ctx);
```

Review comment:
May be it make sense to return pointer directly to vx_context? Looks like it is and should be the only item vxContext is used for.
**File:** modules/core/src/stat.cpp
**Change Type:** modified
**Context:** PR #7135: Outdated ICV restrictions were removed; - ### This pullrequest changes Removes outdated restrictions on ICV API, since ICV is in sync with I...

**Code Changes:**
```diff
@@ -1299,7 +1299,6 @@ namespace cv {
 
 static bool ipp_countNonZero( Mat &src, int &res )
 {
-#if !defined HAVE_IPP_ICV_ONLY
     Ipp32s count = 0;
     IppStatus status = ippStsNoErr;
 
@@ -1323,9 +1322,6 @@ static bool ipp_countNonZero( Mat &src, int &res )
         res = ((Ipp32s)src.total() - count);
```

Review comment:
We observed issues here on 32-bit builds. Tests for x64 builds were fine on AMD CPUs. What is about this condition? ``` #if !((defined _MSC_VER && defined _M_IX86) || defined __i386__) || IPP_DISABLE_BLOCK ```
**File:** modules/core/src/stat.cpp
**Change Type:** modified
**Context:** PR #7135: Outdated ICV restrictions were removed; - ### This pullrequest changes Removes outdated restrictions on ICV API, since ICV is in sync with I...

**Code Changes:**
```diff
@@ -1299,7 +1299,6 @@ namespace cv {
 
 static bool ipp_countNonZero( Mat &src, int &res )
 {
-#if !defined HAVE_IPP_ICV_ONLY
     Ipp32s count = 0;
     IppStatus status = ippStsNoErr;
 
@@ -1323,9 +1322,6 @@ static bool ipp_countNonZero( Mat &src, int &res )
         res = ((Ipp32s)src.total() - count);
```

Review comment:
Is there details on this issue, track id? I see id only for NAN problem.
**File:** modules/imgcodecs/src/ios_conversions.mm
**Change Type:** modified
**Context:** PR #7122: handle images with alpha better - resolves #7121 ### This pullrequest changes initializes the Mat before drawing a UIImage with an alpha cha...
**Review Line:** 122

**Code Changes:**
```diff
@@ -116,6 +118,8 @@ void UIImageToMat(const UIImage* image,
         if (!alphaExist)
             bitmapInfo = kCGImageAlphaNoneSkipLast |
                                 kCGBitmapByteOrderDefault;
+        else
+            m = cv::Scalar(0);
         contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
                                            m.step[0], colorSpace,
                                            bitmapInfo);
```

Review comment:
Looks like here we have an alpha channel and going to store it to RGBA image. Shouldn't we use kCGImageAlphaLast to store alpha channel as well?
**File:** modules/imgcodecs/src/ios_conversions.mm
**Change Type:** modified
**Context:** PR #7122: handle images with alpha better - resolves #7121 ### This pullrequest changes initializes the Mat before drawing a UIImage with an alpha cha...
**Review Line:** 122

**Code Changes:**
```diff
@@ -116,6 +118,8 @@ void UIImageToMat(const UIImage* image,
         if (!alphaExist)
             bitmapInfo = kCGImageAlphaNoneSkipLast |
                                 kCGBitmapByteOrderDefault;
+        else
+            m = cv::Scalar(0);
         contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
                                            m.step[0], colorSpace,
                                            bitmapInfo);
```

Review comment:
Oh I see now. May be it make sense to initialize the Mat for other branch(alphaExist==false) as well to ensure the alpha channel doesn't contain garbage. As far as I understand it wouldn't be changed during CGContextDrawImage execution.
**File:** modules/imgcodecs/src/ios_conversions.mm
**Change Type:** modified
**Context:** PR #7122: handle images with alpha better - resolves #7121 ### This pullrequest changes initializes the Mat before drawing a UIImage with an alpha cha...
**Review Line:** 122

**Code Changes:**
```diff
@@ -116,6 +118,8 @@ void UIImageToMat(const UIImage* image,
         if (!alphaExist)
             bitmapInfo = kCGImageAlphaNoneSkipLast |
                                 kCGBitmapByteOrderDefault;
+        else
+            m = cv::Scalar(0);
         contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
                                            m.step[0], colorSpace,
                                            bitmapInfo);
```

Review comment:
I considered that. I chose not to do so for efficiency reasons since setting all those bytes takes time and this function is called to process frames in video streams in some use cases (like my current one). Since the alpha channel is ignored it seemed like a reasonable efficiency tradeoff.
**File:** modules/imgcodecs/src/ios_conversions.mm
**Change Type:** modified
**Context:** PR #7122: handle images with alpha better - resolves #7121 ### This pullrequest changes initializes the Mat before drawing a UIImage with an alpha cha...
**Review Line:** 122

**Code Changes:**
```diff
@@ -116,6 +118,8 @@ void UIImageToMat(const UIImage* image,
         if (!alphaExist)
             bitmapInfo = kCGImageAlphaNoneSkipLast |
                                 kCGBitmapByteOrderDefault;
+        else
+            m = cv::Scalar(0);
         contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
                                            m.step[0], colorSpace,
                                            bitmapInfo);
```

Review comment:
I didn't actually time the cost of setting all those bytes to zero on a mobile device, but since 3/4 of the work is duplicated in the draw call (which sets RGB), it seemed wasteful. We could initialize just the alpha channel to zero I suppose, if that's more efficient (misaligned data access may actually make this more costly on some processors/architectures).
**File:** modules/imgcodecs/src/ios_conversions.mm
**Change Type:** modified
**Context:** PR #7122: handle images with alpha better - resolves #7121 ### This pullrequest changes initializes the Mat before drawing a UIImage with an alpha cha...
**Review Line:** 122

**Code Changes:**
```diff
@@ -116,6 +118,8 @@ void UIImageToMat(const UIImage* image,
         if (!alphaExist)
             bitmapInfo = kCGImageAlphaNoneSkipLast |
                                 kCGBitmapByteOrderDefault;
+        else
+            m = cv::Scalar(0);
         contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
                                            m.step[0], colorSpace,
                                            bitmapInfo);
```

Review comment:
it's the same cost - whether you set the whole image to 0's or just alpha channel, since the data is interleaved. I would say, in principle, setting the whole image to 0's may be even faster, if compiler generates proper instructions for it.
**File:** modules/imgcodecs/src/ios_conversions.mm
**Change Type:** modified
**Context:** PR #7122: handle images with alpha better - resolves #7121 ### This pullrequest changes initializes the Mat before drawing a UIImage with an alpha cha...
**Review Line:** 122

**Code Changes:**
```diff
@@ -116,6 +118,8 @@ void UIImageToMat(const UIImage* image,
         if (!alphaExist)
             bitmapInfo = kCGImageAlphaNoneSkipLast |
                                 kCGBitmapByteOrderDefault;
+        else
+            m = cv::Scalar(0);
         contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
                                            m.step[0], colorSpace,
                                            bitmapInfo);
```

Review comment:
yes, that's what I was saying about misaligned data access making setting only the alpha potentially slower than just setting all 4 channels. In my case, the cost is not something necessary and reduces performance, hence my intentionally leaving that out when the image isn't using an alpha channel. For real time video frame processing you really don't want any unnecessary computation cost. I could add a comment in the header file about this if you think that's useful.
**File:** modules/videoio/include/opencv2/videoio.hpp
**Change Type:** modified
**Context:** PR #6995: Naming some enumerations in videoio - resolves #6746 ### This pullrequest changes This PR names base enums (API, Props and Mode Identifiers)...

**Code Changes:**
```diff
@@ -48,6 +48,8 @@
 /**
   @defgroup videoio Media I/O
   @{
+    @defgroup videoio_flags_base Flags for video I/O
+    @defgroup videoio_flags_others Additional flags for video I/O API backends
     @defgroup videoio_c C API
     @defgroup videoio_ios iOS glue
     @defgroup videoio_winrt WinRT glue
@@ -65,6 +67,8 @@ namespace cv
```

Review comment:
I suggest removing `ID` suffix from all identifiers and use plural forms: `VideoCaptureAPIs`, `VideoCaptureProperties`, `VideoCaptureModes`, etc.
**File:** modules/videoio/include/opencv2/videoio.hpp
**Change Type:** modified
**Context:** PR #6995: Naming some enumerations in videoio - resolves #6746 ### This pullrequest changes This PR names base enums (API, Props and Mode Identifiers)...

**Code Changes:**
```diff
@@ -48,6 +48,8 @@
 /**
   @defgroup videoio Media I/O
   @{
+    @defgroup videoio_flags_base Flags for video I/O
+    @defgroup videoio_flags_others Additional flags for video I/O API backends
     @defgroup videoio_c C API
     @defgroup videoio_ios iOS glue
     @defgroup videoio_winrt WinRT glue
@@ -65,6 +67,8 @@ namespace cv
```

Review comment:
> and use plural forms I believe it is useless and looks strange in general. But it is already [happened](https://github.com/opencv/opencv/commit/6aa7a86ae992d3aacaf898c2d7c791d73311d2dd#diff-82807d0ed5d1eae81b6cb4467af33e92R178)...
**File:** modules/python/src2/gen2.py
**Change Type:** modified
**Context:** PR #7056: User-defined conversions for python bindings inside module source directory - This PR adds more functionality to python bindings generator. ...
**Review Line:** 33

**Code Changes:**
```diff
@@ -30,7 +30,7 @@
 gen_template_simple_call_constructor_prelude = Template("""self = PyObject_NEW(pyopencv_${name}_t, &pyopencv_${name}_Type);
         if(self) """)
 
-gen_template_simple_call_constructor = Template("""self->v = ${cname}${args}""")
+gen_template_simple_call_constructor = Template("""new (&(self->v)) ${cname}${args}""")
 
 gen_template_parse_args = Template("""const char* keywords[] = { $kw_list, NULL };
     if( PyArg_ParseTupleAndKeywords(args, kw, "$fmtspec", (char**)keywords, $parse_arglist)$code_cvt )""")
@@ -74,13 +74,14 @@
 
```

Review comment:
Such code previously made `operator=()(<invalid object from python's malloc()>, Class(args))` Now it directly constucts object on allocated data using placement new, no extra assigment is perfomed.
**File:** modules/python/src2/gen2.py
**Change Type:** modified
**Context:** PR #7056: User-defined conversions for python bindings inside module source directory - This PR adds more functionality to python bindings generator. ...
**Review Line:** 77

**Code Changes:**
```diff
     if( PyArg_ParseTupleAndKeywords(args, kw, "$fmtspec", (char**)keywords, $parse_arglist)$code_cvt )""")
@@ -74,13 +74,14 @@
 
 static void pyopencv_${name}_dealloc(PyObject* self)
 {
+    ((pyopencv_${name}_t*)self)->v.${cname}::~${sname}();
     PyObject_Del(self);
 }
 
 template<> PyObject* pyopencv_from(const ${cname}& r)
 {
```

Review comment:
There is not explicit destructor previously. It is ok and fast for trivial structs, but unacceptable for more complex classes. As for performance, compiler's optimizations should elimnate possible overhead on trival classes.
**File:** modules/python/src2/gen2.py
**Change Type:** modified
**Context:** PR #7056: User-defined conversions for python bindings inside module source directory - This PR adds more functionality to python bindings generator. ...
**Review Line:** 83

**Code Changes:**
```diff
     PyObject_Del(self);
 }
 
 template<> PyObject* pyopencv_from(const ${cname}& r)
 {
     pyopencv_${name}_t *m = PyObject_NEW(pyopencv_${name}_t, &pyopencv_${name}_Type);
-    m->v = r;
+    new (&m->v) ${cname}(r); //Copy constructor
     return (PyObject*)m;
 }
 
```

Review comment:
Copy constructor `Class(r)` instead of `operator = (<invalid state obj>, r)`
**File:** modules/core/include/opencv2/core/core_c.h
**Change Type:** modified
**Context:** PR #6949: Update FileStorage's docs and tests - [GSoC 2016] FileStorage. Update Base64 functions and also add some test and documentation. ### This pu...

**Code Changes:**
```diff
@@ -1976,15 +1976,24 @@ CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header,
 
 The function opens file storage for reading or writing data. In the latter case, a new file is
 created or an existing file is rewritten. The type of the read or written file is determined by the
-filename extension: .xml for XML and .yml or .yaml for YAML. The function returns a pointer to the
-CvFileStorage structure. If the file cannot be opened then the function returns NULL.
+filename extension: .xml for XML and .yml or .yaml for YAML.
+
+At the same time, it also supports adding parameters like "example.xml?base64". The three ways
+are the same:
```

Review comment:
see https://github.com/opencv/opencv/issues/6938. Please, extract code snippets to a separate cpp file.
**File:** modules/core/src/persistence.cpp
**Change Type:** modified
**Context:** PR #6949: Update FileStorage's docs and tests - [GSoC 2016] FileStorage. Update Base64 functions and also add some test and documentation. ### This pu...

**Code Changes:**
```diff
@@ -183,7 +183,20 @@ typedef struct CvXMLStackRecord
 }
 CvXMLStackRecord;
 
-namespace base64 { class Base64Writer; }
+namespace base64
+{
+    class Base64Writer;
+
+    namespace fs
```

Review comment:
please, use std::string instead of manually allocated `char*`
**File:** modules/core/src/persistence.cpp
**Change Type:** modified
**Context:** PR #6949: Update FileStorage's docs and tests - [GSoC 2016] FileStorage. Update Base64 functions and also add some test and documentation. ### This pu...

**Code Changes:**
```diff
@@ -183,7 +183,20 @@ typedef struct CvXMLStackRecord
 }
 CvXMLStackRecord;
 
-namespace base64 { class Base64Writer; }
+namespace base64
+{
+    class Base64Writer;
+
+    namespace fs
```

Review comment:
Let's reserve less than that initially, say, 1MB
**File:** modules/core/src/persistence.cpp
**Change Type:** modified
**Context:** PR #6949: Update FileStorage's docs and tests - [GSoC 2016] FileStorage. Update Base64 functions and also add some test and documentation. ### This pu...
**Review Line:** 263

**Code Changes:**
```diff
     base64::Base64Writer * base64_writer;
+    bool is_default_using_base64;
+    base64::fs::State state_of_writing_base64;  /**< used in WriteRawData only */
+
+    bool is_write_struct_delayed;
+    char* delayed_struct_key;
+    int   delayed_struct_flags;
+    char* delayed_type_name;
 
     bool is_opened;
 }
```

Review comment:
let's use std::string for these things too. use std::string::empty() to check whether the strings are empty
**File:** modules/imgproc/src/moments.cpp
**Change Type:** modified
**Context:** PR #6983: improve MomentsInTile_SIMD<uchar, int, int>() - I improve the code. I remove wasted '_mm_sad_epu8()' instruction. I use simd instruction for...

**Code Changes:**
```diff
@@ -227,31 +227,37 @@ struct MomentsInTile_SIMD<uchar, int, int>
 
         if( useSIMD )
         {
-            __m128i qx_init = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
             __m128i dx = _mm_set1_epi16(8);
-            __m128i z = _mm_setzero_si128(), qx0 = z, qx1 = z, qx2 = z, qx3 = z, qx = qx_init;
+            __m128i z = _mm_setzero_si128(), qx0 = z, qx1 = z, qx2 = z, qx3 = z, qx = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
 
             for( ; x <= len - 8; x += 8 )
```

Review comment:
hm, why is this correct? p is packed 16-bit integers; you should use _mm_add_epi16 then or something like that
**File:** modules/calib3d/test/test_cameracalibration.cpp
**Change Type:** modified
**Context:** PR #6955: add test for #6836 - @vpisarev, @vicproon I've converted the reproducing sample from #6836 to a regression test
**Review Line:** 1350

**Code Changes:**
```diff
@@ -1346,6 +1346,108 @@ void CV_ProjectPointsTest_CPP::project( const Mat& objectPoints, const Mat& rvec
 
 ///////////////////////////////// Stereo Calibration /////////////////////////////////////
 
+class CV_StereoCalibrationCornerTest : public cvtest::BaseTest
+{
+public:
+    CV_StereoCalibrationCornerTest();
+    ~CV_StereoCalibrationCornerTest();
+    void clear();
+protected:
```

Review comment:
please, avoid obsolete `cvtest::BaseTest`-based tests. Use pure Google Test tests.
**File:** modules/calib3d/test/test_cameracalibration.cpp
**Change Type:** modified
**Context:** PR #6955: add test for #6836 - @vpisarev, @vicproon I've converted the reproducing sample from #6836 to a regression test
**Review Line:** 1350

**Code Changes:**
```diff
@@ -1346,6 +1346,108 @@ void CV_ProjectPointsTest_CPP::project( const Mat& objectPoints, const Mat& rvec
 
 ///////////////////////////////// Stereo Calibration /////////////////////////////////////
 
+class CV_StereoCalibrationCornerTest : public cvtest::BaseTest
+{
+public:
+    CV_StereoCalibrationCornerTest();
+    ~CV_StereoCalibrationCornerTest();
+    void clear();
+protected:
```

Review comment:
I follow the "consistency is better than brilliance" principle. Every other test in this file looks like this. So, I follow the common pattern. If the conversion should happen, it should, probably, happen all at once.
**File:** modules/calib3d/test/test_cameracalibration.cpp
**Change Type:** modified
**Context:** PR #6955: add test for #6836 - @vpisarev, @vicproon I've converted the reproducing sample from #6836 to a regression test
**Review Line:** 1350

**Code Changes:**
```diff
@@ -1346,6 +1346,108 @@ void CV_ProjectPointsTest_CPP::project( const Mat& objectPoints, const Mat& rvec
 
 ///////////////////////////////// Stereo Calibration /////////////////////////////////////
 
+class CV_StereoCalibrationCornerTest : public cvtest::BaseTest
+{
+public:
+    CV_StereoCalibrationCornerTest();
+    ~CV_StereoCalibrationCornerTest();
+    void clear();
+protected:
```

Review comment:
These test are obsolete and hard to read. It's easy and better to support Google Test based tests > Every other test in this file looks like this Let's create another file with proper tests :smile:
**File:** modules/calib3d/test/test_cameracalibration.cpp
**Change Type:** modified
**Context:** PR #6955: add test for #6836 - @vpisarev, @vicproon I've converted the reproducing sample from #6836 to a regression test
**Review Line:** 1437

**Code Changes:**
```diff
+    remap(image, src_result, srcRmap[0], srcRmap[1], INTER_LINEAR);
+    resize(src_result, src_result, Size(), scale, scale, INTER_LINEAR);
+    // perform resize-remap
+    Mat rsz_result;
+    resize(image, rsz_result, Size(), scale, scale, INTER_LINEAR);
+    remap(rsz_result, rsz_result, rszRmap[0], rszRmap[1], INTER_LINEAR);
+
+    // modifying the camera matrix with resizeCameraMatrix must yield the same
+    // result as calibrating the downscaled images
+    int cnz = countNonZero((cv::Mat(src_result - rsz_result) != 0)(
+                               cv::Rect(src_result.cols / 3, src_result.rows / 3,
```

Review comment:
this part looks a bit weird to me. You check that resize(remap(img)) == remap(resize(img)), which is generally not true, because of rounding operations and many other reasons; It can only be true if img is constant image. In your test the image is simple but non-constant, and this is strange that it passed the test, probably, the results should be visualized to see what's going on
**File:** modules/calib3d/test/test_cameracalibration.cpp
**Change Type:** modified
**Context:** PR #6955: add test for #6836 - @vpisarev, @vicproon I've converted the reproducing sample from #6836 to a regression test
**Review Line:** 1437

**Code Changes:**
```diff
+    remap(image, src_result, srcRmap[0], srcRmap[1], INTER_LINEAR);
+    resize(src_result, src_result, Size(), scale, scale, INTER_LINEAR);
+    // perform resize-remap
+    Mat rsz_result;
+    resize(image, rsz_result, Size(), scale, scale, INTER_LINEAR);
+    remap(rsz_result, rsz_result, rszRmap[0], rszRmap[1], INTER_LINEAR);
+
+    // modifying the camera matrix with resizeCameraMatrix must yield the same
+    // result as calibrating the downscaled images
+    int cnz = countNonZero((cv::Mat(src_result - rsz_result) != 0)(
+                               cv::Rect(src_result.cols / 3, src_result.rows / 3,
```

Review comment:
This is what happens - we work on an image with a constant rectangle area close the the center (moved in top-left direction). Prior to change (buggy behavior) - it would completely disappear from one of the images. After the change (correct behavior) - it stays roughly where it was. You are correct in that the borders of the rectangle do not match perfectly (because of rounding, etc.) - but below I check only the inner part (3.1 divisor instead of 3) to work around this. I agree, that it's not the tidiest test ever. But still, it seems kind of ok to me as a "regression" test for a corner-case issue.
**File:** modules/core/src/cuda/gpu_mat.cu
**Change Type:** modified
**Context:** PR #6991: cudev: add feature to convert FP32(float) from/to FP16(half) on GPU - ### This pullrequest changes - GPU version of #6830, #6447 - add featu...
**Review Line:** 612

**Code Changes:**
```diff
+    case CV_16S:
+        ddepth = CV_32F;
+        break;
+    default:
+        CV_Error(Error::StsUnsupportedFormat, "Unsupported input depth");
+        return;
+    }
+    int type = CV_MAKE_TYPE(CV_MAT_DEPTH(ddepth), src.channels());
+    _dst.create(src.size(), type);
+    GpuMat dst = _dst.getGpuMat();
+
```

Review comment:
I think it will be better to raise an error here, eg. ``` CV_Error(cv::StsUnsupportedFormat, "Unsupported input depth"); ```
**File:** modules/cudev/include/opencv2/cudev/functional/functional.hpp
**Change Type:** modified
**Context:** PR #6991: cudev: add feature to convert FP32(float) from/to FP16(half) on GPU - ### This pullrequest changes - GPU version of #6830, #6447 - add featu...

**Code Changes:**
```diff
@@ -668,6 +668,27 @@ template <typename T, typename D> struct saturate_cast_func : unary_function<T,
     }
 };
 
+// Convert Fp16 dummy
+template <typename T, typename D> struct saturate_cast_fp16_func;
+
+// Convert Fp16 from Fp32
+template <> struct saturate_cast_fp16_func<float, short> : unary_function<float, short>
+{
```

Review comment:
I think it will be better to leave the class unimplemented for the default case. In this case, compiler will raise an error, if someone tries to use it with unsupported types: ``` template <typename T, typename D> struct saturate_cast_fp16_func; template <> struct saturate_cast_fp16_func<float, short> : unary_function<float, short> { ... }; ```