@@ -103,11 +103,11 @@ class FacemarkAAMImpl : public FacemarkAAM {
103
103
104
104
bool getData (void * items) CV_OVERRIDE;
105
105
106
- bool fitConfig ( InputArray image, const std::vector< Rect >& roi, std::vector<std::vector<Point2f> >& _landmarks, const std::vector<Config> &runtime_params ) CV_OVERRIDE;
106
+ bool fitConfig ( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector<Config> &runtime_params ) CV_OVERRIDE;
107
107
108
108
protected:
109
109
110
- bool fit ( InputArray image, const std::vector< Rect >& faces, CV_OUT std::vector<std::vector<Point2f> >& landmarks ) CV_OVERRIDE;
110
+ bool fit ( InputArray image, InputArray faces, OutputArrayOfArrays landmarks ) CV_OVERRIDE;
111
111
bool fitImpl ( const Mat image, std::vector<Point2f>& landmarks,const Mat R,const Point2f T,const float scale, const int sclIdx=0 );
112
112
113
113
bool addTrainingSample (InputArray image, InputArray landmarks) CV_OVERRIDE;
@@ -322,18 +322,54 @@ void FacemarkAAMImpl::training(void* parameters){
322
322
if (params.verbose ) printf (" Training is completed\n " );
323
323
}
324
324
325
- bool FacemarkAAMImpl::fit ( InputArray image, const std::vector<Rect >& roi, CV_OUT std::vector<std::vector<Point2f> >& _landmarks )
325
+ /* *
326
+ * @brief Copy the contents of a corners vector to an OutputArray, settings its size.
327
+ */
328
+ static void _copyVector2Output (std::vector< std::vector< Point2f > > &vec, OutputArrayOfArrays out)
329
+ {
330
+ out.create ((int )vec.size (), 1 , CV_32FC2);
331
+
332
+ if (out.isMatVector ()) {
333
+ for (unsigned int i = 0 ; i < vec.size (); i++) {
334
+ out.create (68 , 1 , CV_32FC2, i);
335
+ Mat &m = out.getMatRef (i);
336
+ Mat (Mat (vec[i]).t ()).copyTo (m);
337
+ }
338
+ }
339
+ else if (out.isUMatVector ()) {
340
+ for (unsigned int i = 0 ; i < vec.size (); i++) {
341
+ out.create (68 , 1 , CV_32FC2, i);
342
+ UMat &m = out.getUMatRef (i);
343
+ Mat (Mat (vec[i]).t ()).copyTo (m);
344
+ }
345
+ }
346
+ else if (out.kind () == _OutputArray::STD_VECTOR_VECTOR) {
347
+ for (unsigned int i = 0 ; i < vec.size (); i++) {
348
+ out.create (68 , 1 , CV_32FC2, i);
349
+ Mat m = out.getMat (i);
350
+ Mat (Mat (vec[i]).t ()).copyTo (m);
351
+ }
352
+ }
353
+ else {
354
+ CV_Error (cv::Error::StsNotImplemented,
355
+ " Only Mat vector, UMat vector, and vector<vector> OutputArrays are currently supported." );
356
+ }
357
+ }
358
+
359
+
360
+ bool FacemarkAAMImpl::fit ( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks )
326
361
{
327
362
std::vector<Config> config; // empty
328
363
return fitConfig (image, roi, _landmarks, config);
329
364
}
330
365
331
- bool FacemarkAAMImpl::fitConfig ( InputArray image, const std::vector< Rect >& roi, std::vector<std::vector<Point2f> >& _landmarks, const std::vector<Config> &configs )
366
+ bool FacemarkAAMImpl::fitConfig ( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector<Config> &configs )
332
367
{
333
- const std::vector<Rect > & faces = roi;
368
+ Mat roimat = roi.getMat ();
369
+ std::vector<Rect > faces = roimat.reshape (4 , roimat.rows );
334
370
if (faces.size ()<1 ) return false ;
335
371
336
- std::vector<std::vector<Point2f> > & landmarks = _landmarks ;
372
+ std::vector<std::vector<Point2f> > landmarks;
337
373
landmarks.resize (faces.size ());
338
374
339
375
Mat img = image.getMat ();
@@ -354,6 +390,7 @@ bool FacemarkAAMImpl::fitConfig( InputArray image, const std::vector<Rect>& roi,
354
390
fitImpl (img, landmarks[i], R,t, scale);
355
391
}
356
392
}
393
+ _copyVector2Output (landmarks, _landmarks);
357
394
358
395
return true ;
359
396
}
0 commit comments