fateme
June 14, 2022, 3:15pm
1
using this face_landmark_model.dat
in python
facemark = cv2.face.createFacemarkKazemi()
facemark.loadModel("face_landmark_model.dat")
ok, landmarks = facemark.fit(gray, faces)
and in c++
Ptr<Facemark> facemark = FacemarkKazemi::create();
facemark->loadModel("kazemi_model_helen.dat");
bool success = facemark->fit(frame,faces,landmarks);
for the same image, I get completely different landmark coordinates.
and when I draw the landmarks, using cpp API I get a reasonable output but the python result is irrelevant. I think fit function in python is buggy.
1 Like
berak
June 14, 2022, 4:59pm
2
can you add an example image & face rect(s), and print out the found landmarks, please ?
also, what is kazemi_model_helen.dat
? why are you using different models for this ?
dont tell me, it’s really a grayscale image (needs to be CV_8UC3 !)
1 Like
fateme
June 17, 2022, 4:20pm
3
sorry about the confusion about model names. It was just a typo, though the same model.
My issue was resolved after using CV_8UC3! It seems it was due to the grayscale image. but why shouldn’t a grayscale work?
berak
June 17, 2022, 4:50pm
4
admittedly hard to spot, but the (c++ !) src code tries to access it as CV_8UC3 (Vec3b):
Mat C,D;
for(size_t j=0;j<pixel_coordinates.size();j++){
C = (Mat_<double>(3,1) << pixel_coordinates[j].x, pixel_coordinates[j].y, 1);
D = transform_mat*C;
pixel_coordinates[j].x = float(D.at<double>(0,0));
pixel_coordinates[j].y = float(D.at<double>(1,0));
}
int val;
for(unsigned long j=0;j<pixel_coordinates.size();j++){
if(pixel_coordinates[j].x>0&&pixel_coordinates[j].x<img.cols&&pixel_coordinates[j].y>0&&pixel_coordinates[j].y<img.rows){
Vec3b val1 = img.at<Vec3b>((int)pixel_coordinates[j].y,(int)pixel_coordinates[j].x);
val = (int)(val1[0]+val1[1]+val1[2])/3;
}
else
val = 0;
pixel_intensities.push_back(val);
}
return true;
}
vector<regtree> FacemarkKazemiImpl::gradientBoosting(vector<training_sample>& samples,vector<Point2f> pixel_coordinates){
vector<regtree> forest;
we probably should improve documentation and add an assert here …