Comments (9)
- If you can understand Chinese, please refer to this post. Otherwise, please refer to Appendix B of the book Statistical Models of Appearance for Computer Vision. You can access it here.
- Regression targets is the difference of ground truth shape and current shape. If you don't do alignment, this difference will mean nothing to testing, considering various size and orientations of face images.
from facealignment.
thanks! the post link is not chinese, the same as "here",is it wrong?
I'm still confused why the regress_target should be transfromed accroding to the mean shape.The paper only point out the index-shape feature should transfrom like this.
2.besides, I'm confused why the threshold should be seleced randomly. and in the code: "(-0.2_max_diff,0.2_max_diff)" what's the purpose of scaling the range by 0.2 factor ?
i am wondering sorting the difference between two feature point and select the difference which best fit the data as threshold, does it work?
from facealignment.
- @chenliangren Sorry the link is wrong, and I have updated it.
- Please refer to Chapter 4 of the book Statistical Models of Appearance for Computer Vision via the above link, especially the section Aligning the Training Set
- In fact, the threshold can be chosen in other ways, for example, choose the threshold to minimize the entropy and many other measures. You could try it.
from facealignment.
@Soundsilence Hi, I'm confused about the code of SimilarityTransform function.
I have read your post and also the appendix of the materials your referred. But I don't understand your method calculating the "scale" in the code.
In the post, we need firstly get a and b, and then using s^2 = a^2 + b^2 to the final result. But you just calculated the covariance matrix and used the ratio of their L2-norm as the scale. Could you explain the underlying principle?
from facealignment.
@windpls It's indeed quite confusing. The code snippet is inconsistent with Appendix B of the book
from facealignment.
I have no idea what's going on with this function's code, but the output really doesn't make sense. I've tried implementing it as explained in Appendix B and it was simple and yielded a logical output that had lesser MSE than that produced by the current implementation. I suggest re-implementing this function.
from facealignment.
Sorry that the code is very old and I am not even sure whether this is the version I use. Feel free to paste the correct code here and I would be happy to correct it. Thanks.
from facealignment.
Here is my code, let me know if there's any adjustments to be made.
void SimilarityTransform(const Mat_& shape1, const Mat_& shape2,
Mat_& rotation,double& scale){
rotation = Mat::zeros(2,2,CV_64FC1);
scale = 0;
// center the data
double center_x_1 = 0;
double center_y_1 = 0;
double center_x_2 = 0;
double center_y_2 = 0;
for (int i = 0; i < shape1.rows; i++) {
center_x_1 += shape1(i, 0);
center_y_1 += shape1(i, 1);
center_x_2 += shape2(i, 0);
center_y_2 += shape2(i, 1);
}
center_x_1 /= shape1.rows;
center_y_1 /= shape1.rows;
center_x_2 /= shape2.rows;
center_y_2 /= shape2.rows;
Mat_<double> temp1 = shape1.clone();
Mat_<double> temp2 = shape2.clone();
for (int i = 0; i < shape1.rows; i++) {
temp1(i, 0) -= center_x_1;
temp1(i, 1) -= center_y_1;
temp2(i, 0) -= center_x_2;
temp2(i, 1) -= center_y_2;
}
double num_a = 0;
double num_b = 0;
double den = 0;
for (int i = 0; i < shape1.rows; i++) {
num_a = num_a + temp1(i, 0) * temp2(i, 0) + temp1(i, 1) * temp2(i, 1);
num_b = num_b + temp1(i, 0) * temp2(i, 1) - temp1(i, 1) * temp2(i, 0);
den = den + temp1(i, 0) * temp1(i, 0) + temp1(i, 1) * temp1(i, 1);
}
double a = num_a / den;
double b = num_b / den;
double theta = atan(b / a);
double scale = sqrt(pow(a, 2) + pow(b, 2));
double cos_theta = cos(theta);
double sin_theta = sin(theta);
rotation(0,0) = cos_theta;
rotation(0,1) = -sin_theta;
rotation(1,0) = sin_theta;
rotation(1,1) = cos_theta;
}
from facealignment.
Here is my code, let me know if there's any adjustments to be made.
void SimilarityTransform(const Mat_& shape1, const Mat_& shape2,
Mat_& rotation,double& scale){
rotation = Mat::zeros(2,2,CV_64FC1);
scale = 0;// center the data double center_x_1 = 0; double center_y_1 = 0; double center_x_2 = 0; double center_y_2 = 0; for (int i = 0; i < shape1.rows; i++) { center_x_1 += shape1(i, 0); center_y_1 += shape1(i, 1); center_x_2 += shape2(i, 0); center_y_2 += shape2(i, 1); } center_x_1 /= shape1.rows; center_y_1 /= shape1.rows; center_x_2 /= shape2.rows; center_y_2 /= shape2.rows; Mat_<double> temp1 = shape1.clone(); Mat_<double> temp2 = shape2.clone(); for (int i = 0; i < shape1.rows; i++) { temp1(i, 0) -= center_x_1; temp1(i, 1) -= center_y_1; temp2(i, 0) -= center_x_2; temp2(i, 1) -= center_y_2; } double num_a = 0; double num_b = 0; double den = 0; for (int i = 0; i < shape1.rows; i++) { num_a = num_a + temp1(i, 0) * temp2(i, 0) + temp1(i, 1) * temp2(i, 1); num_b = num_b + temp1(i, 0) * temp2(i, 1) - temp1(i, 1) * temp2(i, 0); den = den + temp1(i, 0) * temp1(i, 0) + temp1(i, 1) * temp1(i, 1); } double a = num_a / den; double b = num_b / den; double theta = atan(b / a); double scale = sqrt(pow(a, 2) + pow(b, 2)); double cos_theta = cos(theta); double sin_theta = sin(theta); rotation(0,0) = cos_theta; rotation(0,1) = -sin_theta; rotation(1,0) = sin_theta; rotation(1,1) = cos_theta;
}
There's an error due to redefinition of scale, so remove the double before scale near the end.
from facealignment.
Related Issues (20)
- How much time does it cost to do predicting for an image? HOT 4
- how long would this code spend when we detect feature points HOT 1
- how to get boundingbox.txt and keypoints.txt? HOT 1
- It seem has a bug in 天河
- The trained Model HOT 5
- Sir, can you upload the dabaset and tain model which is shown in the sample results.
- Segmentation Fault in test code HOT 1
- keypoint.txt landmark is error?
- Performance issue
- Couldn't get output model.txt after trainning HOT 1
- CMakeLists.txt should include opencv headers
- The purpose of the bounding box HOT 1
- Can I detect the face_profile with the original code?
- Bug in calculate_covariance? HOT 1
- How to accelerate the algorithm ,And OpenMP is OK?
- Training Own model
- Quite confused by "find max correlation" in Fern.cpp
- Random Projection
- how to understand the random projection in this parper
- Missing term in correlation calculation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facealignment.