|
|
@ -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: |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
|
void printHelp() |
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
cout << "Histogram of Oriented Gradients descriptor and detector sample.\n"; |
|
|
|
cout << "Histogram of Oriented Gradients descriptor and detector sample.\n" |
|
|
|
if (argc < 2) |
|
|
|
<< "\nUsage: hog_gpu\n" |
|
|
|
{ |
|
|
|
<< " (<image>|--video <vide>|--camera <camera_id>) # frames source\n" |
|
|
|
cout << "\nUsage: hog_gpu\n" |
|
|
|
<< " [--make_gray <true/false>] # convert image to gray one or not\n" |
|
|
|
<< " --src <path> # it's image file by default\n" |
|
|
|
<< " [--resize_src <true/false>] # do resize of the source image or not\n" |
|
|
|
<< " [--src-is-video <true/false>] # says to interpretate src as video\n" |
|
|
|
|
|
|
|
<< " [--src-is-camera <true/false>] # says to interpretate src as camera\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" |
|
|
|
<< " [--width <int>] # resized image width\n" |
|
|
|
<< " [--height <int>] # resized image height\n" |
|
|
|
<< " [--height <int>] # resized image height\n" |
|
|
|
<< " [--hit-threshold <double>] # classifying plane distance threshold (0.0 usually)\n" |
|
|
|
<< " [--hit_threshold <double>] # classifying plane distance threshold (0.0 usually)\n" |
|
|
|
<< " [--scale <double>] # HOG window scale factor\n" |
|
|
|
<< " [--scale <double>] # HOG window scale factor\n" |
|
|
|
<< " [--nlevels <int>] # max number of HOG window scales\n" |
|
|
|
<< " [--nlevels <int>] # max number of HOG window scales\n" |
|
|
|
<< " [--win-width <int>] # width of the window (48 or 64)\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_width <int>] # distance by OX axis between neighbour wins\n" |
|
|
|
<< " [--win-stride-height <int>] # distance by OY 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" |
|
|
|
<< " [--gr_threshold <int>] # merging similar rects constant\n" |
|
|
|
<< " [--gamma-correct <int>] # do gamma correction or not\n" |
|
|
|
<< " [--gamma_correct <int>] # do gamma correction or not\n" |
|
|
|
<< " [--write-video <bool>] # write video or not\n" |
|
|
|
<< " [--write_video <bool>] # write video or not\n" |
|
|
|
<< " [--dst-video <path>] # output video path\n" |
|
|
|
<< " [--dst_video <path>] # output video path\n" |
|
|
|
<< " [--dst-video-fps <double>] # output video fps\n"; |
|
|
|
<< " [--dst_video_fps <double>] # output video fps\n"; |
|
|
|
return 1; |
|
|
|
help_showed = true; |
|
|
|
} |
|
|
|
} |
|
|
|
App app(Args::read(argc, argv)); |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (argc < 2) |
|
|
|
|
|
|
|
printHelp(); |
|
|
|
|
|
|
|
Args args = Args::read(argc, argv); |
|
|
|
|
|
|
|
if (help_showed) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
App app(args); |
|
|
|
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 |
|
|
|