-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Python bindings for Facemark Training Code #2197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saiteja-talluri
wants to merge
2
commits into
opencv:4.x
Choose a base branch
from
saiteja-talluri:facemark_python
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,77 @@ bool FacemarkKazemiImpl::setFaceDetector(FN_FaceDetector f, void* userData){ | |
} | ||
bool FacemarkKazemiImpl::getFaces(InputArray image, OutputArray faces) | ||
{ | ||
CV_Assert(faceDetector); | ||
if (!faceDetector) | ||
{ | ||
std::vector<Rect> faces_; | ||
defaultFaceDetector(image.getMat(), faces_); | ||
Mat(faces_).copyTo(faces); | ||
return true; | ||
} | ||
return faceDetector(image, faces, faceDetectorData); | ||
} | ||
bool FacemarkKazemiImpl::defaultFaceDetector(const Mat& image, std::vector<Rect>& faces){ | ||
Mat gray; | ||
|
||
faces.clear(); | ||
|
||
if (image.channels() > 1) | ||
{ | ||
cvtColor(image, gray, COLOR_BGR2GRAY); | ||
} | ||
else | ||
{ | ||
gray = image; | ||
} | ||
|
||
equalizeHist(gray, gray); | ||
|
||
if (face_cascade.empty()) | ||
{ | ||
{ /* check the cascade classifier file */ | ||
std::ifstream infile; | ||
infile.open(params.faceCascadefile.c_str(), std::ios::in); | ||
if (!infile) | ||
CV_Error_(Error::StsBadArg, ("The cascade classifier model is not found: %s", params.faceCascadefile.c_str())); | ||
} | ||
face_cascade.load(params.faceCascadefile.c_str()); | ||
CV_Assert(!face_cascade.empty()); | ||
} | ||
face_cascade.detectMultiScale(gray, faces, 1.05, 2, CASCADE_SCALE_IMAGE, Size(30, 30) ); | ||
return true; | ||
} | ||
bool FacemarkKazemiImpl::getData(void * items){ | ||
CV_UNUSED(items); | ||
return false; | ||
} | ||
bool FacemarkKazemiImpl::addTrainingSample(InputArray image, std::vector<Point2f> & landmarks){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some asserts for input values can be useful here. |
||
std::vector<Point2f> & _landmarks = landmarks; | ||
training_images.push_back(image.getMat()); | ||
training_facePoints.push_back(_landmarks); | ||
return true; | ||
} | ||
bool FacemarkKazemiImpl::setParams(const String& face_cascade_name,const String& facemark_model_name, const String& config_file_path, InputArray scale){ | ||
if(face_cascade_name.empty() && facemark_model_name.empty() && config_file_path.empty() && scale.empty()) | ||
{ | ||
CV_Error_(Error::StsBadArg, ("face cascade name, facemark model name, config file and scale all are empty")); | ||
} | ||
if(!face_cascade_name.empty()) | ||
params.faceCascadefile = face_cascade_name; | ||
if(!facemark_model_name.empty()) | ||
params.modelfile = facemark_model_name; | ||
if(!config_file_path.empty()) | ||
params.configfile = config_file_path; | ||
|
||
Mat scale_mat = scale.getMat(); | ||
std::vector<int> _scale = scale_mat.reshape(1, scale_mat.rows); | ||
if(_scale.size() != 2){ | ||
CV_Error(Error::StsBadArg, "Please set the scale argument properly"); | ||
return false; | ||
} | ||
params.scale = Size(_scale[0], _scale[1]); | ||
CV_UNUSED(config_file_path); | ||
return true; | ||
} | ||
FacemarkKazemiImpl::FacemarkKazemiImpl(const FacemarkKazemi::Params& parameters) : | ||
faceDetector(NULL), | ||
faceDetectorData(NULL) | ||
|
@@ -45,6 +113,9 @@ FacemarkKazemi::Params::Params(){ | |
//These variables are used for training data | ||
//These are initialised as described in the research paper | ||
//referenced above | ||
configfile = ""; | ||
modelfile = ""; | ||
faceCascadefile = ""; | ||
cascade_depth = 15; | ||
tree_depth = 5; | ||
num_trees_per_cascade_level = 500; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some asserts for input values can be useful here.