diff --git a/samples/gpu/cascadeclassifier.cpp b/samples/gpu/cascadeclassifier.cpp index cfd32a78530dc6487621e92026d54b085e0abb59..dbb2895e964bdaa0bfa89d80bf3a6b2ca3c67012 100644 --- a/samples/gpu/cascadeclassifier.cpp +++ b/samples/gpu/cascadeclassifier.cpp @@ -6,7 +6,6 @@ #include <iostream> #include <iomanip> -#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 6803bf9e94f53619db18f35a0ccb851f301c0ee6..a9081c56b7eea2c2210fa7116b93729d3b5c5f64 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 bb75cf5e315d2a7d6242dd903168ff5f70cee3cb..0997165f1fd581bf62def9f312390ac6785cc59e 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 4e3de21dbdde6e5c83fc653ed21810d429b00f28..63173cd4201b1b81064847d38e563157a726f617 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 0000000000000000000000000000000000000000..d0a428b8786a5422f5e6f6c044896901f975e8c2 --- /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 04cf4e47ce2f2f08e79fdb08b63c0c3510ec8044..d8d6e136f8c4522280d9107195b6f7c529ff43f2 100644 --- a/samples/gpu/video_reader.cpp +++ b/samples/gpu/video_reader.cpp @@ -13,7 +13,8 @@ #include <opencv2/core/opengl.hpp> #include <opencv2/cudacodec.hpp> #include <opencv2/highgui.hpp> -#include <opencv2/contrib.hpp> + +#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<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname); - cv::TickMeter tm; + TickMeter tm; std::vector<double> cpu_times; std::vector<double> gpu_times; diff --git a/samples/gpu/video_writer.cpp b/samples/gpu/video_writer.cpp index 607f8d3c058cf2c2b56197a2408ac967ff34a0d6..33d6abbf03a0b0d5b6d9129cb3750f6afc924f06 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[]) {