Commit 0fd21baa authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #3174 from rokm:samples-fix

parents 7dd666e4 d9db950c
......@@ -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;
......
......@@ -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;
......
......@@ -4,7 +4,11 @@ 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()
if(HAVE_opencv_bgsegm)
ocv_include_directories("${opencv_bgsegm_SOURCE_DIR}/include")
endif()
add_executable(${the_target} ${sources} ${headers})
......@@ -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")
......
......@@ -12,7 +12,6 @@
#include "opencv2/cudaoptflow.hpp"
#include "opencv2/cudabgsegm.hpp"
#include "opencv2/legacy.hpp"
#include "performance.h"
#include "opencv2/opencv_modules.hpp"
......@@ -22,6 +21,10 @@
#include "opencv2/xfeatures2d/nonfree.hpp"
#endif
#ifdef HAVE_OPENCV_BGSEGM
#include "opencv2/bgsegm.hpp"
#endif
using namespace std;
using namespace cv;
......@@ -281,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<KeyPoint> keypoints;
Mat descriptors;
......@@ -1267,62 +1270,7 @@ TEST(FarnebackOpticalFlow)
}}}
}
namespace cv
{
template<> void DefaultDeleter<CvBGStatModel>::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<CvBGStatModel> 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<BackgroundSubtractor> 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();
}
#ifdef HAVE_OPENCV_BGSEGM
TEST(MOG)
{
......@@ -1334,7 +1282,7 @@ TEST(MOG)
cv::Mat frame;
cap >> frame;
cv::Ptr<cv::BackgroundSubtractor> mog = cv::createBackgroundSubtractorMOG();
cv::Ptr<cv::BackgroundSubtractor> mog = cv::bgsegm::createBackgroundSubtractorMOG();
cv::Mat foreground;
mog->apply(frame, foreground, 0.01);
......@@ -1375,6 +1323,8 @@ TEST(MOG)
TestSystem::instance().gpuComplete();
}
#endif
TEST(MOG2)
{
const std::string inputFile = abspath("768x576.avi");
......
#include <opencv2/core/utility.hpp>
#include <opencv2/cuda.hpp>
#include <opencv2/softcascade.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
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<int>("device"));
std::string cascadePath = parser.get<std::string>("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<float>("min_scale");
float maxScale = parser.get<float>("max_scale");
int scales = parser.get<int>("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<std::string>("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<int>("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<int>(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;
}
......@@ -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;
......
......@@ -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;
......@@ -34,8 +35,8 @@ static Ptr<DenseOpticalFlowExt> 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)
......
#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
......@@ -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;
......
......@@ -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[])
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment