From 8908b22c9d51ce8552e4220d2b73349f89776366 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Fri, 29 Aug 2014 23:52:22 +0200 Subject: [PATCH 1/8] samples: gpu: removed softcascade example The example in question cannot be compiled anymore as the softcascade module has been removed in 3858f2291d64652a82fea930ba5c598045633843. --- samples/gpu/softcascade.cpp | 109 ------------------------------------ 1 file changed, 109 deletions(-) delete mode 100644 samples/gpu/softcascade.cpp diff --git a/samples/gpu/softcascade.cpp b/samples/gpu/softcascade.cpp deleted file mode 100644 index e5258aaa64..0000000000 --- a/samples/gpu/softcascade.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include -#include - -typedef cv::softcascade::Detection Detection; - -int main(int argc, char** argv) -{ - const std::string keys = - "{help h usage ? | | print this message }" - "{cascade c | | path to configuration xml }" - "{frames f | | path to configuration xml }" - "{min_scale |0.4f | path to configuration xml }" - "{max_scale |5.0f | path to configuration xml }" - "{total_scales |55 | path to configuration xml }" - "{device d |0 | path to configuration xml }" - ; - - cv::CommandLineParser parser(argc, argv, keys); - parser.about("Soft cascade training application."); - - if (parser.has("help")) - { - parser.printMessage(); - return 0; - } - - if (!parser.check()) - { - parser.printErrors(); - return 1; - } - - cv::cuda::setDevice(parser.get("device")); - - std::string cascadePath = parser.get("cascade"); - - cv::FileStorage fs(cascadePath, cv::FileStorage::READ); - if(!fs.isOpened()) - { - std::cout << "Soft Cascade file " << cascadePath << " can't be opened." << std::endl << std::flush; - return 1; - } - - std::cout << "Read cascade from file " << cascadePath << std::endl; - - float minScale = parser.get("min_scale"); - float maxScale = parser.get("max_scale"); - int scales = parser.get("total_scales"); - - using cv::softcascade::SCascade; - SCascade cascade(minScale, maxScale, scales); - - if (!cascade.load(fs.getFirstTopLevelNode())) - { - std::cout << "Soft Cascade can't be parsed." << std::endl << std::flush; - return 1; - } - - std::string frames = parser.get("frames"); - cv::VideoCapture capture(frames); - if(!capture.isOpened()) - { - std::cout << "Frame source " << frames << " can't be opened." << std::endl << std::flush; - return 1; - } - - cv::cuda::GpuMat objects(1, sizeof(Detection) * 10000, CV_8UC1); - cv::cuda::printShortCudaDeviceInfo(parser.get("device")); - for (;;) - { - cv::Mat frame; - if (!capture.read(frame)) - { - std::cout << "Nothing to read. " << std::endl << std::flush; - return 0; - } - - cv::cuda::GpuMat dframe(frame), roi(frame.rows, frame.cols, CV_8UC1); - roi.setTo(cv::Scalar::all(1)); - cascade.detect(dframe, roi, objects); - - cv::Mat dt(objects); - - Detection* dts = ((Detection*)dt.data) + 1; - int* count = dt.ptr(0); - - std::cout << *count << std::endl; - - cv::Mat result; - frame.copyTo(result); - - - for (int i = 0; i < *count; ++i) - { - Detection d = dts[i]; - cv::rectangle(result, cv::Rect(d.x, d.y, d.w, d.h), cv::Scalar(255, 0, 0, 255), 1); - } - - std::cout << "working..." << std::endl; - cv::imshow("Soft Cascade demo", result); - if (27 == cv::waitKey(10)) - break; - } - - return 0; -} From e0c8721830f7bca0873f40c9938e5af81e887e19 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 30 Aug 2014 00:00:11 +0200 Subject: [PATCH 2/8] samples: gpu: removed inclusion of non-existent opencv2/contrib/contrib.hpp header, re-introduced TickMeter class in a separate header This patch removes inclusion of opencv2/contrib/contrib.hpp header, which does not exist anymore due to removal of opencv_contrib module. The samples including this header appear to be doing so in order to use TickMeter class; therefore, the latter is now provided by tick_meter.hpp header file, located in samples/gpu folder. --- samples/gpu/cascadeclassifier.cpp | 3 +- samples/gpu/generalized_hough.cpp | 3 +- samples/gpu/stereo_multi.cpp | 3 +- samples/gpu/super_resolution.cpp | 3 +- samples/gpu/tick_meter.hpp | 48 +++++++++++++++++++++++++++++++ samples/gpu/video_reader.cpp | 5 ++-- samples/gpu/video_writer.cpp | 1 - 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 samples/gpu/tick_meter.hpp diff --git a/samples/gpu/cascadeclassifier.cpp b/samples/gpu/cascadeclassifier.cpp index cfd32a7853..dbb2895e96 100644 --- a/samples/gpu/cascadeclassifier.cpp +++ b/samples/gpu/cascadeclassifier.cpp @@ -6,7 +6,6 @@ #include #include -#include "opencv2/contrib/contrib.hpp" #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" @@ -14,6 +13,8 @@ #include "opencv2/cudaimgproc.hpp" #include "opencv2/cudawarping.hpp" +#include "tick_meter.hpp" + using namespace std; using namespace cv; using namespace cv::cuda; diff --git a/samples/gpu/generalized_hough.cpp b/samples/gpu/generalized_hough.cpp index 6803bf9e94..a9081c56b7 100644 --- a/samples/gpu/generalized_hough.cpp +++ b/samples/gpu/generalized_hough.cpp @@ -7,7 +7,8 @@ #include "opencv2/imgproc.hpp" #include "opencv2/cudaimgproc.hpp" #include "opencv2/highgui.hpp" -#include "opencv2/contrib.hpp" + +#include "tick_meter.hpp" using namespace std; using namespace cv; diff --git a/samples/gpu/stereo_multi.cpp b/samples/gpu/stereo_multi.cpp index bb75cf5e31..0997165f1f 100644 --- a/samples/gpu/stereo_multi.cpp +++ b/samples/gpu/stereo_multi.cpp @@ -15,9 +15,10 @@ #include "opencv2/core.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/contrib.hpp" #include "opencv2/cudastereo.hpp" +#include "tick_meter.hpp" + using namespace std; using namespace cv; using namespace cv::cuda; diff --git a/samples/gpu/super_resolution.cpp b/samples/gpu/super_resolution.cpp index 4e3de21dbd..63173cd420 100644 --- a/samples/gpu/super_resolution.cpp +++ b/samples/gpu/super_resolution.cpp @@ -7,11 +7,12 @@ #include "opencv2/core/utility.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/contrib.hpp" #include "opencv2/superres.hpp" #include "opencv2/superres/optical_flow.hpp" #include "opencv2/opencv_modules.hpp" +#include "tick_meter.hpp" + using namespace std; using namespace cv; using namespace cv::superres; diff --git a/samples/gpu/tick_meter.hpp b/samples/gpu/tick_meter.hpp new file mode 100644 index 0000000000..d0a428b878 --- /dev/null +++ b/samples/gpu/tick_meter.hpp @@ -0,0 +1,48 @@ +#ifndef OPENCV_CUDA_SAMPLES_TICKMETER_ +#define OPENCV_CUDA_SAMPLES_TICKMETER_ + +class CV_EXPORTS TickMeter +{ +public: + TickMeter(); + void start(); + void stop(); + + int64 getTimeTicks() const; + double getTimeMicro() const; + double getTimeMilli() const; + double getTimeSec() const; + int64 getCounter() const; + + void reset(); +private: + int64 counter; + int64 sumTime; + int64 startTime; +}; + +std::ostream& operator << (std::ostream& out, const TickMeter& tm); + + +TickMeter::TickMeter() { reset(); } +int64 TickMeter::getTimeTicks() const { return sumTime; } +double TickMeter::getTimeMicro() const { return (double)getTimeTicks()/cv::getTickFrequency(); } +double TickMeter::getTimeMilli() const { return getTimeMicro()*1e-3; } +double TickMeter::getTimeSec() const { return getTimeMilli()*1e-3; } +int64 TickMeter::getCounter() const { return counter; } +void TickMeter::reset() {startTime = 0; sumTime = 0; counter = 0; } + +void TickMeter::start(){ startTime = cv::getTickCount(); } +void TickMeter::stop() +{ + int64 time = cv::getTickCount(); + if ( startTime == 0 ) + return; + ++counter; + sumTime += ( time - startTime ); + startTime = 0; +} + +std::ostream& operator << (std::ostream& out, const TickMeter& tm) { return out << tm.getTimeSec() << "sec"; } + +#endif diff --git a/samples/gpu/video_reader.cpp b/samples/gpu/video_reader.cpp index 04cf4e47ce..d8d6e136f8 100644 --- a/samples/gpu/video_reader.cpp +++ b/samples/gpu/video_reader.cpp @@ -13,7 +13,8 @@ #include #include #include -#include + +#include "tick_meter.hpp" int main(int argc, const char* argv[]) { @@ -32,7 +33,7 @@ int main(int argc, const char* argv[]) cv::cuda::GpuMat d_frame; cv::Ptr d_reader = cv::cudacodec::createVideoReader(fname); - cv::TickMeter tm; + TickMeter tm; std::vector cpu_times; std::vector gpu_times; diff --git a/samples/gpu/video_writer.cpp b/samples/gpu/video_writer.cpp index 607f8d3c05..33d6abbf03 100644 --- a/samples/gpu/video_writer.cpp +++ b/samples/gpu/video_writer.cpp @@ -10,7 +10,6 @@ #include "opencv2/core.hpp" #include "opencv2/cudacodec.hpp" #include "opencv2/highgui.hpp" -#include "opencv2/contrib.hpp" int main(int argc, const char* argv[]) { From 51311779b3ae693e8b52c29e153d1365921189d8 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 30 Aug 2014 00:03:59 +0200 Subject: [PATCH 3/8] samples: gpu: performance: remove inclusion of opencv2/legacy.hpp header The header is gone now, along with the opencv_legacy module. --- samples/gpu/performance/tests.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index 4d6f778a48..305f0cc3c5 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -12,7 +12,6 @@ #include "opencv2/cudaoptflow.hpp" #include "opencv2/cudabgsegm.hpp" -#include "opencv2/legacy.hpp" #include "performance.h" #include "opencv2/opencv_modules.hpp" From f739990f4c139fe83583bcae7e39545e4a669de7 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 30 Aug 2014 00:05:52 +0200 Subject: [PATCH 4/8] samples: gpu: performance: removed FGDStatModel performance comparison test The FGD background subtraction model was part of opencv_legacy module; as it is gone now, it makes little sense to benchmark the GPU version, either, so the whole test is removed. --- samples/gpu/performance/tests.cpp | 57 ------------------------------- 1 file changed, 57 deletions(-) diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index 305f0cc3c5..cecf1ce101 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -1266,63 +1266,6 @@ TEST(FarnebackOpticalFlow) }}} } -namespace cv -{ - template<> void DefaultDeleter::operator ()(CvBGStatModel* obj) const - { - cvReleaseBGStatModel(&obj); - } -} - -TEST(FGDStatModel) -{ - const std::string inputFile = abspath("768x576.avi"); - - VideoCapture cap(inputFile); - if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi"); - - Mat frame; - cap >> frame; - - IplImage ipl_frame = frame; - Ptr model(cvCreateFGDStatModel(&ipl_frame)); - - while (!TestSystem::instance().stop()) - { - cap >> frame; - ipl_frame = frame; - - TestSystem::instance().cpuOn(); - - cvUpdateBGStatModel(&ipl_frame, model); - - TestSystem::instance().cpuOff(); - } - TestSystem::instance().cpuComplete(); - - cap.open(inputFile); - - cap >> frame; - - cuda::GpuMat d_frame(frame), d_fgmask; - Ptr d_fgd = cuda::createBackgroundSubtractorFGD(); - - d_fgd->apply(d_frame, d_fgmask); - - while (!TestSystem::instance().stop()) - { - cap >> frame; - d_frame.upload(frame); - - TestSystem::instance().gpuOn(); - - d_fgd->apply(d_frame, d_fgmask); - - TestSystem::instance().gpuOff(); - } - TestSystem::instance().gpuComplete(); -} - TEST(MOG) { const std::string inputFile = abspath("768x576.avi"); From 653bca8b741f9455e1da24dcf3ebc1bdab74baf2 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 30 Aug 2014 00:15:23 +0200 Subject: [PATCH 5/8] samples: gpu: super_resolution: disable simple optical flow The cv::superres::createOptFlow_Simple() function along with the simple optical flow class implementation is currently commented out in the superres module's code, so comment it out in the example as well. --- samples/gpu/super_resolution.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/gpu/super_resolution.cpp b/samples/gpu/super_resolution.cpp index 63173cd420..95147a6d07 100644 --- a/samples/gpu/super_resolution.cpp +++ b/samples/gpu/super_resolution.cpp @@ -35,8 +35,8 @@ static Ptr createOptFlow(const string& name, bool useGpu) else return createOptFlow_Farneback(); } - else if (name == "simple") - return createOptFlow_Simple(); + /*else if (name == "simple") + return createOptFlow_Simple();*/ else if (name == "tvl1") { if (useGpu) From fbf28bcc63bc195e9736a5b2251accf050c69036 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 30 Aug 2014 00:49:56 +0200 Subject: [PATCH 6/8] samples: gpu: performance: fix include path for opencv_xfeatures2d As opencv_xfeatures2d is part of opencv-contrib and not opencv repository, ${OpenCV_SOURCE_DIR}/modules/modules/include is not a correct include path - use ${opencv_xfeatures2d_SOURCE_DIR}/include instead --- samples/gpu/performance/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index 0b256633ce..d283c7650a 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -4,7 +4,7 @@ file(GLOB sources "performance/*.cpp") file(GLOB headers "performance/*.h") if(HAVE_opencv_xfeatures2d) - ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/xfeatures2d/include") + ocv_include_directories("${opencv_xfeatures2d_SOURCE_DIR}/include") endif() add_executable(${the_target} ${sources} ${headers}) From db391fdfdd6b9381dd4b1ca408dffca96f5df4ac Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 30 Aug 2014 00:55:06 +0200 Subject: [PATCH 7/8] samples: gpu: performance: BackgroundSubtractorMOG is now part of opencv_bgsegm module --- samples/gpu/performance/CMakeLists.txt | 8 ++++++++ samples/gpu/performance/tests.cpp | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index d283c7650a..9c9fb5b676 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -7,6 +7,10 @@ if(HAVE_opencv_xfeatures2d) ocv_include_directories("${opencv_xfeatures2d_SOURCE_DIR}/include") endif() +if(HAVE_opencv_bgsegm) + ocv_include_directories("${opencv_bgsegm_SOURCE_DIR}/include") +endif() + add_executable(${the_target} ${sources} ${headers}) ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS}) @@ -14,6 +18,10 @@ if(HAVE_opencv_xfeatures2d) ocv_target_link_libraries(${the_target} opencv_xfeatures2d) endif() +if(HAVE_opencv_bgsegm) + ocv_target_link_libraries(${the_target} opencv_bgsegm) +endif() + set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "performance_gpu" PROJECT_LABEL "(EXAMPLE_CUDA) performance") diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index cecf1ce101..e5bdb049b1 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -21,6 +21,10 @@ #include "opencv2/xfeatures2d/nonfree.hpp" #endif +#ifdef HAVE_OPENCV_BGSEGM +#include "opencv2/bgsegm.hpp" +#endif + using namespace std; using namespace cv; @@ -1266,6 +1270,8 @@ TEST(FarnebackOpticalFlow) }}} } +#ifdef HAVE_OPENCV_BGSEGM + TEST(MOG) { const std::string inputFile = abspath("768x576.avi"); @@ -1276,7 +1282,7 @@ TEST(MOG) cv::Mat frame; cap >> frame; - cv::Ptr mog = cv::createBackgroundSubtractorMOG(); + cv::Ptr mog = cv::bgsegm::createBackgroundSubtractorMOG(); cv::Mat foreground; mog->apply(frame, foreground, 0.01); @@ -1317,6 +1323,8 @@ TEST(MOG) TestSystem::instance().gpuComplete(); } +#endif + TEST(MOG2) { const std::string inputFile = abspath("768x576.avi"); From d9db950c0e047be2b1fac3eb07fae65348693865 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 30 Aug 2014 00:58:36 +0200 Subject: [PATCH 8/8] samples: gpu: performance: SURF is now part of opencv_xfeatures2d --- samples/gpu/performance/tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index e5bdb049b1..9f2c2d13b8 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -284,7 +284,7 @@ TEST(SURF) Mat src = imread(abspath("aloeL.jpg"), IMREAD_GRAYSCALE); if (src.empty()) throw runtime_error("can't open aloeL.jpg"); - SURF surf; + xfeatures2d::SURF surf; vector keypoints; Mat descriptors;