Exemplo n.º 1
0
/**
 * The entry point for console version of ShowGraph
 */
static int doAll( int argc, char **argv)
{
    QApplication app(argc, argv);
    app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);

    Conf conf;
    conf.addOption( new Option( OPT_STRING, "f", "file", "input graph description file name"));
    conf.addOption( new Option( OPT_STRING, "o", "output", "output image file name"));
    conf.readArgs( argc, argv);
    
    Option *fopt = conf.longOption("file");
    Option *out_opt = conf.longOption("output");
    
    assertd( isNotNullP( fopt));
    assertd( isNotNullP( out_opt));
    if ( fopt->isDefined())
    {
        QString xmlname = fopt->string();
        QString outname("image.png");
        Renderer r;
        if ( out_opt->isDefined())
        {
            outname = out_opt->string();
        }
        r.render( xmlname, outname);
    } else
    {
        conf.printOpts(); // Print options to console
    }
    //return app.exec();
    return 0;
}
Exemplo n.º 2
0
PlaneVisionMessage Vision::findPlane(IplImage* image, double blobX, double blobY){
  if(image == nullptr){
    return PlaneVisionMessage();
  }
  vector<ImageMessage> extras;
  pair<CvBlobs,IplImage*> candidatesWithLabel = findCandidates(image,extras);
  auto candidates = candidatesWithLabel.first;
  Option<CvBlob> bestCandidate = None<CvBlob>();
  double bestDistance = DBL_MAX;
    for (CvBlobs::const_iterator it=candidates.begin(); it!=candidates.end(); ++it){
      auto blob = it->second;
      double dx = blob->centroid.x - blobX;
      double dy = blob->centroid.y - blobY;
      if (dx * dx + dy * dy  < bestDistance){
        bestDistance = dx * dx + dy * dy;
        bestCandidate = Some<CvBlob>(*blob);
      }
    }
    cvReleaseBlobs(candidates);
    if (bestCandidate.isDefined()) {
      return PlaneVisionMessage(*bestCandidate,image,extras,true);
    } else {
      return PlaneVisionMessage(image,extras);
    }
}
Exemplo n.º 3
0
  template<typename T> T StabConfig::getOpt(const QCommandLineParser &parser, ErrorMessageHelper &die,
    const QCommandLineOption &opt, const Option<T> &min, const Option<T> &max, T def,
    QString parseErrMsg, QString outOfRangeErrMsg) {

    bool ok = false;
    T i;
    if (parser.isSet(opt)) {
      if (is_same<int, T>::value)
        i = parser.value(opt).toInt(&ok);
      if (is_same<float, T>::value)
        i = parser.value(opt).toFloat(&ok);
      if (is_same<double, T>::value)
        i = parser.value(opt).toDouble(&ok);

      if (!ok) die << parseErrMsg;

      if ((min.isDefined() && i < *min) || (max.isDefined() && i > *max))
        die << outOfRangeErrMsg;

      return i;
    }
    return def;
  }
Exemplo n.º 4
0
PlaneVisionMessage Vision::findPlane( IplImage* image,
    list<PlaneVisionMessage> previousPlanes){

  if(image == nullptr){
    return PlaneVisionMessage();
  }

  if (blobXOption.isDefined() && blobYOption.isDefined()){
    PlaneVisionMessage result = findPlane(image,*blobXOption,*blobYOption);
    blobXOption = None<double>();
    blobYOption = None<double>();
    return result;
  }

  vector<ImageMessage> extras;
  pair<CvBlobs,IplImage*> candidatesWithLabel = findCandidates(image,extras);

  auto candidates = candidatesWithLabel.first;
  auto label = candidatesWithLabel.second;
  int minBlobPX = minBlobSize * (double)image->height;
  int maxBlobPX = maxBlobSize * (double)image->height;

  double maxScore = -DBL_MAX;
  Option<CvBlob> bestCandidate = None<CvBlob>();

  DEBUG("PROFILE: Scoring begins for " + boost::lexical_cast<string>(candidates.size())
             + " candidates, " + boost::lexical_cast<string>(previousPlanes.size()) +
             " previous planes." );

  if ( previousPlanes.size() >= 1){
    auto lastBlob = previousPlanes.front().planeBlob;
    for (CvBlobs::const_iterator it=candidates.begin(); it!=candidates.end(); ++it){
      auto blob = it->second;
      auto displacementVector = getDisplacement(blob,&lastBlob);
      double dPosition = sqrt(pow(displacementVector[0],2)+ pow(displacementVector[1],2));

      double blobHeight = blob->maxy - blob->miny;
      double blobWidth = blob->maxx - blob->minx;

      if ( blobHeight > maxBlobPX || blobHeight < minBlobPX ){
        DEBUG("Filtered blob by height: Exceeds " + boost::lexical_cast<string>(maxBlobPX));
        continue;
      }

      if ( blobWidth > maxBlobPX || blobWidth < minBlobPX ){
        DEBUG("Filtered blob by width");
        continue;
      }

      if ( dPosition > image->width * image->height / (25.0 * positionThresh)){
        DEBUG("Filtered blob by position");
        continue;
      }

      if ( sizeThresh != 0){ 
        if ( (double)blob->area / (double)lastBlob.area < (0.1 * sizeThresh) || 
             (double)blob->area / (double)lastBlob.area > (10.0 / sizeThresh)) {
          DEBUG("Filtered blob by size");
           continue;
        }
      }

      if (useColor && hasColor){
        CvScalar color = cvBlobMeanColor(blob,label,image);
        double h,s,v;
        Vision::rgbToHsv(color.val[0],color.val[1],color.val[2],h,s,v);
        double dColor = fabs(h - goodH); 
        if (dColor > 360.0 * (1.0 - colorThresh)) {
          DEBUG("Filtered blob by color: " + boost::lexical_cast<string>(dColor));
          continue;
        }
      } else if (!useColor) {
        cvReleaseImage(&label);
      }
      double score = -dPosition;
      if ( score > maxScore ){
        maxScore = score;
        bestCandidate = Some<CvBlob>(*blob);
      }
    }
  } 
  cvReleaseBlobs(candidates);
  if (bestCandidate.isDefined()) {
    if (!hasColor && useColor){
      auto candidate = bestCandidate.get();
      CvScalar color = cvBlobMeanColor(&candidate,label,image);
      rgbToHsv(color.val[2],color.val[1],color.val[0],goodH,goodS,goodV);
      Log::log("Color found");
      Log::log("GoodH: " + boost::lexical_cast<string>(goodH));
      Log::log("GoodS: " + boost::lexical_cast<string>(goodS));
      Log::log("GoodV: " + boost::lexical_cast<string>(goodV));
      hasColor = true;
    }
    cvReleaseImage(&label);
    return PlaneVisionMessage(*bestCandidate,image,extras);
  } else {
    return PlaneVisionMessage(image,extras);
  }
}