Ask Your Question
0

How do I change predict method in class FaceRecognizer

asked 2013-03-16 19:17:24 -0600

updated 2013-03-16 19:32:30 -0600

I trying to custom predict method for my application, but doesn't work. How can I do this?

I wanna change this part in facerec.cpp, where would be calculated Mahalanobis distance:

for(size_t sampleIdx = 0; sampleIdx < _projections.size(); sampleIdx++) {
        double dist = norm(_projections[sampleIdx], q, NORM_L2);
        if((dist < minDist) && (dist < _threshold)) {
            minDist = dist;
            minClass = _labels.at<int>((int)sampleIdx);
        }
    }

I change in contrib.hpp to:

 virtual int predict(InputArray src,int distance) const = 0;

where distance is the type identifier of the distance to be calculated (Euclidian, Mahalanobis, Cosine)

edit retag flag offensive close merge delete

Comments

what are you trying ? where did it went wrong ? what did you customize ?

-1 for "it doesn't work"

berak gravatar imageberak ( 2013-03-16 19:19:07 -0600 )edit

which one is it, actually ? eigen, lbp, fisher ? ah eigen ( looking at the code )

berak gravatar imageberak ( 2013-03-16 19:36:51 -0600 )edit

But I will change for three.

Bruno Teixeira gravatar imageBruno Teixeira ( 2013-03-16 19:39:09 -0600 )edit

still, you'll have to change fisher and lbp as well,

and, believe me, you don't want mahalanobis distance with lbp ( chi_square is the recommended distance there [histograms] )

berak gravatar imageberak ( 2013-03-16 20:16:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-03-16 19:48:32 -0600

berak gravatar image

updated 2013-03-16 20:50:30 -0600

"i got a hammer, now everything looks like a nail"


eigen, fisher, lbp, they all inherit a virtual method predict(one of 2 actually) method from FaceRecognizer, so, if you insist on your current approach(modifying the interface), you 'll have to modify FaceRecognizer,

and EVERYTHING, that inherits FaceRecognizer.

not recommended.

( oh, and please DON'T try to abuse the distance param for this, it's needed elsewhere)

better approach , imho (since it does not need to modify the FaceRecognizer interface),

extend the Algorithm interface:

  1. add a variable to the Eigen recognizer, that holds the comparison flag (NORM_L2 vs NORM_MALAHANOBIS)
  2. make it accessible via the get() set() params interface ( so you can switch the behaviour by set() ing a value at runtime)
  3. additionally you'll have to modify the serialization ( save() load() )

again, PLEASE TRY WITHOUT MODYFYING THE INTERFACE!

if your idea (changing the distance func ) turns out nicely, ofc. you want EVERYONE to use it. make it an option as easy to use as possible.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-16 19:17:24 -0600

Seen: 469 times

Last updated: Mar 16 '13