Merge remote-tracking branch 'origin/2.4' into merge-2.4
authorRoman Donchenko <roman.donchenko@itseez.com>
Tue, 3 Dec 2013 11:50:44 +0000 (15:50 +0400)
committerRoman Donchenko <roman.donchenko@itseez.com>
Tue, 3 Dec 2013 13:35:21 +0000 (17:35 +0400)
Conflicts:
CMakeLists.txt
cmake/OpenCVDetectCUDA.cmake
doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.rst
modules/core/src/cmdparser.cpp
modules/gpu/CMakeLists.txt
modules/gpu/doc/introduction.rst
modules/gpu/perf/perf_video.cpp
modules/highgui/doc/reading_and_writing_images_and_video.rst
modules/ocl/src/cl_context.cpp
modules/video/include/opencv2/video/background_segm.hpp
samples/cpp/image_sequence.cpp
samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp
samples/python/chessboard.py
samples/python/cvutils.py
samples/python/demhist.py
samples/python/dft.py
samples/python/distrans.py
samples/python/edge.py
samples/python/ffilldemo.py
samples/python/fitellipse.py
samples/python/houghlines.py
samples/python/inpaint.py
samples/python/logpolar.py
samples/python/morphology.py
samples/python/numpy_array.py
samples/python/watershed.py

67 files changed:
1  2 
CMakeLists.txt
apps/traincascade/boost.cpp
apps/traincascade/cascadeclassifier.cpp
cmake/OpenCVCompilerOptions.cmake
cmake/OpenCVDetectCUDA.cmake
doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.rst
doc/tutorials/features2d/feature_description/feature_description.rst
doc/tutorials/features2d/trackingmotion/corner_subpixeles/corner_subpixeles.rst
doc/tutorials/features2d/trackingmotion/good_features_to_track/good_features_to_track.rst
doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.rst
doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.rst
doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.rst
doc/tutorials/imgproc/histograms/back_projection/back_projection.rst
doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.rst
doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst
doc/tutorials/imgproc/histograms/histogram_equalization/histogram_equalization.rst
doc/tutorials/imgproc/histograms/template_matching/template_matching.rst
doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.rst
doc/tutorials/imgproc/imgtrans/copyMakeBorder/copyMakeBorder.rst
doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.rst
doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.rst
doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.rst
doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.rst
doc/tutorials/imgproc/imgtrans/remap/remap.rst
doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.rst
doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.rst
doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.rst
doc/tutorials/imgproc/pyramids/pyramids.rst
doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.rst
doc/tutorials/imgproc/shapedescriptors/bounding_rotated_ellipses/bounding_rotated_ellipses.rst
doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.rst
doc/tutorials/imgproc/shapedescriptors/hull/hull.rst
doc/tutorials/imgproc/shapedescriptors/moments/moments.rst
doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.rst
doc/tutorials/imgproc/threshold/threshold.rst
doc/tutorials/objdetect/cascade_classifier/cascade_classifier.rst
doc/user_guide/ug_highgui.rst
modules/contrib/doc/facerec/src/facerec_eigenfaces.cpp
modules/contrib/doc/facerec/src/facerec_fisherfaces.cpp
modules/contrib/doc/facerec/src/facerec_save_load.cpp
modules/contrib/src/facerec.cpp
modules/core/doc/basic_structures.rst
modules/core/src/command_line_parser.cpp
modules/cuda/CMakeLists.txt
modules/cuda/doc/introduction.rst
modules/cudaarithm/CMakeLists.txt
modules/cudabgsegm/CMakeLists.txt
modules/cudabgsegm/perf/perf_bgsegm.cpp
modules/cudacodec/CMakeLists.txt
modules/cudafeatures2d/CMakeLists.txt
modules/cudafilters/CMakeLists.txt
modules/cudaimgproc/CMakeLists.txt
modules/cudaoptflow/CMakeLists.txt
modules/cudastereo/CMakeLists.txt
modules/cudawarping/CMakeLists.txt
modules/highgui/doc/reading_and_writing_images_and_video.rst
modules/highgui/doc/user_interface.rst
modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst
modules/objdetect/doc/cascade_classification.rst
modules/ocl/include/opencv2/ocl/matrix_operations.hpp
modules/ocl/src/cl_context.cpp
modules/ocl/src/cl_operations.cpp
modules/ocl/src/haar.cpp
modules/ocl/src/mssegmentation.cpp
samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp
samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp
samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp

diff --cc CMakeLists.txt
@@@ -116,10 -127,10 +116,10 @@@ endif(
  OCV_OPTION(WITH_1394           "Include IEEE1394 support"                    ON   IF (NOT ANDROID AND NOT IOS) )
  OCV_OPTION(WITH_AVFOUNDATION   "Use AVFoundation for Video I/O"              ON   IF IOS)
  OCV_OPTION(WITH_CARBON         "Use Carbon for UI instead of Cocoa"          OFF  IF APPLE )
- OCV_OPTION(WITH_CUDA           "Include NVidia Cuda Runtime support"                                         ON  IF (NOT ANDROID AND NOT IOS) )
- OCV_OPTION(WITH_CUFFT          "Include NVidia Cuda Fast Fourier Transform (FFT) library support"            ON  IF (NOT ANDROID AND NOT IOS) )
- OCV_OPTION(WITH_CUBLAS         "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (NOT ANDROID AND NOT IOS) )
- OCV_OPTION(WITH_NVCUVID        "Include NVidia Video Decoding library support"                               OFF IF (NOT ANDROID AND NOT IOS AND NOT APPLE) )
 -OCV_OPTION(WITH_CUDA           "Include NVidia Cuda Runtime support"         ON   IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) )
 -OCV_OPTION(WITH_CUFFT          "Include NVidia Cuda Fast Fourier Transform (FFT) library support"            ON  IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) )
 -OCV_OPTION(WITH_CUBLAS         "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT IOS) )
 -OCV_OPTION(WITH_NVCUVID        "Include NVidia Video Decoding library support"                               OFF IF (CMAKE_VERSION VERSION_GREATER "2.8" AND NOT ANDROID AND NOT IOS AND NOT APPLE) )
++OCV_OPTION(WITH_CUDA           "Include NVidia Cuda Runtime support"                                         ON  IF (NOT IOS) )
++OCV_OPTION(WITH_CUFFT          "Include NVidia Cuda Fast Fourier Transform (FFT) library support"            ON  IF (NOT IOS) )
++OCV_OPTION(WITH_CUBLAS         "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" OFF IF (NOT IOS) )
++OCV_OPTION(WITH_NVCUVID        "Include NVidia Video Decoding library support"                               OFF IF (NOT IOS AND NOT APPLE) )
  OCV_OPTION(WITH_EIGEN          "Include Eigen2/Eigen3 support"               ON)
  OCV_OPTION(WITH_VFW            "Include Video for Windows support"           ON   IF WIN32 )
  OCV_OPTION(WITH_FFMPEG         "Include FFMPEG support"                      ON   IF (NOT ANDROID AND NOT IOS))
@@@ -1,17 -1,17 +1,30 @@@
 -#include "opencv2/core/core.hpp"
 -#include "opencv2/core/internal.hpp"
 +#include "opencv2/core.hpp"
 +#include "opencv2/core/utility.hpp"
 +
 +using cv::Size;
 +using cv::Mat;
 +using cv::Point;
 +using cv::FileStorage;
 +using cv::Rect;
 +using cv::Ptr;
 +using cv::FileNode;
 +using cv::Mat_;
 +using cv::Range;
 +using cv::FileNodeIterator;
 +using cv::ParallelLoopBody;
++
+ using cv::Size;
+ using cv::Mat;
+ using cv::Point;
+ using cv::FileStorage;
+ using cv::Rect;
+ using cv::Ptr;
+ using cv::FileNode;
+ using cv::Mat_;
+ using cv::Range;
+ using cv::FileNodeIterator;
+ using cv::ParallelLoopBody;
  
  
  #include "boost.h"
Simple merge
@@@ -168,9 -180,13 +178,17 @@@ if(CUDA_FOUND
        # we remove -Wsign-promo as it generates warnings under linux
        string(REPLACE "-Wsign-promo" "" ${var} "${${var}}")
  
 +      # we remove -fvisibility-inlines-hidden because it's used for C++ compiler
 +      # but NVCC uses C compiler by default
 +      string(REPLACE "-fvisibility-inlines-hidden" "" ${var} "${${var}}")
++
+       # we remove -Wno-delete-non-virtual-dtor because it's used for C++ compiler
+       # but NVCC uses C compiler by default
+       string(REPLACE "-Wno-delete-non-virtual-dtor" "" ${var} "${${var}}")
+       # we remove -frtti because it's used for C++ compiler
+       # but NVCC uses C compiler by default
+       string(REPLACE "-frtti" "" ${var} "${${var}}")
      endforeach()
  
      if(BUILD_SHARED_LIBS)
Simple merge
Simple merge
Simple merge
index b082fae,0000000..7a0284f
mode 100644,000000..100644
--- /dev/null
@@@ -1,512 -1,0 +1,511 @@@
-             for (int h = 0; h < 2; h++)
-             {
-                 if (s[0] == '-')
-                     s = s.substr(1, s.length() - 1);
-             }
-             impl->apply_params(s, "true");
 +#include "precomp.hpp"
 +#include <sstream>
 +
 +namespace cv
 +{
 +
 +struct CommandLineParserParams
 +{
 +public:
 +    String help_message;
 +    String def_value;
 +    std::vector<String> keys;
 +    int number;
 +};
 +
 +
 +struct CommandLineParser::Impl
 +{
 +    bool error;
 +    String error_message;
 +    String about_message;
 +
 +    String path_to_app;
 +    String app_name;
 +
 +    std::vector<CommandLineParserParams> data;
 +
 +    std::vector<String> split_range_string(const String& str, char fs, char ss) const;
 +    std::vector<String> split_string(const String& str, char symbol = ' ', bool create_empty_item = false) const;
 +    String cat_string(const String& str) const;
 +
 +    void apply_params(const String& key, const String& value);
 +    void apply_params(int i, String value);
 +
 +    void sort_params();
 +    int refcount;
 +};
 +
 +
 +static String get_type_name(int type)
 +{
 +    if( type == Param::INT )
 +        return "int";
 +    if( type == Param::UNSIGNED_INT )
 +        return "unsigned";
 +    if( type == Param::UINT64 )
 +        return "unsigned long long";
 +    if( type == Param::FLOAT )
 +        return "float";
 +    if( type == Param::REAL )
 +        return "double";
 +    if( type == Param::STRING )
 +        return "string";
 +    return "unknown";
 +}
 +
 +static void from_str(const String& str, int type, void* dst)
 +{
 +    std::stringstream ss(str.c_str());
 +    if( type == Param::INT )
 +        ss >> *(int*)dst;
 +    else if( type == Param::UNSIGNED_INT )
 +        ss >> *(unsigned*)dst;
 +    else if( type == Param::UINT64 )
 +        ss >> *(uint64*)dst;
 +    else if( type == Param::FLOAT )
 +        ss >> *(float*)dst;
 +    else if( type == Param::REAL )
 +        ss >> *(double*)dst;
 +    else if( type == Param::STRING )
 +        *(String*)dst = str;
 +    else
 +        throw cv::Exception(CV_StsBadArg, "unknown/unsupported parameter type", "", __FILE__, __LINE__);
 +
 +    if (ss.fail())
 +    {
 +        String err_msg = "can not convert: [" + str +
 +        + "] to [" + get_type_name(type) + "]";
 +
 +        throw cv::Exception(CV_StsBadArg, err_msg, "", __FILE__, __LINE__);
 +    }
 +}
 +
 +void CommandLineParser::getByName(const String& name, bool space_delete, int type, void* dst) const
 +{
 +    try
 +    {
 +        for (size_t i = 0; i < impl->data.size(); i++)
 +        {
 +            for (size_t j = 0; j < impl->data[i].keys.size(); j++)
 +            {
 +                if (name.compare(impl->data[i].keys[j]) == 0)
 +                {
 +                    String v = impl->data[i].def_value;
 +                    if (space_delete)
 +                        v = impl->cat_string(v);
 +                    from_str(v, type, dst);
 +                    return;
 +                }
 +            }
 +        }
 +        impl->error = true;
 +        impl->error_message = impl->error_message + "Unknown parametes " + name + "\n";
 +    }
 +    catch (std::exception& e)
 +    {
 +        impl->error = true;
 +        impl->error_message = impl->error_message + "Exception: " + String(e.what()) + "\n";
 +    }
 +}
 +
 +
 +void CommandLineParser::getByIndex(int index, bool space_delete, int type, void* dst) const
 +{
 +    try
 +    {
 +        for (size_t i = 0; i < impl->data.size(); i++)
 +        {
 +            if (impl->data[i].number == index)
 +            {
 +                String v = impl->data[i].def_value;
 +                if (space_delete == true) v = impl->cat_string(v);
 +                from_str(v, type, dst);
 +                return;
 +            }
 +        }
 +        impl->error = true;
 +        impl->error_message = impl->error_message + "Unknown parametes #" + format("%d", index) + "\n";
 +    }
 +    catch(std::exception & e)
 +    {
 +        impl->error = true;
 +        impl->error_message = impl->error_message + "Exception: " + String(e.what()) + "\n";
 +    }
 +}
 +
 +static bool cmp_params(const CommandLineParserParams & p1, const CommandLineParserParams & p2)
 +{
 +    if (p1.number < p2.number)
 +        return true;
 +
 +    if (p1.number > p2.number)
 +        return false;
 +
 +    return p1.keys[0].compare(p2.keys[0]) < 0;
 +}
 +
 +CommandLineParser::CommandLineParser(int argc, const char* const argv[], const String& keys)
 +{
 +    impl = new Impl;
 +    impl->refcount = 1;
 +
 +    // path to application
 +    size_t pos_s = String(argv[0]).find_last_of("/\\");
 +    if (pos_s == String::npos)
 +    {
 +        impl->path_to_app = "";
 +        impl->app_name = String(argv[0]);
 +    }
 +    else
 +    {
 +        impl->path_to_app = String(argv[0]).substr(0, pos_s);
 +        impl->app_name = String(argv[0]).substr(pos_s + 1, String(argv[0]).length() - pos_s);
 +    }
 +
 +    impl->error = false;
 +    impl->error_message = "";
 +
 +    // parse keys
 +    std::vector<String> k = impl->split_range_string(keys, '{', '}');
 +
 +    int jj = 0;
 +    for (size_t i = 0; i < k.size(); i++)
 +    {
 +        std::vector<String> l = impl->split_string(k[i], '|', true);
 +        CommandLineParserParams p;
 +        p.keys = impl->split_string(l[0]);
 +        p.def_value = l[1];
 +        p.help_message = impl->cat_string(l[2]);
 +        p.number = -1;
 +        if (p.keys.size() <= 0)
 +        {
 +            impl->error = true;
 +            impl->error_message = "Field KEYS could not be empty\n";
 +        }
 +        else
 +        {
 +            if (p.keys[0][0] == '@')
 +            {
 +                p.number = jj;
 +                jj++;
 +            }
 +
 +            impl->data.push_back(p);
 +        }
 +    }
 +
 +    // parse argv
 +    jj = 0;
 +    for (int i = 1; i < argc; i++)
 +    {
 +        String s = String(argv[i]);
 +
 +        if (s.find('=') != String::npos && s.find('=') < s.length())
 +        {
 +            std::vector<String> k_v = impl->split_string(s, '=', true);
 +            for (int h = 0; h < 2; h++)
 +            {
 +                if (k_v[0][0] == '-')
 +                    k_v[0] = k_v[0].substr(1, k_v[0].length() -1);
 +            }
 +            impl->apply_params(k_v[0], k_v[1]);
 +        }
++        else if (s.length() > 2 && s[0] == '-' && s[1] == '-')
++        {
++            impl->apply_params(s.substr(2), "true");
++        }
 +        else if (s.length() > 1 && s[0] == '-')
 +        {
-         else if (s[0] != '-')
++            impl->apply_params(s.substr(1), "true");
 +        }
++        else
 +        {
 +            impl->apply_params(jj, s);
 +            jj++;
 +        }
 +    }
 +
 +    impl->sort_params();
 +}
 +
 +
 +CommandLineParser::CommandLineParser(const CommandLineParser& parser)
 +{
 +    impl = parser.impl;
 +    CV_XADD(&impl->refcount, 1);
 +}
 +
 +CommandLineParser& CommandLineParser::operator = (const CommandLineParser& parser)
 +{
 +    if( this != &parser )
 +    {
 +        if(CV_XADD(&impl->refcount, -1) == 1)
 +            delete impl;
 +        impl = parser.impl;
 +        CV_XADD(&impl->refcount, 1);
 +    }
 +    return *this;
 +}
 +
 +void CommandLineParser::about(const String& message)
 +{
 +    impl->about_message = message;
 +}
 +
 +void CommandLineParser::Impl::apply_params(const String& key, const String& value)
 +{
 +    for (size_t i = 0; i < data.size(); i++)
 +    {
 +        for (size_t k = 0; k < data[i].keys.size(); k++)
 +        {
 +            if (key.compare(data[i].keys[k]) == 0)
 +            {
 +                data[i].def_value = value;
 +                break;
 +            }
 +        }
 +    }
 +}
 +
 +void CommandLineParser::Impl::apply_params(int i, String value)
 +{
 +    for (size_t j = 0; j < data.size(); j++)
 +    {
 +        if (data[j].number == i)
 +        {
 +            data[j].def_value = value;
 +            break;
 +        }
 +    }
 +}
 +
 +void CommandLineParser::Impl::sort_params()
 +{
 +    for (size_t i = 0; i < data.size(); i++)
 +    {
 +        std::sort(data[i].keys.begin(), data[i].keys.end());
 +    }
 +
 +    std::sort (data.begin(), data.end(), cmp_params);
 +}
 +
 +String CommandLineParser::Impl::cat_string(const String& str) const
 +{
 +    int left = 0, right = (int)str.length();
 +    while( left <= right && str[left] == ' ' )
 +        left++;
 +    while( right > left && str[right-1] == ' ' )
 +        right--;
 +    return left >= right ? String("") : str.substr(left, right-left);
 +}
 +
 +String CommandLineParser::getPathToApplication() const
 +{
 +    return impl->path_to_app;
 +}
 +
 +bool CommandLineParser::has(const String& name) const
 +{
 +    for (size_t i = 0; i < impl->data.size(); i++)
 +    {
 +        for (size_t j = 0; j < impl->data[i].keys.size(); j++)
 +        {
 +            if (name.compare(impl->data[i].keys[j]) == 0 && String("true").compare(impl->data[i].def_value) == 0)
 +            {
 +                return true;
 +            }
 +        }
 +    }
 +    return false;
 +}
 +
 +bool CommandLineParser::check() const
 +{
 +    return impl->error == false;
 +}
 +
 +void CommandLineParser::printErrors() const
 +{
 +    if (impl->error)
 +    {
 +        printf("\nERRORS:\n%s\n", impl->error_message.c_str());
 +        fflush(stdout);
 +    }
 +}
 +
 +void CommandLineParser::printMessage() const
 +{
 +    if (impl->about_message != "")
 +        printf("%s\n", impl->about_message.c_str());
 +
 +    printf("Usage: %s [params] ", impl->app_name.c_str());
 +
 +    for (size_t i = 0; i < impl->data.size(); i++)
 +    {
 +        if (impl->data[i].number > -1)
 +        {
 +            String name = impl->data[i].keys[0].substr(1, impl->data[i].keys[0].length() - 1);
 +            printf("%s ", name.c_str());
 +        }
 +    }
 +
 +    printf("\n\n");
 +
 +    for (size_t i = 0; i < impl->data.size(); i++)
 +    {
 +        if (impl->data[i].number == -1)
 +        {
 +            printf("\t");
 +            for (size_t j = 0; j < impl->data[i].keys.size(); j++)
 +            {
 +                String k = impl->data[i].keys[j];
 +                if (k.length() > 1)
 +                {
 +                    printf("--");
 +                }
 +                else
 +                {
 +                    printf("-");
 +                }
 +                printf("%s", k.c_str());
 +
 +                if (j != impl->data[i].keys.size() - 1)
 +                {
 +                    printf(", ");
 +                }
 +            }
 +            String dv = impl->cat_string(impl->data[i].def_value);
 +            if (dv.compare("") != 0)
 +            {
 +                printf(" (value:%s)", dv.c_str());
 +            }
 +            printf("\n\t\t%s\n", impl->data[i].help_message.c_str());
 +        }
 +    }
 +    printf("\n");
 +
 +    for (size_t i = 0; i < impl->data.size(); i++)
 +    {
 +        if (impl->data[i].number != -1)
 +        {
 +            printf("\t");
 +            String k = impl->data[i].keys[0];
 +            k = k.substr(1, k.length() - 1);
 +
 +            printf("%s", k.c_str());
 +
 +            String dv = impl->cat_string(impl->data[i].def_value);
 +            if (dv.compare("") != 0)
 +            {
 +                printf(" (value:%s)", dv.c_str());
 +            }
 +            printf("\n\t\t%s\n", impl->data[i].help_message.c_str());
 +        }
 +    }
 +}
 +
 +std::vector<String> CommandLineParser::Impl::split_range_string(const String& _str, char fs, char ss) const
 +{
 +    String str = _str;
 +    std::vector<String> vec;
 +    String word = "";
 +    bool begin = false;
 +
 +    while (!str.empty())
 +    {
 +        if (str[0] == fs)
 +        {
 +            if (begin == true)
 +            {
 +                throw cv::Exception(CV_StsParseError,
 +                         String("error in split_range_string(")
 +                         + str
 +                         + String(", ")
 +                         + String(1, fs)
 +                         + String(", ")
 +                         + String(1, ss)
 +                         + String(")"),
 +                         "", __FILE__, __LINE__
 +                         );
 +            }
 +            begin = true;
 +            word = "";
 +            str = str.substr(1, str.length() - 1);
 +        }
 +
 +        if (str[0] == ss)
 +        {
 +            if (begin == false)
 +            {
 +                throw cv::Exception(CV_StsParseError,
 +                         String("error in split_range_string(")
 +                         + str
 +                         + String(", ")
 +                         + String(1, fs)
 +                         + String(", ")
 +                         + String(1, ss)
 +                         + String(")"),
 +                         "", __FILE__, __LINE__
 +                         );
 +            }
 +            begin = false;
 +            vec.push_back(word);
 +        }
 +
 +        if (begin == true)
 +        {
 +            word = word + str[0];
 +        }
 +        str = str.substr(1, str.length() - 1);
 +    }
 +
 +    if (begin == true)
 +    {
 +        throw cv::Exception(CV_StsParseError,
 +                 String("error in split_range_string(")
 +                 + str
 +                 + String(", ")
 +                 + String(1, fs)
 +                 + String(", ")
 +                 + String(1, ss)
 +                 + String(")"),
 +                 "", __FILE__, __LINE__
 +                );
 +    }
 +
 +    return vec;
 +}
 +
 +std::vector<String> CommandLineParser::Impl::split_string(const String& _str, char symbol, bool create_empty_item) const
 +{
 +    String str = _str;
 +    std::vector<String> vec;
 +    String word = "";
 +
 +    while (!str.empty())
 +    {
 +        if (str[0] == symbol)
 +        {
 +            if (!word.empty() || create_empty_item)
 +            {
 +                vec.push_back(word);
 +                word = "";
 +            }
 +        }
 +        else
 +        {
 +            word = word + str[0];
 +        }
 +        str = str.substr(1, str.length() - 1);
 +    }
 +
 +    if (word != "" || create_empty_item)
 +    {
 +        vec.push_back(word);
 +    }
 +
 +    return vec;
 +}
 +
 +}
index c8047b1,0000000..a79b7d3
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cuda)
 +endif()
 +
 +set(the_description "CUDA-accelerated Computer Vision")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter)
 +
 +ocv_define_module(cuda opencv_calib3d opencv_objdetect opencv_cudaarithm opencv_cudawarping OPTIONAL opencv_cudalegacy)
index a299d7f,0000000..589a39f
mode 100644,000000..100644
--- /dev/null
@@@ -1,61 -1,0 +1,61 @@@
- With this algorithm, a dual GPU gave a 180% performance increase comparing to the single Fermi GPU. For a source code example, see http://code.opencv.org/projects/opencv/repository/revisions/master/entry/samples/gpu/.
 +CUDA Module Introduction
 +========================
 +
 +.. highlight:: cpp
 +
 +
 +
 +General Information
 +-------------------
 +
 +The OpenCV CUDA module is a set of classes and functions to utilize CUDA computational capabilities. It is implemented using NVIDIA* CUDA* Runtime API and supports only NVIDIA GPUs. The OpenCV CUDA module includes utility functions, low-level vision primitives, and high-level algorithms. The utility functions and low-level primitives provide a powerful infrastructure for developing fast vision algorithms taking advantage of CUDA whereas the high-level functionality includes some state-of-the-art algorithms (such as stereo correspondence, face and people detectors, and others) ready to be used by the application developers.
 +
 +The CUDA module is designed as a host-level API. This means that if you have pre-compiled OpenCV CUDA binaries, you are not required to have the CUDA Toolkit installed or write any extra code to make use of the CUDA.
 +
 +The OpenCV CUDA module is designed for ease of use and does not require any knowledge of CUDA. Though, such a knowledge will certainly be useful to handle non-trivial cases or achieve the highest performance. It is helpful to understand the cost of various operations, what the GPU does, what the preferred data formats are, and so on. The CUDA module is an effective instrument for quick implementation of CUDA-accelerated computer vision algorithms. However, if your algorithm involves many simple operations, then, for the best possible performance, you may still need to write your own kernels to avoid extra write and read operations on the intermediate results.
 +
 +To enable CUDA support, configure OpenCV using ``CMake`` with ``WITH_CUDA=ON`` . When the flag is set and if CUDA is installed, the full-featured OpenCV CUDA module is built. Otherwise, the module is still built but at runtime all functions from the module throw
 +:ocv:class:`Exception` with ``CV_GpuNotSupported`` error code, except for
 +:ocv:func:`cuda::getCudaEnabledDeviceCount()`. The latter function returns zero GPU count in this case. Building OpenCV without CUDA support does not perform device code compilation, so it does not require the CUDA Toolkit installed. Therefore, using the
 +:ocv:func:`cuda::getCudaEnabledDeviceCount()` function, you can implement a high-level algorithm that will detect GPU presence at runtime and choose an appropriate implementation (CPU or GPU) accordingly.
 +
 +Compilation for Different NVIDIA* Platforms
 +-------------------------------------------
 +
 +NVIDIA* compiler enables generating binary code (cubin and fatbin) and intermediate code (PTX). Binary code often implies a specific GPU architecture and generation, so the compatibility with other GPUs is not guaranteed. PTX is targeted for a virtual platform that is defined entirely by the set of capabilities or features. Depending on the selected virtual platform, some of the instructions are emulated or disabled, even if the real hardware supports all the features.
 +
 +At the first call, the PTX code is compiled to binary code for the particular GPU using a JIT compiler. When the target GPU has a compute capability (CC) lower than the PTX code, JIT fails.
 +By default, the OpenCV CUDA module includes:
 +
 +*
 +    Binaries for compute capabilities 1.3 and 2.0 (controlled by ``CUDA_ARCH_BIN``     in ``CMake``)
 +
 +*
 +    PTX code for compute capabilities 1.1 and 1.3 (controlled by ``CUDA_ARCH_PTX``     in ``CMake``)
 +
 +This means that for devices with CC 1.3 and 2.0 binary images are ready to run. For all newer platforms, the PTX code for 1.3 is JIT'ed to a binary image. For devices with CC 1.1 and 1.2, the PTX for 1.1 is JIT'ed. For devices with CC 1.0, no code is available and the functions throw
 +:ocv:class:`Exception`. For platforms where JIT compilation is performed first, the run is slow.
 +
 +On a GPU with CC 1.0, you can still compile the CUDA module and most of the functions will run flawlessly. To achieve this, add "1.0" to the list of binaries, for example, ``CUDA_ARCH_BIN="1.0 1.3 2.0"`` . The functions that cannot be run on CC 1.0 GPUs throw an exception.
 +
 +You can always determine at runtime whether the OpenCV GPU-built binaries (or PTX code) are compatible with your GPU. The function
 +:ocv:func:`cuda::DeviceInfo::isCompatible` returns the compatibility status (true/false).
 +
 +Utilizing Multiple GPUs
 +-----------------------
 +
 +In the current version, each of the OpenCV CUDA algorithms can use only a single GPU. So, to utilize multiple GPUs, you have to manually distribute the work between GPUs.
 +Switching active devie can be done using :ocv:func:`cuda::setDevice()` function.  For more details please read Cuda C Programing Guide.
 +
 +While developing algorithms for multiple GPUs, note a data passing overhead. For primitive functions and small images, it can be significant, which may eliminate all the advantages of having multiple GPUs. But for high-level algorithms, consider using multi-GPU acceleration. For example, the Stereo Block Matching algorithm has been successfully parallelized using the following algorithm:
 +
 +
 + 1.   Split each image of the stereo pair into two horizontal overlapping stripes.
 +
 +
 + 2.   Process each pair of stripes (from the left and right images) on a separate Fermi* GPU.
 +
 +
 + 3.   Merge the results into a single disparity map.
 +
++With this algorithm, a dual GPU gave a 180% performance increase comparing to the single Fermi GPU. For a source code example, see https://github.com/Itseez/opencv/tree/master/samples/gpu/.
index f44c283,0000000..e3df9d2
mode 100644,000000..100644
--- /dev/null
@@@ -1,29 -1,0 +1,29 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudaarithm)
 +endif()
 +
 +set(the_description "CUDA-accelerated Operations on Matrices")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
 +
 +ocv_add_module(cudaarithm opencv_core OPTIONAL opencv_cudev)
 +
 +ocv_module_include_directories()
 +ocv_glob_module_sources()
 +
 +set(extra_libs "")
 +
 +if(HAVE_CUBLAS)
 +  list(APPEND extra_libs ${CUDA_cublas_LIBRARY})
 +endif()
 +
 +if(HAVE_CUFFT)
 +  list(APPEND extra_libs ${CUDA_cufft_LIBRARY})
 +endif()
 +
 +ocv_create_module(${extra_libs})
 +
 +ocv_add_precompiled_headers(${the_module})
 +
 +ocv_add_accuracy_tests(DEPENDS_ON opencv_imgproc)
 +ocv_add_perf_tests(DEPENDS_ON opencv_imgproc)
index fbfd2ae,0000000..526e4b1
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudabgsegm)
 +endif()
 +
 +set(the_description "CUDA-accelerated Background Segmentation")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
 +
 +ocv_define_module(cudabgsegm opencv_video OPTIONAL opencv_legacy opencv_imgproc opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)
index ef2bea8,0000000..9d3da29
mode 100644,000000..100644
--- /dev/null
@@@ -1,557 -1,0 +1,773 @@@
-         for (int i = 0; i < 10; ++i)
 +/*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
 +//                For Open Source Computer Vision Library
 +//
 +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
 +// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
 +// Third party copyrights are property of their respective owners.
 +//
 +// Redistribution and use in source and binary forms, with or without modification,
 +// are permitted provided that the following conditions are met:
 +//
 +//   * Redistribution's of source code must retain the above copyright notice,
 +//     this list of conditions and the following disclaimer.
 +//
 +//   * Redistribution's in binary form must reproduce the above copyright notice,
 +//     this list of conditions and the following disclaimer in the documentation
 +//     and/or other materials provided with the distribution.
 +//
 +//   * The name of the copyright holders may not be used to endorse or promote products
 +//     derived from this software without specific prior written permission.
 +//
 +// This software is provided by the copyright holders and contributors "as is" and
 +// any express or implied warranties, including, but not limited to, the implied
 +// warranties of merchantability and fitness for a particular purpose are disclaimed.
 +// In no event shall the Intel Corporation or contributors be liable for any direct,
 +// indirect, incidental, special, exemplary, or consequential damages
 +// (including, but not limited to, procurement of substitute goods or services;
 +// loss of use, data, or profits; or business interruption) however caused
 +// and on any theory of liability, whether in contract, strict liability,
 +// or tort (including negligence or otherwise) arising in any way out of
 +// the use of this software, even if advised of the possibility of such damage.
 +//
 +//M*/
 +
 +#include "perf_precomp.hpp"
 +
 +#ifdef HAVE_OPENCV_LEGACY
 +#  include "opencv2/legacy.hpp"
 +#endif
 +
 +#ifdef HAVE_OPENCV_CUDAIMGPROC
 +#  include "opencv2/cudaimgproc.hpp"
 +#endif
 +
 +using namespace std;
 +using namespace testing;
 +using namespace perf;
 +
 +#if defined(HAVE_XINE)         || \
 +    defined(HAVE_GSTREAMER)    || \
 +    defined(HAVE_QUICKTIME)    || \
 +    defined(HAVE_QTKIT)        || \
 +    defined(HAVE_AVFOUNDATION) || \
 +    defined(HAVE_FFMPEG)       || \
 +    defined(WIN32) /* assume that we have ffmpeg */
 +
 +#  define BUILD_WITH_VIDEO_INPUT_SUPPORT 1
 +#else
 +#  define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
 +#endif
 +
 +//////////////////////////////////////////////////////
 +// FGDStatModel
 +
 +#if BUILD_WITH_VIDEO_INPUT_SUPPORT
 +
 +#ifdef HAVE_OPENCV_LEGACY
 +
 +namespace cv
 +{
 +    template<> void DefaultDeleter<CvBGStatModel>::operator ()(CvBGStatModel* obj) const
 +    {
 +        cvReleaseBGStatModel(&obj);
 +    }
 +}
 +
 +#endif
 +
 +DEF_PARAM_TEST_1(Video, string);
 +
 +PERF_TEST_P(Video, FGDStatModel,
 +            Values(string("gpu/video/768x576.avi")))
 +{
++    const int numIters = 10;
++
 +    declare.time(60);
 +
 +    const string inputFile = perf::TestBase::getDataPath(GetParam());
 +
 +    cv::VideoCapture cap(inputFile);
 +    ASSERT_TRUE(cap.isOpened());
 +
 +    cv::Mat frame;
 +    cap >> frame;
 +    ASSERT_FALSE(frame.empty());
 +
 +    if (PERF_RUN_CUDA())
 +    {
 +        cv::cuda::GpuMat d_frame(frame), foreground;
 +
 +        cv::Ptr<cv::cuda::BackgroundSubtractorFGD> d_fgd = cv::cuda::createBackgroundSubtractorFGD();
 +        d_fgd->apply(d_frame, foreground);
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            d_frame.upload(frame);
 +
-         for (int i = 0; i < 10; ++i)
++            startTimer();
++            if(!next())
++                break;
++
 +            d_fgd->apply(d_frame, foreground);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            ASSERT_FALSE(frame.empty());
++
++            d_frame.upload(frame);
++
++            d_fgd->apply(d_frame, foreground);
++        }
++
 +        CUDA_SANITY_CHECK(foreground, 1e-2, ERROR_RELATIVE);
 +
 +#ifdef HAVE_OPENCV_CUDAIMGPROC
 +        cv::cuda::GpuMat background3, background;
 +        d_fgd->getBackgroundImage(background3);
 +        cv::cuda::cvtColor(background3, background, cv::COLOR_BGR2BGRA);
 +        CUDA_SANITY_CHECK(background, 1e-2, ERROR_RELATIVE);
 +#endif
 +    }
 +    else
 +    {
 +#ifdef HAVE_OPENCV_LEGACY
 +        IplImage ipl_frame = frame;
 +        cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            ipl_frame = frame;
 +
-         for (int i = 0; i < 10; ++i)
++            startTimer();
++            if(!next())
++                break;
++
 +            cvUpdateBGStatModel(&ipl_frame, model);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            ASSERT_FALSE(frame.empty());
++
++            ipl_frame = frame;
++
++            cvUpdateBGStatModel(&ipl_frame, model);
++        }
++
 +        const cv::Mat background = cv::cvarrToMat(model->background);
 +        const cv::Mat foreground = cv::cvarrToMat(model->foreground);
 +
 +        CPU_SANITY_CHECK(background);
 +        CPU_SANITY_CHECK(foreground);
 +#else
 +        FAIL_NO_CPU();
 +#endif
 +    }
 +}
 +
 +#endif
 +
 +//////////////////////////////////////////////////////
 +// MOG
 +
 +#if BUILD_WITH_VIDEO_INPUT_SUPPORT
 +
 +DEF_PARAM_TEST(Video_Cn_LearningRate, string, MatCn, double);
 +
 +PERF_TEST_P(Video_Cn_LearningRate, MOG,
 +            Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"),
 +                    CUDA_CHANNELS_1_3_4,
 +                    Values(0.0, 0.01)))
 +{
++    const int numIters = 10;
++
 +    const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
 +    const int cn = GET_PARAM(1);
 +    const float learningRate = static_cast<float>(GET_PARAM(2));
 +
 +    cv::VideoCapture cap(inputFile);
 +    ASSERT_TRUE(cap.isOpened());
 +
 +    cv::Mat frame;
 +
 +    cap >> frame;
 +    ASSERT_FALSE(frame.empty());
 +
 +    if (cn != 3)
 +    {
 +        cv::Mat temp;
 +        if (cn == 1)
 +            cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +        else
 +            cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +        cv::swap(temp, frame);
 +    }
 +
 +    if (PERF_RUN_CUDA())
 +    {
 +        cv::Ptr<cv::BackgroundSubtractor> d_mog = cv::cuda::createBackgroundSubtractorMOG();
 +
 +        cv::cuda::GpuMat d_frame(frame);
 +        cv::cuda::GpuMat foreground;
 +
 +        d_mog->apply(d_frame, foreground, learningRate);
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
 +            d_frame.upload(frame);
 +
-         for (int i = 0; i < 10; ++i)
++            startTimer();
++            if(!next())
++                break;
++
 +            d_mog->apply(d_frame, foreground, learningRate);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            ASSERT_FALSE(frame.empty());
++
++            if (cn != 3)
++            {
++                cv::Mat temp;
++                if (cn == 1)
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
++                else
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
++                cv::swap(temp, frame);
++            }
++
++            d_frame.upload(frame);
++
++            d_mog->apply(d_frame, foreground, learningRate);
++        }
++
 +        CUDA_SANITY_CHECK(foreground);
 +    }
 +    else
 +    {
 +        cv::Ptr<cv::BackgroundSubtractor> mog = cv::createBackgroundSubtractorMOG();
 +        cv::Mat foreground;
 +
 +        mog->apply(frame, foreground, learningRate);
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
- PERF_TEST_P(Video_Cn, MOG2,
++            startTimer();
++            if(!next())
++                break;
++
 +            mog->apply(frame, foreground, learningRate);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            ASSERT_FALSE(frame.empty());
++
++            if (cn != 3)
++            {
++                cv::Mat temp;
++                if (cn == 1)
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
++                else
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
++                cv::swap(temp, frame);
++            }
++
++            mog->apply(frame, foreground, learningRate);
++        }
++
 +        CPU_SANITY_CHECK(foreground);
 +    }
 +}
 +
 +#endif
 +
 +//////////////////////////////////////////////////////
 +// MOG2
 +
 +#if BUILD_WITH_VIDEO_INPUT_SUPPORT
 +
 +DEF_PARAM_TEST(Video_Cn, string, int);
 +
-         for (int i = 0; i < 10; ++i)
++PERF_TEST_P(Video_Cn, DISABLED_MOG2,
 +            Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"),
 +                    CUDA_CHANNELS_1_3_4))
 +{
++    const int numIters = 10;
++
 +    const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
 +    const int cn = GET_PARAM(1);
 +
 +    cv::VideoCapture cap(inputFile);
 +    ASSERT_TRUE(cap.isOpened());
 +
 +    cv::Mat frame;
 +
 +    cap >> frame;
 +    ASSERT_FALSE(frame.empty());
 +
 +    if (cn != 3)
 +    {
 +        cv::Mat temp;
 +        if (cn == 1)
 +            cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +        else
 +            cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +        cv::swap(temp, frame);
 +    }
 +
 +    if (PERF_RUN_CUDA())
 +    {
 +        cv::Ptr<cv::BackgroundSubtractorMOG2> d_mog2 = cv::cuda::createBackgroundSubtractorMOG2();
 +        d_mog2->setDetectShadows(false);
 +
 +        cv::cuda::GpuMat d_frame(frame);
 +        cv::cuda::GpuMat foreground;
 +
 +        d_mog2->apply(d_frame, foreground);
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
 +            d_frame.upload(frame);
 +
-         for (int i = 0; i < 10; ++i)
++            startTimer();
++            if(!next())
++                break;
++
 +            d_mog2->apply(d_frame, foreground);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            ASSERT_FALSE(frame.empty());
++
++            if (cn != 3)
++            {
++                cv::Mat temp;
++                if (cn == 1)
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
++                else
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
++                cv::swap(temp, frame);
++            }
++
++            d_frame.upload(frame);
++
++            d_mog2->apply(d_frame, foreground);
++        }
++
 +        CUDA_SANITY_CHECK(foreground);
 +    }
 +    else
 +    {
 +        cv::Ptr<cv::BackgroundSubtractorMOG2> mog2 = cv::createBackgroundSubtractorMOG2();
 +        mog2->setDetectShadows(false);
 +
 +        cv::Mat foreground;
 +
 +        mog2->apply(frame, foreground);
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
-         for (int i = 0; i < 150; ++i)
++            startTimer();
++            if(!next())
++                break;
++
 +            mog2->apply(frame, foreground);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            ASSERT_FALSE(frame.empty());
++
++            if (cn != 3)
++            {
++                cv::Mat temp;
++                if (cn == 1)
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
++                else
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
++                cv::swap(temp, frame);
++            }
++
++            mog2->apply(frame, foreground);
++        }
++
 +        CPU_SANITY_CHECK(foreground);
 +    }
 +}
 +
 +#endif
 +
 +//////////////////////////////////////////////////////
 +// MOG2GetBackgroundImage
 +
 +#if BUILD_WITH_VIDEO_INPUT_SUPPORT
 +
 +PERF_TEST_P(Video_Cn, MOG2GetBackgroundImage,
 +            Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"),
 +                    CUDA_CHANNELS_1_3_4))
 +{
 +    const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
 +    const int cn = GET_PARAM(1);
 +
 +    cv::VideoCapture cap(inputFile);
 +    ASSERT_TRUE(cap.isOpened());
 +
 +    cv::Mat frame;
 +
 +    if (PERF_RUN_CUDA())
 +    {
 +        cv::Ptr<cv::BackgroundSubtractor> d_mog2 = cv::cuda::createBackgroundSubtractorMOG2();
 +
 +        cv::cuda::GpuMat d_frame;
 +        cv::cuda::GpuMat d_foreground;
 +
 +        for (int i = 0; i < 10; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
 +            d_frame.upload(frame);
 +
 +            d_mog2->apply(d_frame, d_foreground);
 +        }
 +
 +        cv::cuda::GpuMat background;
 +
 +        TEST_CYCLE() d_mog2->getBackgroundImage(background);
 +
 +        CUDA_SANITY_CHECK(background, 1);
 +    }
 +    else
 +    {
 +        cv::Ptr<cv::BackgroundSubtractor> mog2 = cv::createBackgroundSubtractorMOG2();
 +        cv::Mat foreground;
 +
 +        for (int i = 0; i < 10; ++i)
 +        {
 +            cap >> frame;
 +            ASSERT_FALSE(frame.empty());
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
 +            mog2->apply(frame, foreground);
 +        }
 +
 +        cv::Mat background;
 +
 +        TEST_CYCLE() mog2->getBackgroundImage(background);
 +
 +        CPU_SANITY_CHECK(background);
 +    }
 +}
 +
 +#endif
 +
 +//////////////////////////////////////////////////////
 +// GMG
 +
 +#if BUILD_WITH_VIDEO_INPUT_SUPPORT
 +
 +DEF_PARAM_TEST(Video_Cn_MaxFeatures, string, MatCn, int);
 +
 +PERF_TEST_P(Video_Cn_MaxFeatures, GMG,
 +            Combine(Values(string("gpu/video/768x576.avi")),
 +                    CUDA_CHANNELS_1_3_4,
 +                    Values(20, 40, 60)))
 +{
++    const int numIters = 150;
++
 +    const std::string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
 +    const int cn = GET_PARAM(1);
 +    const int maxFeatures = GET_PARAM(2);
 +
 +    cv::VideoCapture cap(inputFile);
 +    ASSERT_TRUE(cap.isOpened());
 +
 +    cv::Mat frame;
 +    cap >> frame;
 +    ASSERT_FALSE(frame.empty());
 +
 +    if (cn != 3)
 +    {
 +        cv::Mat temp;
 +        if (cn == 1)
 +            cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +        else
 +            cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +        cv::swap(temp, frame);
 +    }
 +
 +    if (PERF_RUN_CUDA())
 +    {
 +        cv::cuda::GpuMat d_frame(frame);
 +        cv::cuda::GpuMat foreground;
 +
 +        cv::Ptr<cv::BackgroundSubtractorGMG> d_gmg = cv::cuda::createBackgroundSubtractorGMG();
 +        d_gmg->setMaxFeatures(maxFeatures);
 +
 +        d_gmg->apply(d_frame, foreground);
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            if (frame.empty())
 +            {
 +                cap.release();
 +                cap.open(inputFile);
 +                cap >> frame;
 +            }
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
 +            d_frame.upload(frame);
 +
-         for (int i = 0; i < 150; ++i)
++            startTimer();
++            if(!next())
++                break;
++
 +            d_gmg->apply(d_frame, foreground);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            if (frame.empty())
++            {
++                cap.release();
++                cap.open(inputFile);
++                cap >> frame;
++            }
++
++            if (cn != 3)
++            {
++                cv::Mat temp;
++                if (cn == 1)
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
++                else
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
++                cv::swap(temp, frame);
++            }
++
++            d_frame.upload(frame);
++
++            d_gmg->apply(d_frame, foreground);
++        }
++
 +        CUDA_SANITY_CHECK(foreground);
 +    }
 +    else
 +    {
 +        cv::Mat foreground;
 +        cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0));
 +
 +        cv::Ptr<cv::BackgroundSubtractorGMG> gmg = cv::createBackgroundSubtractorGMG();
 +        gmg->setMaxFeatures(maxFeatures);
 +
 +        gmg->apply(frame, foreground);
 +
-             startTimer(); next();
++        int i = 0;
++
++        // collect performance data
++        for (; i < numIters; ++i)
 +        {
 +            cap >> frame;
 +            if (frame.empty())
 +            {
 +                cap.release();
 +                cap.open(inputFile);
 +                cap >> frame;
 +            }
 +
 +            if (cn != 3)
 +            {
 +                cv::Mat temp;
 +                if (cn == 1)
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
 +                else
 +                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
 +                cv::swap(temp, frame);
 +            }
 +
++            startTimer();
++            if(!next())
++                break;
++
 +            gmg->apply(frame, foreground);
++
 +            stopTimer();
 +        }
 +
++        // process last frame in sequence to get data for sanity test
++        for (; i < numIters; ++i)
++        {
++            cap >> frame;
++            if (frame.empty())
++            {
++                cap.release();
++                cap.open(inputFile);
++                cap >> frame;
++            }
++
++            if (cn != 3)
++            {
++                cv::Mat temp;
++                if (cn == 1)
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
++                else
++                    cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
++                cv::swap(temp, frame);
++            }
++
++            gmg->apply(frame, foreground);
++        }
++
 +        CPU_SANITY_CHECK(foreground);
 +    }
 +}
 +
 +#endif
index 1dd4c92,0000000..30d95ba
mode 100644,000000..100644
--- /dev/null
@@@ -1,29 -1,0 +1,29 @@@
- if(ANDROID OR IOS OR APPLE)
++if(IOS OR APPLE)
 +  ocv_module_disable(cudacodec)
 +endif()
 +
 +set(the_description "CUDA-accelerated Video Encoding/Decoding")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef)
 +
 +ocv_add_module(cudacodec opencv_highgui OPTIONAL opencv_cudev)
 +
 +ocv_module_include_directories()
 +ocv_glob_module_sources()
 +
 +set(extra_libs "")
 +
 +if(HAVE_NVCUVID)
 +  list(APPEND extra_libs ${CUDA_CUDA_LIBRARY} ${CUDA_nvcuvid_LIBRARY})
 +
 +  if(WIN32)
 +    list(APPEND extra_libs ${CUDA_nvcuvenc_LIBRARY})
 +  endif()
 +endif()
 +
 +ocv_create_module(${extra_libs})
 +
 +ocv_add_precompiled_headers(${the_module})
 +
 +ocv_add_accuracy_tests()
 +ocv_add_perf_tests()
index 9bca959,0000000..69eba34
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudafeatures2d)
 +endif()
 +
 +set(the_description "CUDA-accelerated Feature Detection and Description")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter)
 +
 +ocv_define_module(cudafeatures2d opencv_features2d opencv_cudafilters opencv_cudawarping)
index 35b9432,0000000..8589881
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudafilters)
 +endif()
 +
 +set(the_description "CUDA-accelerated Image Filtering")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
 +
 +ocv_define_module(cudafilters opencv_imgproc opencv_cudaarithm)
index bfb8f35,0000000..9617029
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudaimgproc)
 +endif()
 +
 +set(the_description "CUDA-accelerated Image Processing")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter)
 +
 +ocv_define_module(cudaimgproc opencv_imgproc OPTIONAL opencv_cudaarithm opencv_cudafilters)
index c72fde0,0000000..27dbc6a
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudaoptflow)
 +endif()
 +
 +set(the_description "CUDA-accelerated Optical Flow")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
 +
 +ocv_define_module(cudaoptflow opencv_video opencv_legacy opencv_cudaarithm opencv_cudawarping opencv_cudaimgproc OPTIONAL opencv_cudalegacy)
index bf485ea,0000000..6f63add
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudastereo)
 +endif()
 +
 +set(the_description "CUDA-accelerated Stereo Correspondence")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
 +
 +ocv_define_module(cudastereo opencv_calib3d)
index 6aedc28,0000000..a6b38f9
mode 100644,000000..100644
--- /dev/null
@@@ -1,9 -1,0 +1,9 @@@
- if(ANDROID OR IOS)
++if(IOS)
 +  ocv_module_disable(cudawarping)
 +endif()
 +
 +set(the_description "CUDA-accelerated Image Warping")
 +
 +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
 +
 +ocv_define_module(cudawarping opencv_imgproc OPTIONAL opencv_cudalegacy)
@@@ -248,9 -249,11 +248,9 @@@ VideoCapture constructors
  .. ocv:pyfunction:: cv2.VideoCapture(device) -> <VideoCapture object>
  
  .. ocv:cfunction:: CvCapture* cvCaptureFromCAM( int device )
 -.. ocv:pyoldfunction:: cv.CaptureFromCAM(index) -> CvCapture
  .. ocv:cfunction:: CvCapture* cvCaptureFromFile( const char* filename )
 -.. ocv:pyoldfunction:: cv.CaptureFromFile(filename) -> CvCapture
  
-     :param filename: name of the opened video file (eg. video.avi) or image sequence (eg. img%02d.jpg)
+     :param filename: name of the opened video file (eg. video.avi) or image sequence (eg. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
  
      :param device: id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0.
  
@@@ -44,6 -44,8 +44,8 @@@
  #ifndef __OPENCV_OCL_MATRIX_OPERATIONS_HPP__
  #define __OPENCV_OCL_MATRIX_OPERATIONS_HPP__
  
 -#include "opencv2/ocl/ocl.hpp"
++#include "opencv2/ocl.hpp"
  namespace cv
  {
  
@@@ -532,22 -531,32 +531,32 @@@ Context* Context::getContext(
  {
      if (currentContext == NULL)
      {
-         if (!__initialized || !__deviceSelected)
+         static bool defaultInitiaization = false;
+         if (!defaultInitiaization)
          {
              cv::AutoLock lock(getInitializationMutex());
-             if (!__initialized)
+             try
              {
-                 if (initializeOpenCLDevices() == 0)
+                 if (!__initialized)
                  {
-                     CV_Error(Error::OpenCLInitError, "OpenCL not available");
+                     if (initializeOpenCLDevices() == 0)
+                     {
 -                        CV_Error(CV_OpenCLInitError, "OpenCL not available");
++                        CV_Error(Error::OpenCLInitError, "OpenCL not available");
+                     }
                  }
-             }
-             if (!__deviceSelected)
-             {
-                 if (!selectOpenCLDevice())
+                 if (!__deviceSelected)
                  {
-                     CV_Error(Error::OpenCLInitError, "Can't select OpenCL device");
+                     if (!selectOpenCLDevice())
+                     {
 -                        CV_Error(CV_OpenCLInitError, "Can't select OpenCL device");
++                        CV_Error(Error::OpenCLInitError, "Can't select OpenCL device");
+                     }
                  }
+                 defaultInitiaization = true;
+             }
+             catch (...)
+             {
+                 defaultInitiaization = true;
+                 throw;
              }
          }
          CV_Assert(currentContext != NULL);
Simple merge
Simple merge
Simple merge
  #include "opencv2/highgui/highgui.hpp"
  #include "opencv2/imgproc/imgproc.hpp"
  #include <iostream>
- #include <stdio.h>
  
 +using namespace std;
  using namespace cv;
  
- /**
-  * @function main
-  */
- int main(int, char** argv)
+ namespace
+ {
+     // windows and trackbars name
+     const std::string windowName = "Hough Circle Detection Demo";
+     const std::string cannyThresholdTrackbarName = "Canny threshold";
+     const std::string accumulatorThresholdTrackbarName = "Accumulator Threshold";
+     const std::string usage = "Usage : tutorial_HoughCircle_Demo <path_to_input_image>\n";
+     // initial and max values of the parameters of interests.
+     const int cannyThresholdInitialValue = 200;
+     const int accumulatorThresholdInitialValue = 50;
+     const int maxAccumulatorThreshold = 200;
+     const int maxCannyThreshold = 255;
+     void HoughDetection(const Mat& src_gray, const Mat& src_display, int cannyThreshold, int accumulatorThreshold)
+     {
+         // will hold the results of the detection
+         std::vector<Vec3f> circles;
+         // runs the actual detection
 -        HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, cannyThreshold, accumulatorThreshold, 0, 0 );
++        HoughCircles( src_gray, circles, HOUGH_GRADIENT, 1, src_gray.rows/8, cannyThreshold, accumulatorThreshold, 0, 0 );
+         // clone the colour, input image for displaying purposes
+         Mat display = src_display.clone();
+         for( size_t i = 0; i < circles.size(); i++ )
+         {
+             Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
+             int radius = cvRound(circles[i][2]);
+             // circle center
+             circle( display, center, 3, Scalar(0,255,0), -1, 8, 0 );
+             // circle outline
+             circle( display, center, radius, Scalar(0,0,255), 3, 8, 0 );
+         }
+         // shows the results
+         imshow( windowName, display);
+     }
+ }
+ int main(int argc, char** argv)
  {
-    Mat src, src_gray;
+     Mat src, src_gray;
+     if (argc < 2)
+     {
+         std::cerr<<"No input image specified\n";
+         std::cout<<usage;
+         return -1;
+     }
  
-    /// Read the image
-    src = imread( argv[1], 1 );
+     // Read the image
+     src = imread( argv[1], 1 );
  
-    if( !src.data )
-      { return -1; }
+     if( !src.data )
+     {
+         std::cerr<<"Invalid input image\n";
+         std::cout<<usage;
+         return -1;
+     }
  
-    /// Convert it to gray
+     // Convert it to gray
      cvtColor( src, src_gray, COLOR_BGR2GRAY );
  
-    /// Reduce the noise so we avoid false circle detection
+     // Reduce the noise so we avoid false circle detection
      GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
  
-     vector<Vec3f> circles;
+     //declare and initialize both parameters that are subjects to change
+     int cannyThreshold = cannyThresholdInitialValue;
+     int accumulatorThreshold = accumulatorThresholdInitialValue;
  
-    /// Apply the Hough Transform to find the circles
-     HoughCircles( src_gray, circles, HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );
+     // create the main window, and attach the trackbars
+     namedWindow( windowName, WINDOW_AUTOSIZE );
+     createTrackbar(cannyThresholdTrackbarName, windowName, &cannyThreshold,maxCannyThreshold);
+     createTrackbar(accumulatorThresholdTrackbarName, windowName, &accumulatorThreshold, maxAccumulatorThreshold);
  
-    /// Draw the circles detected
-     for( size_t i = 0; i < circles.size(); i++ )
+     // infinite loop to display
+     // and refresh the content of the output image
+     // until the user presses q or Q
+     int key = 0;
+     while(key != 'q' && key != 'Q')
      {
-          Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
-          int radius = cvRound(circles[i][2]);
-          // circle center
-          circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
-          // circle outline
-          circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
-     }
+         // those paramaters cannot be =0
+         // so we must check here
+         cannyThreshold = std::max(cannyThreshold, 1);
+         accumulatorThreshold = std::max(accumulatorThreshold, 1);
  
-    /// Show your results
-     namedWindow( "Hough Circle Transform Demo", WINDOW_AUTOSIZE );
-     imshow( "Hough Circle Transform Demo", src );
+         //runs the detection, and update the display
+         HoughDetection(src_gray, src, cannyThreshold, accumulatorThreshold);
+         // get user key
+         key = waitKey(10);
+     }
  
-     waitKey(0);
      return 0;
  }