Пример #1
0
std::string recCard(const Image<PixRGB<byte> > &img)
{
  std::string cardName;

  std::vector< rutz::shared_ptr<VisualObjectMatch> > matches;
  rutz::shared_ptr<VisualObject>
    vo(new VisualObject("PIC", "PIC", img,
          Point2D<int>(-1,-1),
          std::vector<double>(),
          std::vector< rutz::shared_ptr<Keypoint> >(),
          USECOLOR));

    const uint nm =
      itsObjectDB.getObjectMatches(vo, matches, VOMA_SIMPLE,
      100U, //max objs to return
      0.5F, //keypoint distance score default 0.5F
      0.5F, //affine distance score default 0.5F
      1.0F, //minscore  default 1.0F
      3U, //min # of keypoint match
      100U, //keypoint selection thershold
      false //sort by preattentive
      );

    LINFO("Found %i", nm);

    if (nm > 0)
    {
      cardName = matches[0]->getVoTest()->getName();
      LINFO("***** %u object recognition match(es) *****", nm);
      for (uint i = 0 ; i < nm; i ++)
        LINFO("   Match with '%s' [score = %f]",
            matches[i]->getVoTest()->getName().c_str(),
            matches[i]->getScore());
    }
    else
      LINFO("***** Could not identify attended object! *****");


  return cardName;
}
Пример #2
0
std::string matchObject(Image<PixRGB<byte> > &ima){

  //find object in the database
  std::vector< rutz::shared_ptr<VisualObjectMatch> > matches;
  rutz::shared_ptr<VisualObject>
    vo(new VisualObject("PIC", "PIC", ima,
                        Point2D<int>(-1,-1),
                        std::vector<float>(),
                        std::vector< rutz::shared_ptr<Keypoint> >(),
                        USECOLOR));

  const uint nmatches = vdb.getObjectMatches(vo, matches, VOMA_SIMPLE,
      10000U, //max objs to return
      0.5F, //keypoint distance score default 0.5F
      0.5F, //affine distance score default 0.5F
      1.0F, //minscore  default 1.0F
      3U, //min # of keypoint match
      100U, //keypoint selection thershold
      false //sort by preattentive
      );

  std::string objName;
  //LINFO("Found %i", nmatches);
  if (nmatches > 0 ){
    rutz::shared_ptr<VisualObject> obj; //so we will have a ref to the last matches obj
    rutz::shared_ptr<VisualObjectMatch> vom;
    //for(unsigned int i=0; i< nmatches; i++){
    for(unsigned int i=0; i< 1; i++){
      vom = matches[i];
      obj = vom->getVoTest();

//      LINFO("### Object match with '%s' score=%f ID:%i",
//          obj->getName().c_str(), vom->getScore(), objId);
      objName = obj->getName();
    }

  }

  return objName;
}
Пример #3
0
std::string matchObject(Image<PixRGB<byte> > &ima)
{
  //find object in the database
  std::vector< rutz::shared_ptr<VisualObjectMatch> > matches;
  rutz::shared_ptr<VisualObject>
    vo(new VisualObject("PIC", "PIC", ima,
                        Point2D(-1,-1),
                        std::vector<double>(),
                        std::vector< rutz::shared_ptr<Keypoint> >(),
                        USECOLOR));

  const uint nmatches = vdb.getObjectMatches(vo, matches, VOMA_SIMPLE,
      5U, //max objs to return
      0.5F, //keypoint distance score default 0.5F
      0.5F, //affine distance score default 0.5F
      1.0F, //minscore  default 1.0F
      3U, //min # of keypoint match
      6U, //keypoint selection thershold
      false //sort by preattentive
      );

  LINFO("Found %i", nmatches);
  float score = 0, avgScore = 0, affineAvgDist = 0;
  int nkeyp = 0;
  int objId = -1;
  if (nmatches > 0 ){
    rutz::shared_ptr<VisualObject> obj; //so we will have a ref to the last matches obj
    rutz::shared_ptr<VisualObjectMatch> vom;
    //for(unsigned int i=0; i< nmatches; i++){
    for(unsigned int i=0; i< 1; i++){
      vom = matches[i];
      obj = vom->getVoTest();
      score = vom->getScore();
      nkeyp = vom->size();
      avgScore = vom->getKeypointAvgDist();
      affineAvgDist = vom->getAffineAvgDist();

      objId = atoi(obj->getName().c_str()+3);

      return obj->getName();
      LINFO("### Object match with '%s' score=%f ID:%i",
          obj->getName().c_str(), vom->getScore(), objId);

      //calculate the actual distance (location of keypoints) between
      //keypoints. If the same patch was found, then the distance should
      //be close to 0
      double dist = 0;
      for (int keyp=0; keyp<nkeyp; keyp++){
        const KeypointMatch kpm = vom->getKeypointMatch(keyp);

        float refX = kpm.refkp->getX();
        float refY = kpm.refkp->getY();

        float tstX = kpm.tstkp->getX();
        float tstY = kpm.tstkp->getY();
        dist += (refX-tstX) * (refX-tstX);
        dist += (refY-tstY) * (refY-tstY);
      }

   //   printf("%i:%s %i %f %i %f %f %f\n", objNum, obj->getName().c_str(),
   //       nmatches, score, nkeyp, avgScore, affineAvgDist, sqrt(dist));

      //analizeImage();
    }

  }

  return std::string("nomatch");
}
/*! Load a database, an image, and find best matches. */
int main(const int argc, const char **argv)
{
  MYLOGVERB = LOG_INFO;

  // check command-line args:
  if (argc < 3 || argc > 4)
    LFATAL("USAGE: app-match-SIFT-database <dbname.vdb> <image.png> "
           "[<fused.png>]");

  // load the database:
  VisualObjectDB vdb;
  if (vdb.loadFrom(argv[1]) == false)
    LFATAL("Cannot operate without a valid database.");

  // get input image:
  Image< PixRGB<byte> > colim = Raster::ReadRGB(argv[2]);

  // create visual object and extract keypoints:
  rutz::shared_ptr<VisualObject> vo(new VisualObject(argv[2], argv[2], colim));

  // get the matching objects:
  std::vector< rutz::shared_ptr<VisualObjectMatch> > matches;
  const uint nmatches = vdb.getObjectMatches(vo, matches, VOMA_KDTREEBBF);

  // prepare the fused image:
  Image< PixRGB<byte> > mimg;
  std::vector<Point2D<int> > tl, tr, br, bl;

  // if no match, forget it:
  if (nmatches == 0U)
    LINFO("### No matching object found.");
  else
    {
      // let the user know about the matches:
      for (uint i = 0; i < nmatches; i ++)
        {
          rutz::shared_ptr<VisualObjectMatch> vom = matches[i];
          rutz::shared_ptr<VisualObject> obj = vom->getVoTest();

          LINFO("### Object match with '%s' score=%f",
                obj->getName().c_str(), vom->getScore());

          // add to our fused image if desired:
          if (argc > 3)
            {
              mimg = vom->getTransfTestImage(mimg);

              // also keep track of the corners of the test image, for
              // later drawing:
              Point2D<int> ptl, ptr, pbr, pbl;
              vom->getTransfTestOutline(ptl, ptr, pbr, pbl);
              tl.push_back(ptl); tr.push_back(ptr);
              br.push_back(pbr); bl.push_back(pbl);
            }
        }

      // do a final mix between given image and matches:
      if (mimg.initialized())
        {
          mimg = Image<PixRGB<byte> >(mimg * 0.5F + colim * 0.5F);

          // finally draw all the object outlines:
          PixRGB<byte> col(255, 255, 0);
          for (uint i = 0; i < tl.size(); i ++)
            {
              drawLine(mimg, tl[i], tr[i], col, 1);
              drawLine(mimg, tr[i], br[i], col, 1);
              drawLine(mimg, br[i], bl[i], col, 1);
              drawLine(mimg, bl[i], tl[i], col, 1);
            }
        }
    }

  // save result image if desired:
  if (argc > 3)
    {
      if (mimg.initialized() == false)
        mimg = Image< PixRGB<byte> >(colim * 0.5F);
      Raster::WriteRGB(mimg, std::string(argv[3]));
    }

  return 0;
}