Merge remote-tracking branch 'origin/2.4' into merge-2.4

Conflicts:
	CMakeLists.txt
	modules/calib3d/src/calibration.cpp
	modules/ocl/src/cl_programcache.cpp
	modules/ocl/src/filtering.cpp
	modules/ocl/src/imgproc.cpp
	samples/ocl/adaptive_bilateral_filter.cpp
	samples/ocl/bgfg_segm.cpp
	samples/ocl/clahe.cpp
	samples/ocl/facedetect.cpp
	samples/ocl/pyrlk_optical_flow.cpp
	samples/ocl/squares.cpp
	samples/ocl/surf_matcher.cpp
	samples/ocl/tvl1_optical_flow.cpp
This commit is contained in:
Roman Donchenko
2013-10-28 13:38:25 +04:00
182 changed files with 894 additions and 1088 deletions
+5 -1
View File
@@ -222,7 +222,11 @@ int main(int argc, const char* argv[])
if(useOcl)
{
MEASURE_TIME(superRes->nextFrame(result_));
MEASURE_TIME(
{
superRes->nextFrame(result_);
ocl::finish();
});
}
else
#endif
+18 -13
View File
@@ -13,17 +13,27 @@ int main( int argc, const char** argv )
{
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.has("help"))
{
cout << "Usage : adaptive_bilateral_filter [options]" << endl;
cout << "Available options:" << endl;
cmd.printMessage();
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;
@@ -33,17 +43,12 @@ int main( int argc, const char** argv )
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;
}
+10 -17
View File
@@ -15,19 +15,18 @@ using namespace cv::ocl;
int main(int argc, const char** argv)
{
cv::CommandLineParser cmd(argc, argv,
"{ c camera | false | use camera }"
"{ f file | 768x576.avi | input video file }"
"{ m method | mog | method (mog, mog2) }"
"{ h help | false | print help message }");
if (cmd.get<bool>("help"))
if (cmd.has("help"))
{
cout << "Usage : bgfg_segm [options]" << endl;
cout << "Available options:" << endl;
cmd.printMessage();
return 0;
return EXIT_SUCCESS;
}
bool useCamera = cmd.get<bool>("camera");
@@ -37,13 +36,12 @@ int main(int argc, const char** argv)
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
@@ -51,8 +49,8 @@ int main(int argc, const char** argv)
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;
@@ -63,15 +61,11 @@ int main(int argc, const char** argv)
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)
{
@@ -84,7 +78,7 @@ int main(int argc, const char** argv)
break;
}
for(;;)
for (;;)
{
cap >> frame;
if (frame.empty())
@@ -124,10 +118,9 @@ int main(int argc, const char** argv)
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;
}
+31 -29
View File
@@ -10,15 +10,13 @@ using namespace std;
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)
@@ -32,63 +30,64 @@ int main(int argc, char** argv)
"{ 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 }";
CommandLineParser cmd(argc, argv, keys);
string infile = cmd.get<string>("i");
outfile = cmd.get<string>("o");
cv::CommandLineParser cmd(argc, argv, keys);
if (cmd.has("help"))
{
cout << "Usage : clahe [options]" << endl;
cout << "Available options:" << endl;
cmd.printMessage();
return EXIT_SUCCESS;
}
string infile = cmd.get<string>("i"), outfile = cmd.get<string>("o");
int camid = cmd.get<int>("c");
bool use_cpu = cmd.get<bool>("s");
VideoCapture capture;
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.open(camid);
}
cout << "\nControls:\n"
<< "\to - save output image\n"
<< "\tESC - exit\n";
while(running)
for (;;)
{
if(capture.isOpened())
capture.read(frame);
else
frame = imread(infile);
if(frame.empty())
{
continue;
}
if(use_cpu)
{
cvtColor(frame, frame, COLOR_BGR2GRAY);
@@ -96,15 +95,18 @@ int main(int argc, char** argv)
}
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)waitKey(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;
}
+16 -31
View File
@@ -32,6 +32,7 @@ static void workBegin()
{
work_begin = getTickCount();
}
static void workEnd()
{
work_end += (getTickCount() - work_begin);
@@ -42,16 +43,17 @@ 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::OclCascadeClassifier& 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.
@@ -59,7 +61,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)
double checkRectSimilarity(Size sz, vector<Rect>& cpu_rst, vector<Rect>& gpu_rst);
int main( int argc, const char** argv )
{
const char* keys =
@@ -75,10 +76,12 @@ int main( int argc, const char** argv )
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
{
cout << "Usage : facedetect [options]" << endl;
cout << "Available options:" << endl;
cmd.printMessage();
return 0;
return EXIT_SUCCESS;
}
CvCapture* capture = 0;
Mat frame, frameCopy, image;
@@ -92,8 +95,8 @@ int main( int argc, const char** argv )
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() )
@@ -102,25 +105,17 @@ int main( int argc, const char** argv )
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 )
@@ -137,24 +132,16 @@ int main( int argc, const char** argv )
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
@@ -167,9 +154,7 @@ _cleanup_:
{
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);
+9 -1
View File
@@ -73,6 +73,14 @@ int main(int argc, char** argv)
"{ l |larger_win| false | use 64x128 window}"
"{ o | output | | specify output path when input is images}";
CommandLineParser cmd(argc, argv, keys);
if (cmd.has("help"))
{
cout << "Usage : hog [options]" << endl;
cout << "Available options:" << endl;
cmd.printMessage();
return EXIT_SUCCESS;
}
App app(cmd);
try
{
@@ -90,7 +98,7 @@ int main(int argc, char** argv)
{
return cout << "unknown exception" << endl, 1;
}
return 0;
return EXIT_SUCCESS;
}
App::App(CommandLineParser& cmd)
+8 -12
View File
@@ -45,7 +45,8 @@ static void download(const oclMat& d_mat, vector<uchar>& vec)
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)
{
@@ -105,7 +106,7 @@ int main(int argc, const char* argv[])
cout << "Usage: pyrlk_optical_flow [options]" << endl;
cout << "Available options:" << endl;
cmd.printMessage();
return 0;
return EXIT_SUCCESS;
}
bool defaultPicturesFail = false;
@@ -137,7 +138,7 @@ int main(int argc, const char* argv[])
Mat frame0Gray, frame1Gray;
Mat ptr0, ptr1;
if(vdofile == "")
if(vdofile.empty())
capture.open( inputName );
else
capture.open(vdofile.c_str());
@@ -145,14 +146,12 @@ int main(int argc, const char* argv[])
int c = inputName ;
if(!capture.isOpened())
{
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;
}
@@ -212,12 +211,9 @@ int main(int argc, const char* argv[])
}
if( waitKey( 10 ) >= 0 )
goto _cleanup_;
break;
}
waitKey(0);
_cleanup_:
capture.release();
}
else
@@ -264,5 +260,5 @@ nocamera:
waitKey();
return 0;
return EXIT_SUCCESS;
}
+13 -9
View File
@@ -14,9 +14,9 @@
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(
@@ -279,27 +279,31 @@ int main(int argc, char** argv)
{
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.printMessage();
return 0;
return EXIT_SUCCESS;
}
int iterations = 10;
namedWindow( wndname, 1 );
namedWindow( wndname, WINDOW_AUTOSIZE );
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
@@ -308,7 +312,7 @@ int main(int argc, char** argv)
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
@@ -333,5 +337,5 @@ int main(int argc, char** argv)
imwrite(outfile, result);
waitKey(0);
return 0;
return EXIT_SUCCESS;
}
+6 -2
View File
@@ -78,8 +78,9 @@ int main(int argc, char** argv)
"{ 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"))
{
@@ -87,6 +88,7 @@ int main(int argc, char** argv)
cmd.printMessage();
return 0;
}
try
{
App app(cmd);
@@ -98,7 +100,8 @@ int main(int argc, char** argv)
{
cout << "error: " << e.what() << endl;
}
return 0;
return EXIT_SUCCESS;
}
App::App(CommandLineParser& cmd)
@@ -116,6 +119,7 @@ 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");
+14 -20
View File
@@ -15,21 +15,20 @@ const int LOOP_NUM = 10;
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)getTickFrequency() * 1000.);
}
@@ -60,7 +59,7 @@ struct SURFMatcher
}
};
Mat drawGoodMatches(
static Mat drawGoodMatches(
const Mat& cpu_img1,
const Mat& cpu_img2,
const std::vector<KeyPoint>& keypoints1,
@@ -130,7 +129,6 @@ Mat drawGoodMatches(
return img_matches;
}
}
////////////////////////////////////////////////////
// This program demonstrates the usage of SURF_OCL.
// use cpu findHomography interface to calculate the transformation matrix
@@ -143,12 +141,14 @@ int main(int argc, char* argv[])
"{ output o | SURF_output.jpg | specify output save path (only works in CPU or GPU only mode) }"
"{ use_cpu c | false | use CPU algorithms }"
"{ use_all a | 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.printMessage();
return 0;
return EXIT_SUCCESS;
}
Mat cpu_img1, cpu_img2, cpu_img1_grey, cpu_img2_grey;
@@ -169,23 +169,17 @@ int main(int argc, char* argv[])
cvtColor(cpu_img2, cpu_img2_grey, COLOR_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
@@ -331,5 +325,5 @@ int main(int argc, char* argv[])
imshow("ocl surf matches", ocl_img_matches);
}
waitKey(0);
return 0;
return EXIT_SUCCESS;
}
+6 -26
View File
@@ -97,10 +97,9 @@ int main(int argc, const char* argv[])
cout << "Usage: pyrlk_optical_flow [options]" << endl;
cout << "Available options:" << endl;
cmd.printMessage();
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");
@@ -114,21 +113,10 @@ int main(int argc, const char* argv[])
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;
VideoCapture capture( inputName );
if (!capture.isOpened())
{
cout << "Can't load input images" << endl;
return -1;
}
}
if (useCamera)
{
@@ -137,22 +125,17 @@ int main(int argc, const char* argv[])
Mat frame0Gray, frame1Gray;
Mat ptr0, ptr1;
if(vdofile == "")
if(vdofile.empty())
capture.open( inputName );
else
capture.open(vdofile.c_str());
int c = inputName ;
if(!capture.isOpened())
{
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;
}
@@ -205,12 +188,9 @@ int main(int argc, const char* argv[])
}
if( waitKey( 10 ) >= 0 )
goto _cleanup_;
break;
}
waitKey(0);
_cleanup_:
capture.release();
}
else
@@ -253,5 +233,5 @@ nocamera:
waitKey();
return 0;
return EXIT_SUCCESS;
}