mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 05:06:29 +08:00
Updated CLI for GPU samples
This commit is contained in:
parent
5656a9dd6b
commit
a2090a44db
@ -19,7 +19,7 @@ using namespace cv::gpu;
|
|||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
cout << "Usage: ./cascadeclassifier <cascade_file> <image_or_video_or_cameraid>\n"
|
cout << "Usage: ./cascadeclassifier_gpu \n\t--cascade <cascade_file>\n\t(<image>|--video <video>|--camera <camera_id>)\n"
|
||||||
"Using OpenCV version " << CV_VERSION << endl << endl;
|
"Using OpenCV version " << CV_VERSION << endl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,9 +98,10 @@ void displayState(Mat &canvas, bool bHelp, bool bGpu, bool bLargestFace, bool bF
|
|||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 3)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
return help(), -1;
|
help();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getCudaEnabledDeviceCount() == 0)
|
if (getCudaEnabledDeviceCount() == 0)
|
||||||
@ -108,10 +109,42 @@ int main(int argc, const char *argv[])
|
|||||||
return cerr << "No GPU found or the library is compiled without GPU support" << endl, -1;
|
return cerr << "No GPU found or the library is compiled without GPU support" << endl, -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoCapture capture;
|
string cascadeName;
|
||||||
|
string inputName;
|
||||||
|
bool isInputImage = false;
|
||||||
|
bool isInputVideo = false;
|
||||||
|
bool isInputCamera = false;
|
||||||
|
|
||||||
string cascadeName = argv[1];
|
for (int i = 1; i < argc; ++i)
|
||||||
string inputName = argv[2];
|
{
|
||||||
|
if (string(argv[i]) == "--cascade")
|
||||||
|
cascadeName = argv[++i];
|
||||||
|
else if (string(argv[i]) == "--video")
|
||||||
|
{
|
||||||
|
inputName = argv[++i];
|
||||||
|
isInputVideo = true;
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--camera")
|
||||||
|
{
|
||||||
|
inputName = argv[++i];
|
||||||
|
isInputCamera = true;
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--help")
|
||||||
|
{
|
||||||
|
help();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (!isInputImage)
|
||||||
|
{
|
||||||
|
inputName = argv[i];
|
||||||
|
isInputImage = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Unknown key: " << argv[i] << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CascadeClassifier_GPU cascade_gpu;
|
CascadeClassifier_GPU cascade_gpu;
|
||||||
if (!cascade_gpu.load(cascadeName))
|
if (!cascade_gpu.load(cascadeName))
|
||||||
@ -125,22 +158,23 @@ int main(int argc, const char *argv[])
|
|||||||
return cerr << "ERROR: Could not load cascade classifier \"" << cascadeName << "\"" << endl, help(), -1;
|
return cerr << "ERROR: Could not load cascade classifier \"" << cascadeName << "\"" << endl, help(), -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat image = imread(inputName);
|
VideoCapture capture;
|
||||||
|
Mat image;
|
||||||
|
|
||||||
if (image.empty())
|
if (isInputImage)
|
||||||
{
|
{
|
||||||
if (!capture.open(inputName))
|
image = imread(inputName);
|
||||||
{
|
CV_Assert(!image.empty());
|
||||||
int camid = -1;
|
|
||||||
istringstream iss(inputName);
|
|
||||||
iss >> camid;
|
|
||||||
|
|
||||||
if (!capture.open(camid))
|
|
||||||
{
|
|
||||||
cout << "Can't open source" << endl;
|
|
||||||
return help(), -1;
|
|
||||||
}
|
}
|
||||||
|
else if (isInputVideo)
|
||||||
|
{
|
||||||
|
capture.open(inputName);
|
||||||
|
CV_Assert(capture.isOpened());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
capture.open(atoi(inputName.c_str()));
|
||||||
|
CV_Assert(capture.isOpened());
|
||||||
}
|
}
|
||||||
|
|
||||||
namedWindow("result", 1);
|
namedWindow("result", 1);
|
||||||
@ -160,7 +194,7 @@ int main(int argc, const char *argv[])
|
|||||||
int detections_num;
|
int detections_num;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (capture.isOpened())
|
if (isInputCamera || isInputVideo)
|
||||||
{
|
{
|
||||||
capture >> frame;
|
capture >> frame;
|
||||||
if (frame.empty())
|
if (frame.empty())
|
||||||
|
@ -54,8 +54,14 @@ inline void safeCall_(int code, const char* expr, const char* file, int line)
|
|||||||
// Each GPU is associated with its own context
|
// Each GPU is associated with its own context
|
||||||
CUcontext contexts[2];
|
CUcontext contexts[2];
|
||||||
|
|
||||||
int main()
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
cout << "CUDA driver API sample\n";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int num_devices = getCudaEnabledDeviceCount();
|
int num_devices = getCudaEnabledDeviceCount();
|
||||||
if (num_devices < 2)
|
if (num_devices < 2)
|
||||||
{
|
{
|
||||||
|
@ -76,11 +76,16 @@ GpuMat d_result[2];
|
|||||||
// CPU result
|
// CPU result
|
||||||
Mat result;
|
Mat result;
|
||||||
|
|
||||||
|
void printHelp()
|
||||||
|
{
|
||||||
|
std::cout << "Usage: driver_api_stereo_multi_gpu --left <left_image> --right <right_image>\n";
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 3)
|
if (argc < 5)
|
||||||
{
|
{
|
||||||
std::cout << "Usage: stereo_multi_gpu <left_image> <right_image>\n";
|
printHelp();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,19 +109,27 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load input data
|
// Load input data
|
||||||
Mat left = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
|
Mat left, right;
|
||||||
Mat right = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
|
for (int i = 1; i < argc; ++i)
|
||||||
if (left.empty())
|
|
||||||
{
|
{
|
||||||
std::cout << "Cannot open '" << argv[1] << "'\n";
|
if (string(argv[i]) == "--left")
|
||||||
|
{
|
||||||
|
left = imread(argv[++i], CV_LOAD_IMAGE_GRAYSCALE);
|
||||||
|
CV_Assert(!left.empty());
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--right")
|
||||||
|
{
|
||||||
|
right = imread(argv[++i], CV_LOAD_IMAGE_GRAYSCALE);
|
||||||
|
CV_Assert(!right.empty());
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--help")
|
||||||
|
{
|
||||||
|
printHelp();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (right.empty())
|
|
||||||
{
|
|
||||||
std::cout << "Cannot open '" << argv[2] << "'\n";
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Init CUDA Driver API
|
// Init CUDA Driver API
|
||||||
safeCall(cuInit(0));
|
safeCall(cuInit(0));
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
|
bool help_showed = false;
|
||||||
|
|
||||||
class Args
|
class Args
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -84,35 +86,39 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void printHelp()
|
||||||
|
{
|
||||||
|
cout << "Histogram of Oriented Gradients descriptor and detector sample.\n"
|
||||||
|
<< "\nUsage: hog_gpu\n"
|
||||||
|
<< " (<image>|--video <vide>|--camera <camera_id>) # frames source\n"
|
||||||
|
<< " [--make_gray <true/false>] # convert image to gray one or not\n"
|
||||||
|
<< " [--resize_src <true/false>] # do resize of the source image or not\n"
|
||||||
|
<< " [--width <int>] # resized image width\n"
|
||||||
|
<< " [--height <int>] # resized image height\n"
|
||||||
|
<< " [--hit_threshold <double>] # classifying plane distance threshold (0.0 usually)\n"
|
||||||
|
<< " [--scale <double>] # HOG window scale factor\n"
|
||||||
|
<< " [--nlevels <int>] # max number of HOG window scales\n"
|
||||||
|
<< " [--win_width <int>] # width of the window (48 or 64)\n"
|
||||||
|
<< " [--win_stride_width <int>] # distance by OX axis between neighbour wins\n"
|
||||||
|
<< " [--win_stride_height <int>] # distance by OY axis between neighbour wins\n"
|
||||||
|
<< " [--gr_threshold <int>] # merging similar rects constant\n"
|
||||||
|
<< " [--gamma_correct <int>] # do gamma correction or not\n"
|
||||||
|
<< " [--write_video <bool>] # write video or not\n"
|
||||||
|
<< " [--dst_video <path>] # output video path\n"
|
||||||
|
<< " [--dst_video_fps <double>] # output video fps\n";
|
||||||
|
help_showed = true;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cout << "Histogram of Oriented Gradients descriptor and detector sample.\n";
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
printHelp();
|
||||||
cout << "\nUsage: hog_gpu\n"
|
Args args = Args::read(argc, argv);
|
||||||
<< " --src <path> # it's image file by default\n"
|
if (help_showed)
|
||||||
<< " [--src-is-video <true/false>] # says to interpretate src as video\n"
|
return -1;
|
||||||
<< " [--src-is-camera <true/false>] # says to interpretate src as camera\n"
|
App app(args);
|
||||||
<< " [--make-gray <true/false>] # convert image to gray one or not\n"
|
|
||||||
<< " [--resize-src <true/false>] # do resize of the source image or not\n"
|
|
||||||
<< " [--width <int>] # resized image width\n"
|
|
||||||
<< " [--height <int>] # resized image height\n"
|
|
||||||
<< " [--hit-threshold <double>] # classifying plane distance threshold (0.0 usually)\n"
|
|
||||||
<< " [--scale <double>] # HOG window scale factor\n"
|
|
||||||
<< " [--nlevels <int>] # max number of HOG window scales\n"
|
|
||||||
<< " [--win-width <int>] # width of the window (48 or 64)\n"
|
|
||||||
<< " [--win-stride-width <int>] # distance by OX axis between neighbour wins\n"
|
|
||||||
<< " [--win-stride-height <int>] # distance by OY axis between neighbour wins\n"
|
|
||||||
<< " [--gr-threshold <int>] # merging similar rects constant\n"
|
|
||||||
<< " [--gamma-correct <int>] # do gamma correction or not\n"
|
|
||||||
<< " [--write-video <bool>] # write video or not\n"
|
|
||||||
<< " [--dst-video <path>] # output video path\n"
|
|
||||||
<< " [--dst-video-fps <double>] # output video fps\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
App app(Args::read(argc, argv));
|
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
catch (const Exception& e) { return cout << "error: " << e.what() << endl, 1; }
|
catch (const Exception& e) { return cout << "error: " << e.what() << endl, 1; }
|
||||||
@ -154,34 +160,32 @@ Args::Args()
|
|||||||
Args Args::read(int argc, char** argv)
|
Args Args::read(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Args args;
|
Args args;
|
||||||
for (int i = 1; i < argc - 1; i += 2)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
string key = argv[i];
|
if (string(argv[i]) == "--make_gray") args.make_gray = (string(argv[++i]) == "true");
|
||||||
string val = argv[i + 1];
|
else if (string(argv[i]) == "--resize_src") args.resize_src = (string(argv[++i]) == "true");
|
||||||
if (key == "--src") args.src = val;
|
else if (string(argv[i]) == "--width") args.width = atoi(argv[++i]);
|
||||||
else if (key == "--src-is-video") args.src_is_video = (val == "true");
|
else if (string(argv[i]) == "--height") args.height = atoi(argv[++i]);
|
||||||
else if (key == "--src-is-camera") args.src_is_camera = (val == "true");
|
else if (string(argv[i]) == "--hit_threshold")
|
||||||
else if (key == "--camera-id") args.camera_id = atoi(val.c_str());
|
|
||||||
else if (key == "--make-gray") args.make_gray = (val == "true");
|
|
||||||
else if (key == "--resize-src") args.resize_src = (val == "true");
|
|
||||||
else if (key == "--width") args.width = atoi(val.c_str());
|
|
||||||
else if (key == "--height") args.height = atoi(val.c_str());
|
|
||||||
else if (key == "--hit-threshold")
|
|
||||||
{
|
{
|
||||||
args.hit_threshold = atof(val.c_str());
|
args.hit_threshold = atof(argv[++i]);
|
||||||
args.hit_threshold_auto = false;
|
args.hit_threshold_auto = false;
|
||||||
}
|
}
|
||||||
else if (key == "--scale") args.scale = atof(val.c_str());
|
else if (string(argv[i]) == "--scale") args.scale = atof(argv[++i]);
|
||||||
else if (key == "--nlevels") args.nlevels = atoi(val.c_str());
|
else if (string(argv[i]) == "--nlevels") args.nlevels = atoi(argv[++i]);
|
||||||
else if (key == "--win-width") args.win_width = atoi(val.c_str());
|
else if (string(argv[i]) == "--win_width") args.win_width = atoi(argv[++i]);
|
||||||
else if (key == "--win-stride-width") args.win_stride_width = atoi(val.c_str());
|
else if (string(argv[i]) == "--win_stride_width") args.win_stride_width = atoi(argv[++i]);
|
||||||
else if (key == "--win-stride-height") args.win_stride_height = atoi(val.c_str());
|
else if (string(argv[i]) == "--win_stride_height") args.win_stride_height = atoi(argv[++i]);
|
||||||
else if (key == "--gr-threshold") args.gr_threshold = atoi(val.c_str());
|
else if (string(argv[i]) == "--gr_threshold") args.gr_threshold = atoi(argv[++i]);
|
||||||
else if (key == "--gamma-correct") args.gamma_corr = (val == "true");
|
else if (string(argv[i]) == "--gamma_correct") args.gamma_corr = (string(argv[++i]) == "true");
|
||||||
else if (key == "--write-video") args.write_video = (val == "true");
|
else if (string(argv[i]) == "--write_video") args.write_video = (string(argv[++i]) == "true");
|
||||||
else if (key == "--dst-video") args.dst_video = val;
|
else if (string(argv[i]) == "--dst_video") args.dst_video = argv[++i];
|
||||||
else if (key == "--dst-video-fps") args.dst_video_fps= atof(val.c_str());
|
else if (string(argv[i]) == "--dst_video_fps") args.dst_video_fps = atof(argv[++i]);
|
||||||
else throw runtime_error((string("unknown key: ") + key));
|
else if (string(argv[i]) == "--help") printHelp();
|
||||||
|
else if (string(argv[i]) == "--video") { args.src = argv[++i]; args.src_is_video = true; }
|
||||||
|
else if (string(argv[i]) == "--camera") { args.camera_id = atoi(argv[++i]); args.src_is_camera = true; }
|
||||||
|
else if (args.src.empty()) args.src = argv[i];
|
||||||
|
else throw runtime_error((string("unknown key: ") + argv[i]));
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
@ -267,7 +271,11 @@ void App::run()
|
|||||||
{
|
{
|
||||||
vc.open(args.camera_id);
|
vc.open(args.camera_id);
|
||||||
if (!vc.isOpened())
|
if (!vc.isOpened())
|
||||||
throw runtime_error(string("can't open video file: " + args.src));
|
{
|
||||||
|
stringstream msg;
|
||||||
|
msg << "can't open camera: " << args.camera_id;
|
||||||
|
throw runtime_error(msg.str());
|
||||||
|
}
|
||||||
vc >> frame;
|
vc >> frame;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -61,7 +61,7 @@ void ErodeDilate(int, void*)
|
|||||||
int main( int argc, char** argv )
|
int main( int argc, char** argv )
|
||||||
{
|
{
|
||||||
char* filename = argc == 2 ? argv[1] : (char*)"baboon.jpg";
|
char* filename = argc == 2 ? argv[1] : (char*)"baboon.jpg";
|
||||||
if( (src = imread(filename,1)).data == 0 )
|
if(string(argv[1]) == "--help" || (src = imread(filename,1)).data == 0)
|
||||||
return help(), -1;
|
return help(), -1;
|
||||||
|
|
||||||
help();
|
help();
|
||||||
|
@ -25,16 +25,19 @@ int main(int argc, const char* argv[])
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define PARAM_INPUT "--input"
|
#define PARAM_LEFT "--left"
|
||||||
|
#define PARAM_RIGHT "--right"
|
||||||
#define PARAM_SCALE "--scale"
|
#define PARAM_SCALE "--scale"
|
||||||
#define PARAM_ALPHA "--alpha"
|
#define PARAM_ALPHA "--alpha"
|
||||||
#define PARAM_GAMMA "--gamma"
|
#define PARAM_GAMMA "--gamma"
|
||||||
#define PARAM_INNER "--inner"
|
#define PARAM_INNER "--inner"
|
||||||
#define PARAM_OUTER "--outer"
|
#define PARAM_OUTER "--outer"
|
||||||
#define PARAM_SOLVER "--solver"
|
#define PARAM_SOLVER "--solver"
|
||||||
#define PARAM_TIME_STEP "--time-step"
|
#define PARAM_TIME_STEP "--time_step"
|
||||||
#define PARAM_HELP "--help"
|
#define PARAM_HELP "--help"
|
||||||
|
|
||||||
|
bool help_showed = false;
|
||||||
|
|
||||||
void printHelp()
|
void printHelp()
|
||||||
{
|
{
|
||||||
cout << "Usage help:\n";
|
cout << "Usage help:\n";
|
||||||
@ -42,12 +45,14 @@ void printHelp()
|
|||||||
cout << "\t" << setw(15) << PARAM_ALPHA << " - set alpha\n";
|
cout << "\t" << setw(15) << PARAM_ALPHA << " - set alpha\n";
|
||||||
cout << "\t" << setw(15) << PARAM_GAMMA << " - set gamma\n";
|
cout << "\t" << setw(15) << PARAM_GAMMA << " - set gamma\n";
|
||||||
cout << "\t" << setw(15) << PARAM_INNER << " - set number of inner iterations\n";
|
cout << "\t" << setw(15) << PARAM_INNER << " - set number of inner iterations\n";
|
||||||
cout << "\t" << setw(15) << PARAM_INPUT << " - specify input file names (2 image files)\n";
|
cout << "\t" << setw(15) << PARAM_LEFT << " - specify left image\n";
|
||||||
|
cout << "\t" << setw(15) << PARAM_RIGHT << " - specify right image\n";
|
||||||
cout << "\t" << setw(15) << PARAM_OUTER << " - set number of outer iterations\n";
|
cout << "\t" << setw(15) << PARAM_OUTER << " - set number of outer iterations\n";
|
||||||
cout << "\t" << setw(15) << PARAM_SCALE << " - set pyramid scale factor\n";
|
cout << "\t" << setw(15) << PARAM_SCALE << " - set pyramid scale factor\n";
|
||||||
cout << "\t" << setw(15) << PARAM_SOLVER << " - set number of basic solver iterations\n";
|
cout << "\t" << setw(15) << PARAM_SOLVER << " - set number of basic solver iterations\n";
|
||||||
cout << "\t" << setw(15) << PARAM_TIME_STEP << " - set frame interpolation time step\n";
|
cout << "\t" << setw(15) << PARAM_TIME_STEP << " - set frame interpolation time step\n";
|
||||||
cout << "\t" << setw(15) << PARAM_HELP << " - display this help message\n";
|
cout << "\t" << setw(15) << PARAM_HELP << " - display this help message\n";
|
||||||
|
help_showed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int processCommandLine(int argc, const char* argv[], float& timeStep, string& frame0Name, string& frame1Name, BroxOpticalFlow& flow)
|
int processCommandLine(int argc, const char* argv[], float& timeStep, string& frame0Name, string& frame1Name, BroxOpticalFlow& flow)
|
||||||
@ -56,13 +61,17 @@ int processCommandLine(int argc, const char* argv[], float& timeStep, string& fr
|
|||||||
|
|
||||||
for (int iarg = 1; iarg < argc; ++iarg)
|
for (int iarg = 1; iarg < argc; ++iarg)
|
||||||
{
|
{
|
||||||
if (strcmp(argv[iarg], PARAM_INPUT) == 0)
|
if (strcmp(argv[iarg], PARAM_LEFT) == 0)
|
||||||
{
|
|
||||||
if (iarg + 2 < argc)
|
|
||||||
{
|
{
|
||||||
|
if (iarg + 1 < argc)
|
||||||
frame0Name = argv[++iarg];
|
frame0Name = argv[++iarg];
|
||||||
frame1Name = argv[++iarg];
|
else
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (strcmp(argv[iarg], PARAM_RIGHT) == 0)
|
||||||
|
{
|
||||||
|
if (iarg + 1 < argc)
|
||||||
|
frame1Name = argv[++iarg];
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -181,6 +190,8 @@ int main(int argc, const char* argv[])
|
|||||||
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
|
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
|
||||||
|
|
||||||
int result = processCommandLine(argc, argv, timeStep, frame0Name, frame1Name, d_flow);
|
int result = processCommandLine(argc, argv, timeStep, frame0Name, frame1Name, d_flow);
|
||||||
|
if (help_showed)
|
||||||
|
return -1;
|
||||||
if (argc == 1 || result)
|
if (argc == 1 || result)
|
||||||
{
|
{
|
||||||
printHelp();
|
printHelp();
|
||||||
|
@ -30,7 +30,8 @@ int main( int argc, const char** argv )
|
|||||||
//using std::tr1::shared_ptr;
|
//using std::tr1::shared_ptr;
|
||||||
using cv::Ptr;
|
using cv::Ptr;
|
||||||
|
|
||||||
#define PARAM_INPUT "--input"
|
#define PARAM_LEFT "--left"
|
||||||
|
#define PARAM_RIGHT "--right"
|
||||||
#define PARAM_SCALE "--scale"
|
#define PARAM_SCALE "--scale"
|
||||||
#define PARAM_ALPHA "--alpha"
|
#define PARAM_ALPHA "--alpha"
|
||||||
#define PARAM_GAMMA "--gamma"
|
#define PARAM_GAMMA "--gamma"
|
||||||
@ -276,7 +277,8 @@ void PrintHelp ()
|
|||||||
std::cout << "\t" << std::setw(15) << PARAM_ALPHA << " - set alpha\n";
|
std::cout << "\t" << std::setw(15) << PARAM_ALPHA << " - set alpha\n";
|
||||||
std::cout << "\t" << std::setw(15) << PARAM_GAMMA << " - set gamma\n";
|
std::cout << "\t" << std::setw(15) << PARAM_GAMMA << " - set gamma\n";
|
||||||
std::cout << "\t" << std::setw(15) << PARAM_INNER << " - set number of inner iterations\n";
|
std::cout << "\t" << std::setw(15) << PARAM_INNER << " - set number of inner iterations\n";
|
||||||
std::cout << "\t" << std::setw(15) << PARAM_INPUT << " - specify input file names (2 image files)\n";
|
std::cout << "\t" << std::setw(15) << PARAM_LEFT << " - specify left image\n";
|
||||||
|
std::cout << "\t" << std::setw(15) << PARAM_RIGHT << " - specify right image\n";
|
||||||
std::cout << "\t" << std::setw(15) << PARAM_OUTER << " - set number of outer iterations\n";
|
std::cout << "\t" << std::setw(15) << PARAM_OUTER << " - set number of outer iterations\n";
|
||||||
std::cout << "\t" << std::setw(15) << PARAM_SCALE << " - set pyramid scale factor\n";
|
std::cout << "\t" << std::setw(15) << PARAM_SCALE << " - set pyramid scale factor\n";
|
||||||
std::cout << "\t" << std::setw(15) << PARAM_SOLVER << " - set number of basic solver iterations\n";
|
std::cout << "\t" << std::setw(15) << PARAM_SOLVER << " - set number of basic solver iterations\n";
|
||||||
@ -293,11 +295,19 @@ int ProcessCommandLine(int argc, char **argv,
|
|||||||
timeStep = 0.25f;
|
timeStep = 0.25f;
|
||||||
for (int iarg = 1; iarg < argc; ++iarg)
|
for (int iarg = 1; iarg < argc; ++iarg)
|
||||||
{
|
{
|
||||||
if (strcmp(argv[iarg], PARAM_INPUT) == 0)
|
if (strcmp(argv[iarg], PARAM_LEFT) == 0)
|
||||||
{
|
{
|
||||||
if (iarg + 2 < argc)
|
if (iarg + 1 < argc)
|
||||||
{
|
{
|
||||||
frame0Name = argv[++iarg];
|
frame0Name = argv[++iarg];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (strcmp(argv[iarg], PARAM_RIGHT) == 0)
|
||||||
|
{
|
||||||
|
if (iarg + 1 < argc)
|
||||||
|
{
|
||||||
frame1Name = argv[++iarg];
|
frame1Name = argv[++iarg];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
bool help_showed = false;
|
||||||
|
|
||||||
struct Params
|
struct Params
|
||||||
{
|
{
|
||||||
@ -71,6 +72,14 @@ private:
|
|||||||
double work_fps;
|
double work_fps;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void printHelp()
|
||||||
|
{
|
||||||
|
cout << "Usage: stereo_match_gpu\n"
|
||||||
|
<< "\t--left <left_view> --right <right_view> # must be rectified\n"
|
||||||
|
<< "\t--method <stereo_match_method> # BM | BP | CSBP\n"
|
||||||
|
<< "\t--ndisp <number> # number of disparity levels\n";
|
||||||
|
help_showed = true;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@ -78,12 +87,13 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
cout << "Usage: stereo_match_gpu\n"
|
printHelp();
|
||||||
<< "\t-l <left_view> -r <right_view> # must be rectified\n"
|
|
||||||
<< "\t-m <stereo_match_method> # BM | BP | CSBP\n";
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
App app(Params::read(argc, argv));
|
Params args = Params::read(argc, argv);
|
||||||
|
if (help_showed)
|
||||||
|
return -1;
|
||||||
|
App app(args);
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
catch (const exception& e)
|
catch (const exception& e)
|
||||||
@ -105,21 +115,21 @@ Params Params::read(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
Params p;
|
Params p;
|
||||||
|
|
||||||
for (int i = 1; i < argc - 1; i += 2)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
string key = argv[i];
|
if (string(argv[i]) == "--left") p.left = argv[++i];
|
||||||
string val = argv[i + 1];
|
else if (string(argv[i]) == "--right") p.right = argv[++i];
|
||||||
if (key == "-l") p.left = val;
|
else if (string(argv[i]) == "--method")
|
||||||
else if (key == "-r") p.right = val;
|
|
||||||
else if (key == "-m")
|
|
||||||
{
|
{
|
||||||
if (val == "BM") p.method = BM;
|
if (string(argv[i + 1]) == "BM") p.method = BM;
|
||||||
else if (val == "BP") p.method = BP;
|
else if (string(argv[i + 1]) == "BP") p.method = BP;
|
||||||
else if (val == "CSBP") p.method = CSBP;
|
else if (string(argv[i + 1]) == "CSBP") p.method = CSBP;
|
||||||
else throw runtime_error("unknown stereo match method: " + val);
|
else throw runtime_error("unknown stereo match method: " + string(argv[i + 1]));
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
else if (key == "-ndisp") p.ndisp = atoi(val.c_str());
|
else if (string(argv[i]) == "--ndisp") p.ndisp = atoi(argv[++i]);
|
||||||
else throw runtime_error("unknown key: " + key);
|
else if (string(argv[i]) == "--help") printHelp();
|
||||||
|
else throw runtime_error("unknown key: " + string(argv[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
@ -47,11 +47,16 @@ GpuMat d_result[2];
|
|||||||
// CPU result
|
// CPU result
|
||||||
Mat result;
|
Mat result;
|
||||||
|
|
||||||
|
void printHelp()
|
||||||
|
{
|
||||||
|
std::cout << "Usage: stereo_multi_gpu --left <image> --right <image>\n";
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 3)
|
if (argc < 5)
|
||||||
{
|
{
|
||||||
std::cout << "Usage: stereo_multi_gpu <left_image> <right_image>\n";
|
printHelp();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,17 +79,24 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load input data
|
// Load input data
|
||||||
Mat left = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
|
Mat left, right;
|
||||||
Mat right = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
|
for (int i = 1; i < argc; ++i)
|
||||||
if (left.empty())
|
|
||||||
{
|
{
|
||||||
std::cout << "Cannot open '" << argv[1] << "'\n";
|
if (string(argv[i]) == "--left")
|
||||||
|
{
|
||||||
|
left = imread(argv[++i], CV_LOAD_IMAGE_GRAYSCALE);
|
||||||
|
CV_Assert(!left.empty());
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--right")
|
||||||
|
{
|
||||||
|
right = imread(argv[++i], CV_LOAD_IMAGE_GRAYSCALE);
|
||||||
|
CV_Assert(!right.empty());
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--help")
|
||||||
|
{
|
||||||
|
printHelp();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (right.empty())
|
|
||||||
{
|
|
||||||
std::cout << "Cannot open '" << argv[2] << "'\n";
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split source images for processing on the GPU #0
|
// Split source images for processing on the GPU #0
|
||||||
|
@ -12,24 +12,36 @@ using namespace cv::gpu;
|
|||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
cout << "\nThis program demonstrates using SURF_GPU features detector, descriptor extractor and BruteForceMatcher_GPU" << endl;
|
cout << "\nThis program demonstrates using SURF_GPU features detector, descriptor extractor and BruteForceMatcher_GPU" << endl;
|
||||||
cout << "\nUsage:\n\tmatcher_simple_gpu <image1> <image2>" << endl;
|
cout << "\nUsage:\n\tmatcher_simple_gpu --left <image1> --right <image2>" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if (argc != 3)
|
if (argc != 5)
|
||||||
{
|
{
|
||||||
help();
|
help();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpuMat img1(imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE));
|
GpuMat img1, img2;
|
||||||
GpuMat img2(imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE));
|
for (int i = 1; i < argc; ++i)
|
||||||
if (img1.empty() || img2.empty())
|
|
||||||
{
|
{
|
||||||
cout << "Can't read one of the images" << endl;
|
if (string(argv[i]) == "--left")
|
||||||
|
{
|
||||||
|
img1 = imread(argv[++i], CV_LOAD_IMAGE_GRAYSCALE);
|
||||||
|
CV_Assert(!img1.empty());
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--right")
|
||||||
|
{
|
||||||
|
img2 = imread(argv[++i], CV_LOAD_IMAGE_GRAYSCALE);
|
||||||
|
CV_Assert(!img2.empty());
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--help")
|
||||||
|
{
|
||||||
|
help();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SURF_GPU surf;
|
SURF_GPU surf;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user