Merge pull request #1659 from ilya-lavrenov:ocl_examples
This commit is contained in:
commit
6dda2652cd
@ -12,17 +12,27 @@ int main( int argc, const char** argv )
|
|||||||
{
|
{
|
||||||
const char* keys =
|
const char* keys =
|
||||||
"{ i | input | | specify input image }"
|
"{ 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);
|
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");
|
string src_path = cmd.get<string>("i");
|
||||||
int ks = cmd.get<int>("k");
|
int ks = cmd.get<int>("k");
|
||||||
const char * winName[] = {"input", "adaptive bilateral CPU", "adaptive bilateral OpenCL", "bilateralFilter OpenCL"};
|
const char * winName[] = {"input", "adaptive bilateral CPU", "adaptive bilateral OpenCL", "bilateralFilter OpenCL"};
|
||||||
|
|
||||||
Mat src = imread(src_path);
|
Mat src = imread(src_path), abFilterCPU;
|
||||||
Mat abFilterCPU;
|
if (src.empty())
|
||||||
if(src.empty()){
|
{
|
||||||
//cout << "error read image: " << src_path << endl;
|
cout << "error read image: " << src_path << endl;
|
||||||
return -1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ocl::oclMat dsrc(src), dABFilter, dBFilter;
|
ocl::oclMat dsrc(src), dABFilter, dBFilter;
|
||||||
@ -32,17 +42,12 @@ int main( int argc, const char** argv )
|
|||||||
ocl::adaptiveBilateralFilter(dsrc, dABFilter, ksize, 10);
|
ocl::adaptiveBilateralFilter(dsrc, dABFilter, ksize, 10);
|
||||||
ocl::bilateralFilter(dsrc, dBFilter, ks, 30, 9);
|
ocl::bilateralFilter(dsrc, dBFilter, ks, 30, 9);
|
||||||
|
|
||||||
Mat abFilter = dABFilter;
|
Mat abFilter = dABFilter, bFilter = dBFilter;
|
||||||
Mat bFilter = dBFilter;
|
|
||||||
imshow(winName[0], src);
|
imshow(winName[0], src);
|
||||||
|
|
||||||
imshow(winName[1], abFilterCPU);
|
imshow(winName[1], abFilterCPU);
|
||||||
|
|
||||||
imshow(winName[2], abFilter);
|
imshow(winName[2], abFilter);
|
||||||
|
|
||||||
imshow(winName[3], bFilter);
|
imshow(winName[3], bFilter);
|
||||||
|
|
||||||
waitKey();
|
waitKey();
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ using namespace cv::ocl;
|
|||||||
|
|
||||||
int main(int argc, const char** argv)
|
int main(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
cv::CommandLineParser cmd(argc, argv,
|
cv::CommandLineParser cmd(argc, argv,
|
||||||
"{ c | camera | false | use camera }"
|
"{ c | camera | false | use camera }"
|
||||||
"{ f | file | 768x576.avi | input video file }"
|
"{ f | file | 768x576.avi | input video file }"
|
||||||
@ -26,7 +25,7 @@ int main(int argc, const char** argv)
|
|||||||
cout << "Usage : bgfg_segm [options]" << endl;
|
cout << "Usage : bgfg_segm [options]" << endl;
|
||||||
cout << "Available options:" << endl;
|
cout << "Available options:" << endl;
|
||||||
cmd.printParams();
|
cmd.printParams();
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool useCamera = cmd.get<bool>("camera");
|
bool useCamera = cmd.get<bool>("camera");
|
||||||
@ -36,13 +35,12 @@ int main(int argc, const char** argv)
|
|||||||
if (method != "mog" && method != "mog2")
|
if (method != "mog" && method != "mog2")
|
||||||
{
|
{
|
||||||
cerr << "Incorrect method" << endl;
|
cerr << "Incorrect method" << endl;
|
||||||
return -1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m = method == "mog" ? M_MOG : M_MOG2;
|
int m = method == "mog" ? M_MOG : M_MOG2;
|
||||||
|
|
||||||
VideoCapture cap;
|
VideoCapture cap;
|
||||||
|
|
||||||
if (useCamera)
|
if (useCamera)
|
||||||
cap.open(0);
|
cap.open(0);
|
||||||
else
|
else
|
||||||
@ -50,8 +48,8 @@ int main(int argc, const char** argv)
|
|||||||
|
|
||||||
if (!cap.isOpened())
|
if (!cap.isOpened())
|
||||||
{
|
{
|
||||||
cerr << "can not open camera or video file" << endl;
|
cout << "can not open camera or video file" << endl;
|
||||||
return -1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat frame;
|
Mat frame;
|
||||||
@ -62,15 +60,11 @@ int main(int argc, const char** argv)
|
|||||||
cv::ocl::MOG mog;
|
cv::ocl::MOG mog;
|
||||||
cv::ocl::MOG2 mog2;
|
cv::ocl::MOG2 mog2;
|
||||||
|
|
||||||
oclMat d_fgmask;
|
oclMat d_fgmask, d_fgimg, d_bgimg;
|
||||||
oclMat d_fgimg;
|
|
||||||
oclMat d_bgimg;
|
|
||||||
|
|
||||||
d_fgimg.create(d_frame.size(), d_frame.type());
|
d_fgimg.create(d_frame.size(), d_frame.type());
|
||||||
|
|
||||||
Mat fgmask;
|
Mat fgmask, fgimg, bgimg;
|
||||||
Mat fgimg;
|
|
||||||
Mat bgimg;
|
|
||||||
|
|
||||||
switch (m)
|
switch (m)
|
||||||
{
|
{
|
||||||
@ -83,7 +77,7 @@ int main(int argc, const char** argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
cap >> frame;
|
cap >> frame;
|
||||||
if (frame.empty())
|
if (frame.empty())
|
||||||
@ -123,10 +117,9 @@ int main(int argc, const char** argv)
|
|||||||
if (!bgimg.empty())
|
if (!bgimg.empty())
|
||||||
imshow("mean background image", bgimg);
|
imshow("mean background image", bgimg);
|
||||||
|
|
||||||
int key = waitKey(30);
|
if (27 == waitKey(30))
|
||||||
if (key == 27)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,13 @@ using namespace std;
|
|||||||
Ptr<CLAHE> pFilter;
|
Ptr<CLAHE> pFilter;
|
||||||
int tilesize;
|
int tilesize;
|
||||||
int cliplimit;
|
int cliplimit;
|
||||||
string outfile;
|
|
||||||
|
|
||||||
static void TSize_Callback(int pos)
|
static void TSize_Callback(int pos)
|
||||||
{
|
{
|
||||||
if(pos==0)
|
if(pos==0)
|
||||||
{
|
|
||||||
pFilter->setTilesGridSize(Size(1,1));
|
pFilter->setTilesGridSize(Size(1,1));
|
||||||
}
|
else
|
||||||
pFilter->setTilesGridSize(Size(tilesize,tilesize));
|
pFilter->setTilesGridSize(Size(tilesize,tilesize));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Clip_Callback(int)
|
static void Clip_Callback(int)
|
||||||
@ -31,63 +29,64 @@ int main(int argc, char** argv)
|
|||||||
"{ i | input | | specify input image }"
|
"{ i | input | | specify input image }"
|
||||||
"{ c | camera | 0 | specify camera id }"
|
"{ c | camera | 0 | specify camera id }"
|
||||||
"{ s | use_cpu | false | use cpu algorithm }"
|
"{ 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 }";
|
||||||
|
|
||||||
CommandLineParser cmd(argc, argv, keys);
|
cv::CommandLineParser cmd(argc, argv, keys);
|
||||||
string infile = cmd.get<string>("i");
|
if (cmd.get<bool>("help"))
|
||||||
outfile = cmd.get<string>("o");
|
{
|
||||||
|
cout << "Usage : clahe [options]" << endl;
|
||||||
|
cout << "Available options:" << endl;
|
||||||
|
cmd.printParams();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
string infile = cmd.get<string>("i"), outfile = cmd.get<string>("o");
|
||||||
int camid = cmd.get<int>("c");
|
int camid = cmd.get<int>("c");
|
||||||
bool use_cpu = cmd.get<bool>("s");
|
bool use_cpu = cmd.get<bool>("s");
|
||||||
CvCapture* capture = 0;
|
CvCapture* capture = 0;
|
||||||
bool running = true;
|
|
||||||
|
|
||||||
namedWindow("CLAHE");
|
namedWindow("CLAHE");
|
||||||
createTrackbar("Tile Size", "CLAHE", &tilesize, 32, (TrackbarCallback)TSize_Callback);
|
createTrackbar("Tile Size", "CLAHE", &tilesize, 32, (TrackbarCallback)TSize_Callback);
|
||||||
createTrackbar("Clip Limit", "CLAHE", &cliplimit, 20, (TrackbarCallback)Clip_Callback);
|
createTrackbar("Clip Limit", "CLAHE", &cliplimit, 20, (TrackbarCallback)Clip_Callback);
|
||||||
|
|
||||||
Mat frame, outframe;
|
Mat frame, outframe;
|
||||||
ocl::oclMat d_outframe;
|
ocl::oclMat d_outframe, d_frame;
|
||||||
|
|
||||||
int cur_clip;
|
int cur_clip;
|
||||||
Size cur_tilesize;
|
Size cur_tilesize;
|
||||||
if(use_cpu)
|
pFilter = use_cpu ? createCLAHE() : ocl::createCLAHE();
|
||||||
{
|
|
||||||
pFilter = createCLAHE();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pFilter = ocl::createCLAHE();
|
|
||||||
}
|
|
||||||
cur_clip = (int)pFilter->getClipLimit();
|
cur_clip = (int)pFilter->getClipLimit();
|
||||||
cur_tilesize = pFilter->getTilesGridSize();
|
cur_tilesize = pFilter->getTilesGridSize();
|
||||||
setTrackbarPos("Tile Size", "CLAHE", cur_tilesize.width);
|
setTrackbarPos("Tile Size", "CLAHE", cur_tilesize.width);
|
||||||
setTrackbarPos("Clip Limit", "CLAHE", cur_clip);
|
setTrackbarPos("Clip Limit", "CLAHE", cur_clip);
|
||||||
|
|
||||||
if(infile != "")
|
if(infile != "")
|
||||||
{
|
{
|
||||||
frame = imread(infile);
|
frame = imread(infile);
|
||||||
if(frame.empty())
|
if(frame.empty())
|
||||||
{
|
{
|
||||||
cout << "error read image: " << infile << endl;
|
cout << "error read image: " << infile << endl;
|
||||||
return -1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
capture = cvCaptureFromCAM(camid);
|
capture = cvCaptureFromCAM(camid);
|
||||||
}
|
|
||||||
cout << "\nControls:\n"
|
cout << "\nControls:\n"
|
||||||
<< "\to - save output image\n"
|
<< "\to - save output image\n"
|
||||||
<< "\tESC - exit\n";
|
<< "\tESC - exit\n";
|
||||||
while(running)
|
|
||||||
|
for (;;)
|
||||||
{
|
{
|
||||||
if(capture)
|
if(capture)
|
||||||
frame = cvQueryFrame(capture);
|
frame = cvQueryFrame(capture);
|
||||||
else
|
else
|
||||||
frame = imread(infile);
|
frame = imread(infile);
|
||||||
if(frame.empty())
|
if(frame.empty())
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if(use_cpu)
|
if(use_cpu)
|
||||||
{
|
{
|
||||||
cvtColor(frame, frame, COLOR_BGR2GRAY);
|
cvtColor(frame, frame, COLOR_BGR2GRAY);
|
||||||
@ -95,15 +94,18 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ocl::oclMat d_frame(frame);
|
ocl::cvtColor(d_frame = frame, d_outframe, COLOR_BGR2GRAY);
|
||||||
ocl::cvtColor(d_frame, d_outframe, COLOR_BGR2GRAY);
|
|
||||||
pFilter->apply(d_outframe, d_outframe);
|
pFilter->apply(d_outframe, d_outframe);
|
||||||
d_outframe.download(outframe);
|
d_outframe.download(outframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
imshow("CLAHE", outframe);
|
imshow("CLAHE", outframe);
|
||||||
|
|
||||||
char key = (char)cvWaitKey(3);
|
char key = (char)cvWaitKey(3);
|
||||||
if(key == 'o') imwrite(outfile, outframe);
|
if(key == 'o')
|
||||||
else if(key == 27) running = false;
|
imwrite(outfile, outframe);
|
||||||
|
else if(key == 27)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -28,27 +28,29 @@ static void workBegin()
|
|||||||
{
|
{
|
||||||
work_begin = getTickCount();
|
work_begin = getTickCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void workEnd()
|
static void workEnd()
|
||||||
{
|
{
|
||||||
work_end += (getTickCount() - work_begin);
|
work_end += (getTickCount() - work_begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double getTime()
|
static double getTime()
|
||||||
{
|
{
|
||||||
return work_end /((double)cvGetTickFrequency() * 1000.);
|
return work_end /((double)cvGetTickFrequency() * 1000.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void detect( Mat& img, vector<Rect>& faces,
|
static void detect( Mat& img, vector<Rect>& faces,
|
||||||
ocl::OclCascadeClassifierBuf& cascade,
|
ocl::OclCascadeClassifierBuf& cascade,
|
||||||
double scale, bool calTime);
|
double scale, bool calTime);
|
||||||
|
|
||||||
|
|
||||||
void detectCPU( Mat& img, vector<Rect>& faces,
|
static void detectCPU( Mat& img, vector<Rect>& faces,
|
||||||
CascadeClassifier& cascade,
|
CascadeClassifier& cascade,
|
||||||
double scale, bool calTime);
|
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.
|
// This function test if gpu_rst matches cpu_rst.
|
||||||
@ -56,7 +58,6 @@ void Draw(Mat& img, vector<Rect>& faces, double scale);
|
|||||||
// Else if will return (total diff of each cpu and gpu rects covered pixels)/(total cpu rects covered pixels)
|
// 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);
|
double checkRectSimilarity(Size sz, vector<Rect>& cpu_rst, vector<Rect>& gpu_rst);
|
||||||
|
|
||||||
|
|
||||||
int main( int argc, const char** argv )
|
int main( int argc, const char** argv )
|
||||||
{
|
{
|
||||||
const char* keys =
|
const char* keys =
|
||||||
@ -72,10 +73,12 @@ int main( int argc, const char** argv )
|
|||||||
CommandLineParser cmd(argc, argv, keys);
|
CommandLineParser cmd(argc, argv, keys);
|
||||||
if (cmd.get<bool>("help"))
|
if (cmd.get<bool>("help"))
|
||||||
{
|
{
|
||||||
|
cout << "Usage : facedetect [options]" << endl;
|
||||||
cout << "Available options:" << endl;
|
cout << "Available options:" << endl;
|
||||||
cmd.printParams();
|
cmd.printParams();
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CvCapture* capture = 0;
|
CvCapture* capture = 0;
|
||||||
Mat frame, frameCopy, image;
|
Mat frame, frameCopy, image;
|
||||||
|
|
||||||
@ -89,8 +92,8 @@ int main( int argc, const char** argv )
|
|||||||
|
|
||||||
if( !cascade.load( cascadeName ) || !cpu_cascade.load(cascadeName) )
|
if( !cascade.load( cascadeName ) || !cpu_cascade.load(cascadeName) )
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Could not load classifier cascade" << endl;
|
cout << "ERROR: Could not load classifier cascade" << endl;
|
||||||
return -1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( inputName.empty() )
|
if( inputName.empty() )
|
||||||
@ -99,25 +102,17 @@ int main( int argc, const char** argv )
|
|||||||
if(!capture)
|
if(!capture)
|
||||||
cout << "Capture from CAM 0 didn't work" << endl;
|
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() )
|
if( image.empty() )
|
||||||
{
|
{
|
||||||
capture = cvCaptureFromAVI( inputName.c_str() );
|
capture = cvCaptureFromAVI( inputName.c_str() );
|
||||||
if(!capture)
|
if(!capture)
|
||||||
cout << "Capture from AVI didn't work" << endl;
|
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 );
|
cvNamedWindow( "result", 1 );
|
||||||
if( capture )
|
if( capture )
|
||||||
@ -134,24 +129,16 @@ int main( int argc, const char** argv )
|
|||||||
frame.copyTo( frameCopy );
|
frame.copyTo( frameCopy );
|
||||||
else
|
else
|
||||||
flip( frame, frameCopy, 0 );
|
flip( frame, frameCopy, 0 );
|
||||||
|
|
||||||
if(useCPU)
|
if(useCPU)
|
||||||
{
|
|
||||||
detectCPU(frameCopy, faces, cpu_cascade, scale, false);
|
detectCPU(frameCopy, faces, cpu_cascade, scale, false);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
detect(frameCopy, faces, cascade, scale, false);
|
detect(frameCopy, faces, cascade, scale, false);
|
||||||
}
|
|
||||||
Draw(frameCopy, faces, scale);
|
Draw(frameCopy, faces, scale);
|
||||||
if( waitKey( 10 ) >= 0 )
|
if( waitKey( 10 ) >= 0 )
|
||||||
goto _cleanup_;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
waitKey(0);
|
|
||||||
|
|
||||||
|
|
||||||
_cleanup_:
|
|
||||||
cvReleaseCapture( &capture );
|
cvReleaseCapture( &capture );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -164,9 +151,7 @@ _cleanup_:
|
|||||||
{
|
{
|
||||||
cout << "loop" << i << endl;
|
cout << "loop" << i << endl;
|
||||||
if(useCPU)
|
if(useCPU)
|
||||||
{
|
|
||||||
detectCPU(image, faces, cpu_cascade, scale, i==0?false:true);
|
detectCPU(image, faces, cpu_cascade, scale, i==0?false:true);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
detect(image, faces, cascade, scale, i==0?false:true);
|
detect(image, faces, cascade, scale, i==0?false:true);
|
||||||
|
@ -72,6 +72,14 @@ int main(int argc, char** argv)
|
|||||||
"{ l |larger_win| false | use 64x128 window}"
|
"{ l |larger_win| false | use 64x128 window}"
|
||||||
"{ o | output | | specify output path when input is images}";
|
"{ o | output | | specify output path when input is images}";
|
||||||
CommandLineParser cmd(argc, argv, keys);
|
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);
|
App app(cmd);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -89,7 +97,7 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
return cout << "unknown exception" << endl, 1;
|
return cout << "unknown exception" << endl, 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
App::App(CommandLineParser& cmd)
|
App::App(CommandLineParser& cmd)
|
||||||
|
@ -44,7 +44,8 @@ static void download(const oclMat& d_mat, vector<uchar>& vec)
|
|||||||
d_mat.download(mat);
|
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)
|
for (size_t i = 0; i < prevPts.size(); ++i)
|
||||||
{
|
{
|
||||||
@ -104,7 +105,7 @@ int main(int argc, const char* argv[])
|
|||||||
cout << "Usage: pyrlk_optical_flow [options]" << endl;
|
cout << "Usage: pyrlk_optical_flow [options]" << endl;
|
||||||
cout << "Available options:" << endl;
|
cout << "Available options:" << endl;
|
||||||
cmd.printParams();
|
cmd.printParams();
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool defaultPicturesFail = false;
|
bool defaultPicturesFail = false;
|
||||||
@ -136,7 +137,7 @@ int main(int argc, const char* argv[])
|
|||||||
Mat frame0Gray, frame1Gray;
|
Mat frame0Gray, frame1Gray;
|
||||||
Mat ptr0, ptr1;
|
Mat ptr0, ptr1;
|
||||||
|
|
||||||
if(vdofile == "")
|
if(vdofile.empty())
|
||||||
capture = cvCaptureFromCAM( inputName );
|
capture = cvCaptureFromCAM( inputName );
|
||||||
else
|
else
|
||||||
capture = cvCreateFileCapture(vdofile.c_str());
|
capture = cvCreateFileCapture(vdofile.c_str());
|
||||||
@ -144,14 +145,12 @@ int main(int argc, const char* argv[])
|
|||||||
int c = inputName ;
|
int c = inputName ;
|
||||||
if(!capture)
|
if(!capture)
|
||||||
{
|
{
|
||||||
if(vdofile == "")
|
if(vdofile.empty())
|
||||||
cout << "Capture from CAM " << c << " didn't work" << endl;
|
cout << "Capture from CAM " << c << " didn't work" << endl;
|
||||||
else
|
else
|
||||||
cout << "Capture from file " << vdofile << " failed" <<endl;
|
cout << "Capture from file " << vdofile << " failed" <<endl;
|
||||||
if (defaultPicturesFail)
|
if (defaultPicturesFail)
|
||||||
{
|
return EXIT_FAILURE;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
goto nocamera;
|
goto nocamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,12 +211,9 @@ int main(int argc, const char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( waitKey( 10 ) >= 0 )
|
if( waitKey( 10 ) >= 0 )
|
||||||
goto _cleanup_;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
waitKey(0);
|
|
||||||
|
|
||||||
_cleanup_:
|
|
||||||
cvReleaseCapture( &capture );
|
cvReleaseCapture( &capture );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -264,5 +260,5 @@ nocamera:
|
|||||||
|
|
||||||
waitKey();
|
waitKey();
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
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
|
// check if two vectors of vector of points are near or not
|
||||||
// prior assumption is that they are in correct order
|
// prior assumption is that they are in correct order
|
||||||
static bool checkPoints(
|
static bool checkPoints(
|
||||||
@ -278,27 +278,31 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
const char* keys =
|
const char* keys =
|
||||||
"{ i | input | | specify input image }"
|
"{ 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);
|
CommandLineParser cmd(argc, argv, keys);
|
||||||
string inputName = cmd.get<string>("i");
|
string inputName = cmd.get<string>("i");
|
||||||
string outfile = cmd.get<string>("o");
|
string outfile = cmd.get<string>("o");
|
||||||
if(inputName.empty())
|
|
||||||
|
if(cmd.get<bool>("help"))
|
||||||
{
|
{
|
||||||
|
cout << "Usage : squares [options]" << endl;
|
||||||
cout << "Available options:" << endl;
|
cout << "Available options:" << endl;
|
||||||
cmd.printParams();
|
cmd.printParams();
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int iterations = 10;
|
int iterations = 10;
|
||||||
namedWindow( wndname, 1 );
|
namedWindow( wndname, CV_LOAD_IMAGE_COLOR );
|
||||||
vector<vector<Point> > squares_cpu, squares_ocl;
|
vector<vector<Point> > squares_cpu, squares_ocl;
|
||||||
|
|
||||||
Mat image = imread(inputName, 1);
|
Mat image = imread(inputName, 1);
|
||||||
if( image.empty() )
|
if( image.empty() )
|
||||||
{
|
{
|
||||||
cout << "Couldn't load " << inputName << endl;
|
cout << "Couldn't load " << inputName << endl;
|
||||||
return -1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int j = iterations;
|
int j = iterations;
|
||||||
int64 t_ocl = 0, t_cpp = 0;
|
int64 t_ocl = 0, t_cpp = 0;
|
||||||
//warm-ups
|
//warm-ups
|
||||||
@ -307,7 +311,7 @@ int main(int argc, char** argv)
|
|||||||
findSquares_ocl(image, squares_ocl);
|
findSquares_ocl(image, squares_ocl);
|
||||||
|
|
||||||
|
|
||||||
#if ACCURACY_CHECK
|
#ifdef ACCURACY_CHECK
|
||||||
cout << "Checking ocl accuracy ... " << endl;
|
cout << "Checking ocl accuracy ... " << endl;
|
||||||
cout << (checkPoints(squares_cpu, squares_ocl) ? "Pass" : "Failed") << endl;
|
cout << (checkPoints(squares_cpu, squares_ocl) ? "Pass" : "Failed") << endl;
|
||||||
#endif
|
#endif
|
||||||
@ -332,5 +336,5 @@ int main(int argc, char** argv)
|
|||||||
imwrite(outfile, result);
|
imwrite(outfile, result);
|
||||||
cvWaitKey(0);
|
cvWaitKey(0);
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,9 @@ int main(int argc, char** argv)
|
|||||||
"{ l | left | | specify left image }"
|
"{ l | left | | specify left image }"
|
||||||
"{ r | right | | specify right image }"
|
"{ r | right | | specify right image }"
|
||||||
"{ m | method | BM | specify match method(BM/BP/CSBP) }"
|
"{ 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}";
|
"{ o | output | stereo_match_output.jpg | specify output path when input is images}";
|
||||||
|
|
||||||
CommandLineParser cmd(argc, argv, keys);
|
CommandLineParser cmd(argc, argv, keys);
|
||||||
if (cmd.get<bool>("help"))
|
if (cmd.get<bool>("help"))
|
||||||
{
|
{
|
||||||
@ -85,6 +86,7 @@ int main(int argc, char** argv)
|
|||||||
cmd.printParams();
|
cmd.printParams();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
App app(cmd);
|
App app(cmd);
|
||||||
@ -96,7 +98,8 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
cout << "error: " << e.what() << endl;
|
cout << "error: " << e.what() << endl;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
App::App(CommandLineParser& cmd)
|
App::App(CommandLineParser& cmd)
|
||||||
@ -114,6 +117,7 @@ App::App(CommandLineParser& cmd)
|
|||||||
<< "\t2/w - increase/decrease window size (for BM only)\n"
|
<< "\t2/w - increase/decrease window size (for BM only)\n"
|
||||||
<< "\t3/e - increase/decrease iteration count (for BP and CSBP 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";
|
<< "\t4/r - increase/decrease level count (for BP and CSBP only)\n";
|
||||||
|
|
||||||
l_img = cmd.get<string>("l");
|
l_img = cmd.get<string>("l");
|
||||||
r_img = cmd.get<string>("r");
|
r_img = cmd.get<string>("r");
|
||||||
string mstr = cmd.get<string>("m");
|
string mstr = cmd.get<string>("m");
|
||||||
|
@ -14,21 +14,20 @@ const int LOOP_NUM = 10;
|
|||||||
const int GOOD_PTS_MAX = 50;
|
const int GOOD_PTS_MAX = 50;
|
||||||
const float GOOD_PORTION = 0.15f;
|
const float GOOD_PORTION = 0.15f;
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
|
|
||||||
int64 work_begin = 0;
|
int64 work_begin = 0;
|
||||||
int64 work_end = 0;
|
int64 work_end = 0;
|
||||||
|
|
||||||
void workBegin()
|
static void workBegin()
|
||||||
{
|
{
|
||||||
work_begin = getTickCount();
|
work_begin = getTickCount();
|
||||||
}
|
}
|
||||||
void workEnd()
|
|
||||||
|
static void workEnd()
|
||||||
{
|
{
|
||||||
work_end = getTickCount() - work_begin;
|
work_end = getTickCount() - work_begin;
|
||||||
}
|
}
|
||||||
double getTime()
|
|
||||||
|
static double getTime()
|
||||||
{
|
{
|
||||||
return work_end /((double)cvGetTickFrequency() * 1000.);
|
return work_end /((double)cvGetTickFrequency() * 1000.);
|
||||||
}
|
}
|
||||||
@ -59,7 +58,7 @@ struct SURFMatcher
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Mat drawGoodMatches(
|
static Mat drawGoodMatches(
|
||||||
const Mat& cpu_img1,
|
const Mat& cpu_img1,
|
||||||
const Mat& cpu_img2,
|
const Mat& cpu_img2,
|
||||||
const vector<KeyPoint>& keypoints1,
|
const vector<KeyPoint>& keypoints1,
|
||||||
@ -129,7 +128,6 @@ Mat drawGoodMatches(
|
|||||||
return img_matches;
|
return img_matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// This program demonstrates the usage of SURF_OCL.
|
// This program demonstrates the usage of SURF_OCL.
|
||||||
// use cpu findHomography interface to calculate the transformation matrix
|
// use cpu findHomography interface to calculate the transformation matrix
|
||||||
@ -142,12 +140,14 @@ int main(int argc, char* argv[])
|
|||||||
"{ o | output | SURF_output.jpg | specify output save path (only works in CPU or GPU only mode) }"
|
"{ o | output | SURF_output.jpg | specify output save path (only works in CPU or GPU only mode) }"
|
||||||
"{ c | use_cpu | false | use CPU algorithms }"
|
"{ c | use_cpu | false | use CPU algorithms }"
|
||||||
"{ a | use_all | false | use both CPU and GPU algorithms}";
|
"{ a | use_all | false | use both CPU and GPU algorithms}";
|
||||||
|
|
||||||
CommandLineParser cmd(argc, argv, keys);
|
CommandLineParser cmd(argc, argv, keys);
|
||||||
if (cmd.get<bool>("help"))
|
if (cmd.get<bool>("help"))
|
||||||
{
|
{
|
||||||
|
std::cout << "Usage: surf_matcher [options]" << std::endl;
|
||||||
std::cout << "Available options:" << std::endl;
|
std::cout << "Available options:" << std::endl;
|
||||||
cmd.printParams();
|
cmd.printParams();
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat cpu_img1, cpu_img2, cpu_img1_grey, cpu_img2_grey;
|
Mat cpu_img1, cpu_img2, cpu_img1_grey, cpu_img2_grey;
|
||||||
@ -168,23 +168,17 @@ int main(int argc, char* argv[])
|
|||||||
cvtColor(cpu_img2, cpu_img2_grey, CV_BGR2GRAY);
|
cvtColor(cpu_img2, cpu_img2_grey, CV_BGR2GRAY);
|
||||||
img2 = cpu_img2_grey;
|
img2 = cpu_img2_grey;
|
||||||
|
|
||||||
if(useALL)
|
if (useALL)
|
||||||
{
|
useCPU = useGPU = false;
|
||||||
useCPU = false;
|
else if(!useCPU && !useALL)
|
||||||
useGPU = false;
|
|
||||||
}
|
|
||||||
else if(useCPU==false && useALL==false)
|
|
||||||
{
|
|
||||||
useGPU = true;
|
useGPU = true;
|
||||||
}
|
|
||||||
|
|
||||||
if(!useCPU)
|
if(!useCPU)
|
||||||
{
|
|
||||||
std::cout
|
std::cout
|
||||||
<< "Device name:"
|
<< "Device name:"
|
||||||
<< cv::ocl::Context::getContext()->getDeviceInfo().deviceName
|
<< cv::ocl::Context::getContext()->getDeviceInfo().deviceName
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
|
||||||
double surf_time = 0.;
|
double surf_time = 0.;
|
||||||
|
|
||||||
//declare input/output
|
//declare input/output
|
||||||
@ -330,5 +324,5 @@ int main(int argc, char* argv[])
|
|||||||
imshow("ocl surf matches", ocl_img_matches);
|
imshow("ocl surf matches", ocl_img_matches);
|
||||||
}
|
}
|
||||||
waitKey(0);
|
waitKey(0);
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,9 @@ int main(int argc, const char* argv[])
|
|||||||
cout << "Usage: pyrlk_optical_flow [options]" << endl;
|
cout << "Usage: pyrlk_optical_flow [options]" << endl;
|
||||||
cout << "Available options:" << endl;
|
cout << "Available options:" << endl;
|
||||||
cmd.printParams();
|
cmd.printParams();
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool defaultPicturesFail = false;
|
|
||||||
string fname0 = cmd.get<string>("l");
|
string fname0 = cmd.get<string>("l");
|
||||||
string fname1 = cmd.get<string>("r");
|
string fname1 = cmd.get<string>("r");
|
||||||
string vdofile = cmd.get<string>("v");
|
string vdofile = cmd.get<string>("v");
|
||||||
@ -113,22 +112,10 @@ int main(int argc, const char* argv[])
|
|||||||
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1();
|
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1();
|
||||||
cv::ocl::OpticalFlowDual_TVL1_OCL d_alg;
|
cv::ocl::OpticalFlowDual_TVL1_OCL d_alg;
|
||||||
|
|
||||||
|
|
||||||
Mat flow, show_flow;
|
Mat flow, show_flow;
|
||||||
Mat flow_vec[2];
|
Mat flow_vec[2];
|
||||||
if (frame0.empty() || frame1.empty())
|
if (frame0.empty() || frame1.empty())
|
||||||
{
|
|
||||||
useCamera = true;
|
useCamera = true;
|
||||||
defaultPicturesFail = true;
|
|
||||||
CvCapture* capture = 0;
|
|
||||||
capture = cvCaptureFromCAM( inputName );
|
|
||||||
if (!capture)
|
|
||||||
{
|
|
||||||
cout << "Can't load input images" << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (useCamera)
|
if (useCamera)
|
||||||
{
|
{
|
||||||
@ -137,22 +124,17 @@ int main(int argc, const char* argv[])
|
|||||||
Mat frame0Gray, frame1Gray;
|
Mat frame0Gray, frame1Gray;
|
||||||
Mat ptr0, ptr1;
|
Mat ptr0, ptr1;
|
||||||
|
|
||||||
if(vdofile == "")
|
if(vdofile.empty())
|
||||||
capture = cvCaptureFromCAM( inputName );
|
capture = cvCaptureFromCAM( inputName );
|
||||||
else
|
else
|
||||||
capture = cvCreateFileCapture(vdofile.c_str());
|
capture = cvCreateFileCapture(vdofile.c_str());
|
||||||
|
|
||||||
int c = inputName ;
|
|
||||||
if(!capture)
|
if(!capture)
|
||||||
{
|
{
|
||||||
if(vdofile == "")
|
if(vdofile.empty())
|
||||||
cout << "Capture from CAM " << c << " didn't work" << endl;
|
cout << "Capture from CAM " << inputName << " didn't work" << endl;
|
||||||
else
|
else
|
||||||
cout << "Capture from file " << vdofile << " failed" <<endl;
|
cout << "Capture from file " << vdofile << " failed" <<endl;
|
||||||
if (defaultPicturesFail)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
goto nocamera;
|
goto nocamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,12 +188,9 @@ int main(int argc, const char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( waitKey( 10 ) >= 0 )
|
if( waitKey( 10 ) >= 0 )
|
||||||
goto _cleanup_;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
waitKey(0);
|
|
||||||
|
|
||||||
_cleanup_:
|
|
||||||
cvReleaseCapture( &capture );
|
cvReleaseCapture( &capture );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -254,5 +233,5 @@ nocamera:
|
|||||||
|
|
||||||
waitKey();
|
waitKey();
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user