@@ -243,7 +243,7 @@ void FacemarkAAMImpl::training(void* parameters){
243
243
244
244
/* get PCA Projection vectors */
245
245
Mat S;
246
- getProjection (M.t (),S, param_max_n);
246
+ getProjection (M.t (), S, param_max_n);
247
247
/* Create similarity eig*/
248
248
Mat shape_S,shape_Q;
249
249
calcSimilarityEig (AAM.s0 ,S,AAM.Q ,AAM.S );
@@ -259,7 +259,7 @@ void FacemarkAAMImpl::training(void* parameters){
259
259
260
260
/* get the min and max of x and y coordinate*/
261
261
double min_x, max_x, min_y, max_y;
262
- s0_scaled_m = s0_scaled_m.reshape (1 );
262
+ s0_scaled_m = s0_scaled_m.reshape (1 , ( int )s0_scaled_m. total () );
263
263
Mat s0_scaled_x = s0_scaled_m.col (0 );
264
264
Mat s0_scaled_y = s0_scaled_m.col (1 );
265
265
minMaxIdx (s0_scaled_x, &min_x, &max_x);
@@ -287,7 +287,7 @@ void FacemarkAAMImpl::training(void* parameters){
287
287
if (params.verbose ) printf (" extract features from image #%i/%i\n " , (int )(i+1 ), (int )images.size ());
288
288
warped = warpImage (images[i],base_shape, facePoints[i], AAM.triangles , AAM.textures [scale].resolution ,AAM.textures [scale].textureIdx );
289
289
feat = getFeature<uchar>(warped, AAM.textures [scale].ind1 );
290
- texture_feats.push_back (feat.t ( ));
290
+ texture_feats.push_back (feat.reshape (feat. channels (), 1 ));
291
291
}
292
292
Mat T= texture_feats.t ();
293
293
@@ -307,7 +307,7 @@ void FacemarkAAMImpl::training(void* parameters){
307
307
for (int i =0 ;i<AAM.textures [scale].A .cols ;i++){
308
308
Mat c = AAM.textures [scale].A .col (i);
309
309
ud = getFeature<float >(c,fe_map);
310
- U_data.push_back (ud.t ( ));
310
+ U_data.push_back (ud.reshape (ud. channels (), 1 ));
311
311
}
312
312
Mat U = U_data.t ();
313
313
AAM.textures [scale].AA = orthonormal (U);
@@ -413,7 +413,7 @@ bool FacemarkAAMImpl::fitImpl( const Mat image, std::vector<Point2f>& landmarks,
413
413
Mat Wx_dp, Wy_dp;
414
414
createWarpJacobian (S, AAM.Q , AAM.triangles , AAM.textures [scl],Wx_dp, Wy_dp, Tp);
415
415
416
- std::vector<Point2f> s0_init = Mat (Mat (R*scale*AAM.scales [scl]*Mat (Mat (s0).reshape (1 )).t ()).t ()).reshape (2 );
416
+ std::vector<Point2f> s0_init = Mat (Mat (R*scale*AAM.scales [scl]*Mat (Mat (s0).reshape (1 , ( int )s0. size () )).t ()).t ()).reshape (2 );
417
417
std::vector<Point2f> curr_shape = Mat (Mat (s0_init)+Scalar (T.x ,T.y ));
418
418
curr_shape = Mat (1.0 /scale*Mat (curr_shape)).reshape (2 );
419
419
@@ -444,8 +444,8 @@ bool FacemarkAAMImpl::fitImpl( const Mat image, std::vector<Point2f>& landmarks,
444
444
AAM.textures [scl].resolution ,
445
445
AAM.textures [scl].textureIdx );
446
446
447
- I = getFeature<uchar>(warped, AAM.textures [scl].ind1 );
448
- II = getFeature<uchar>(warped, AAM.textures [scl].ind2 );
447
+ I = getFeature<uchar>(warped, AAM.textures [scl].ind1 ). t () ;
448
+ II = getFeature<uchar>(warped, AAM.textures [scl].ind2 ). t () ;
449
449
450
450
if (t==0 ){
451
451
c = A.t ()*(I-AAM.textures [scl].A0 ); // little bit different to matlab, probably due to datatype
@@ -480,8 +480,8 @@ bool FacemarkAAMImpl::fitImpl( const Mat image, std::vector<Point2f>& landmarks,
480
480
invert (Hfsic, iHfsic);
481
481
482
482
/* compute dp dq and dc*/
483
- Mat dqp = iHfsic*Jfsic.t ()*(II-AAM.textures [scl].AA0 );
484
- dc = AA.t ()*(II-Mat (Irec_vec)-J*dqp);
483
+ Mat dqp = iHfsic*Jfsic.t ()*(II-AAM.textures [scl].AA0 . t () );
484
+ dc = AA.t ()*(II-Mat (Irec_vec). t () -J*dqp);
485
485
warpUpdate (curr_shape, dqp, s0,S, AAM.Q , AAM.triangles ,Tp);
486
486
}
487
487
landmarks = Mat (scale*Mat (curr_shape)).reshape (2 );
@@ -602,16 +602,17 @@ Mat FacemarkAAMImpl::procrustes(std::vector<Point2f> P, std::vector<Point2f> Q,
602
602
reduce (Ys,sumYs, 0 , REDUCE_SUM);
603
603
604
604
// calculate the normrnd
605
- double normX = sqrt (Mat (sumXs.reshape (1 )).at <float >(0 )+Mat (sumXs.reshape (1 )).at <float >(1 ));
606
- double normY = sqrt (Mat (sumYs.reshape (1 )).at <float >(0 )+Mat (sumYs.reshape (1 )).at <float >(1 ));
605
+ Point2f sumXs0 = sumXs.at <Point2f>(0 ), sumYs0 = sumYs.at <Point2f>(0 );
606
+ double normX = sqrt (sumXs0.x + sumXs0.y );
607
+ double normY = sqrt (sumYs0.x + sumYs0.y );
607
608
608
609
// normalization
609
610
X0 = X0/normX;
610
611
Y0 = Y0/normY;
611
612
612
613
// reshape, convert to 2D Matrix
613
- Mat Xn=X0.reshape (1 );
614
- Mat Yn=Y0.reshape (1 );
614
+ Mat Xn=X0.reshape (1 , ( int )X0. total () );
615
+ Mat Yn=Y0.reshape (1 , ( int )Y0. total () );
615
616
616
617
// calculate the covariance matrix
617
618
Mat M = Xn.t ()*Yn;
@@ -634,7 +635,7 @@ Mat FacemarkAAMImpl::procrustes(std::vector<Point2f> P, std::vector<Point2f> Q,
634
635
trans[1 ] = t.at <float >(1 );
635
636
636
637
// calculate the recovered form
637
- Mat Qmat = Mat (Q).reshape (1 );
638
+ Mat Qmat = Mat (Q).reshape (1 , ( int )Q. size () );
638
639
639
640
return Mat (scale*Qmat*rot+trans).clone ();
640
641
}
@@ -777,7 +778,7 @@ Mat FacemarkAAMImpl::orthonormal(Mat Mo){
777
778
return O.colRange (0 ,k).clone ();
778
779
}
779
780
780
- void FacemarkAAMImpl::calcSimilarityEig (std::vector<Point2f> s0,Mat S, Mat & Q_orth, Mat & S_orth){
781
+ void FacemarkAAMImpl::calcSimilarityEig (std::vector<Point2f> s0, Mat S, Mat & Q_orth, Mat & S_orth){
781
782
int npts = (int )s0.size ();
782
783
783
784
Mat Q = Mat::zeros (2 *npts,4 ,CV_32FC1);
@@ -792,7 +793,7 @@ void FacemarkAAMImpl::calcSimilarityEig(std::vector<Point2f> s0,Mat S, Mat & Q_o
792
793
w.copyTo (c0);
793
794
794
795
/* c1 = [-s0(npts:2*npts); s0(0:npts-1)]*/
795
- Mat s0_mat = Mat (s0).reshape (1 );
796
+ Mat s0_mat = Mat (s0).reshape (1 , ( int )s0. size () );
796
797
// s0_mat.convertTo(s0_mat, CV_64FC1);
797
798
Mat swapper = Mat::zeros (2 ,npts,CV_32FC1);
798
799
Mat s00 = s0_mat.col (0 );
@@ -826,11 +827,15 @@ void FacemarkAAMImpl::calcSimilarityEig(std::vector<Point2f> s0,Mat S, Mat & Q_o
826
827
Mat allOrth = orthonormal (all.t ());
827
828
Q_orth = allOrth.colRange (0 ,4 ).clone ();
828
829
S_orth = allOrth.colRange (4 ,allOrth.cols ).clone ();
829
-
830
830
}
831
831
832
832
inline Mat FacemarkAAMImpl::linearize (Mat s){ // all x values and then all y values
833
- return Mat (s.reshape (1 ).t ()).reshape (1 ,2 *s.rows );
833
+ int npoints = s.rows ;
834
+ if (s.channels () > 1 ) {
835
+ npoints = (int )s.total ();
836
+ s = s.reshape (1 , npoints);
837
+ }
838
+ return Mat (s.t ()).reshape (1 , 2 *npoints);
834
839
}
835
840
inline Mat FacemarkAAMImpl::linearize (std::vector<Point2f> s){ // all x values and then all y values
836
841
return linearize (Mat (s));
@@ -843,7 +848,7 @@ void FacemarkAAMImpl::delaunay(std::vector<Point2f> s, std::vector<Vec3i> & tria
843
848
std::vector<Vec6f> tp;
844
849
845
850
double min_x, max_x, min_y, max_y;
846
- Mat S = Mat (s).reshape (1 );
851
+ Mat S = Mat (s).reshape (1 , ( int )s. size () );
847
852
Mat s_x = S.col (0 );
848
853
Mat s_y = S.col (1 );
849
854
minMaxIdx (s_x, &min_x, &max_x);
@@ -954,8 +959,8 @@ Mat FacemarkAAMImpl::warpImage(
954
959
source[1 ] = curr_shape[triangles[i][1 ]];
955
960
source[2 ] = curr_shape[triangles[i][2 ]];
956
961
957
- Mat target_mtx = Mat (target).reshape (1 )-1.0 ;
958
- Mat source_mtx = Mat (source).reshape (1 )-1.0 ;
962
+ Mat target_mtx = Mat (target).reshape (1 ,( int )target. size () )-1.0 ;
963
+ Mat source_mtx = Mat (source).reshape (1 ,( int )source. size () )-1.0 ;
959
964
Mat U = target_mtx.col (0 );
960
965
Mat V = target_mtx.col (1 );
961
966
Mat X = source_mtx.col (0 );
@@ -979,7 +984,7 @@ Mat FacemarkAAMImpl::warpImage(
979
984
R=A.colRange (0 ,2 );
980
985
t=A.colRange (2 ,3 );
981
986
982
- Mat pts_ori = Mat (textureIdx[i]).reshape (1 );
987
+ Mat pts_ori = Mat (textureIdx[i]).reshape (1 , ( int )textureIdx[i]. size () );
983
988
Mat pts = pts_ori.t (); // matlab
984
989
Mat bx = pts_ori.col (0 );
985
990
Mat by = pts_ori.col (1 );
@@ -1081,8 +1086,9 @@ void FacemarkAAMImpl::warpUpdate(std::vector<Point2f> & shape, Mat delta, std::v
1081
1086
Mat (ds0, Range ((int )s0.size (),(int )s0.size ()*2 )).copyTo (c1);
1082
1087
1083
1088
Mat s_new = computeWarpParts (shape,s0,ds0_mat, triangles, Tp);
1089
+ s_new -= Mat (s0).reshape (1 , (int )s0.size ());
1084
1090
1085
- Mat diff =linearize (Mat ( s_new - Mat (s0). reshape ( 1 )) );
1091
+ Mat diff = linearize (s_new);
1086
1092
1087
1093
Mat r = Q.t ()*diff;
1088
1094
Mat p = S.t ()*diff;
@@ -1118,8 +1124,9 @@ Mat FacemarkAAMImpl::computeWarpParts(std::vector<Point2f> curr_shape,std::vecto
1118
1124
source[2 ] = curr_shape[triangles[idx][2 ]];
1119
1125
1120
1126
A = getAffineTransform (target,source);
1127
+ Mat p_m = Mat (p).reshape (1 , (int )p.size ());
1121
1128
1122
- Mat (A*Mat (p) ).reshape (2 ).copyTo (v);
1129
+ Mat (A*p_m ).reshape (2 ).copyTo (v);
1123
1130
vx.push_back (v[0 ].x );
1124
1131
vy.push_back (v[0 ].y );
1125
1132
}// j
@@ -1134,7 +1141,7 @@ Mat FacemarkAAMImpl::computeWarpParts(std::vector<Point2f> curr_shape,std::vecto
1134
1141
new_shape.push_back (Point2f (mx,my));
1135
1142
} // s0.size()
1136
1143
1137
- return Mat (new_shape).reshape (1 ).clone ();
1144
+ return Mat (new_shape).reshape (1 , ( int )new_shape. size () ).clone ();
1138
1145
}
1139
1146
1140
1147
void FacemarkAAMImpl::gradient (const Mat M, Mat & gx, Mat & gy){
0 commit comments