{
const char* keys =
"{ i | input | | specify input image }"
- "{ k | ksize | 5 | specify kernel size }";
+ "{ k | ksize | 5 | specify kernel size }"
+ "{ h | help | false | print help message }";
+
CommandLineParser cmd(argc, argv, keys);
+ if (cmd.get<bool>("help"))
+ {
+ cout << "Usage : adaptive_bilateral_filter [options]" << endl;
+ cout << "Available options:" << endl;
+ cmd.printParams();
+ return EXIT_SUCCESS;
+ }
+
string src_path = cmd.get<string>("i");
int ks = cmd.get<int>("k");
const char * winName[] = {"input", "adaptive bilateral CPU", "adaptive bilateral OpenCL", "bilateralFilter OpenCL"};
- Mat src = imread(src_path);
- Mat abFilterCPU;
- if(src.empty()){
- //cout << "error read image: " << src_path << endl;
- return -1;
+ Mat src = imread(src_path), abFilterCPU;
+ if (src.empty())
+ {
+ cout << "error read image: " << src_path << endl;
+ return EXIT_FAILURE;
}
ocl::oclMat dsrc(src), dABFilter, dBFilter;
ocl::adaptiveBilateralFilter(dsrc, dABFilter, ksize, 10);
ocl::bilateralFilter(dsrc, dBFilter, ks, 30, 9);
- Mat abFilter = dABFilter;
- Mat bFilter = dBFilter;
+ Mat abFilter = dABFilter, bFilter = dBFilter;
imshow(winName[0], src);
-
imshow(winName[1], abFilterCPU);
-
imshow(winName[2], abFilter);
-
imshow(winName[3], bFilter);
-
waitKey();
- return 0;
+ return EXIT_SUCCESS;
}
int main(int argc, const char** argv)
{
-
cv::CommandLineParser cmd(argc, argv,
"{ c | camera | false | use camera }"
"{ f | file | 768x576.avi | input video file }"
cout << "Usage : bgfg_segm [options]" << endl;
cout << "Available options:" << endl;
cmd.printParams();
- return 0;
+ return EXIT_SUCCESS;
}
bool useCamera = cmd.get<bool>("camera");
if (method != "mog" && method != "mog2")
{
cerr << "Incorrect method" << endl;
- return -1;
+ return EXIT_FAILURE;
}
int m = method == "mog" ? M_MOG : M_MOG2;
VideoCapture cap;
-
if (useCamera)
cap.open(0);
else
if (!cap.isOpened())
{
- cerr << "can not open camera or video file" << endl;
- return -1;
+ cout << "can not open camera or video file" << endl;
+ return EXIT_FAILURE;
}
Mat frame;
cv::ocl::MOG mog;
cv::ocl::MOG2 mog2;
- oclMat d_fgmask;
- oclMat d_fgimg;
- oclMat d_bgimg;
+ oclMat d_fgmask, d_fgimg, d_bgimg;
d_fgimg.create(d_frame.size(), d_frame.type());
- Mat fgmask;
- Mat fgimg;
- Mat bgimg;
+ Mat fgmask, fgimg, bgimg;
switch (m)
{
break;
}
- for(;;)
+ for (;;)
{
cap >> frame;
if (frame.empty())
if (!bgimg.empty())
imshow("mean background image", bgimg);
- int key = waitKey(30);
- if (key == 27)
+ if (27 == waitKey(30))
break;
}
- return 0;
+ return EXIT_SUCCESS;
}
Ptr<CLAHE> pFilter;
int tilesize;
int cliplimit;
-string outfile;
static void TSize_Callback(int pos)
{
if(pos==0)
- {
pFilter->setTilesGridSize(Size(1,1));
- }
- pFilter->setTilesGridSize(Size(tilesize,tilesize));
+ else
+ pFilter->setTilesGridSize(Size(tilesize,tilesize));
}
static void Clip_Callback(int)
"{ i | input | | specify input image }"
"{ c | camera | 0 | specify camera id }"
"{ s | use_cpu | false | use cpu algorithm }"
- "{ o | output | clahe_output.jpg | specify output save path}";
+ "{ o | output | clahe_output.jpg | specify output save path}"
+ "{ h | help | false | print help message }";
+
+ cv::CommandLineParser cmd(argc, argv, keys);
+ if (cmd.get<bool>("help"))
+ {
+ cout << "Usage : clahe [options]" << endl;
+ cout << "Available options:" << endl;
+ cmd.printParams();
+ return EXIT_SUCCESS;
+ }
- CommandLineParser cmd(argc, argv, keys);
- string infile = cmd.get<string>("i");
- outfile = cmd.get<string>("o");
+ string infile = cmd.get<string>("i"), outfile = cmd.get<string>("o");
int camid = cmd.get<int>("c");
bool use_cpu = cmd.get<bool>("s");
CvCapture* capture = 0;
- bool running = true;
namedWindow("CLAHE");
createTrackbar("Tile Size", "CLAHE", &tilesize, 32, (TrackbarCallback)TSize_Callback);
createTrackbar("Clip Limit", "CLAHE", &cliplimit, 20, (TrackbarCallback)Clip_Callback);
Mat frame, outframe;
- ocl::oclMat d_outframe;
+ ocl::oclMat d_outframe, d_frame;
int cur_clip;
Size cur_tilesize;
- if(use_cpu)
- {
- pFilter = createCLAHE();
- }
- else
- {
- pFilter = ocl::createCLAHE();
- }
+ pFilter = use_cpu ? createCLAHE() : ocl::createCLAHE();
+
cur_clip = (int)pFilter->getClipLimit();
cur_tilesize = pFilter->getTilesGridSize();
setTrackbarPos("Tile Size", "CLAHE", cur_tilesize.width);
setTrackbarPos("Clip Limit", "CLAHE", cur_clip);
+
if(infile != "")
{
frame = imread(infile);
if(frame.empty())
{
cout << "error read image: " << infile << endl;
- return -1;
+ return EXIT_FAILURE;
}
}
else
- {
capture = cvCaptureFromCAM(camid);
- }
+
cout << "\nControls:\n"
<< "\to - save output image\n"
<< "\tESC - exit\n";
- while(running)
+
+ for (;;)
{
if(capture)
frame = cvQueryFrame(capture);
else
frame = imread(infile);
if(frame.empty())
- {
continue;
- }
+
if(use_cpu)
{
cvtColor(frame, frame, COLOR_BGR2GRAY);
}
else
{
- ocl::oclMat d_frame(frame);
- ocl::cvtColor(d_frame, d_outframe, COLOR_BGR2GRAY);
+ ocl::cvtColor(d_frame = frame, d_outframe, COLOR_BGR2GRAY);
pFilter->apply(d_outframe, d_outframe);
d_outframe.download(outframe);
}
+
imshow("CLAHE", outframe);
+
char key = (char)cvWaitKey(3);
- if(key == 'o') imwrite(outfile, outframe);
- else if(key == 27) running = false;
+ if(key == 'o')
+ imwrite(outfile, outframe);
+ else if(key == 27)
+ break;
}
- return 0;
+ return EXIT_SUCCESS;
}
{
work_begin = getTickCount();
}
+
static void workEnd()
{
work_end += (getTickCount() - work_begin);
}
+
static double getTime()
{
return work_end /((double)cvGetTickFrequency() * 1000.);
}
-void detect( Mat& img, vector<Rect>& faces,
+static void detect( Mat& img, vector<Rect>& faces,
ocl::OclCascadeClassifierBuf& cascade,
double scale, bool calTime);
-void detectCPU( Mat& img, vector<Rect>& faces,
+static void detectCPU( Mat& img, vector<Rect>& faces,
CascadeClassifier& cascade,
double scale, bool calTime);
-void Draw(Mat& img, vector<Rect>& faces, double scale);
+static void Draw(Mat& img, vector<Rect>& faces, double scale);
// This function test if gpu_rst matches cpu_rst.
// Else if will return (total diff of each cpu and gpu rects covered pixels)/(total cpu rects covered pixels)
double checkRectSimilarity(Size sz, vector<Rect>& cpu_rst, vector<Rect>& gpu_rst);
-
int main( int argc, const char** argv )
{
const char* keys =
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
{
+ cout << "Usage : facedetect [options]" << endl;
cout << "Available options:" << endl;
cmd.printParams();
- return 0;
+ return EXIT_SUCCESS;
}
+
CvCapture* capture = 0;
Mat frame, frameCopy, image;
if( !cascade.load( cascadeName ) || !cpu_cascade.load(cascadeName) )
{
- cerr << "ERROR: Could not load classifier cascade" << endl;
- return -1;
+ cout << "ERROR: Could not load classifier cascade" << endl;
+ return EXIT_FAILURE;
}
if( inputName.empty() )
if(!capture)
cout << "Capture from CAM 0 didn't work" << endl;
}
- else if( inputName.size() )
+ else
{
- image = imread( inputName, 1 );
+ image = imread( inputName, CV_LOAD_IMAGE_COLOR );
if( image.empty() )
{
capture = cvCaptureFromAVI( inputName.c_str() );
if(!capture)
cout << "Capture from AVI didn't work" << endl;
- return -1;
+ return EXIT_FAILURE;
}
}
- else
- {
- image = imread( "lena.jpg", 1 );
- if(image.empty())
- cout << "Couldn't read lena.jpg" << endl;
- return -1;
- }
-
cvNamedWindow( "result", 1 );
if( capture )
frame.copyTo( frameCopy );
else
flip( frame, frameCopy, 0 );
+
if(useCPU)
- {
detectCPU(frameCopy, faces, cpu_cascade, scale, false);
- }
else
- {
detect(frameCopy, faces, cascade, scale, false);
- }
+
Draw(frameCopy, faces, scale);
if( waitKey( 10 ) >= 0 )
- goto _cleanup_;
+ break;
}
-
-
- waitKey(0);
-
-
-_cleanup_:
cvReleaseCapture( &capture );
}
else
{
cout << "loop" << i << endl;
if(useCPU)
- {
detectCPU(image, faces, cpu_cascade, scale, i==0?false:true);
- }
else
{
detect(image, faces, cascade, scale, i==0?false:true);
"{ l |larger_win| false | use 64x128 window}"
"{ o | output | | specify output path when input is images}";
CommandLineParser cmd(argc, argv, keys);
+ if (cmd.get<bool>("help"))
+ {
+ cout << "Usage : hog [options]" << endl;
+ cout << "Available options:" << endl;
+ cmd.printParams();
+ return EXIT_SUCCESS;
+ }
+
App app(cmd);
try
{
{
return cout << "unknown exception" << endl, 1;
}
- return 0;
+ return EXIT_SUCCESS;
}
App::App(CommandLineParser& cmd)
d_mat.download(mat);
}
-static void drawArrows(Mat& frame, const vector<Point2f>& prevPts, const vector<Point2f>& nextPts, const vector<uchar>& status, Scalar line_color = Scalar(0, 0, 255))
+static void drawArrows(Mat& frame, const vector<Point2f>& prevPts, const vector<Point2f>& nextPts, const vector<uchar>& status,
+ Scalar line_color = Scalar(0, 0, 255))
{
for (size_t i = 0; i < prevPts.size(); ++i)
{
cout << "Usage: pyrlk_optical_flow [options]" << endl;
cout << "Available options:" << endl;
cmd.printParams();
- return 0;
+ return EXIT_SUCCESS;
}
bool defaultPicturesFail = false;
Mat frame0Gray, frame1Gray;
Mat ptr0, ptr1;
- if(vdofile == "")
+ if(vdofile.empty())
capture = cvCaptureFromCAM( inputName );
else
capture = cvCreateFileCapture(vdofile.c_str());
int c = inputName ;
if(!capture)
{
- if(vdofile == "")
+ if(vdofile.empty())
cout << "Capture from CAM " << c << " didn't work" << endl;
else
cout << "Capture from file " << vdofile << " failed" <<endl;
if (defaultPicturesFail)
- {
- return -1;
- }
+ return EXIT_FAILURE;
goto nocamera;
}
}
if( waitKey( 10 ) >= 0 )
- goto _cleanup_;
+ break;
}
- waitKey(0);
-
-_cleanup_:
cvReleaseCapture( &capture );
}
else
waitKey();
- return 0;
+ return EXIT_SUCCESS;
}
using namespace cv;
using namespace std;
-#define ACCURACY_CHECK 1
+#define ACCURACY_CHECK
-#if ACCURACY_CHECK
+#ifdef ACCURACY_CHECK
// check if two vectors of vector of points are near or not
// prior assumption is that they are in correct order
static bool checkPoints(
{
const char* keys =
"{ i | input | | specify input image }"
- "{ o | output | squares_output.jpg | specify output save path}";
+ "{ o | output | squares_output.jpg | specify output save path}"
+ "{ h | help | false | print help message }";
CommandLineParser cmd(argc, argv, keys);
string inputName = cmd.get<string>("i");
string outfile = cmd.get<string>("o");
- if(inputName.empty())
+
+ if(cmd.get<bool>("help"))
{
+ cout << "Usage : squares [options]" << endl;
cout << "Available options:" << endl;
cmd.printParams();
- return 0;
+ return EXIT_SUCCESS;
}
int iterations = 10;
- namedWindow( wndname, 1 );
+ namedWindow( wndname, CV_LOAD_IMAGE_COLOR );
vector<vector<Point> > squares_cpu, squares_ocl;
Mat image = imread(inputName, 1);
if( image.empty() )
{
cout << "Couldn't load " << inputName << endl;
- return -1;
+ return EXIT_FAILURE;
}
+
int j = iterations;
int64 t_ocl = 0, t_cpp = 0;
//warm-ups
findSquares_ocl(image, squares_ocl);
-#if ACCURACY_CHECK
+#ifdef ACCURACY_CHECK
cout << "Checking ocl accuracy ... " << endl;
cout << (checkPoints(squares_cpu, squares_ocl) ? "Pass" : "Failed") << endl;
#endif
imwrite(outfile, result);
cvWaitKey(0);
- return 0;
+ return EXIT_SUCCESS;
}
"{ l | left | | specify left image }"
"{ r | right | | specify right image }"
"{ m | method | BM | specify match method(BM/BP/CSBP) }"
- "{ n | ndisp | 64 | specify number of disparity levels }"
+ "{ n | ndisp | 64 | specify number of disparity levels }"
"{ o | output | stereo_match_output.jpg | specify output path when input is images}";
+
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
{
cmd.printParams();
return 0;
}
+
try
{
App app(cmd);
{
cout << "error: " << e.what() << endl;
}
- return 0;
+
+ return EXIT_SUCCESS;
}
App::App(CommandLineParser& cmd)
<< "\t2/w - increase/decrease window size (for BM only)\n"
<< "\t3/e - increase/decrease iteration count (for BP and CSBP only)\n"
<< "\t4/r - increase/decrease level count (for BP and CSBP only)\n";
+
l_img = cmd.get<string>("l");
r_img = cmd.get<string>("r");
string mstr = cmd.get<string>("m");
const int GOOD_PTS_MAX = 50;
const float GOOD_PORTION = 0.15f;
-namespace
-{
-
int64 work_begin = 0;
int64 work_end = 0;
-void workBegin()
+static void workBegin()
{
work_begin = getTickCount();
}
-void workEnd()
+
+static void workEnd()
{
work_end = getTickCount() - work_begin;
}
-double getTime()
+
+static double getTime()
{
return work_end /((double)cvGetTickFrequency() * 1000.);
}
}
};
-Mat drawGoodMatches(
+static Mat drawGoodMatches(
const Mat& cpu_img1,
const Mat& cpu_img2,
const vector<KeyPoint>& keypoints1,
return img_matches;
}
-}
////////////////////////////////////////////////////
// This program demonstrates the usage of SURF_OCL.
// use cpu findHomography interface to calculate the transformation matrix
"{ o | output | SURF_output.jpg | specify output save path (only works in CPU or GPU only mode) }"
"{ c | use_cpu | false | use CPU algorithms }"
"{ a | use_all | false | use both CPU and GPU algorithms}";
+
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
{
+ std::cout << "Usage: surf_matcher [options]" << std::endl;
std::cout << "Available options:" << std::endl;
cmd.printParams();
- return 0;
+ return EXIT_SUCCESS;
}
Mat cpu_img1, cpu_img2, cpu_img1_grey, cpu_img2_grey;
cvtColor(cpu_img2, cpu_img2_grey, CV_BGR2GRAY);
img2 = cpu_img2_grey;
- if(useALL)
- {
- useCPU = false;
- useGPU = false;
- }
- else if(useCPU==false && useALL==false)
- {
+ if (useALL)
+ useCPU = useGPU = false;
+ else if(!useCPU && !useALL)
useGPU = true;
- }
if(!useCPU)
- {
std::cout
<< "Device name:"
<< cv::ocl::Context::getContext()->getDeviceInfo().deviceName
<< std::endl;
- }
+
double surf_time = 0.;
//declare input/output
imshow("ocl surf matches", ocl_img_matches);
}
waitKey(0);
- return 0;
+ return EXIT_SUCCESS;
}
cout << "Usage: pyrlk_optical_flow [options]" << endl;
cout << "Available options:" << endl;
cmd.printParams();
- return 0;
+ return EXIT_SUCCESS;
}
- bool defaultPicturesFail = false;
string fname0 = cmd.get<string>("l");
string fname1 = cmd.get<string>("r");
string vdofile = cmd.get<string>("v");
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1();
cv::ocl::OpticalFlowDual_TVL1_OCL d_alg;
-
Mat flow, show_flow;
Mat flow_vec[2];
if (frame0.empty() || frame1.empty())
- {
useCamera = true;
- defaultPicturesFail = true;
- CvCapture* capture = 0;
- capture = cvCaptureFromCAM( inputName );
- if (!capture)
- {
- cout << "Can't load input images" << endl;
- return -1;
- }
- }
-
if (useCamera)
{
Mat frame0Gray, frame1Gray;
Mat ptr0, ptr1;
- if(vdofile == "")
+ if(vdofile.empty())
capture = cvCaptureFromCAM( inputName );
else
capture = cvCreateFileCapture(vdofile.c_str());
- int c = inputName ;
if(!capture)
{
- if(vdofile == "")
- cout << "Capture from CAM " << c << " didn't work" << endl;
+ if(vdofile.empty())
+ cout << "Capture from CAM " << inputName << " didn't work" << endl;
else
cout << "Capture from file " << vdofile << " failed" <<endl;
- if (defaultPicturesFail)
- {
- return -1;
- }
goto nocamera;
}
}
if( waitKey( 10 ) >= 0 )
- goto _cleanup_;
+ break;
}
- waitKey(0);
-
-_cleanup_:
cvReleaseCapture( &capture );
}
else
waitKey();
- return 0;
+ return EXIT_SUCCESS;
}