This commit is contained in:
ValeryTyumen
2015-08-01 20:24:23 +05:00
committed by Maksim Shabunin
parent 5cdf0e3e89
commit 297808e6b9
57 changed files with 950 additions and 1052 deletions

View File

@@ -18,11 +18,6 @@
using namespace std;
using namespace cv;
// Functions to parse command-line arguments
static string getCommandOption(const vector<string>&, const string&);
static void setCommandOptions(vector<string>&, int, char**);
static bool doesCmdOptionExist(const vector<string>& , const string&);
// Functions for facial feature detection
static void help();
static void detectFaces(Mat&, vector<Rect_<int> >&, string);
@@ -36,22 +31,23 @@ string face_cascade_path, eye_cascade_path, nose_cascade_path, mouth_cascade_pat
int main(int argc, char** argv)
{
if(argc < 3)
cv::CommandLineParser parser(argc, argv,
"{eyes||}{nose||}{mouth||}{help h||}");
if (parser.has("help"))
{
help();
return 0;
}
input_image_path = parser.get<string>(0);
face_cascade_path = parser.get<string>(1);
eye_cascade_path = parser.has("eyes") ? parser.get<string>("eyes") : "";
nose_cascade_path = parser.has("nose") ? parser.get<string>("nose") : "";
mouth_cascade_path = parser.has("mouth") ? parser.get<string>("mouth") : "";
if (input_image_path.empty() || face_cascade_path.empty())
{
cout << "IMAGE or FACE_CASCADE are not specified";
return 1;
}
// Extract command-line options
vector<string> args;
setCommandOptions(args, argc, argv);
input_image_path = argv[1];
face_cascade_path = argv[2];
eye_cascade_path = (doesCmdOptionExist(args, "-eyes")) ? getCommandOption(args, "-eyes") : "";
nose_cascade_path = (doesCmdOptionExist(args, "-nose")) ? getCommandOption(args, "-nose") : "";
mouth_cascade_path = (doesCmdOptionExist(args, "-mouth")) ? getCommandOption(args, "-mouth") : "";
// Load image and cascade classifier files
Mat image;
image = imread(input_image_path);
@@ -67,30 +63,6 @@ int main(int argc, char** argv)
return 0;
}
void setCommandOptions(vector<string>& args, int argc, char** argv)
{
for(int i = 1; i < argc; ++i)
{
args.push_back(argv[i]);
}
return;
}
string getCommandOption(const vector<string>& args, const string& opt)
{
string answer;
vector<string>::const_iterator it = find(args.begin(), args.end(), opt);
if(it != args.end() && (++it != args.end()))
answer = *it;
return answer;
}
bool doesCmdOptionExist(const vector<string>& args, const string& opt)
{
vector<string>::const_iterator it = find(args.begin(), args.end(), opt);
return (it != args.end());
}
static void help()
{
cout << "\nThis file demonstrates facial feature points detection using Haarcascade classifiers.\n"
@@ -103,15 +75,15 @@ static void help()
"FACE_CASCSDE\n\t Path to a haarcascade classifier for face detection.\n"
"OPTIONS: \nThere are 3 options available which are described in detail. There must be a "
"space between the option and it's argument (All three options accept arguments).\n"
"\t-eyes : Specify the haarcascade classifier for eye detection.\n"
"\t-nose : Specify the haarcascade classifier for nose detection.\n"
"\t-mouth : Specify the haarcascade classifier for mouth detection.\n";
"\t-eyes=<eyes_cascade> : Specify the haarcascade classifier for eye detection.\n"
"\t-nose=<nose_cascade> : Specify the haarcascade classifier for nose detection.\n"
"\t-mouth=<mouth-cascade> : Specify the haarcascade classifier for mouth detection.\n";
cout << "EXAMPLE:\n"
"(1) ./cpp-example-facial_features image.jpg face.xml -eyes eyes.xml -mouth mouth.xml\n"
"(1) ./cpp-example-facial_features image.jpg face.xml -eyes=eyes.xml -mouth=mouth.xml\n"
"\tThis will detect the face, eyes and mouth in image.jpg.\n"
"(2) ./cpp-example-facial_features image.jpg face.xml -nose nose.xml\n"
"(2) ./cpp-example-facial_features image.jpg face.xml -nose=nose.xml\n"
"\tThis will detect the face and nose in image.jpg.\n"
"(3) ./cpp-example-facial_features image.jpg face.xml\n"
"\tThis will detect only the face in image.jpg.\n";