2

In recent versions, OpenCV allows easy creation of keypoint detectors, descriptors or matchers using the create function, e.g.

cv::Ptr<cv::FeatureDetector> featureDetector = cv::FeatureDetector::create("FAST")

This call does NOT support parameters. E.g. SURF, FAST, etc. all have many parameters.

How can I change them now? I already figured out parts of it, e.g. I can get the list (list of strings) of parameters via

std::vector<std::string> parameters;
featureDetector->getParams(parameters);

and apparently I need to get somehow to the cv::Algorithm* object to call set(char*, bool/int/float/... value), but I don't know how.

MShekow
  • 1,526
  • 2
  • 14
  • 28
  • Oh lol I'm so dumb. featureDetector IS already an ALgorithm object. Just call `featureDetector->set("someParam", someValue)` – MShekow Jun 12 '12 at 15:52
  • You should delete this comment and make this the answer as well as accept it, so that others can see it was answered. Future visitors may have this same problem :) – mevatron Jun 12 '12 at 19:25

1 Answers1

5

Actually as it turns out, featureDetector already is an Algorithm object, i.e. you can simply set parameters on it directly, e.g.

featureDetector->set("someParam", someValue)

If you want to know about the parameters of a feature detector, you can use this function which prints them for you:

void ClassificationUtilities::printParams( cv::Algorithm* algorithm ) {
    std::vector<std::string> parameters;
    algorithm->getParams(parameters);

    for (int i = 0; i < (int) parameters.size(); i++) {
        std::string param = parameters[i];
        int type = algorithm->paramType(param);
        std::string helpText = algorithm->paramHelp(param);
        std::string typeText;

        switch (type) {
        case cv::Param::BOOLEAN:
            typeText = "bool";
            break;
        case cv::Param::INT:
            typeText = "int";
            break;
        case cv::Param::REAL:
            typeText = "real (double)";
            break;
        case cv::Param::STRING:
            typeText = "string";
            break;
        case cv::Param::MAT:
            typeText = "Mat";
            break;
        case cv::Param::ALGORITHM:
            typeText = "Algorithm";
            break;
        case cv::Param::MAT_VECTOR:
            typeText = "Mat vector";
            break;
        }
        std::cout << "Parameter '" << param << "' type=" << typeText << " help=" << helpText << std::endl;
    }
}
MShekow
  • 1,526
  • 2
  • 14
  • 28