Using the PatMax Tool

This section describes how to use the PatMax vision tool. The following steps describe how to train PatMax using training image, and how to run PatMax to find instances of the trained pattern in a run-time image.

  1. Acquire an image to use for pattern training.
  2. Create a ccPMAlignPattern and train it using the training image.
  3. ccPMAlignPattern pat;
    pat.train(win);

  4. Set the pattern origin to a meaningful location within the training image.
  5. pat.origin(cc2Vect(50,50)); // In client coordinates

  6. Create a ccPMAlignResultSet to contain the results of the search.
  7. ccPMAlignResultSet set;

  8. Create a ccPMAlignRunParams and configure it with the number of results to find, the zone, and the degrees of freedom.
  9. ccPMAlignRunParams params;
    params.numToFind(3);
    params.zoneEnable(ccPMAlignDefs::kUniformScale);
    params.zone(ccPMAlignDefs::kUniformScale, 1, 1.2);

  10. Perform the search by calling the ccPMAlignPattern::run() member function and supplying a run-time image, the ccPMAlignRunParams specifying the search parameters, and the ccPMAlignResultSet to contain the results of the search.
  11. pat.run(image, params, set);

  12. Extract the results from the ccPMAlignResultSet.
  13. cogOut << "number found = " << set.numFound() << std::endl;

    int i;
    for (i=0; i<set.numFound(); i++)
    {
    ccPMAlignResult r;
    set.getResult(i, r);

    cogOut << "result " << i << " = (x,y):(" << r.location().x()
    << "," << r.location().y() << ")" << " "
    << (r.accepted() ? "accepted" : "not accepted") << std::endl;
    }