nareshmlx/opencv-pr huggingface dataset:
**File:** modules/imgproc/src/connectedcomponents.cpp
**Change Type:** modified
**Context:** PR #1342: correct range computation in connectedcomponents stats - I originally tried doing a more efficient implementation but it was difficult to do...

**Code Changes:**
```diff
@@ -92,20 +92,10 @@ namespace cv{
         }
         void operator()(int r, int c, int l){
             int *row = &statsv.at<int>(l, 0);
-            if(c > row[CC_STAT_WIDTH]){
-                row[CC_STAT_WIDTH] = c;
-            }else{
-                if(c < row[CC_STAT_LEFT]){
-                    row[CC_STAT_LEFT] = c;
-                }
```

Review comment:
the same bug
**File:** modules/core/include/opencv2/core/utility.hpp
**Change Type:** modified
**Context:** PR #1366: AutoBuffer with initial zero size fixed. - Zero sized array are restricted by C++ standard.

**Code Changes:**
```diff
@@ -116,8 +116,8 @@ template<typename _Tp, size_t fixed_size = 1024/sizeof(_Tp)+8> class AutoBuffer
     _Tp* ptr;
     //! size of the real buffer
     size_t sz;
-    //! pre-allocated buffer
-    _Tp buf[fixed_size];
+    //! pre-allocated buffer. At least 1 element to confirm C++ standard reqirements
+    _Tp buf[(fixed_size > 0) ? fixed_size : 1];
 };
 
```

Review comment:
What do you mean, "even"?
**File:** modules/core/include/opencv2/core/ocl.hpp
**Change Type:** modified
**Context:** PR #2685: exposed OpenCL-control functions to python - new functions are visible in Python as `cv2.ocl_<funcname>`
**Review Line:** 54

**Code Changes:**
```diff
+CV_EXPORTS_W bool haveOpenCL();
+CV_EXPORTS_W bool useOpenCL();
+CV_EXPORTS_W bool haveAmdBlas();
+CV_EXPORTS_W bool haveAmdFft();
+CV_EXPORTS_W void setUseOpenCL(bool flag);
+CV_EXPORTS_W void finish();
 
 class CV_EXPORTS Context;
 class CV_EXPORTS Device;
```

Review comment:
I'm not sure users should call `cl::finish()` in app code; it's exported only for perf tests that neds to call it
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #2221: opencv_test_all.sh script added to -tests package.

**Code Changes:**
```diff
@@ -275,6 +275,9 @@ endif()
 set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples")
 
 set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin")
+if(NOT OPENCV_TEST_INSTALL_PATH)
+  set(OPENCV_TEST_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}")
+endif()
 
 if(ANDROID)
   set(LIBRARY_OUTPUT_PATH         "${OpenCV_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}")
```

Review comment:
The `IMMEDIATE` option is obsolete and does nothing. Don't use it. (I should've said that for the one before, too, but I didn't notice.)
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #2221: opencv_test_all.sh script added to -tests package.

**Code Changes:**
```diff
@@ -275,6 +275,9 @@ endif()
 set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples")
 
 set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin")
+if(NOT OPENCV_TEST_INSTALL_PATH)
+  set(OPENCV_TEST_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}")
+endif()
 
 if(ANDROID)
   set(LIBRARY_OUTPUT_PATH         "${OpenCV_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}")
```

Review comment:
Not even `OWNER_WRITE`? :wink:
**File:** modules/imgproc/src/morph.cpp
**Change Type:** modified
**Context:** PR #1163: Add IPP erosion and dilation
**Review Line:** 1139

**Code Changes:**
```diff
@@ -1136,11 +1136,151 @@ class MorphologyRunner : public ParallelLoopBody
     Scalar borderValue;
 };
 
+#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
+static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kernel, const Point &anchor)
+{
+	int type = src.type();
+	const Mat* _src = &src;
+	Mat temp;
```

Review comment:
Let's reduce the code duplication by using function pointers and if's. 1. First of all, IPPDilateReplicate and IPPErodeReplicate look same except for the dilate/erode calls. Let's make a single function that takes erode/dilate parameter and use it inside the switch. 2. Secondly, let's use the 2 function pointers and set the first one to one of ippiMorphologyInitAlloc_*, depending on the type and second one to the processing function. The further logic can be executed after the switch. 3. Temporary buffer should be made cv::Mat: <pre> const Mat\* _src = &src; Mat temp; if( src.data == dst.data ) { src.copyTo(temp); _src = &temp; } </pre> it's much easier and the memory is managed automatically.
**File:** modules/imgproc/src/morph.cpp
**Change Type:** modified
**Context:** PR #1163: Add IPP erosion and dilation

**Code Changes:**
```diff
@@ -1136,11 +1136,151 @@ class MorphologyRunner : public ParallelLoopBody
     Scalar borderValue;
 };
 
+#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
+static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kernel, const Point &anchor)
+{
+	int type = src.type();
+	const Mat* _src = &src;
+	Mat temp;
```

Review comment:
if you look at the OpenCV functions cv::erode and cv::dilate, you will see that they use constant border mode by default. In other words, in most cases the IPP acceleration will not be even called. You should check that if borderType == BORDER_CONSTANT and borderValue is equal to morphologyDefaultBorderValue() and if kernel at the anchor point is non-zero then IPP function can also be used. I repeat, without this modification IPP acceleration here is almost useless.
**File:** modules/imgproc/src/morph.cpp
**Change Type:** modified
**Context:** PR #1163: Add IPP erosion and dilation

**Code Changes:**
```diff
@@ -1136,11 +1136,151 @@ class MorphologyRunner : public ParallelLoopBody
     Scalar borderValue;
 };
 
+#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
+static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kernel, const Point &anchor)
+{
+	int type = src.type();
+	const Mat* _src = &src;
+	Mat temp;
```

Review comment:
InputArray and OutputArray are references themselves. Please, remove extra references. "int&" should also be replaced with "int".
**File:** modules/imgproc/src/morph.cpp
**Change Type:** modified
**Context:** PR #1163: Add IPP erosion and dilation

**Code Changes:**
```diff
@@ -1136,11 +1136,151 @@ class MorphologyRunner : public ParallelLoopBody
     Scalar borderValue;
 };
 
+#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
+static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kernel, const Point &anchor)
+{
+	int type = src.type();
+	const Mat* _src = &src;
+	Mat temp;
```

Review comment:
this is too much extra {. Could you remove "{" and "}" that surround a single operator (here, below and above)
**File:** modules/core/test/test_operations.cpp
**Change Type:** modified
**Context:** PR #1011: Support elementwise division for Matx with "operator /" - While most of the features with Matx can be accessed by converting to Mat and back...
**Review Line:** 78

**Code Changes:**
```diff
@@ -75,6 +75,7 @@ class CV_OperationsTest : public cvtest::BaseTest
     bool TestSparseMat();
     bool TestVec();
     bool TestMatxMultiplication();
+    bool TestMatxElementwiseDivison();
     bool TestSubMatAccess();
     bool TestExp();
     bool TestSVD();
@@ -891,6 +892,28 @@ bool CV_OperationsTest::TestMatxMultiplication()
     return true;
```

Review comment:
This is not enough. You also have to call it from `CV_OperationsTest::run`.
**File:** modules/core/test/test_operations.cpp
**Change Type:** modified
**Context:** PR #1011: Support elementwise division for Matx with "operator /" - While most of the features with Matx can be accessed by converting to Mat and back...

**Code Changes:**
```diff
@@ -75,6 +75,7 @@ class CV_OperationsTest : public cvtest::BaseTest
     bool TestSparseMat();
     bool TestVec();
     bool TestMatxMultiplication();
+    bool TestMatxElementwiseDivison();
     bool TestSubMatAccess();
     bool TestExp();
     bool TestSVD();
@@ -891,6 +892,28 @@ bool CV_OperationsTest::TestMatxMultiplication()
     return true;
```

Review comment:
Doesn't look like an identity matrix to me...
**File:** modules/androidcamera/camera_wrapper/camera_wrapper.cpp
**Change Type:** modified
**Context:** PR #1820: Native camera support for Android 4.4 KitKat
**Review Line:** 689

**Code Changes:**
```diff
     }
 
     camera->stopPreview();
-#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
+#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \
+ || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_3_0)
     camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
 #endif
     camera->disconnect();
@@ -914,7 +937,8 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
 
```

Review comment:
I just noticed `ANDROID_r4_3_0` is used twice here. Sounds like a bug...
**File:** modules/androidcamera/camera_wrapper/camera_wrapper.cpp
**Change Type:** modified
**Context:** PR #1820: Native camera support for Android 4.4 KitKat
**Review Line:** 689

**Code Changes:**
```diff
     }
 
     camera->stopPreview();
-#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
+#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \
+ || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_3_0)
     camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
 #endif
     camera->disconnect();
@@ -914,7 +937,8 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
 
```

Review comment:
Yes it's a bug. I'll prepare pull request.
**File:** doc/conf.py
**Change Type:** modified
**Context:** PR #1315: Added the tutorial on background subtraction, in the video section - Added a tutorial on background subtraction, in the video section. I als...

**Code Changes:**
```diff
@@ -401,5 +401,9 @@
             'brute_force_matcher' : ('http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=bruteforcematcher#bruteforcematcher%s', None ),
             'cascade_classifier' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=cascadeclassifier#cascadeclassifier%s', None ),
             'cascade_classifier_load' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=load#cascadeclassifier-load%s', None ),
-            'cascade_classifier_detect_multiscale' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale%s', None )
+            'cascade_classifier_detect_multiscale' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale%s', None ),
+            'background_subtractor' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractor#backgroundsubtractor%s', None),
+            'background_subtractor_mog' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG#backgroundsubtractormog%s', None),
+            'background_subtractor_mog_two' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG2#backgroundsubtractormog2%s', None),
+            'video_capture' : ('http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#videocapture%s', None)
```

Review comment:
These lines are misaligned.
**File:** samples/cpp/tutorial_code/video/bg_sub.cpp
**Change Type:** added
**Context:** PR #1315: Added the tutorial on background subtraction, in the video section - Added a tutorial on background subtraction, in the video section. I als...

**Code Changes:**
```diff
@@ -0,0 +1,186 @@
+/**
+ * @file bg_sub.cpp
+ * @brief Background subtraction tutorial sample code
+ * @author Domenico D. Bloisi
+ */
+
+//opencv
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/video/background_segm.hpp>
```

Review comment:
It would be preferred if you didn't use the C API in new tutorials.
**File:** cmake/templates/opencv_testing.sh.in
**Change Type:** added
**Context:** PR #2215: Multiple fixes for tests deb package build. - Added opencv_testing.sh.in file; opencv_testing.sh installation guarded by OS check.

**Code Changes:**
```diff
@@ -0,0 +1,2 @@
+# Environment setup for OpenCV testing
+export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata
\ No newline at end of file
```

Review comment:
Why not use `CMAKE_INSTALL_PREFIX` directly?
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #2215: Multiple fixes for tests deb package build. - Added opencv_testing.sh.in file; opencv_testing.sh installation guarded by OS check.

**Code Changes:**
```diff
@@ -561,6 +561,13 @@ include(cmake/OpenCVGenConfig.cmake)
 # Generate Info.plist for the IOS framework
 include(cmake/OpenCVGenInfoPlist.cmake)
 
+# Generate environment setup file
+if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX AND NOT ANDROID)
+  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in"
+                 "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY IMMEDIATE)
+  install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" DESTINATION /etc/profile.d/ COMPONENT tests)
+endif()
```

Review comment:
I'd rather prefer if this had to be specified explicitly. I have `OPENCV_TEST_DATA_PATH` set in my environment all the time (so that I can run tests easily), but that doesn't mean I want to package the test data.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #2215: Multiple fixes for tests deb package build. - Added opencv_testing.sh.in file; opencv_testing.sh installation guarded by OS check.

**Code Changes:**
```diff
@@ -561,6 +561,13 @@ include(cmake/OpenCVGenConfig.cmake)
 # Generate Info.plist for the IOS framework
 include(cmake/OpenCVGenInfoPlist.cmake)
 
+# Generate environment setup file
+if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX AND NOT ANDROID)
+  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in"
+                 "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY IMMEDIATE)
+  install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" DESTINATION /etc/profile.d/ COMPONENT tests)
+endif()
```

Review comment:
Why not put this in the same section that other similar files are generated in?
**File:** data/CMakeLists.txt
**Change Type:** modified
**Context:** PR #2215: Multiple fixes for tests deb package build. - Added opencv_testing.sh.in file; opencv_testing.sh installation guarded by OS check.

**Code Changes:**
```diff
@@ -9,10 +9,10 @@ elseif(NOT WIN32)
   install(FILES ${LBP_CASCADES}  DESTINATION share/OpenCV/lbpcascades  COMPONENT libs)
 endif()
 
-if (OPENCV_TEST_DATA_PATH)
+if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
   if(ANDROID)
-    install(FILES ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests)
+    install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests)
   elseif(NOT WIN32)
```

Review comment:
This should be a status line (predicated on `INSTALL_TESTS`, probably).
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #2215: Multiple fixes for tests deb package build. - Added opencv_testing.sh.in file; opencv_testing.sh installation guarded by OS check.

**Code Changes:**
```diff
@@ -561,6 +561,13 @@ include(cmake/OpenCVGenConfig.cmake)
 # Generate Info.plist for the IOS framework
 include(cmake/OpenCVGenInfoPlist.cmake)
 
+# Generate environment setup file
+if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX AND NOT ANDROID)
+  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in"
+                 "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY IMMEDIATE)
+  install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" DESTINATION /etc/profile.d/ COMPONENT tests)
+endif()
```

Review comment:
You didn't really address my previous comment.
**File:** data/CMakeLists.txt
**Change Type:** modified
**Context:** PR #2215: Multiple fixes for tests deb package build. - Added opencv_testing.sh.in file; opencv_testing.sh installation guarded by OS check.

**Code Changes:**
```diff
@@ -9,10 +9,10 @@ elseif(NOT WIN32)
   install(FILES ${LBP_CASCADES}  DESTINATION share/OpenCV/lbpcascades  COMPONENT libs)
 endif()
 
-if (OPENCV_TEST_DATA_PATH)
+if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
   if(ANDROID)
-    install(FILES ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests)
+    install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests)
   elseif(NOT WIN32)
```

Review comment:
`INSTALL_TESTS AND`, perhaps?
**File:** modules/highgui/include/opencv2/highgui/highgui_c.h
**Change Type:** modified
**Context:** PR #2144: Added get and set for extra PVAPI property - `CV_CAP_PROP_FRAMESTARTTRIGGERMODE`

**Code Changes:**
```diff
@@ -420,8 +420,11 @@ enum
     CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION,
 
     // Properties of cameras available through GStreamer interface
-    CV_CAP_GSTREAMER_QUEUE_LENGTH   = 200, // default is 1
-    CV_CAP_PROP_PVAPI_MULTICASTIP   = 300, // ip for anable multicast master mode. 0 for disable multicast
+    CV_CAP_GSTREAMER_QUEUE_LENGTH           = 200, // default is 1
+
+    // PVAPI
+    CV_CAP_PROP_PVAPI_MULTICASTIP           = 300, // ip for anable multicast master mode. 0 for disable multicast
```

Review comment:
These magic numbers should be in an enum of their own.
**File:** modules/highgui/include/opencv2/highgui.hpp
**Change Type:** modified
**Context:** PR #2144: Added get and set for extra PVAPI property - `CV_CAP_PROP_FRAMESTARTTRIGGERMODE`

**Code Changes:**
```diff
@@ -385,9 +385,17 @@ enum { CAP_PROP_GSTREAMER_QUEUE_LENGTH = 200 // default is 1
 
 
 // PVAPI
-enum { CAP_PROP_PVAPI_MULTICASTIP = 300 // ip for anable multicast master mode. 0 for disable multicast
+enum { CAP_PROP_PVAPI_MULTICASTIP               = 300, // ip for anable multicast master mode. 0 for disable multicast
+       CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE     = 301  // FrameStartTriggerMode: Determines how a frame is initiated
      };
 
+// PVAPI: FrameStartTriggerMode
```

Review comment:
missing comma after `300`
**File:** cmake/OpenCVDetectAndroidSDK.cmake
**Change Type:** modified
**Context:** PR #2276: Multiple improvements in OpenCV examples build. - EMBED_CUDA and FORCE_EMBED_IOENCV flags added to cmake macro add_android_project; INSTALL_...

**Code Changes:**
```diff
@@ -180,7 +180,7 @@ unset(__android_project_chain CACHE)
 # add_android_project(target_name ${path} NATIVE_DEPS opencv_core LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11)
 macro(add_android_project target path)
   # parse arguments
-  set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST)
+  set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST EMBED_CUDA FORCE_EMBED_OPENCV)
   set(__varname "android_proj_")
   foreach(v ${android_proj_arglist})
     set(${__varname}${v} "")
@@ -303,6 +303,46 @@ macro(add_android_project target path)
```

Review comment:
Can't tell if that's "if" or "or". :smiley:
**File:** cmake/OpenCVDetectAndroidSDK.cmake
**Change Type:** modified
**Context:** PR #2276: Multiple improvements in OpenCV examples build. - EMBED_CUDA and FORCE_EMBED_IOENCV flags added to cmake macro add_android_project; INSTALL_...

**Code Changes:**
```diff
@@ -180,7 +180,7 @@ unset(__android_project_chain CACHE)
 # add_android_project(target_name ${path} NATIVE_DEPS opencv_core LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11)
 macro(add_android_project target path)
   # parse arguments
-  set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST)
+  set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST EMBED_CUDA FORCE_EMBED_OPENCV)
   set(__varname "android_proj_")
   foreach(v ${android_proj_arglist})
     set(${__varname}${v} "")
@@ -303,6 +303,46 @@ macro(add_android_project target path)
```

Review comment:
Missing a "d" in "Embedding".
**File:** cmake/OpenCVDetectAndroidSDK.cmake
**Change Type:** modified
**Context:** PR #2276: Multiple improvements in OpenCV examples build. - EMBED_CUDA and FORCE_EMBED_IOENCV flags added to cmake macro add_android_project; INSTALL_...

**Code Changes:**
```diff
@@ -180,7 +180,7 @@ unset(__android_project_chain CACHE)
 # add_android_project(target_name ${path} NATIVE_DEPS opencv_core LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11)
 macro(add_android_project target path)
   # parse arguments
-  set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST)
+  set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST EMBED_CUDA FORCE_EMBED_OPENCV)
   set(__varname "android_proj_")
   foreach(v ${android_proj_arglist})
     set(${__varname}${v} "")
@@ -303,6 +303,46 @@ macro(add_android_project target path)
```

Review comment:
Also, this needs a `DEPENDS`/`MAIN_DEPENDENCY` option. And preferably `VERBATIM`, too.
**File:** cmake/OpenCVDetectAndroidSDK.cmake
**Change Type:** modified
**Context:** PR #2276: Multiple improvements in OpenCV examples build. - EMBED_CUDA and FORCE_EMBED_IOENCV flags added to cmake macro add_android_project; INSTALL_...
**Review Line:** 344

**Code Changes:**
```diff
+            OUTPUT "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}"
+            COMMAND ${CMAKE_COMMAND} -E copy "${lib}" "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}"
+            DEPENDS "${lib}" VERBATIM
+            COMMENT "Embedding ${f}")
+          list(APPEND android_proj_file_deps "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}")
+        endforeach()
+      endif()
     endif()
 
     # build java part
```

Review comment:
The code here is the same as above (same comments apply, even). Move it into a function, perhaps?
**File:** cmake/OpenCVDetectAndroidSDK.cmake
**Change Type:** modified
**Context:** PR #2276: Multiple improvements in OpenCV examples build. - EMBED_CUDA and FORCE_EMBED_IOENCV flags added to cmake macro add_android_project; INSTALL_...
**Review Line:** 308

**Code Changes:**
```diff
             add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${android_proj_jni_location}")
         endif()
       endif()
+
+      # copy opencv_java, tbb if it is shared and dynamicuda if present if FORCE_EMBED_OPENCV flag is set
+      if(android_proj_FORCE_EMBED_OPENCV)
+        set(native_deps ${android_proj_NATIVE_DEPS})
+        # filter out gpu module as it is always static library on Android
+        list(REMOVE_ITEM native_deps "opencv_gpu")
+        if(ENABLE_DYNAMIC_CUDA)
+          list(APPEND native_deps "opencv_dynamicuda")
```

Review comment:
The name of this option bothers me. "force" implies that there is some way to do it without forcing. But if that's the case, shouldn't this code already exist somewhere? Also the comment above is misleading, because this block special-cases neither opencv_java, nor tbb.
**File:** cmake/OpenCVUtils.cmake
**Change Type:** modified
**Context:** PR #2276: Multiple improvements in OpenCV examples build. - EMBED_CUDA and FORCE_EMBED_IOENCV flags added to cmake macro add_android_project; INSTALL_...

**Code Changes:**
```diff
@@ -448,6 +448,20 @@ macro(ocv_convert_to_full_paths VAR)
 endmacro()
 
 
+# convert list of paths to libraries names without lib prefix
+macro(ocv_convert_to_lib_name var)
+  set(__tmp "")
+  foreach(path ${ARGN})
+    get_filename_component(__tmp_name "${path}" NAME_WE)
+    string(REGEX REPLACE "^lib" "" __tmp_name ${__tmp_name})
```

Review comment:
I suggest using `ARGN` as input - much easier to use that way.