From ac0f506d0e313a3aeaada67656eb195a0da3fb69 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 17 Apr 2013 18:35:09 +0400 Subject: [PATCH] split gpuvideo onto gpuoptflow and gpubgsegm --- modules/gpu/CMakeLists.txt | 2 +- modules/gpu/include/opencv2/gpu.hpp | 3 +- modules/gpubgsegm/CMakeLists.txt | 9 + .../doc/background_segmentation.rst} | 0 modules/gpubgsegm/doc/gpubgsegm.rst | 8 + .../include/opencv2/gpubgsegm.hpp} | 266 +-------- modules/gpubgsegm/perf/perf_bgfg.cpp | 536 ++++++++++++++++++ .../perf/perf_main.cpp | 0 .../perf/perf_precomp.cpp | 0 .../perf/perf_precomp.hpp | 3 +- .../{gpuvideo => gpubgsegm}/src/bgfg_gmg.cpp | 0 .../{gpuvideo => gpubgsegm}/src/bgfg_mog.cpp | 0 .../src/cuda/bgfg_gmg.cu | 0 .../src/cuda/bgfg_mog.cu | 0 .../src/cuda/fgd_bgfg.cu | 0 .../src/cuda/fgd_bgfg_common.hpp | 0 .../{gpuvideo => gpubgsegm}/src/fgd_bgfg.cpp | 0 .../{gpuvideo => gpubgsegm}/src/precomp.cpp | 0 .../{gpuvideo => gpubgsegm}/src/precomp.hpp | 3 +- .../test/test_bgfg.cpp | 0 .../test/test_main.cpp | 0 .../test/test_precomp.cpp | 0 modules/gpubgsegm/test/test_precomp.hpp | 64 +++ modules/gpuimgproc/doc/image_processing.rst | 31 + modules/gpuimgproc/perf/perf_imgproc.cpp | 39 ++ modules/gpuoptflow/CMakeLists.txt | 9 + modules/gpuoptflow/doc/gpuoptflow.rst | 8 + modules/gpuoptflow/doc/optflow.rst | 238 ++++++++ .../gpuoptflow/include/opencv2/gpuoptflow.hpp | 310 ++++++++++ modules/gpuoptflow/perf/perf_main.cpp | 47 ++ .../perf/perf_optflow.cpp} | 528 ----------------- modules/gpuoptflow/perf/perf_precomp.cpp | 43 ++ modules/gpuoptflow/perf/perf_precomp.hpp | 66 +++ .../src/cuda/optflowbm.cu | 0 .../src/cuda/optical_flow.cu | 0 .../src/cuda/optical_flow_farneback.cu | 0 .../src/cuda/pyrlk.cu | 0 .../src/cuda/tvl1flow.cu | 0 .../src/optflowbm.cpp | 0 .../src/optical_flow.cpp | 0 .../src/optical_flow_farneback.cpp | 0 modules/gpuoptflow/src/precomp.cpp | 43 ++ modules/gpuoptflow/src/precomp.hpp | 62 ++ .../{gpuvideo => gpuoptflow}/src/pyrlk.cpp | 0 .../{gpuvideo => gpuoptflow}/src/tvl1flow.cpp | 0 modules/gpuoptflow/test/test_main.cpp | 45 ++ .../test/test_optflow.cpp | 82 --- modules/gpuoptflow/test/test_precomp.cpp | 43 ++ .../test/test_precomp.hpp | 3 +- modules/gpuvideo/CMakeLists.txt | 9 - modules/gpuvideo/doc/gpuvideo.rst | 8 - samples/cpp/CMakeLists.txt | 3 +- samples/gpu/CMakeLists.txt | 2 +- 53 files changed, 1613 insertions(+), 900 deletions(-) create mode 100644 modules/gpubgsegm/CMakeLists.txt rename modules/{gpuvideo/doc/video.rst => gpubgsegm/doc/background_segmentation.rst} (100%) create mode 100644 modules/gpubgsegm/doc/gpubgsegm.rst rename modules/{gpuvideo/include/opencv2/gpuvideo.hpp => gpubgsegm/include/opencv2/gpubgsegm.hpp} (60%) create mode 100644 modules/gpubgsegm/perf/perf_bgfg.cpp rename modules/{gpuvideo => gpubgsegm}/perf/perf_main.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/perf/perf_precomp.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/perf/perf_precomp.hpp (97%) rename modules/{gpuvideo => gpubgsegm}/src/bgfg_gmg.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/src/bgfg_mog.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/src/cuda/bgfg_gmg.cu (100%) rename modules/{gpuvideo => gpubgsegm}/src/cuda/bgfg_mog.cu (100%) rename modules/{gpuvideo => gpubgsegm}/src/cuda/fgd_bgfg.cu (100%) rename modules/{gpuvideo => gpubgsegm}/src/cuda/fgd_bgfg_common.hpp (100%) rename modules/{gpuvideo => gpubgsegm}/src/fgd_bgfg.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/src/precomp.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/src/precomp.hpp (97%) rename modules/{gpuvideo => gpubgsegm}/test/test_bgfg.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/test/test_main.cpp (100%) rename modules/{gpuvideo => gpubgsegm}/test/test_precomp.cpp (100%) create mode 100644 modules/gpubgsegm/test/test_precomp.hpp create mode 100644 modules/gpuoptflow/CMakeLists.txt create mode 100644 modules/gpuoptflow/doc/gpuoptflow.rst create mode 100644 modules/gpuoptflow/doc/optflow.rst create mode 100644 modules/gpuoptflow/include/opencv2/gpuoptflow.hpp create mode 100644 modules/gpuoptflow/perf/perf_main.cpp rename modules/{gpuvideo/perf/perf_video.cpp => gpuoptflow/perf/perf_optflow.cpp} (53%) create mode 100644 modules/gpuoptflow/perf/perf_precomp.cpp create mode 100644 modules/gpuoptflow/perf/perf_precomp.hpp rename modules/{gpuvideo => gpuoptflow}/src/cuda/optflowbm.cu (100%) rename modules/{gpuvideo => gpuoptflow}/src/cuda/optical_flow.cu (100%) rename modules/{gpuvideo => gpuoptflow}/src/cuda/optical_flow_farneback.cu (100%) rename modules/{gpuvideo => gpuoptflow}/src/cuda/pyrlk.cu (100%) rename modules/{gpuvideo => gpuoptflow}/src/cuda/tvl1flow.cu (100%) rename modules/{gpuvideo => gpuoptflow}/src/optflowbm.cpp (100%) rename modules/{gpuvideo => gpuoptflow}/src/optical_flow.cpp (100%) rename modules/{gpuvideo => gpuoptflow}/src/optical_flow_farneback.cpp (100%) create mode 100644 modules/gpuoptflow/src/precomp.cpp create mode 100644 modules/gpuoptflow/src/precomp.hpp rename modules/{gpuvideo => gpuoptflow}/src/pyrlk.cpp (100%) rename modules/{gpuvideo => gpuoptflow}/src/tvl1flow.cpp (100%) create mode 100644 modules/gpuoptflow/test/test_main.cpp rename modules/{gpuvideo => gpuoptflow}/test/test_optflow.cpp (89%) create mode 100644 modules/gpuoptflow/test/test_precomp.cpp rename modules/{gpuvideo => gpuoptflow}/test/test_precomp.hpp (98%) delete mode 100644 modules/gpuvideo/CMakeLists.txt delete mode 100644 modules/gpuvideo/doc/gpuvideo.rst diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 662a652b9..1d108b00e 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -7,7 +7,7 @@ set(the_description "GPU-accelerated Computer Vision") ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter) ocv_define_module(gpu opencv_gpuarithm opencv_gpufilters opencv_gpuwarping opencv_gpuimgproc - opencv_gpufeatures2d opencv_gpuvideo opencv_gpustereo) + opencv_gpufeatures2d opencv_gpuoptflow opencv_gpubgsegm opencv_gpustereo) if(HAVE_CUDA) add_subdirectory(perf4au) diff --git a/modules/gpu/include/opencv2/gpu.hpp b/modules/gpu/include/opencv2/gpu.hpp index db6157ab7..166a360a1 100644 --- a/modules/gpu/include/opencv2/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu.hpp @@ -49,7 +49,8 @@ #include "opencv2/gpuwarping.hpp" #include "opencv2/gpuimgproc.hpp" #include "opencv2/gpufeatures2d.hpp" -#include "opencv2/gpuvideo.hpp" +#include "opencv2/gpuoptflow.hpp" +#include "opencv2/gpubgsegm.hpp" #include "opencv2/gpustereo.hpp" namespace cv { namespace gpu { diff --git a/modules/gpubgsegm/CMakeLists.txt b/modules/gpubgsegm/CMakeLists.txt new file mode 100644 index 000000000..4e3266b7e --- /dev/null +++ b/modules/gpubgsegm/CMakeLists.txt @@ -0,0 +1,9 @@ +if(ANDROID OR IOS) + ocv_module_disable(gpubgsegm) +endif() + +set(the_description "GPU-accelerated Background Segmentation") + +ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wmissing-declarations) + +ocv_define_module(gpubgsegm opencv_video opencv_legacy opencv_gpufilters opencv_gpuimgproc) diff --git a/modules/gpuvideo/doc/video.rst b/modules/gpubgsegm/doc/background_segmentation.rst similarity index 100% rename from modules/gpuvideo/doc/video.rst rename to modules/gpubgsegm/doc/background_segmentation.rst diff --git a/modules/gpubgsegm/doc/gpubgsegm.rst b/modules/gpubgsegm/doc/gpubgsegm.rst new file mode 100644 index 000000000..f4988cb21 --- /dev/null +++ b/modules/gpubgsegm/doc/gpubgsegm.rst @@ -0,0 +1,8 @@ +******************************************** +gpu. GPU-accelerated Background Segmentation +******************************************** + +.. toctree:: + :maxdepth: 1 + + background_segmentation diff --git a/modules/gpuvideo/include/opencv2/gpuvideo.hpp b/modules/gpubgsegm/include/opencv2/gpubgsegm.hpp similarity index 60% rename from modules/gpuvideo/include/opencv2/gpuvideo.hpp rename to modules/gpubgsegm/include/opencv2/gpubgsegm.hpp index de3cf7fa7..62d4d9a4c 100644 --- a/modules/gpuvideo/include/opencv2/gpuvideo.hpp +++ b/modules/gpubgsegm/include/opencv2/gpubgsegm.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_GPUVIDEO_HPP__ -#define __OPENCV_GPUVIDEO_HPP__ +#ifndef __OPENCV_GPUBGSEGM_HPP__ +#define __OPENCV_GPUBGSEGM_HPP__ #include @@ -50,266 +50,6 @@ namespace cv { namespace gpu { -////////////////////////////////// Optical Flow ////////////////////////////////////////// - -class CV_EXPORTS BroxOpticalFlow -{ -public: - BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_) : - alpha(alpha_), gamma(gamma_), scale_factor(scale_factor_), - inner_iterations(inner_iterations_), outer_iterations(outer_iterations_), solver_iterations(solver_iterations_) - { - } - - //! Compute optical flow - //! frame0 - source frame (supports only CV_32FC1 type) - //! frame1 - frame to track (with the same size and type as frame0) - //! u - flow horizontal component (along x axis) - //! v - flow vertical component (along y axis) - void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null()); - - //! flow smoothness - float alpha; - - //! gradient constancy importance - float gamma; - - //! pyramid scale factor - float scale_factor; - - //! number of lagged non-linearity iterations (inner loop) - int inner_iterations; - - //! number of warping iterations (number of pyramid levels) - int outer_iterations; - - //! number of linear system solver iterations - int solver_iterations; - - GpuMat buf; -}; - -class CV_EXPORTS PyrLKOpticalFlow -{ -public: - PyrLKOpticalFlow(); - - void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, - GpuMat& status, GpuMat* err = 0); - - void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0); - - void releaseMemory(); - - Size winSize; - int maxLevel; - int iters; - bool useInitialFlow; - -private: - std::vector prevPyr_; - std::vector nextPyr_; - - GpuMat buf_; - - GpuMat uPyr_[2]; - GpuMat vPyr_[2]; -}; - -class CV_EXPORTS FarnebackOpticalFlow -{ -public: - FarnebackOpticalFlow() - { - numLevels = 5; - pyrScale = 0.5; - fastPyramids = false; - winSize = 13; - numIters = 10; - polyN = 5; - polySigma = 1.1; - flags = 0; - } - - int numLevels; - double pyrScale; - bool fastPyramids; - int winSize; - int numIters; - int polyN; - double polySigma; - int flags; - - void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null()); - - void releaseMemory() - { - frames_[0].release(); - frames_[1].release(); - pyrLevel_[0].release(); - pyrLevel_[1].release(); - M_.release(); - bufM_.release(); - R_[0].release(); - R_[1].release(); - blurredFrame_[0].release(); - blurredFrame_[1].release(); - pyramid0_.clear(); - pyramid1_.clear(); - } - -private: - void prepareGaussian( - int n, double sigma, float *g, float *xg, float *xxg, - double &ig11, double &ig03, double &ig33, double &ig55); - - void setPolynomialExpansionConsts(int n, double sigma); - - void updateFlow_boxFilter( - const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat &flowy, - GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]); - - void updateFlow_gaussianBlur( - const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat& flowy, - GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]); - - GpuMat frames_[2]; - GpuMat pyrLevel_[2], M_, bufM_, R_[2], blurredFrame_[2]; - std::vector pyramid0_, pyramid1_; -}; - -// Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method -// -// see reference: -// [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". -// [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". -class CV_EXPORTS OpticalFlowDual_TVL1_GPU -{ -public: - OpticalFlowDual_TVL1_GPU(); - - void operator ()(const GpuMat& I0, const GpuMat& I1, GpuMat& flowx, GpuMat& flowy); - - void collectGarbage(); - - /** - * Time step of the numerical scheme. - */ - double tau; - - /** - * Weight parameter for the data term, attachment parameter. - * This is the most relevant parameter, which determines the smoothness of the output. - * The smaller this parameter is, the smoother the solutions we obtain. - * It depends on the range of motions of the images, so its value should be adapted to each image sequence. - */ - double lambda; - - /** - * Weight parameter for (u - v)^2, tightness parameter. - * It serves as a link between the attachment and the regularization terms. - * In theory, it should have a small value in order to maintain both parts in correspondence. - * The method is stable for a large range of values of this parameter. - */ - double theta; - - /** - * Number of scales used to create the pyramid of images. - */ - int nscales; - - /** - * Number of warpings per scale. - * Represents the number of times that I1(x+u0) and grad( I1(x+u0) ) are computed per scale. - * This is a parameter that assures the stability of the method. - * It also affects the running time, so it is a compromise between speed and accuracy. - */ - int warps; - - /** - * Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time. - * A small value will yield more accurate solutions at the expense of a slower convergence. - */ - double epsilon; - - /** - * Stopping criterion iterations number used in the numerical scheme. - */ - int iterations; - - double scaleStep; - - bool useInitialFlow; - -private: - void procOneScale(const GpuMat& I0, const GpuMat& I1, GpuMat& u1, GpuMat& u2); - - std::vector I0s; - std::vector I1s; - std::vector u1s; - std::vector u2s; - - GpuMat I1x_buf; - GpuMat I1y_buf; - - GpuMat I1w_buf; - GpuMat I1wx_buf; - GpuMat I1wy_buf; - - GpuMat grad_buf; - GpuMat rho_c_buf; - - GpuMat p11_buf; - GpuMat p12_buf; - GpuMat p21_buf; - GpuMat p22_buf; - - GpuMat diff_buf; - GpuMat norm_buf; -}; - -//! Calculates optical flow for 2 images using block matching algorithm */ -CV_EXPORTS void calcOpticalFlowBM(const GpuMat& prev, const GpuMat& curr, - Size block_size, Size shift_size, Size max_range, bool use_previous, - GpuMat& velx, GpuMat& vely, GpuMat& buf, - Stream& stream = Stream::Null()); - -class CV_EXPORTS FastOpticalFlowBM -{ -public: - void operator ()(const GpuMat& I0, const GpuMat& I1, GpuMat& flowx, GpuMat& flowy, int search_window = 21, int block_window = 7, Stream& s = Stream::Null()); - -private: - GpuMat buffer; - GpuMat extended_I0; - GpuMat extended_I1; -}; - - -//! Interpolate frames (images) using provided optical flow (displacement field). -//! frame0 - frame 0 (32-bit floating point images, single channel) -//! frame1 - frame 1 (the same type and size) -//! fu - forward horizontal displacement -//! fv - forward vertical displacement -//! bu - backward horizontal displacement -//! bv - backward vertical displacement -//! pos - new frame position -//! newFrame - new frame -//! buf - temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat; -//! occlusion masks 0, occlusion masks 1, -//! interpolated forward flow 0, interpolated forward flow 1, -//! interpolated backward flow 0, interpolated backward flow 1 -//! -CV_EXPORTS void interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, - const GpuMat& fu, const GpuMat& fv, - const GpuMat& bu, const GpuMat& bv, - float pos, GpuMat& newFrame, GpuMat& buf, - Stream& stream = Stream::Null()); - -CV_EXPORTS void createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMat& vertex, GpuMat& colors); - -//////////////////////// Background/foreground segmentation //////////////////////// - // Foreground Object Detection from Videos Containing Complex Background. // Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian. // ACM MM2003 9p @@ -583,4 +323,4 @@ private: }} // namespace cv { namespace gpu { -#endif /* __OPENCV_GPUVIDEO_HPP__ */ +#endif /* __OPENCV_GPUBGSEGM_HPP__ */ diff --git a/modules/gpubgsegm/perf/perf_bgfg.cpp b/modules/gpubgsegm/perf/perf_bgfg.cpp new file mode 100644 index 000000000..23db3d899 --- /dev/null +++ b/modules/gpubgsegm/perf/perf_bgfg.cpp @@ -0,0 +1,536 @@ +/*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" + +using namespace std; +using namespace testing; +using namespace perf; + +#if defined(HAVE_XINE) || \ + defined(HAVE_GSTREAMER) || \ + defined(HAVE_QUICKTIME) || \ + 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 + +namespace cv +{ + template<> void Ptr::delete_obj() + { + cvReleaseBGStatModel(&obj); + } +} + +////////////////////////////////////////////////////// +// FGDStatModel + +#if BUILD_WITH_VIDEO_INPUT_SUPPORT + +DEF_PARAM_TEST_1(Video, string); + +PERF_TEST_P(Video, Video_FGDStatModel, + Values(string("gpu/video/768x576.avi"))) +{ + 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_GPU()) + { + cv::gpu::GpuMat d_frame(frame); + + cv::gpu::FGDStatModel d_model(4); + d_model.create(d_frame); + + for (int i = 0; i < 10; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + d_frame.upload(frame); + + startTimer(); next(); + d_model.update(d_frame); + stopTimer(); + } + + const cv::gpu::GpuMat background = d_model.background; + const cv::gpu::GpuMat foreground = d_model.foreground; + + GPU_SANITY_CHECK(background, 1e-2, ERROR_RELATIVE); + GPU_SANITY_CHECK(foreground, 1e-2, ERROR_RELATIVE); + } + else + { + IplImage ipl_frame = frame; + cv::Ptr model(cvCreateFGDStatModel(&ipl_frame)); + + for (int i = 0; i < 10; ++i) + { + cap >> frame; + ASSERT_FALSE(frame.empty()); + + ipl_frame = frame; + + startTimer(); next(); + cvUpdateBGStatModel(&ipl_frame, model); + stopTimer(); + } + + const cv::Mat background = cv::cvarrToMat(model->background); + const cv::Mat foreground = cv::cvarrToMat(model->foreground); + + CPU_SANITY_CHECK(background); + CPU_SANITY_CHECK(foreground); + } +} + +#endif + +////////////////////////////////////////////////////// +// MOG + +#if BUILD_WITH_VIDEO_INPUT_SUPPORT + +DEF_PARAM_TEST(Video_Cn_LearningRate, string, MatCn, double); + +PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, + Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), + GPU_CHANNELS_1_3_4, + Values(0.0, 0.01))) +{ + const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); + const int cn = GET_PARAM(1); + const float learningRate = static_cast(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_GPU()) + { + cv::gpu::GpuMat d_frame(frame); + cv::gpu::MOG_GPU d_mog; + cv::gpu::GpuMat foreground; + + d_mog(d_frame, foreground, learningRate); + + 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); + + startTimer(); next(); + d_mog(d_frame, foreground, learningRate); + stopTimer(); + } + + GPU_SANITY_CHECK(foreground); + } + else + { + cv::Ptr mog = cv::createBackgroundSubtractorMOG(); + cv::Mat foreground; + + mog->apply(frame, foreground, learningRate); + + 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); + } + + startTimer(); next(); + mog->apply(frame, foreground, learningRate); + stopTimer(); + } + + CPU_SANITY_CHECK(foreground); + } +} + +#endif + +////////////////////////////////////////////////////// +// MOG2 + +#if BUILD_WITH_VIDEO_INPUT_SUPPORT + +DEF_PARAM_TEST(Video_Cn, string, int); + +PERF_TEST_P(Video_Cn, Video_MOG2, + Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), + GPU_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; + + 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_GPU()) + { + cv::gpu::MOG2_GPU d_mog2; + d_mog2.bShadowDetection = false; + + cv::gpu::GpuMat d_frame(frame); + cv::gpu::GpuMat foreground; + + d_mog2(d_frame, 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); + + startTimer(); next(); + d_mog2(d_frame, foreground); + stopTimer(); + } + + GPU_SANITY_CHECK(foreground); + } + else + { + cv::Ptr mog2 = cv::createBackgroundSubtractorMOG2(); + mog2->set("detectShadows", false); + + cv::Mat foreground; + + mog2->apply(frame, 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); + } + + startTimer(); next(); + mog2->apply(frame, foreground); + stopTimer(); + } + + CPU_SANITY_CHECK(foreground); + } +} + +#endif + +////////////////////////////////////////////////////// +// MOG2GetBackgroundImage + +#if BUILD_WITH_VIDEO_INPUT_SUPPORT + +PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, + Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), + GPU_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_GPU()) + { + cv::gpu::GpuMat d_frame; + cv::gpu::MOG2_GPU d_mog2; + cv::gpu::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(d_frame, d_foreground); + } + + cv::gpu::GpuMat background; + + TEST_CYCLE() d_mog2.getBackgroundImage(background); + + GPU_SANITY_CHECK(background, 1); + } + else + { + cv::Ptr 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, Video_GMG, + Combine(Values(string("gpu/video/768x576.avi")), + GPU_CHANNELS_1_3_4, + Values(20, 40, 60))) +{ + 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_GPU()) + { + cv::gpu::GpuMat d_frame(frame); + cv::gpu::GpuMat foreground; + + cv::gpu::GMG_GPU d_gmg; + d_gmg.maxFeatures = maxFeatures; + + d_gmg(d_frame, foreground); + + for (int i = 0; i < 150; ++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); + + startTimer(); next(); + d_gmg(d_frame, foreground); + stopTimer(); + } + + GPU_SANITY_CHECK(foreground); + } + else + { + cv::Mat foreground; + cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0)); + + cv::Ptr gmg = cv::createBackgroundSubtractorGMG(); + gmg->set("maxFeatures", maxFeatures); + //gmg.initialize(frame.size(), 0.0, 255.0); + + gmg->apply(frame, foreground); + + for (int i = 0; i < 150; ++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(); next(); + gmg->apply(frame, foreground); + stopTimer(); + } + + CPU_SANITY_CHECK(foreground); + } +} + +#endif diff --git a/modules/gpuvideo/perf/perf_main.cpp b/modules/gpubgsegm/perf/perf_main.cpp similarity index 100% rename from modules/gpuvideo/perf/perf_main.cpp rename to modules/gpubgsegm/perf/perf_main.cpp diff --git a/modules/gpuvideo/perf/perf_precomp.cpp b/modules/gpubgsegm/perf/perf_precomp.cpp similarity index 100% rename from modules/gpuvideo/perf/perf_precomp.cpp rename to modules/gpubgsegm/perf/perf_precomp.cpp diff --git a/modules/gpuvideo/perf/perf_precomp.hpp b/modules/gpubgsegm/perf/perf_precomp.hpp similarity index 97% rename from modules/gpuvideo/perf/perf_precomp.hpp rename to modules/gpubgsegm/perf/perf_precomp.hpp index ecb314900..3343fe30a 100644 --- a/modules/gpuvideo/perf/perf_precomp.hpp +++ b/modules/gpubgsegm/perf/perf_precomp.hpp @@ -54,8 +54,7 @@ #include "opencv2/ts.hpp" #include "opencv2/ts/gpu_perf.hpp" -#include "opencv2/gpuvideo.hpp" -#include "opencv2/gpuimgproc.hpp" +#include "opencv2/gpubgsegm.hpp" #include "opencv2/video.hpp" #include "opencv2/legacy.hpp" diff --git a/modules/gpuvideo/src/bgfg_gmg.cpp b/modules/gpubgsegm/src/bgfg_gmg.cpp similarity index 100% rename from modules/gpuvideo/src/bgfg_gmg.cpp rename to modules/gpubgsegm/src/bgfg_gmg.cpp diff --git a/modules/gpuvideo/src/bgfg_mog.cpp b/modules/gpubgsegm/src/bgfg_mog.cpp similarity index 100% rename from modules/gpuvideo/src/bgfg_mog.cpp rename to modules/gpubgsegm/src/bgfg_mog.cpp diff --git a/modules/gpuvideo/src/cuda/bgfg_gmg.cu b/modules/gpubgsegm/src/cuda/bgfg_gmg.cu similarity index 100% rename from modules/gpuvideo/src/cuda/bgfg_gmg.cu rename to modules/gpubgsegm/src/cuda/bgfg_gmg.cu diff --git a/modules/gpuvideo/src/cuda/bgfg_mog.cu b/modules/gpubgsegm/src/cuda/bgfg_mog.cu similarity index 100% rename from modules/gpuvideo/src/cuda/bgfg_mog.cu rename to modules/gpubgsegm/src/cuda/bgfg_mog.cu diff --git a/modules/gpuvideo/src/cuda/fgd_bgfg.cu b/modules/gpubgsegm/src/cuda/fgd_bgfg.cu similarity index 100% rename from modules/gpuvideo/src/cuda/fgd_bgfg.cu rename to modules/gpubgsegm/src/cuda/fgd_bgfg.cu diff --git a/modules/gpuvideo/src/cuda/fgd_bgfg_common.hpp b/modules/gpubgsegm/src/cuda/fgd_bgfg_common.hpp similarity index 100% rename from modules/gpuvideo/src/cuda/fgd_bgfg_common.hpp rename to modules/gpubgsegm/src/cuda/fgd_bgfg_common.hpp diff --git a/modules/gpuvideo/src/fgd_bgfg.cpp b/modules/gpubgsegm/src/fgd_bgfg.cpp similarity index 100% rename from modules/gpuvideo/src/fgd_bgfg.cpp rename to modules/gpubgsegm/src/fgd_bgfg.cpp diff --git a/modules/gpuvideo/src/precomp.cpp b/modules/gpubgsegm/src/precomp.cpp similarity index 100% rename from modules/gpuvideo/src/precomp.cpp rename to modules/gpubgsegm/src/precomp.cpp diff --git a/modules/gpuvideo/src/precomp.hpp b/modules/gpubgsegm/src/precomp.hpp similarity index 97% rename from modules/gpuvideo/src/precomp.hpp rename to modules/gpubgsegm/src/precomp.hpp index a1e1b47d5..9f9dcb94c 100644 --- a/modules/gpuvideo/src/precomp.hpp +++ b/modules/gpubgsegm/src/precomp.hpp @@ -45,11 +45,10 @@ #include -#include "opencv2/gpuvideo.hpp" +#include "opencv2/gpubgsegm.hpp" #include "opencv2/gpuarithm.hpp" #include "opencv2/gpufilters.hpp" -#include "opencv2/gpuwarping.hpp" #include "opencv2/gpuimgproc.hpp" #include "opencv2/video.hpp" diff --git a/modules/gpuvideo/test/test_bgfg.cpp b/modules/gpubgsegm/test/test_bgfg.cpp similarity index 100% rename from modules/gpuvideo/test/test_bgfg.cpp rename to modules/gpubgsegm/test/test_bgfg.cpp diff --git a/modules/gpuvideo/test/test_main.cpp b/modules/gpubgsegm/test/test_main.cpp similarity index 100% rename from modules/gpuvideo/test/test_main.cpp rename to modules/gpubgsegm/test/test_main.cpp diff --git a/modules/gpuvideo/test/test_precomp.cpp b/modules/gpubgsegm/test/test_precomp.cpp similarity index 100% rename from modules/gpuvideo/test/test_precomp.cpp rename to modules/gpubgsegm/test/test_precomp.cpp diff --git a/modules/gpubgsegm/test/test_precomp.hpp b/modules/gpubgsegm/test/test_precomp.hpp new file mode 100644 index 000000000..3c6ad197b --- /dev/null +++ b/modules/gpubgsegm/test/test_precomp.hpp @@ -0,0 +1,64 @@ +/*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*/ + +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-declarations" +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic ignored "-Wmissing-prototypes" +# pragma GCC diagnostic ignored "-Wextra" +# endif +#endif + +#ifndef __OPENCV_TEST_PRECOMP_HPP__ +#define __OPENCV_TEST_PRECOMP_HPP__ + +#include + +#include "opencv2/ts.hpp" +#include "opencv2/ts/gpu_test.hpp" + +#include "opencv2/gpubgsegm.hpp" + +#include "opencv2/video.hpp" +#include "opencv2/legacy.hpp" + +#endif diff --git a/modules/gpuimgproc/doc/image_processing.rst b/modules/gpuimgproc/doc/image_processing.rst index fed3aaf25..352288672 100644 --- a/modules/gpuimgproc/doc/image_processing.rst +++ b/modules/gpuimgproc/doc/image_processing.rst @@ -556,3 +556,34 @@ Downloads results from :ocv:func:`gpu::HoughCircles` to host memory. :param h_circles: Output host array. .. seealso:: :ocv:func:`gpu::HoughCircles` + + + +gpu::GoodFeaturesToTrackDetector_GPU +------------------------------------ +.. ocv:class:: gpu::GoodFeaturesToTrackDetector_GPU + +Class used for strong corners detection on an image. :: + + class GoodFeaturesToTrackDetector_GPU + { + public: + explicit GoodFeaturesToTrackDetector_GPU(int maxCorners_ = 1000, double qualityLevel_ = 0.01, double minDistance_ = 0.0, + int blockSize_ = 3, bool useHarrisDetector_ = false, double harrisK_ = 0.04); + + void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat()); + + int maxCorners; + double qualityLevel; + double minDistance; + + int blockSize; + bool useHarrisDetector; + double harrisK; + + void releaseMemory(); + }; + +The class finds the most prominent corners in the image. + +.. seealso:: :ocv:func:`goodFeaturesToTrack` diff --git a/modules/gpuimgproc/perf/perf_imgproc.cpp b/modules/gpuimgproc/perf/perf_imgproc.cpp index 73e298855..fcfafef5c 100644 --- a/modules/gpuimgproc/perf/perf_imgproc.cpp +++ b/modules/gpuimgproc/perf/perf_imgproc.cpp @@ -1092,3 +1092,42 @@ PERF_TEST_P(Sz_Depth_Cn_KernelSz, BilateralFilter, CPU_SANITY_CHECK(dst); } } + +////////////////////////////////////////////////////// +// GoodFeaturesToTrack + +DEF_PARAM_TEST(Image_MinDistance, string, double); + +PERF_TEST_P(Image_MinDistance, GoodFeaturesToTrack, + Combine(Values("gpu/perf/aloe.png"), + Values(0.0, 3.0))) +{ + const string fileName = GET_PARAM(0); + const double minDistance = GET_PARAM(1); + + const cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(image.empty()); + + const int maxCorners = 8000; + const double qualityLevel = 0.01; + + if (PERF_RUN_GPU()) + { + cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(maxCorners, qualityLevel, minDistance); + + const cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat pts; + + TEST_CYCLE() d_detector(d_image, pts); + + GPU_SANITY_CHECK(pts); + } + else + { + cv::Mat pts; + + TEST_CYCLE() cv::goodFeaturesToTrack(image, pts, maxCorners, qualityLevel, minDistance); + + CPU_SANITY_CHECK(pts); + } +} diff --git a/modules/gpuoptflow/CMakeLists.txt b/modules/gpuoptflow/CMakeLists.txt new file mode 100644 index 000000000..120262d25 --- /dev/null +++ b/modules/gpuoptflow/CMakeLists.txt @@ -0,0 +1,9 @@ +if(ANDROID OR IOS) + ocv_module_disable(gpuoptflow) +endif() + +set(the_description "GPU-accelerated Optical Flow") + +ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wmissing-declarations) + +ocv_define_module(gpuoptflow opencv_video opencv_legacy opencv_gpuarithm opencv_gpuwarping opencv_gpuimgproc OPTIONAL opencv_gpulegacy) diff --git a/modules/gpuoptflow/doc/gpuoptflow.rst b/modules/gpuoptflow/doc/gpuoptflow.rst new file mode 100644 index 000000000..925f39338 --- /dev/null +++ b/modules/gpuoptflow/doc/gpuoptflow.rst @@ -0,0 +1,8 @@ +**************************************** +gpuoptflow. GPU-accelerated Optical Flow +**************************************** + +.. toctree:: + :maxdepth: 1 + + optflow diff --git a/modules/gpuoptflow/doc/optflow.rst b/modules/gpuoptflow/doc/optflow.rst new file mode 100644 index 000000000..d8f153610 --- /dev/null +++ b/modules/gpuoptflow/doc/optflow.rst @@ -0,0 +1,238 @@ +Video Analysis +============== + +.. highlight:: cpp + + + +gpu::BroxOpticalFlow +-------------------- +.. ocv:class:: gpu::BroxOpticalFlow + +Class computing the optical flow for two images using Brox et al Optical Flow algorithm ([Brox2004]_). :: + + class BroxOpticalFlow + { + public: + BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_); + + //! Compute optical flow + //! frame0 - source frame (supports only CV_32FC1 type) + //! frame1 - frame to track (with the same size and type as frame0) + //! u - flow horizontal component (along x axis) + //! v - flow vertical component (along y axis) + void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null()); + + //! flow smoothness + float alpha; + + //! gradient constancy importance + float gamma; + + //! pyramid scale factor + float scale_factor; + + //! number of lagged non-linearity iterations (inner loop) + int inner_iterations; + + //! number of warping iterations (number of pyramid levels) + int outer_iterations; + + //! number of linear system solver iterations + int solver_iterations; + + GpuMat buf; + }; + + + +gpu::GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU +--------------------------------------------------------------------- +Constructor. + +.. ocv:function:: gpu::GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0, int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04) + + :param maxCorners: Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned. + + :param qualityLevel: Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue (see :ocv:func:`gpu::cornerMinEigenVal` ) or the Harris function response (see :ocv:func:`gpu::cornerHarris` ). The corners with the quality measure less than the product are rejected. For example, if the best corner has the quality measure = 1500, and the ``qualityLevel=0.01`` , then all the corners with the quality measure less than 15 are rejected. + + :param minDistance: Minimum possible Euclidean distance between the returned corners. + + :param blockSize: Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See :ocv:func:`cornerEigenValsAndVecs` . + + :param useHarrisDetector: Parameter indicating whether to use a Harris detector (see :ocv:func:`gpu::cornerHarris`) or :ocv:func:`gpu::cornerMinEigenVal`. + + :param harrisK: Free parameter of the Harris detector. + + +gpu::FarnebackOpticalFlow +------------------------- +.. ocv:class:: gpu::FarnebackOpticalFlow + +Class computing a dense optical flow using the Gunnar Farneback’s algorithm. :: + + class CV_EXPORTS FarnebackOpticalFlow + { + public: + FarnebackOpticalFlow() + { + numLevels = 5; + pyrScale = 0.5; + fastPyramids = false; + winSize = 13; + numIters = 10; + polyN = 5; + polySigma = 1.1; + flags = 0; + } + + int numLevels; + double pyrScale; + bool fastPyramids; + int winSize; + int numIters; + int polyN; + double polySigma; + int flags; + + void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null()); + + void releaseMemory(); + + private: + /* hidden */ + }; + + + +gpu::FarnebackOpticalFlow::operator () +-------------------------------------- +Computes a dense optical flow using the Gunnar Farneback’s algorithm. + +.. ocv:function:: void gpu::FarnebackOpticalFlow::operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null()) + + :param frame0: First 8-bit gray-scale input image + :param frame1: Second 8-bit gray-scale input image + :param flowx: Flow horizontal component + :param flowy: Flow vertical component + :param s: Stream + +.. seealso:: :ocv:func:`calcOpticalFlowFarneback` + + + +gpu::FarnebackOpticalFlow::releaseMemory +---------------------------------------- +Releases unused auxiliary memory buffers. + +.. ocv:function:: void gpu::FarnebackOpticalFlow::releaseMemory() + + + +gpu::PyrLKOpticalFlow +--------------------- +.. ocv:class:: gpu::PyrLKOpticalFlow + +Class used for calculating an optical flow. :: + + class PyrLKOpticalFlow + { + public: + PyrLKOpticalFlow(); + + void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, + GpuMat& status, GpuMat* err = 0); + + void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0); + + Size winSize; + int maxLevel; + int iters; + bool useInitialFlow; + + void releaseMemory(); + }; + +The class can calculate an optical flow for a sparse feature set or dense optical flow using the iterative Lucas-Kanade method with pyramids. + +.. seealso:: :ocv:func:`calcOpticalFlowPyrLK` + + + +gpu::PyrLKOpticalFlow::sparse +----------------------------- +Calculate an optical flow for a sparse feature set. + +.. ocv:function:: void gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, GpuMat& status, GpuMat* err = 0) + + :param prevImg: First 8-bit input image (supports both grayscale and color images). + + :param nextImg: Second input image of the same size and the same type as ``prevImg`` . + + :param prevPts: Vector of 2D points for which the flow needs to be found. It must be one row matrix with CV_32FC2 type. + + :param nextPts: Output vector of 2D points (with single-precision floating-point coordinates) containing the calculated new positions of input features in the second image. When ``useInitialFlow`` is true, the vector must have the same size as in the input. + + :param status: Output status vector (CV_8UC1 type). Each element of the vector is set to 1 if the flow for the corresponding features has been found. Otherwise, it is set to 0. + + :param err: Output vector (CV_32FC1 type) that contains the difference between patches around the original and moved points or min eigen value if ``getMinEigenVals`` is checked. It can be NULL, if not needed. + +.. seealso:: :ocv:func:`calcOpticalFlowPyrLK` + + + +gpu::PyrLKOpticalFlow::dense +----------------------------- +Calculate dense optical flow. + +.. ocv:function:: void gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0) + + :param prevImg: First 8-bit grayscale input image. + + :param nextImg: Second input image of the same size and the same type as ``prevImg`` . + + :param u: Horizontal component of the optical flow of the same size as input images, 32-bit floating-point, single-channel + + :param v: Vertical component of the optical flow of the same size as input images, 32-bit floating-point, single-channel + + :param err: Output vector (CV_32FC1 type) that contains the difference between patches around the original and moved points or min eigen value if ``getMinEigenVals`` is checked. It can be NULL, if not needed. + + + +gpu::PyrLKOpticalFlow::releaseMemory +------------------------------------ +Releases inner buffers memory. + +.. ocv:function:: void gpu::PyrLKOpticalFlow::releaseMemory() + + + +gpu::interpolateFrames +---------------------- +Interpolates frames (images) using provided optical flow (displacement field). + +.. ocv:function:: void gpu::interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, const GpuMat& fu, const GpuMat& fv, const GpuMat& bu, const GpuMat& bv, float pos, GpuMat& newFrame, GpuMat& buf, Stream& stream = Stream::Null()) + + :param frame0: First frame (32-bit floating point images, single channel). + + :param frame1: Second frame. Must have the same type and size as ``frame0`` . + + :param fu: Forward horizontal displacement. + + :param fv: Forward vertical displacement. + + :param bu: Backward horizontal displacement. + + :param bv: Backward vertical displacement. + + :param pos: New frame position. + + :param newFrame: Output image. + + :param buf: Temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat: occlusion masks for first frame, occlusion masks for second, interpolated forward horizontal flow, interpolated forward vertical flow, interpolated backward horizontal flow, interpolated backward vertical flow. + + :param stream: Stream for the asynchronous version. + + + +.. [Brox2004] T. Brox, A. Bruhn, N. Papenberg, J. Weickert. *High accuracy optical flow estimation based on a theory for warping*. ECCV 2004. diff --git a/modules/gpuoptflow/include/opencv2/gpuoptflow.hpp b/modules/gpuoptflow/include/opencv2/gpuoptflow.hpp new file mode 100644 index 000000000..4e245195d --- /dev/null +++ b/modules/gpuoptflow/include/opencv2/gpuoptflow.hpp @@ -0,0 +1,310 @@ +/*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*/ + +#ifndef __OPENCV_GPUOPTFLOW_HPP__ +#define __OPENCV_GPUOPTFLOW_HPP__ + +#include "opencv2/core/gpumat.hpp" + +namespace cv { namespace gpu { + +////////////////////////////////// Optical Flow ////////////////////////////////////////// + +class CV_EXPORTS BroxOpticalFlow +{ +public: + BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_) : + alpha(alpha_), gamma(gamma_), scale_factor(scale_factor_), + inner_iterations(inner_iterations_), outer_iterations(outer_iterations_), solver_iterations(solver_iterations_) + { + } + + //! Compute optical flow + //! frame0 - source frame (supports only CV_32FC1 type) + //! frame1 - frame to track (with the same size and type as frame0) + //! u - flow horizontal component (along x axis) + //! v - flow vertical component (along y axis) + void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null()); + + //! flow smoothness + float alpha; + + //! gradient constancy importance + float gamma; + + //! pyramid scale factor + float scale_factor; + + //! number of lagged non-linearity iterations (inner loop) + int inner_iterations; + + //! number of warping iterations (number of pyramid levels) + int outer_iterations; + + //! number of linear system solver iterations + int solver_iterations; + + GpuMat buf; +}; + +class CV_EXPORTS PyrLKOpticalFlow +{ +public: + PyrLKOpticalFlow(); + + void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, + GpuMat& status, GpuMat* err = 0); + + void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0); + + void releaseMemory(); + + Size winSize; + int maxLevel; + int iters; + bool useInitialFlow; + +private: + std::vector prevPyr_; + std::vector nextPyr_; + + GpuMat buf_; + + GpuMat uPyr_[2]; + GpuMat vPyr_[2]; +}; + +class CV_EXPORTS FarnebackOpticalFlow +{ +public: + FarnebackOpticalFlow() + { + numLevels = 5; + pyrScale = 0.5; + fastPyramids = false; + winSize = 13; + numIters = 10; + polyN = 5; + polySigma = 1.1; + flags = 0; + } + + int numLevels; + double pyrScale; + bool fastPyramids; + int winSize; + int numIters; + int polyN; + double polySigma; + int flags; + + void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null()); + + void releaseMemory() + { + frames_[0].release(); + frames_[1].release(); + pyrLevel_[0].release(); + pyrLevel_[1].release(); + M_.release(); + bufM_.release(); + R_[0].release(); + R_[1].release(); + blurredFrame_[0].release(); + blurredFrame_[1].release(); + pyramid0_.clear(); + pyramid1_.clear(); + } + +private: + void prepareGaussian( + int n, double sigma, float *g, float *xg, float *xxg, + double &ig11, double &ig03, double &ig33, double &ig55); + + void setPolynomialExpansionConsts(int n, double sigma); + + void updateFlow_boxFilter( + const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat &flowy, + GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]); + + void updateFlow_gaussianBlur( + const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat& flowy, + GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]); + + GpuMat frames_[2]; + GpuMat pyrLevel_[2], M_, bufM_, R_[2], blurredFrame_[2]; + std::vector pyramid0_, pyramid1_; +}; + +// Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method +// +// see reference: +// [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". +// [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". +class CV_EXPORTS OpticalFlowDual_TVL1_GPU +{ +public: + OpticalFlowDual_TVL1_GPU(); + + void operator ()(const GpuMat& I0, const GpuMat& I1, GpuMat& flowx, GpuMat& flowy); + + void collectGarbage(); + + /** + * Time step of the numerical scheme. + */ + double tau; + + /** + * Weight parameter for the data term, attachment parameter. + * This is the most relevant parameter, which determines the smoothness of the output. + * The smaller this parameter is, the smoother the solutions we obtain. + * It depends on the range of motions of the images, so its value should be adapted to each image sequence. + */ + double lambda; + + /** + * Weight parameter for (u - v)^2, tightness parameter. + * It serves as a link between the attachment and the regularization terms. + * In theory, it should have a small value in order to maintain both parts in correspondence. + * The method is stable for a large range of values of this parameter. + */ + double theta; + + /** + * Number of scales used to create the pyramid of images. + */ + int nscales; + + /** + * Number of warpings per scale. + * Represents the number of times that I1(x+u0) and grad( I1(x+u0) ) are computed per scale. + * This is a parameter that assures the stability of the method. + * It also affects the running time, so it is a compromise between speed and accuracy. + */ + int warps; + + /** + * Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time. + * A small value will yield more accurate solutions at the expense of a slower convergence. + */ + double epsilon; + + /** + * Stopping criterion iterations number used in the numerical scheme. + */ + int iterations; + + double scaleStep; + + bool useInitialFlow; + +private: + void procOneScale(const GpuMat& I0, const GpuMat& I1, GpuMat& u1, GpuMat& u2); + + std::vector I0s; + std::vector I1s; + std::vector u1s; + std::vector u2s; + + GpuMat I1x_buf; + GpuMat I1y_buf; + + GpuMat I1w_buf; + GpuMat I1wx_buf; + GpuMat I1wy_buf; + + GpuMat grad_buf; + GpuMat rho_c_buf; + + GpuMat p11_buf; + GpuMat p12_buf; + GpuMat p21_buf; + GpuMat p22_buf; + + GpuMat diff_buf; + GpuMat norm_buf; +}; + +//! Calculates optical flow for 2 images using block matching algorithm */ +CV_EXPORTS void calcOpticalFlowBM(const GpuMat& prev, const GpuMat& curr, + Size block_size, Size shift_size, Size max_range, bool use_previous, + GpuMat& velx, GpuMat& vely, GpuMat& buf, + Stream& stream = Stream::Null()); + +class CV_EXPORTS FastOpticalFlowBM +{ +public: + void operator ()(const GpuMat& I0, const GpuMat& I1, GpuMat& flowx, GpuMat& flowy, int search_window = 21, int block_window = 7, Stream& s = Stream::Null()); + +private: + GpuMat buffer; + GpuMat extended_I0; + GpuMat extended_I1; +}; + + +//! Interpolate frames (images) using provided optical flow (displacement field). +//! frame0 - frame 0 (32-bit floating point images, single channel) +//! frame1 - frame 1 (the same type and size) +//! fu - forward horizontal displacement +//! fv - forward vertical displacement +//! bu - backward horizontal displacement +//! bv - backward vertical displacement +//! pos - new frame position +//! newFrame - new frame +//! buf - temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat; +//! occlusion masks 0, occlusion masks 1, +//! interpolated forward flow 0, interpolated forward flow 1, +//! interpolated backward flow 0, interpolated backward flow 1 +//! +CV_EXPORTS void interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, + const GpuMat& fu, const GpuMat& fv, + const GpuMat& bu, const GpuMat& bv, + float pos, GpuMat& newFrame, GpuMat& buf, + Stream& stream = Stream::Null()); + +CV_EXPORTS void createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMat& vertex, GpuMat& colors); + +}} // namespace cv { namespace gpu { + +#endif /* __OPENCV_GPUOPTFLOW_HPP__ */ diff --git a/modules/gpuoptflow/perf/perf_main.cpp b/modules/gpuoptflow/perf/perf_main.cpp new file mode 100644 index 000000000..dad5e52bb --- /dev/null +++ b/modules/gpuoptflow/perf/perf_main.cpp @@ -0,0 +1,47 @@ +/*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" + +using namespace perf; + +CV_PERF_TEST_MAIN(gpuoptflow, printCudaInfo()) diff --git a/modules/gpuvideo/perf/perf_video.cpp b/modules/gpuoptflow/perf/perf_optflow.cpp similarity index 53% rename from modules/gpuvideo/perf/perf_video.cpp rename to modules/gpuoptflow/perf/perf_optflow.cpp index 59efd2e4a..febaee5f8 100644 --- a/modules/gpuvideo/perf/perf_video.cpp +++ b/modules/gpuoptflow/perf/perf_optflow.cpp @@ -47,26 +47,6 @@ using namespace std; using namespace testing; using namespace perf; -#if defined(HAVE_XINE) || \ - defined(HAVE_GSTREAMER) || \ - defined(HAVE_QUICKTIME) || \ - 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 - -namespace cv -{ - template<> void Ptr::delete_obj() - { - cvReleaseBGStatModel(&obj); - } -} - ////////////////////////////////////////////////////// // InterpolateFrames @@ -152,45 +132,6 @@ PERF_TEST_P(ImagePair, Video_CreateOpticalFlowNeedleMap, } } -////////////////////////////////////////////////////// -// GoodFeaturesToTrack - -DEF_PARAM_TEST(Image_MinDistance, string, double); - -PERF_TEST_P(Image_MinDistance, Video_GoodFeaturesToTrack, - Combine(Values("gpu/perf/aloe.png"), - Values(0.0, 3.0))) -{ - const string fileName = GET_PARAM(0); - const double minDistance = GET_PARAM(1); - - const cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image.empty()); - - const int maxCorners = 8000; - const double qualityLevel = 0.01; - - if (PERF_RUN_GPU()) - { - cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(maxCorners, qualityLevel, minDistance); - - const cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat pts; - - TEST_CYCLE() d_detector(d_image, pts); - - GPU_SANITY_CHECK(pts); - } - else - { - cv::Mat pts; - - TEST_CYCLE() cv::goodFeaturesToTrack(image, pts, maxCorners, qualityLevel, minDistance); - - CPU_SANITY_CHECK(pts); - } -} - ////////////////////////////////////////////////////// // BroxOpticalFlow @@ -536,472 +477,3 @@ PERF_TEST_P(ImagePair, Video_FastOpticalFlowBM, FAIL_NO_CPU(); } } - -////////////////////////////////////////////////////// -// FGDStatModel - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -DEF_PARAM_TEST_1(Video, string); - -PERF_TEST_P(Video, Video_FGDStatModel, - Values(string("gpu/video/768x576.avi"))) -{ - 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_GPU()) - { - cv::gpu::GpuMat d_frame(frame); - - cv::gpu::FGDStatModel d_model(4); - d_model.create(d_frame); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - d_frame.upload(frame); - - startTimer(); next(); - d_model.update(d_frame); - stopTimer(); - } - - const cv::gpu::GpuMat background = d_model.background; - const cv::gpu::GpuMat foreground = d_model.foreground; - - GPU_SANITY_CHECK(background, 1e-2, ERROR_RELATIVE); - GPU_SANITY_CHECK(foreground, 1e-2, ERROR_RELATIVE); - } - else - { - IplImage ipl_frame = frame; - cv::Ptr model(cvCreateFGDStatModel(&ipl_frame)); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - ipl_frame = frame; - - startTimer(); next(); - cvUpdateBGStatModel(&ipl_frame, model); - stopTimer(); - } - - const cv::Mat background = cv::cvarrToMat(model->background); - const cv::Mat foreground = cv::cvarrToMat(model->foreground); - - CPU_SANITY_CHECK(background); - CPU_SANITY_CHECK(foreground); - } -} - -#endif - -////////////////////////////////////////////////////// -// MOG - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -DEF_PARAM_TEST(Video_Cn_LearningRate, string, MatCn, double); - -PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, - Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), - GPU_CHANNELS_1_3_4, - Values(0.0, 0.01))) -{ - const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); - const int cn = GET_PARAM(1); - const float learningRate = static_cast(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_GPU()) - { - cv::gpu::GpuMat d_frame(frame); - cv::gpu::MOG_GPU d_mog; - cv::gpu::GpuMat foreground; - - d_mog(d_frame, foreground, learningRate); - - 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); - - startTimer(); next(); - d_mog(d_frame, foreground, learningRate); - stopTimer(); - } - - GPU_SANITY_CHECK(foreground); - } - else - { - cv::Ptr mog = cv::createBackgroundSubtractorMOG(); - cv::Mat foreground; - - mog->apply(frame, foreground, learningRate); - - 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); - } - - startTimer(); next(); - mog->apply(frame, foreground, learningRate); - stopTimer(); - } - - CPU_SANITY_CHECK(foreground); - } -} - -#endif - -////////////////////////////////////////////////////// -// MOG2 - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -DEF_PARAM_TEST(Video_Cn, string, int); - -PERF_TEST_P(Video_Cn, Video_MOG2, - Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), - GPU_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; - - 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_GPU()) - { - cv::gpu::MOG2_GPU d_mog2; - d_mog2.bShadowDetection = false; - - cv::gpu::GpuMat d_frame(frame); - cv::gpu::GpuMat foreground; - - d_mog2(d_frame, 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); - - startTimer(); next(); - d_mog2(d_frame, foreground); - stopTimer(); - } - - GPU_SANITY_CHECK(foreground); - } - else - { - cv::Ptr mog2 = cv::createBackgroundSubtractorMOG2(); - mog2->set("detectShadows", false); - - cv::Mat foreground; - - mog2->apply(frame, 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); - } - - startTimer(); next(); - mog2->apply(frame, foreground); - stopTimer(); - } - - CPU_SANITY_CHECK(foreground); - } -} - -#endif - -////////////////////////////////////////////////////// -// MOG2GetBackgroundImage - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, - Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), - GPU_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_GPU()) - { - cv::gpu::GpuMat d_frame; - cv::gpu::MOG2_GPU d_mog2; - cv::gpu::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(d_frame, d_foreground); - } - - cv::gpu::GpuMat background; - - TEST_CYCLE() d_mog2.getBackgroundImage(background); - - GPU_SANITY_CHECK(background, 1); - } - else - { - cv::Ptr 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, Video_GMG, - Combine(Values(string("gpu/video/768x576.avi")), - GPU_CHANNELS_1_3_4, - Values(20, 40, 60))) -{ - 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_GPU()) - { - cv::gpu::GpuMat d_frame(frame); - cv::gpu::GpuMat foreground; - - cv::gpu::GMG_GPU d_gmg; - d_gmg.maxFeatures = maxFeatures; - - d_gmg(d_frame, foreground); - - for (int i = 0; i < 150; ++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); - - startTimer(); next(); - d_gmg(d_frame, foreground); - stopTimer(); - } - - GPU_SANITY_CHECK(foreground); - } - else - { - cv::Mat foreground; - cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0)); - - cv::Ptr gmg = cv::createBackgroundSubtractorGMG(); - gmg->set("maxFeatures", maxFeatures); - //gmg.initialize(frame.size(), 0.0, 255.0); - - gmg->apply(frame, foreground); - - for (int i = 0; i < 150; ++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(); next(); - gmg->apply(frame, foreground); - stopTimer(); - } - - CPU_SANITY_CHECK(foreground); - } -} - -#endif diff --git a/modules/gpuoptflow/perf/perf_precomp.cpp b/modules/gpuoptflow/perf/perf_precomp.cpp new file mode 100644 index 000000000..81f16e8f1 --- /dev/null +++ b/modules/gpuoptflow/perf/perf_precomp.cpp @@ -0,0 +1,43 @@ +/*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" diff --git a/modules/gpuoptflow/perf/perf_precomp.hpp b/modules/gpuoptflow/perf/perf_precomp.hpp new file mode 100644 index 000000000..cdc671b79 --- /dev/null +++ b/modules/gpuoptflow/perf/perf_precomp.hpp @@ -0,0 +1,66 @@ +/*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*/ + +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-declarations" +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic ignored "-Wmissing-prototypes" +# pragma GCC diagnostic ignored "-Wextra" +# endif +#endif + +#ifndef __OPENCV_PERF_PRECOMP_HPP__ +#define __OPENCV_PERF_PRECOMP_HPP__ + +#include "opencv2/ts.hpp" +#include "opencv2/ts/gpu_perf.hpp" + +#include "opencv2/gpuoptflow.hpp" + +#include "opencv2/video.hpp" +#include "opencv2/legacy.hpp" + +#ifdef GTEST_CREATE_SHARED_LIBRARY +#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined +#endif + +#endif diff --git a/modules/gpuvideo/src/cuda/optflowbm.cu b/modules/gpuoptflow/src/cuda/optflowbm.cu similarity index 100% rename from modules/gpuvideo/src/cuda/optflowbm.cu rename to modules/gpuoptflow/src/cuda/optflowbm.cu diff --git a/modules/gpuvideo/src/cuda/optical_flow.cu b/modules/gpuoptflow/src/cuda/optical_flow.cu similarity index 100% rename from modules/gpuvideo/src/cuda/optical_flow.cu rename to modules/gpuoptflow/src/cuda/optical_flow.cu diff --git a/modules/gpuvideo/src/cuda/optical_flow_farneback.cu b/modules/gpuoptflow/src/cuda/optical_flow_farneback.cu similarity index 100% rename from modules/gpuvideo/src/cuda/optical_flow_farneback.cu rename to modules/gpuoptflow/src/cuda/optical_flow_farneback.cu diff --git a/modules/gpuvideo/src/cuda/pyrlk.cu b/modules/gpuoptflow/src/cuda/pyrlk.cu similarity index 100% rename from modules/gpuvideo/src/cuda/pyrlk.cu rename to modules/gpuoptflow/src/cuda/pyrlk.cu diff --git a/modules/gpuvideo/src/cuda/tvl1flow.cu b/modules/gpuoptflow/src/cuda/tvl1flow.cu similarity index 100% rename from modules/gpuvideo/src/cuda/tvl1flow.cu rename to modules/gpuoptflow/src/cuda/tvl1flow.cu diff --git a/modules/gpuvideo/src/optflowbm.cpp b/modules/gpuoptflow/src/optflowbm.cpp similarity index 100% rename from modules/gpuvideo/src/optflowbm.cpp rename to modules/gpuoptflow/src/optflowbm.cpp diff --git a/modules/gpuvideo/src/optical_flow.cpp b/modules/gpuoptflow/src/optical_flow.cpp similarity index 100% rename from modules/gpuvideo/src/optical_flow.cpp rename to modules/gpuoptflow/src/optical_flow.cpp diff --git a/modules/gpuvideo/src/optical_flow_farneback.cpp b/modules/gpuoptflow/src/optical_flow_farneback.cpp similarity index 100% rename from modules/gpuvideo/src/optical_flow_farneback.cpp rename to modules/gpuoptflow/src/optical_flow_farneback.cpp diff --git a/modules/gpuoptflow/src/precomp.cpp b/modules/gpuoptflow/src/precomp.cpp new file mode 100644 index 000000000..3c01a2596 --- /dev/null +++ b/modules/gpuoptflow/src/precomp.cpp @@ -0,0 +1,43 @@ +/*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 "precomp.hpp" diff --git a/modules/gpuoptflow/src/precomp.hpp b/modules/gpuoptflow/src/precomp.hpp new file mode 100644 index 000000000..2bf47b228 --- /dev/null +++ b/modules/gpuoptflow/src/precomp.hpp @@ -0,0 +1,62 @@ +/*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*/ + +#ifndef __OPENCV_PRECOMP_H__ +#define __OPENCV_PRECOMP_H__ + +#include + +#include "opencv2/gpuoptflow.hpp" +#include "opencv2/gpuarithm.hpp" +#include "opencv2/gpuwarping.hpp" + +#include "opencv2/video.hpp" + +#include "opencv2/core/gpu_private.hpp" + +#include "opencv2/opencv_modules.hpp" + +#ifdef HAVE_OPENCV_GPULEGACY +# include "opencv2/gpulegacy/private.hpp" +#endif + +#endif /* __OPENCV_PRECOMP_H__ */ diff --git a/modules/gpuvideo/src/pyrlk.cpp b/modules/gpuoptflow/src/pyrlk.cpp similarity index 100% rename from modules/gpuvideo/src/pyrlk.cpp rename to modules/gpuoptflow/src/pyrlk.cpp diff --git a/modules/gpuvideo/src/tvl1flow.cpp b/modules/gpuoptflow/src/tvl1flow.cpp similarity index 100% rename from modules/gpuvideo/src/tvl1flow.cpp rename to modules/gpuoptflow/src/tvl1flow.cpp diff --git a/modules/gpuoptflow/test/test_main.cpp b/modules/gpuoptflow/test/test_main.cpp new file mode 100644 index 000000000..eea3d7c00 --- /dev/null +++ b/modules/gpuoptflow/test/test_main.cpp @@ -0,0 +1,45 @@ +/*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 "test_precomp.hpp" + +CV_GPU_TEST_MAIN("gpu") diff --git a/modules/gpuvideo/test/test_optflow.cpp b/modules/gpuoptflow/test/test_optflow.cpp similarity index 89% rename from modules/gpuvideo/test/test_optflow.cpp rename to modules/gpuoptflow/test/test_optflow.cpp index 34a08f2cf..893ab89dd 100644 --- a/modules/gpuvideo/test/test_optflow.cpp +++ b/modules/gpuoptflow/test/test_optflow.cpp @@ -151,88 +151,6 @@ GPU_TEST_P(BroxOpticalFlow, OpticalFlowNan) INSTANTIATE_TEST_CASE_P(GPU_Video, BroxOpticalFlow, ALL_DEVICES); -////////////////////////////////////////////////////// -// GoodFeaturesToTrack - -namespace -{ - IMPLEMENT_PARAM_CLASS(MinDistance, double) -} - -PARAM_TEST_CASE(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance) -{ - cv::gpu::DeviceInfo devInfo; - double minDistance; - - virtual void SetUp() - { - devInfo = GET_PARAM(0); - minDistance = GET_PARAM(1); - - cv::gpu::setDevice(devInfo.deviceID()); - } -}; - -GPU_TEST_P(GoodFeaturesToTrack, Accuracy) -{ - cv::Mat image = readImage("opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image.empty()); - - int maxCorners = 1000; - double qualityLevel = 0.01; - - cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance); - - cv::gpu::GpuMat d_pts; - detector(loadMat(image), d_pts); - - ASSERT_FALSE(d_pts.empty()); - - std::vector pts(d_pts.cols); - cv::Mat pts_mat(1, d_pts.cols, CV_32FC2, (void*) &pts[0]); - d_pts.download(pts_mat); - - std::vector pts_gold; - cv::goodFeaturesToTrack(image, pts_gold, maxCorners, qualityLevel, minDistance); - - ASSERT_EQ(pts_gold.size(), pts.size()); - - size_t mistmatch = 0; - for (size_t i = 0; i < pts.size(); ++i) - { - cv::Point2i a = pts_gold[i]; - cv::Point2i b = pts[i]; - - bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1; - - if (!eq) - ++mistmatch; - } - - double bad_ratio = static_cast(mistmatch) / pts.size(); - - ASSERT_LE(bad_ratio, 0.01); -} - -GPU_TEST_P(GoodFeaturesToTrack, EmptyCorners) -{ - int maxCorners = 1000; - double qualityLevel = 0.01; - - cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance); - - cv::gpu::GpuMat src(100, 100, CV_8UC1, cv::Scalar::all(0)); - cv::gpu::GpuMat corners(1, maxCorners, CV_32FC2); - - detector(src, corners); - - ASSERT_TRUE(corners.empty()); -} - -INSTANTIATE_TEST_CASE_P(GPU_Video, GoodFeaturesToTrack, testing::Combine( - ALL_DEVICES, - testing::Values(MinDistance(0.0), MinDistance(3.0)))); - ////////////////////////////////////////////////////// // PyrLKOpticalFlow diff --git a/modules/gpuoptflow/test/test_precomp.cpp b/modules/gpuoptflow/test/test_precomp.cpp new file mode 100644 index 000000000..0fb652180 --- /dev/null +++ b/modules/gpuoptflow/test/test_precomp.cpp @@ -0,0 +1,43 @@ +/*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 "test_precomp.hpp" diff --git a/modules/gpuvideo/test/test_precomp.hpp b/modules/gpuoptflow/test/test_precomp.hpp similarity index 98% rename from modules/gpuvideo/test/test_precomp.hpp rename to modules/gpuoptflow/test/test_precomp.hpp index b2b141aa4..4f993dd8b 100644 --- a/modules/gpuvideo/test/test_precomp.hpp +++ b/modules/gpuoptflow/test/test_precomp.hpp @@ -56,9 +56,8 @@ #include "opencv2/ts.hpp" #include "opencv2/ts/gpu_test.hpp" -#include "opencv2/gpuvideo.hpp" +#include "opencv2/gpuoptflow.hpp" #include "opencv2/gpuimgproc.hpp" - #include "opencv2/video.hpp" #include "opencv2/legacy.hpp" diff --git a/modules/gpuvideo/CMakeLists.txt b/modules/gpuvideo/CMakeLists.txt deleted file mode 100644 index 6c15bd147..000000000 --- a/modules/gpuvideo/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -if(ANDROID OR IOS) - ocv_module_disable(gpuvideo) -endif() - -set(the_description "GPU-accelerated Video Analysis") - -ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wmissing-declarations) - -ocv_define_module(gpuvideo opencv_video opencv_legacy opencv_gpufilters opencv_gpuwarping opencv_gpuimgproc OPTIONAL opencv_gpulegacy) diff --git a/modules/gpuvideo/doc/gpuvideo.rst b/modules/gpuvideo/doc/gpuvideo.rst deleted file mode 100644 index e16d7c427..000000000 --- a/modules/gpuvideo/doc/gpuvideo.rst +++ /dev/null @@ -1,8 +0,0 @@ -*********************************** -gpu. GPU-accelerated Video Analysis -*********************************** - -.. toctree:: - :maxdepth: 1 - - video diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 84913d284..97884825b 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -22,7 +22,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpuwarping/include") ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpuimgproc/include") ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpufeatures2d/include") - ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpuvideo/include") + ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpuoptflow/include") + ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpubgsegm/include") ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpustereo/include") ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include") endif() diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 7fed87be0..1c6f6a963 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -3,7 +3,7 @@ SET(OPENCV_GPU_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc ope opencv_calib3d opencv_legacy opencv_contrib opencv_gpu opencv_nonfree opencv_softcascade opencv_superres opencv_gpucodec opencv_gpuarithm opencv_gpufilters opencv_gpuwarping opencv_gpuimgproc - opencv_gpufeatures2d opencv_gpuvideo + opencv_gpufeatures2d opencv_gpuoptflow opencv_gpubgsegm opencv_gpustereo opencv_gpulegacy) ocv_check_dependencies(${OPENCV_GPU_SAMPLES_REQUIRED_DEPS})