int get_facial_points(Mat& face, vector<Point_<double> >& points) { FaceTracker * tracker = LoadFaceTracker(DefaultFaceTrackerModelPathname().c_str()); FaceTrackerParams *tracker_params = LoadFaceTrackerParams(DefaultFaceTrackerParamsPathname().c_str()); Mat frame_gray; cvtColor(face, frame_gray, CV_RGB2GRAY ); int result = tracker->NewFrame(frame_gray, tracker_params); vector<Point_<double> > shape; Pose pose; if (result >= 1) { points = tracker->getShape(); pose = tracker->getPose(); } else { return 0; } delete tracker; delete tracker_params; return 1; }
int run_image_mode(const Configuration &cfg, const CommandLineArgument<std::string> &image_argument, const CommandLineArgument<std::string> &landmarks_argument) { FaceTracker * tracker = LoadFaceTracker(cfg.model_pathname.c_str()); FaceTrackerParams *tracker_params = LoadFaceTrackerParams(cfg.params_pathname.c_str()); cv::Mat image; cv::Mat_<uint8_t> gray_image = load_grayscale_image(image_argument->c_str(), &image); int result = tracker->NewFrame(gray_image, tracker_params); std::vector<cv::Point_<double> > shape; std::vector<cv::Point3_<double> > shape3; Pose pose; if (result >= cfg.tracking_threshold) { shape = tracker->getShape(); shape3 = tracker->get3DShape(); pose = tracker->getPose(); } if (!have_argument_p(landmarks_argument)) { display_data(cfg, image, shape, pose); } else if (shape.size() > 0) { if (cfg.save_3d_points) save_points3(landmarks_argument->c_str(), shape3); else save_points(landmarks_argument->c_str(), shape); } delete tracker; delete tracker_params; return 0; }
// Helpers int run_lists_mode(const Configuration &cfg, const CommandLineArgument<std::string> &image_argument, const CommandLineArgument<std::string> &landmarks_argument) { FaceTracker * tracker = LoadFaceTracker(cfg.model_pathname.c_str()); FaceTrackerParams *tracker_params = LoadFaceTrackerParams(cfg.params_pathname.c_str()); std::list<std::string> image_pathnames = read_list(image_argument->c_str()); std::list<std::string> landmark_pathnames; if (have_argument_p(landmarks_argument)) { landmark_pathnames = read_list(landmarks_argument->c_str()); if (landmark_pathnames.size() != image_pathnames.size()) throw make_runtime_error("Number of pathnames in list '%s' does not match the number in '%s'", image_argument->c_str(), landmarks_argument->c_str()); } std::list<std::string>::const_iterator image_it = image_pathnames.begin(); std::list<std::string>::const_iterator landmarks_it = landmark_pathnames.begin(); const int number_of_images = image_pathnames.size(); int current_image_index = 1; for (; image_it != image_pathnames.end(); image_it++) { if (cfg.verbose) { printf(" Image %d/%d\r", current_image_index, number_of_images); fflush(stdout); } current_image_index++; cv::Mat image; cv::Mat_<uint8_t> gray_image = load_grayscale_image(image_it->c_str(), &image); int result = tracker->NewFrame(gray_image, tracker_params); std::vector<cv::Point_<double> > shape; std::vector<cv::Point3_<double> > shape3D; Pose pose; if (result >= cfg.tracking_threshold) { shape = tracker->getShape(); shape3D = tracker->get3DShape(); pose = tracker->getPose(); } else { tracker->Reset(); } if (!have_argument_p(landmarks_argument)) { display_data(cfg, image, shape, pose); } else if (shape.size() > 0) { if (cfg.save_3d_points) save_points3(landmarks_it->c_str(), shape3D); else save_points(landmarks_it->c_str(), shape); if (cfg.verbose) display_data(cfg, image, shape, pose); } else if (cfg.verbose) { display_data(cfg, image, shape, pose); } if (have_argument_p(landmarks_argument)) landmarks_it++; } delete tracker; delete tracker_params; return 0; }