Merge branch 'master' of git://code.opencv.org/opencv

This commit is contained in:
Alexander Mordvintsev
2012-09-17 19:37:38 +04:00
222 changed files with 14836 additions and 8305 deletions

7
samples/android/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
bin/
gen/
build.xml
local.properties
proguard-project.txt
project.properties
default.properties

View File

@@ -72,9 +72,9 @@ static void help()
//
const char *keys =
{
"{nf|nframes |300 |frames number}"
"{c |camera |false |use the camera or not}"
"{mf|movie_file|tree.avi |used movie video file}"
"{nf nframes |300 |frames number}"
"{c camera |false |use the camera or not}"
"{mf movie_file|tree.avi |used movie video file}"
};
int main(int argc, const char** argv)
{
@@ -82,7 +82,7 @@ int main(int argc, const char** argv)
CommandLineParser parser(argc, argv, keys);
int nframesToLearnBG = parser.get<int>("nf");
bool useCamera = parser.get<bool>("c");
bool useCamera = parser.has("c");
string filename = parser.get<string>("mf");
IplImage* rawImage = 0, *yuvImage = 0; //yuvImage is for codebook method
IplImage *ImaskCodeBook = 0,*ImaskCodeBookCC = 0;

View File

@@ -18,8 +18,8 @@ static void help()
const char* keys =
{
"{c |camera |true | use camera or not}"
"{fn|file_name|tree.avi | movie file }"
"{c camera | | use camera or not}"
"{fn file_name|tree.avi | movie file }"
};
//this is a sample for foreground detection functions
@@ -28,7 +28,7 @@ int main(int argc, const char** argv)
help();
CommandLineParser parser(argc, argv, keys);
bool useCamera = parser.get<bool>("camera");
bool useCamera = parser.has("camera");
string file = parser.get<string>("file_name");
VideoCapture cap;
bool update_bg_model = true;
@@ -37,7 +37,8 @@ int main(int argc, const char** argv)
cap.open(0);
else
cap.open(file.c_str());
parser.printParams();
parser.printMessage();
if( !cap.isOpened() )
{

View File

@@ -53,8 +53,8 @@ static void help()
const char* keys =
{
"{1| |box.png |the first image}"
"{2| |box_in_scene.png|the second image}"
"{@first_image | box.png | the first image}"
"{@second_image | box_in_scene.png | the second image}"
};
int main(int argc, const char ** argv)
@@ -62,8 +62,8 @@ int main(int argc, const char ** argv)
help();
CommandLineParser parser(argc, argv, keys);
string im1_name = parser.get<string>("1");
string im2_name = parser.get<string>("2");
string im1_name = parser.get<string>(1);
string im2_name = parser.get<string>(2);
Mat im1 = imread(im1_name, CV_LOAD_IMAGE_GRAYSCALE);
Mat im2 = imread(im2_name, CV_LOAD_IMAGE_GRAYSCALE);
@@ -72,7 +72,7 @@ int main(int argc, const char ** argv)
{
cout << "could not open one of the images..." << endl;
cout << "the cmd parameters have next current value: " << endl;
parser.printParams();
parser.printMessage();
return 1;
}

View File

@@ -64,7 +64,7 @@ static void help()
const char* keys =
{
"{1| | 0 | camera number}"
"{@camera_number| 0 | camera number}"
};
int main( int argc, const char** argv )
@@ -77,7 +77,7 @@ int main( int argc, const char** argv )
float hranges[] = {0,180};
const float* phranges = hranges;
CommandLineParser parser(argc, argv, keys);
int camNum = parser.get<int>("1");
int camNum = parser.get<int>(1);
cap.open(camNum);
@@ -86,7 +86,7 @@ int main( int argc, const char** argv )
help();
cout << "***Could not initialize capturing...***\n";
cout << "Current parameter's value: \n";
parser.printParams();
parser.printMessage();
return -1;
}

View File

@@ -19,8 +19,8 @@ static void help()
const char* keys =
{
"{1| |logo_in_clutter.png|image edge map }"
"{2| |logo.png |template edge map}"
"{@logo1 |logo_in_clutter.png |image edge map }"
"{@logo2 |logo.png |template edge map}"
};
int main( int argc, const char** argv )
@@ -29,8 +29,8 @@ int main( int argc, const char** argv )
help();
CommandLineParser parser(argc, argv, keys);
string image = parser.get<string>("1");
string templ = parser.get<string>("2");
string image = parser.get<string>(1);
string templ = parser.get<string>(2);
Mat img = imread(image.c_str(), 0);
Mat tpl = imread(templ.c_str(), 0);

View File

@@ -45,14 +45,14 @@ static void help()
const char* keys =
{
"{1| |stuff.jpg|image for converting to a grayscale}"
"{@image |stuff.jpg|image for converting to a grayscale}"
};
int main( int argc, const char** argv )
{
help();
CommandLineParser parser(argc, argv, keys);
string inputImage = parser.get<string>("1");
string inputImage = parser.get<string>(1);
img = imread(inputImage.c_str(), 0);
if(img.empty())

View File

@@ -62,7 +62,7 @@ static void help()
const char* keys =
{
"{1| |baboon.jpg|input image file}"
"{@image|baboon.jpg|input image file}"
};
int main( int argc, const char** argv )
@@ -70,7 +70,7 @@ int main( int argc, const char** argv )
help();
CommandLineParser parser(argc, argv, keys);
string inputImage = parser.get<string>("1");
string inputImage = parser.get<string>(1);
// Load the source image. HighGUI use.
image = imread( inputImage, 0 );

View File

@@ -17,14 +17,14 @@ static void help()
const char* keys =
{
"{1| |lena.jpg|input image file}"
"{@image|lena.jpg|input image file}"
};
int main(int argc, const char ** argv)
{
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
string filename = parser.get<string>(1);
Mat img = imread(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
if( img.empty() )

View File

@@ -104,14 +104,14 @@ static void help()
const char* keys =
{
"{1| |stuff.jpg|input image file}"
"{@image |stuff.jpg|input image file}"
};
int main( int argc, const char** argv )
{
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
string filename = parser.get<string>(1);
gray = imread(filename.c_str(), 0);
if(gray.empty())
{

View File

@@ -31,7 +31,7 @@ static void help()
const char* keys =
{
"{1| |fruits.jpg|input image name}"
"{@image |fruits.jpg|input image name}"
};
int main( int argc, const char** argv )
@@ -39,7 +39,7 @@ int main( int argc, const char** argv )
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
string filename = parser.get<string>(1);
image = imread(filename, 1);
if(image.empty())

View File

@@ -3,19 +3,23 @@
const char* keys =
{
"{ b |build |false | print complete build info }"
"{ h |help |false | print this help }"
"{ b build | | print complete build info }"
"{ h help | | print this help }"
};
int main(int argc, const char* argv[])
{
cv::CommandLineParser parser(argc, argv, keys);
if (parser.get<bool>("help"))
if (parser.has("help"))
{
parser.printParams();
parser.printMessage();
}
else if (parser.get<bool>("build"))
else if (!parser.check())
{
parser.printErrors();
}
else if (parser.has("build"))
{
std::cout << cv::getBuildInformation() << std::endl;
}
@@ -25,4 +29,4 @@ int main(int argc, const char* argv[])
}
return 0;
}
}

View File

@@ -176,7 +176,7 @@ int main(int argc, char** argv)
// display until user presses q
imshow(winName, reconstruction);
char key = 0;
int key = 0;
while(key != 'q')
key = waitKey();

View File

@@ -64,20 +64,19 @@ static void openGlDrawCallback(void* userdata)
int main(int argc, const char* argv[])
{
const char* keys =
"{ l | left | | left image file name }"
"{ r | right | | right image file name }"
"{ i | intrinsic | | intrinsic camera parameters file name }"
"{ e | extrinsic | | extrinsic camera parameters file name }"
"{ d | ndisp | 256 | number of disparities }"
"{ s | scale | 1.0 | scale factor for point cloud }"
"{ h | help | false | print help message }";
"{ l left | | left image file name }"
"{ r right | | right image file name }"
"{ i intrinsic | | intrinsic camera parameters file name }"
"{ e extrinsic | | extrinsic camera parameters file name }"
"{ d ndisp | 256 | number of disparities }"
"{ s scale | 1.0 | scale factor for point cloud }"
"{ h help | | print help message }";
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
if (cmd.has("help"))
{
cout << "Avaible options:" << endl;
cmd.printParams();
cmd.printMessage();
return 0;
}
@@ -88,11 +87,18 @@ int main(int argc, const char* argv[])
int ndisp = cmd.get<int>("ndisp");
double scale = cmd.get<double>("scale");
if (!cmd.check())
{
cmd.printErrors();
return 0;
}
if (left.empty() || right.empty())
{
cout << "Missed input images" << endl;
cout << "Avaible options:" << endl;
cmd.printParams();
cmd.printMessage();
return 0;
}
@@ -100,7 +106,7 @@ int main(int argc, const char* argv[])
{
cout << "Boss camera parameters must be specified" << endl;
cout << "Avaible options:" << endl;
cmd.printParams();
cmd.printMessage();
return 0;
}

View File

@@ -86,7 +86,7 @@ static void run(int argc, char** argv) {
Mat flow;
float start = getTickCount();
float start = (float)getTickCount();
calcOpticalFlowSF(frame1, frame2,
flow,
3, 2, 4, 4.1, 25.5, 18, 55.0, 25.5, 0.35, 18, 55.0, 25.5, 10);
@@ -131,7 +131,7 @@ static bool readOpticalFlowFromFile(FILE* file, Mat& flow) {
}
static bool isFlowCorrect(float u) {
return !isnan(u) && (fabs(u) < 1e9);
return !cvIsNaN(u) && (fabs(u) < 1e9);
}
static float calc_rmse(Mat flow1, Mat flow2) {
@@ -156,7 +156,7 @@ static float calc_rmse(Mat flow1, Mat flow2) {
}
}
}
return sqrt(sum / (1e-9 + counter));
return (float)sqrt(sum / (1e-9 + counter));
}
static void eval(int argc, char** argv) {

BIN
samples/cpp/templ.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -281,56 +281,56 @@ int main(int argc, const char **argv)
try
{
const char *keys =
"{ 1 | | | | }"
"{ m | model | affine | }"
"{ lp | lin-prog-motion-est | no | }"
"{ | subset | auto | }"
"{ | thresh | auto | }"
"{ | outlier-ratio | 0.5 | }"
"{ | min-inlier-ratio | 0.1 | }"
"{ | nkps | 1000 | }"
"{ | extra-kps | 0 | }"
"{ | local-outlier-rejection | no | }"
"{ sm | save-motions | no | }"
"{ lm | load-motions | no | }"
"{ r | radius | 15 | }"
"{ | stdev | auto | }"
"{ lps | lin-prog-stab | no | }"
"{ | lps-trim-ratio | auto | }"
"{ | lps-w1 | 1 | }"
"{ | lps-w2 | 10 | }"
"{ | lps-w3 | 100 | }"
"{ | lps-w4 | 100 | }"
"{ | deblur | no | }"
"{ | deblur-sens | 0.1 | }"
"{ et | est-trim | yes | }"
"{ t | trim-ratio | 0.1 | }"
"{ ic | incl-constr | no | }"
"{ bm | border-mode | replicate | }"
"{ | mosaic | no | }"
"{ ms | mosaic-stdev | 10.0 | }"
"{ mi | motion-inpaint | no | }"
"{ | mi-dist-thresh | 5.0 | }"
"{ ci | color-inpaint | no | }"
"{ | ci-radius | 2 | }"
"{ ws | wobble-suppress | no | }"
"{ | ws-period | 30 | }"
"{ | ws-model | homography | }"
"{ | ws-subset | auto | }"
"{ | ws-thresh | auto | }"
"{ | ws-outlier-ratio | 0.5 | }"
"{ | ws-min-inlier-ratio | 0.1 | }"
"{ | ws-nkps | 1000 | }"
"{ | ws-extra-kps | 0 | }"
"{ | ws-local-outlier-rejection | no | }"
"{ | ws-lp | no | }"
"{ sm2 | save-motions2 | no | }"
"{ lm2 | load-motions2 | no | }"
"{ gpu | | no }"
"{ o | output | stabilized.avi | }"
"{ | fps | auto | }"
"{ q | quiet | false | }"
"{ h | help | false | }";
"{ @1 | | }"
"{ m model | affine | }"
"{ lp lin-prog-motion-est | no | }"
"{ subset | auto | }"
"{ thresh | auto | }"
"{ outlier-ratio | 0.5 | }"
"{ min-inlier-ratio | 0.1 | }"
"{ nkps | 1000 | }"
"{ extra-kps | 0 | }"
"{ local-outlier-rejection | no | }"
"{ sm save-motions | no | }"
"{ lm load-motions | no | }"
"{ r radius | 15 | }"
"{ stdev | auto | }"
"{ lps lin-prog-stab | no | }"
"{ lps-trim-ratio | auto | }"
"{ lps-w1 | 1 | }"
"{ lps-w2 | 10 | }"
"{ lps-w3 | 100 | }"
"{ lps-w4 | 100 | }"
"{ deblur | no | }"
"{ deblur-sens | 0.1 | }"
"{ et est-trim | yes | }"
"{ t trim-ratio | 0.1 | }"
"{ ic incl-constr | no | }"
"{ bm border-mode | replicate | }"
"{ mosaic | no | }"
"{ ms mosaic-stdev | 10.0 | }"
"{ mi motion-inpaint | no | }"
"{ mi-dist-thresh | 5.0 | }"
"{ ci color-inpaint | no | }"
"{ ci-radius | 2 | }"
"{ ws wobble-suppress | no | }"
"{ ws-period | 30 | }"
"{ ws-model | homography | }"
"{ ws-subset | auto | }"
"{ ws-thresh | auto | }"
"{ ws-outlier-ratio | 0.5 | }"
"{ ws-min-inlier-ratio | 0.1 | }"
"{ ws-nkps | 1000 | }"
"{ ws-extra-kps | 0 | }"
"{ ws-local-outlier-rejection | no | }"
"{ ws-lp | no | }"
"{ sm2 save-motions2 | no | }"
"{ lm2 load-motions2 | no | }"
"{ gpu | no | }"
"{ o output | stabilized.avi | }"
"{ fps | auto | }"
"{ q quiet | | }"
"{ h help | | }";
CommandLineParser cmd(argc, argv, keys);
// parse command arguments

View File

@@ -21,20 +21,19 @@ enum Method
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 (fgd, mog, mog2, vibe, gmg) }"
"{ h | help | false | print help message }");
"{ c camera | | use camera }"
"{ f file | 768x576.avi | input video file }"
"{ m method | mog | method (fgd, mog, mog2, vibe, gmg) }"
"{ h help | | print help message }");
if (cmd.get<bool>("help"))
if (cmd.has("help") || !cmd.check())
{
cout << "Usage : bgfg_segm [options]" << endl;
cout << "Avaible options:" << endl;
cmd.printParams();
cmd.printMessage();
cmd.printErrors();
return 0;
}
bool useCamera = cmd.get<bool>("camera");
bool useCamera = cmd.has("camera");
string file = cmd.get<string>("file");
string method = cmd.get<string>("method");

View File

@@ -25,24 +25,23 @@ int main(int argc, const char* argv[])
try
{
const char* keys =
"{ h | help | false | print help message }"
"{ l | left | | specify left image }"
"{ r | right | | specify right image }"
"{ s | scale | 0.8 | set pyramid scale factor }"
"{ a | alpha | 0.197 | set alpha }"
"{ g | gamma | 50.0 | set gamma }"
"{ i | inner | 10 | set number of inner iterations }"
"{ o | outer | 77 | set number of outer iterations }"
"{ si | solver | 10 | set number of basic solver iterations }"
"{ t | time_step | 0.1 | set frame interpolation time step }";
"{ h help | | print help message }"
"{ l left | | specify left image }"
"{ r right | | specify right image }"
"{ s scale | 0.8 | set pyramid scale factor }"
"{ a alpha | 0.197 | set alpha }"
"{ g gamma | 50.0 | set gamma }"
"{ i inner | 10 | set number of inner iterations }"
"{ o outer | 77 | set number of outer iterations }"
"{ si solver | 10 | set number of basic solver iterations }"
"{ t time_step | 0.1 | set frame interpolation time step }";
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
if (cmd.has("help") || !cmd.check())
{
cout << "Usage: brox_optical_flow [options]" << endl;
cout << "Avaible options:" << endl;
cmd.printParams();
cmd.printMessage();
cmd.printErrors();
return 0;
}

View File

@@ -43,19 +43,19 @@ static void colorizeFlow(const Mat &u, const Mat &v, Mat &dst)
int main(int argc, char **argv)
{
CommandLineParser cmd(argc, argv,
"{ l | left | | specify left image }"
"{ r | right | | specify right image }"
"{ h | help | false | print help message }");
"{ l left | | specify left image }"
"{ r right | | specify right image }"
"{ h help | | print help message }");
if (cmd.get<bool>("help"))
cmd.about("Farneback's optical flow sample.");
if (cmd.has("help") || !cmd.check())
{
cout << "Farneback's optical flow sample.\n\n"
<< "Usage: farneback_optical_flow_gpu [arguments]\n\n"
<< "Arguments:\n";
cmd.printParams();
cmd.printMessage();
cmd.printErrors();
return 0;
}
string pathL = cmd.get<string>("left");
string pathR = cmd.get<string>("right");
if (pathL.empty()) cout << "Specify left image path\n";

View File

@@ -0,0 +1,209 @@
#include <vector>
#include <iostream>
#include <string>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
static Mat loadImage(const string& name)
{
Mat image = imread(name, IMREAD_GRAYSCALE);
if (image.empty())
{
cerr << "Can't load image - " << name << endl;
exit(-1);
}
return image;
}
int main(int argc, const char* argv[])
{
CommandLineParser cmd(argc, argv,
"{ image i | pic1.png | input image }"
"{ template t | templ.png | template image }"
"{ scale s | | estimate scale }"
"{ rotation r | | estimate rotation }"
"{ gpu | | use gpu version }"
"{ minDist | 100 | minimum distance between the centers of the detected objects }"
"{ levels | 360 | R-Table levels }"
"{ votesThreshold | 30 | the accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected }"
"{ angleThresh | 10000 | angle votes treshold }"
"{ scaleThresh | 1000 | scale votes treshold }"
"{ posThresh | 100 | position votes threshold }"
"{ dp | 2 | inverse ratio of the accumulator resolution to the image resolution }"
"{ minScale | 0.5 | minimal scale to detect }"
"{ maxScale | 2 | maximal scale to detect }"
"{ scaleStep | 0.05 | scale step }"
"{ minAngle | 0 | minimal rotation angle to detect in degrees }"
"{ maxAngle | 360 | maximal rotation angle to detect in degrees }"
"{ angleStep | 1 | angle step in degrees }"
"{ maxSize | 1000 | maximal size of inner buffers }"
"{ help h ? | | print help message }"
);
cmd.about("This program demonstrates arbitary object finding with the Generalized Hough transform.");
if (cmd.has("help"))
{
cmd.printMessage();
return 0;
}
const string templName = cmd.get<string>("template");
const string imageName = cmd.get<string>("image");
const bool estimateScale = cmd.has("scale");
const bool estimateRotation = cmd.has("rotation");
const bool useGpu = cmd.has("gpu");
const double minDist = cmd.get<double>("minDist");
const int levels = cmd.get<int>("levels");
const int votesThreshold = cmd.get<int>("votesThreshold");
const int angleThresh = cmd.get<int>("angleThresh");
const int scaleThresh = cmd.get<int>("scaleThresh");
const int posThresh = cmd.get<int>("posThresh");
const double dp = cmd.get<double>("dp");
const double minScale = cmd.get<double>("minScale");
const double maxScale = cmd.get<double>("maxScale");
const double scaleStep = cmd.get<double>("scaleStep");
const double minAngle = cmd.get<double>("minAngle");
const double maxAngle = cmd.get<double>("maxAngle");
const double angleStep = cmd.get<double>("angleStep");
const int maxSize = cmd.get<int>("maxSize");
if (!cmd.check())
{
cmd.printErrors();
return -1;
}
Mat templ = loadImage(templName);
Mat image = loadImage(imageName);
int method = GHT_POSITION;
if (estimateScale)
method += GHT_SCALE;
if (estimateRotation)
method += GHT_ROTATION;
vector<Vec4f> position;
cv::TickMeter tm;
if (useGpu)
{
GpuMat d_templ(templ);
GpuMat d_image(image);
GpuMat d_position;
Ptr<GeneralizedHough_GPU> d_hough = GeneralizedHough_GPU::create(method);
d_hough->set("minDist", minDist);
d_hough->set("levels", levels);
d_hough->set("dp", dp);
d_hough->set("maxSize", maxSize);
if (estimateScale && estimateRotation)
{
d_hough->set("angleThresh", angleThresh);
d_hough->set("scaleThresh", scaleThresh);
d_hough->set("posThresh", posThresh);
}
else
{
d_hough->set("votesThreshold", votesThreshold);
}
if (estimateScale)
{
d_hough->set("minScale", minScale);
d_hough->set("maxScale", maxScale);
d_hough->set("scaleStep", scaleStep);
}
if (estimateRotation)
{
d_hough->set("minAngle", minAngle);
d_hough->set("maxAngle", maxAngle);
d_hough->set("angleStep", angleStep);
}
d_hough->setTemplate(d_templ);
tm.start();
d_hough->detect(d_image, d_position);
d_hough->download(d_position, position);
tm.stop();
}
else
{
Ptr<GeneralizedHough> hough = GeneralizedHough::create(method);
hough->set("minDist", minDist);
hough->set("levels", levels);
hough->set("dp", dp);
if (estimateScale && estimateRotation)
{
hough->set("angleThresh", angleThresh);
hough->set("scaleThresh", scaleThresh);
hough->set("posThresh", posThresh);
hough->set("maxSize", maxSize);
}
else
{
hough->set("votesThreshold", votesThreshold);
}
if (estimateScale)
{
hough->set("minScale", minScale);
hough->set("maxScale", maxScale);
hough->set("scaleStep", scaleStep);
}
if (estimateRotation)
{
hough->set("minAngle", minAngle);
hough->set("maxAngle", maxAngle);
hough->set("angleStep", angleStep);
}
hough->setTemplate(templ);
tm.start();
hough->detect(image, position);
tm.stop();
}
cout << "Found : " << position.size() << " objects" << endl;
cout << "Detection time : " << tm.getTimeMilli() << " ms" << endl;
Mat out;
cvtColor(image, out, COLOR_GRAY2BGR);
for (size_t i = 0; i < position.size(); ++i)
{
Point2f pos(position[i][0], position[i][1]);
float scale = position[i][2];
float angle = position[i][3];
RotatedRect rect;
rect.center = pos;
rect.size = Size2f(templ.cols * scale, templ.rows * scale);
rect.angle = angle;
Point2f pts[4];
rect.points(pts);
line(out, pts[0], pts[1], Scalar(0, 0, 255), 3);
line(out, pts[1], pts[2], Scalar(0, 0, 255), 3);
line(out, pts[2], pts[3], Scalar(0, 0, 255), 3);
line(out, pts[3], pts[0], Scalar(0, 0, 255), 3);
}
imshow("out", out);
waitKey();
return 0;
}

View File

@@ -165,22 +165,23 @@ int main(int argc, const char* argv[])
redirectError(cvErrorCallback);
const char* keys =
"{ h | help | false | print help message }"
"{ f | filter | | filter for test }"
"{ w | workdir | | set working directory }"
"{ l | list | false | show all tests }"
"{ d | device | 0 | device id }"
"{ i | iters | 10 | iteration count }";
"{ h help | | print help message }"
"{ f filter | | filter for test }"
"{ w workdir | | set working directory }"
"{ l list | | show all tests }"
"{ d device | 0 | device id }"
"{ i iters | 10 | iteration count }";
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
if (cmd.has("help") || !cmd.check())
{
cout << "Avaible options:" << endl;
cmd.printParams();
cmd.printMessage();
cmd.printErrors();
return 0;
}
int device = cmd.get<int>("device");
if (device < 0 || device >= num_devices)
{
@@ -198,7 +199,7 @@ int main(int argc, const char* argv[])
string filter = cmd.get<string>("filter");
string workdir = cmd.get<string>("workdir");
bool list = cmd.get<bool>("list");
bool list = cmd.has("list");
int iters = cmd.get<int>("iters");
if (!filter.empty())

View File

@@ -152,23 +152,22 @@ static void getFlowField(const Mat& u, const Mat& v, Mat& flowField)
int main(int argc, const char* argv[])
{
const char* keys =
"{ h | help | false | print help message }"
"{ l | left | | specify left image }"
"{ r | right | | specify right image }"
"{ gray | gray | false | use grayscale sources [PyrLK Sparse] }"
"{ win_size | win_size | 21 | specify windows size [PyrLK] }"
"{ max_level | max_level | 3 | specify max level [PyrLK] }"
"{ iters | iters | 30 | specify iterations count [PyrLK] }"
"{ points | points | 4000 | specify points count [GoodFeatureToTrack] }"
"{ min_dist | min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }";
"{ h help | | print help message }"
"{ l left | | specify left image }"
"{ r right | | specify right image }"
"{ gray | | use grayscale sources [PyrLK Sparse] }"
"{ win_size | 21 | specify windows size [PyrLK] }"
"{ max_level | 3 | specify max level [PyrLK] }"
"{ iters | 30 | specify iterations count [PyrLK] }"
"{ points | 4000 | specify points count [GoodFeatureToTrack] }"
"{ min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }";
CommandLineParser cmd(argc, argv, keys);
if (cmd.get<bool>("help"))
if (cmd.has("help") || !cmd.check())
{
cout << "Usage: pyrlk_optical_flow [options]" << endl;
cout << "Avaible options:" << endl;
cmd.printParams();
cmd.printMessage();
cmd.printErrors();
return 0;
}
@@ -181,7 +180,7 @@ int main(int argc, const char* argv[])
return -1;
}
bool useGray = cmd.get<bool>("gray");
bool useGray = cmd.has("gray");
int winSize = cmd.get<int>("win_size");
int maxLevel = cmd.get<int>("max_level");
int iters = cmd.get<int>("iters");

View File

@@ -0,0 +1,231 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// @Authors
// Peng Xiao, pengxiao@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other oclMaterials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors as is and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include <iostream>
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/ocl/ocl.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;
using namespace cv;
using namespace cv::ocl;
//#define USE_CPU_DESCRIPTOR // use cpu descriptor extractor until ocl descriptor extractor is fixed
//#define USE_CPU_BFMATCHER
void help();
void help()
{
cout << "\nThis program demonstrates using SURF_OCL features detector and descriptor extractor" << endl;
cout << "\nUsage:\n\tsurf_matcher --left <image1> --right <image2>" << endl;
}
////////////////////////////////////////////////////
// This program demonstrates the usage of SURF_OCL.
// use cpu findHomography interface to calculate the transformation matrix
int main(int argc, char* argv[])
{
if (argc != 5 && argc != 1)
{
help();
return -1;
}
vector<cv::ocl::Info> info;
if(!cv::ocl::getDevice(info))
{
cout << "Error: Did not find a valid OpenCL device!" << endl;
return -1;
}
Mat cpu_img1, cpu_img2, cpu_img1_grey, cpu_img2_grey;
oclMat img1, img2;
if(argc != 5)
{
cpu_img1 = imread("o.png");
cvtColor(cpu_img1, cpu_img1_grey, CV_BGR2GRAY);
img1 = cpu_img1_grey;
CV_Assert(!img1.empty());
cpu_img2 = imread("r2.png");
cvtColor(cpu_img2, cpu_img2_grey, CV_BGR2GRAY);
img2 = cpu_img2_grey;
}
else
{
for (int i = 1; i < argc; ++i)
{
if (string(argv[i]) == "--left")
{
cpu_img1 = imread(argv[++i]);
cvtColor(cpu_img1, cpu_img1_grey, CV_BGR2GRAY);
img1 = cpu_img1_grey;
CV_Assert(!img1.empty());
}
else if (string(argv[i]) == "--right")
{
cpu_img2 = imread(argv[++i]);
cvtColor(cpu_img2, cpu_img2_grey, CV_BGR2GRAY);
img2 = cpu_img2_grey;
}
else if (string(argv[i]) == "--help")
{
help();
return -1;
}
}
}
SURF_OCL surf;
//surf.hessianThreshold = 400.f;
//surf.extended = false;
// detecting keypoints & computing descriptors
oclMat keypoints1GPU, keypoints2GPU;
oclMat descriptors1GPU, descriptors2GPU;
// downloading results
vector<KeyPoint> keypoints1, keypoints2;
vector<DMatch> matches;
#ifndef USE_CPU_DESCRIPTOR
surf(img1, oclMat(), keypoints1GPU, descriptors1GPU);
surf(img2, oclMat(), keypoints2GPU, descriptors2GPU);
surf.downloadKeypoints(keypoints1GPU, keypoints1);
surf.downloadKeypoints(keypoints2GPU, keypoints2);
#ifdef USE_CPU_BFMATCHER
//BFMatcher
BFMatcher matcher(cv::NORM_L2);
matcher.match(Mat(descriptors1GPU), Mat(descriptors2GPU), matches);
#else
BruteForceMatcher_OCL_base matcher(BruteForceMatcher_OCL_base::L2Dist);
matcher.match(descriptors1GPU, descriptors2GPU, matches);
#endif
#else
surf(img1, oclMat(), keypoints1GPU);
surf(img2, oclMat(), keypoints2GPU);
surf.downloadKeypoints(keypoints1GPU, keypoints1);
surf.downloadKeypoints(keypoints2GPU, keypoints2);
// use SURF_OCL to detect keypoints and use SURF to extract descriptors
SURF surf_cpu;
Mat descriptors1, descriptors2;
surf_cpu(cpu_img1, Mat(), keypoints1, descriptors1, true);
surf_cpu(cpu_img2, Mat(), keypoints2, descriptors2, true);
matcher.match(descriptors1, descriptors2, matches);
#endif
cout << "OCL: FOUND " << keypoints1GPU.cols << " keypoints on first image" << endl;
cout << "OCL: FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl;
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( size_t i = 0; i < keypoints1.size(); i++ )
{
double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
//-- Draw only "good" matches (i.e. whose distance is less than 2.5*min_dist )
std::vector< DMatch > good_matches;
for( size_t i = 0; i < keypoints1.size(); i++ )
{
if( matches[i].distance < 3*min_dist )
{
good_matches.push_back( matches[i]);
}
}
// drawing the results
Mat img_matches;
drawMatches( cpu_img1, keypoints1, cpu_img2, keypoints2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Localize the object
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for( size_t i = 0; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
obj.push_back( keypoints1[ good_matches[i].queryIdx ].pt );
scene.push_back( keypoints2[ good_matches[i].trainIdx ].pt );
}
Mat H = findHomography( obj, scene, CV_RANSAC );
//-- Get the corners from the image_1 ( the object to be "detected" )
std::vector<Point2f> obj_corners(4);
obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( cpu_img1.cols, 0 );
obj_corners[2] = cvPoint( cpu_img1.cols, cpu_img1.rows ); obj_corners[3] = cvPoint( 0, cpu_img1.rows );
std::vector<Point2f> scene_corners(4);
perspectiveTransform( obj_corners, scene_corners, H);
//-- Draw lines between the corners (the mapped object in the scene - image_2 )
line( img_matches, scene_corners[0] + Point2f( cpu_img1.cols, 0), scene_corners[1] + Point2f( cpu_img1.cols, 0), Scalar( 0, 255, 0), 4 );
line( img_matches, scene_corners[1] + Point2f( cpu_img1.cols, 0), scene_corners[2] + Point2f( cpu_img1.cols, 0), Scalar( 0, 255, 0), 4 );
line( img_matches, scene_corners[2] + Point2f( cpu_img1.cols, 0), scene_corners[3] + Point2f( cpu_img1.cols, 0), Scalar( 0, 255, 0), 4 );
line( img_matches, scene_corners[3] + Point2f( cpu_img1.cols, 0), scene_corners[0] + Point2f( cpu_img1.cols, 0), Scalar( 0, 255, 0), 4 );
//-- Show detected matches
namedWindow("ocl surf matches", 0);
imshow("ocl surf matches", img_matches);
waitKey(0);
return 0;
}