示例#1
0
 TyErrorId
 extractConfigOption(
         const AnnotatorContext& crclConfig,
         const UnicodeString* cpclConfigGroup,
         const ConfigOptionInfo::StOptionInfo& crclOptionInfo,
         T& rclTargetVariable
 ) {
     assert(!crclOptionInfo.bOptionIsMultiValued);
     // assume the worst
     TyErrorId utErrId = UIMA_ERR_CONFIG_SECTION_NOT_FOUND;
     assert(crclOptionInfo.uiNbrOfValuesRequired <= 1);
     if (EXISTS(cpclConfigGroup)) {
         //utErrId = crclConfig.extractValue(crclOptionInfo.cpszOptionName, rclTargetVariable);
         utErrId = crclConfig.extractValue(*cpclConfigGroup, crclOptionInfo.cpszOptionName, rclTargetVariable);
     } else {
         utErrId = crclConfig.extractValue(crclOptionInfo.cpszOptionName, rclTargetVariable);
     }
     if (utErrId != UIMA_ERR_NONE) { // could not find option or value(s)
         if (crclOptionInfo.uiNbrOfValuesRequired != 0
             || crclOptionInfo.cpszDefaultValueAsString == NULL) {
             // required value not there: return error we got from config
             return utErrId;
         }
         convertFromString((std::string) crclOptionInfo.cpszDefaultValueAsString, rclTargetVariable);
         // we used the provided default: this is not an error so we return OK
         utErrId = UIMA_ERR_NONE;
     }
     return utErrId;
 }
示例#2
0
  TyErrorId initialize(AnnotatorContext &ctx)
  {
    outInfo("initialize");

    if(ctx.isParameterDefined("boardRows"))
    {
      ctx.extractValue("boardRows", boardRows);
    }
    if(ctx.isParameterDefined("boardCols"))
    {
      ctx.extractValue("boardCols", boardCols);
    }
    if(ctx.isParameterDefined("boardDistX"))
    {
      ctx.extractValue("boardDistX", boardDistX);
    }
    if(ctx.isParameterDefined("boardDistY"))
    {
      ctx.extractValue("boardDistY", boardDistY);
    }
    if(ctx.isParameterDefined("boardType"))
    {
      std::string sType;
      ctx.extractValue("boardType", sType);
      if(sType == "circle")
      {
        boardType = CIRCLE;
      }
      else if(sType == "chess")
      {
        boardType = CHESS;
      }
    }

    boardSize = cv::Size(boardCols, boardRows);

    // Create world points
    pointsWorld = cv::Mat(boardRows * boardCols, 3, CV_32F);
    for(size_t r = 0; r < pointsWorld.rows; ++r)
    {
      float *it = pointsWorld.ptr<float>(r);
      *it++ = boardDistX * (r % boardCols);
      *it++ = boardDistY * (r / boardCols);
      *it++ = 0;
    }

    return UIMA_ERR_NONE;
  }
  TyErrorId initialize(AnnotatorContext &ctx)
  {
    outInfo("initialize");
    ctx.extractValue("mode", mode);

    return UIMA_ERR_NONE;
  }
示例#4
0
  TyErrorId initialize(AnnotatorContext &ctx)
  {
    outInfo("initialize");
    resourcesPath = ros::package::getPath("rs_resources") + '/';

    ctx.extractValue("DeCafH5File", h5_file);
    ctx.extractValue("DeCafListFile", list_file);
    ctx.extractValue("DeCafKDTreeIndices", kdtree_file);
    ctx.extractValue("DeCafKNeighbors", k);

    ctx.extractValue("caffe_model_file", caffe_model_file);
    ctx.extractValue("caffe_trained_file", caffe_trained_file);
    ctx.extractValue("caffe_mean_file", caffe_mean_file);
    ctx.extractValue("caffe_label_file", caffe_label_file);

    ctx.extractValue("asGT", asGT);

    outInfo(h5_file);
    outInfo(list_file);
    outInfo(kdtree_file);
    outInfo(caffe_model_file);
    outInfo(caffe_trained_file);
    outInfo(caffe_mean_file);
    outInfo(caffe_label_file);

    // Check if the data has already been saved to disk
    if(!boost::filesystem::exists(resourcesPath + h5_file) ||
       !boost::filesystem::exists(resourcesPath + list_file) ||
       !boost::filesystem::exists(resourcesPath + kdtree_file) ||
       !boost::filesystem::exists(resourcesPath + caffe_model_file) ||
       !boost::filesystem::exists(resourcesPath + caffe_trained_file) ||
       !boost::filesystem::exists(resourcesPath + caffe_mean_file) ||
       !boost::filesystem::exists(resourcesPath + caffe_label_file))
    {
      outError("files not found!");
      return UIMA_ERR_USER_ANNOTATOR_COULD_NOT_INIT;
    }
    caffeProxyObj = std::make_shared<CaffeProxy>(resourcesPath + caffe_model_file,
                    resourcesPath + caffe_trained_file,
                    resourcesPath + caffe_mean_file,
                    resourcesPath + caffe_label_file);

    flann::Matrix<float> data;
    loadFileList(models, resourcesPath + list_file);
    flann::load_from_file(data, resourcesPath + h5_file, "training_data");
    outInfo("Training data found. Loaded " << data.rows << " models from " << h5_file << "/" << list_file);

    this->data = cv::Mat(data.rows, data.cols, CV_32F, data.ptr()).clone();
    index.build(this->data, cv::flann::KDTreeIndexParams());

    return UIMA_ERR_NONE;
  }
示例#5
0
  virtual TyErrorId train(AnnotatorContext &ctx, const cv::Mat &descriptors, const cv::Mat &responses)
  {
    if(ctx.isParameterDefined("kNN"))
    {
      ctx.extractValue("kNN", kNN);
    }
    if(ctx.isParameterDefined("maxK"))
    {
      ctx.extractValue("maxK", maxK);
    }
    if(ctx.isParameterDefined("isRegression"))
    {
      ctx.extractValue("isRegression", isRegression);
    }

    model->train(descriptors, responses, cv::Mat(), isRegression, maxK);
    return UIMA_ERR_NONE;
  }
  TyErrorId initialize(AnnotatorContext &ctx)
  {
    outInfo("Initialize");

    if(ctx.isParameterDefined("use_transform"))
    {
      ctx.extractValue("use_transform", use_transform);
    }
    if(ctx.isParameterDefined("voxel_resolution"))
    {
      ctx.extractValue("voxel_resolution", voxel_resolution);
    }
    if(ctx.isParameterDefined("seed_resolution"))
    {
      ctx.extractValue("seed_resolution", seed_resolution);
    }
    if(ctx.isParameterDefined("color_importance"))
    {
      ctx.extractValue("color_importance", color_importance);
    }
    if(ctx.isParameterDefined("spatial_importance"))
    {
      ctx.extractValue("spatial_importance", spatial_importance);
    }
    if(ctx.isParameterDefined("normal_importance"))
    {
      ctx.extractValue("normal_importance", normal_importance);
    }

    return UIMA_ERR_NONE;
  }
 TyErrorId initialize(AnnotatorContext &ctx)
 {
   if(ctx.isParameterDefined("minValueColor"))
   {
     ctx.extractValue("minValueColor", minValueColor);
   }
   if(ctx.isParameterDefined("minSaturationColor"))
   {
     ctx.extractValue("minSaturationColor", minSaturationColor);
   }
   if(ctx.isParameterDefined("maxValueBlack"))
   {
     ctx.extractValue("maxValueBlack", maxValueBlack);
   }
   if(ctx.isParameterDefined("minValueWhite"))
   {
     ctx.extractValue("minValueWhite", minValueWhite);
   }
   if(ctx.isParameterDefined("histogramCols"))
   {
     ctx.extractValue("histogramCols", histogramCols);
   }
   if(ctx.isParameterDefined("histogramRows"))
   {
     ctx.extractValue("histogramRows", histogramRows);
   }
   return UIMA_ERR_NONE;
 }
示例#8
0
  TyErrorId initialize(AnnotatorContext &ctx)
  {
    outInfo("initialize");

    if(ctx.isParameterDefined("border"))
    {
      ctx.extractValue("border", border);
    }
    std::vector<std::string *> temp;
    if(ctx.isParameterDefined("defaultRegions"))
    {
      ctx.extractValue("defaultRegions", temp);
      for(auto s : temp)
      {
        outInfo(*s);
        defaultRegions.push_back(*s);
      }
    }

    if(ctx.isParameterDefined("enable_change_detection"))
    {
      ctx.extractValue("enable_change_detection", changeDetection);
    }
    if(ctx.isParameterDefined("enable_frustum_culling"))
    {
      ctx.extractValue("enable_frustum_culling", frustumCulling_);
    }
    if(ctx.isParameterDefined("pixel_threshold"))
    {
      ctx.extractValue("pixel_threshold", pixelThreshold);
    }
    if(ctx.isParameterDefined("depth_threshold"))
    {
      ctx.extractValue("depth_threshold", depthThreshold);
    }
    if(ctx.isParameterDefined("global_threshold"))
    {
      ctx.extractValue("global_threshold", threshold);
    }
    if(ctx.isParameterDefined("change_timeout"))
    {
      int tmp = 120;
      ctx.extractValue("change_timeout", tmp);
      timeout = tmp;
    }
    return UIMA_ERR_NONE;
  }
示例#9
0
  /*
   * Initializes annotator
   */
  TyErrorId initialize(AnnotatorContext &ctx)
  {
    outInfo("initialize");

    if(ctx.isParameterDefined("keypointDetector"))
    {
      ctx.extractValue("keypointDetector", keypointDetector);
    }
    else
    {
      outError("no keypoint detector provided!");
      return UIMA_ERR_ANNOTATOR_MISSING_INIT;
    }

    if(ctx.isParameterDefined("featureExtractor"))
    {
      ctx.extractValue("featureExtractor", featureExtractor);
    }
    else
    {
      outError("no feature extractor provided!");
      return UIMA_ERR_ANNOTATOR_MISSING_INIT;
    }

    outDebug("creating " << keypointDetector << " key points detector...");
    detector = cv::FeatureDetector::create(keypointDetector);
    if(detector.empty())
    {
      outError("creation failed!");
      return UIMA_ERR_ANNOTATOR_MISSING_INIT;
    }

#if OUT_LEVEL == OUT_LEVEL_DEBUG
    printParams(detector);
#endif
    setupAlgorithm(detector);

    outDebug("creating " << featureExtractor << " feature extractor...");
    extractor = cv::DescriptorExtractor::create(featureExtractor);
    if(extractor.empty())
    {
      outError("creation failed!");
      return UIMA_ERR_ANNOTATOR_MISSING_INIT;
    }

#if OUT_LEVEL == OUT_LEVEL_DEBUG
    printParams(extractor);
#endif
    setupAlgorithm(extractor);

    if(featureExtractor == "SIFT" || featureExtractor == "SURF")
    {
      featureType = "numerical";
    }
    else
    {
      featureType = "binary";
    }

    return UIMA_ERR_NONE;
  }
示例#10
0
TyErrorId
AnnotatorDump::initialize(
  AnnotatorContext & rclAnnotatorContext) {
  TyErrorId                  tyErrId;
  string                     strFileName;
  int                     uiOutputStyle;


  // Default Values

  // in append mode all data in a session/collection is dumped into one file
  // otherwise the same dump file is deleted and rewritten for each document
  // in the session/collection
  // default is false
  iv_bAppendFile = false;

  // we don't dump the Document Buffer
  iv_bDumpDocBuffer = false;
  iv_bSaveDocBuffer = false;

  // the representation will be in Xml-Format
  iv_enOutputStyle = Xml;

  // Reading the Values from the Config-Section

  //Filename for the Output-Stream
  UnicodeString us;
  tyErrId = rclAnnotatorContext.extractValue(ANNOTATOR_DUMP_PARAM_OUTFILE, us);

  // Convert filename to default encoding
  UnicodeStringRef usr(us);
  usr.extract(strFileName);

  if (tyErrId != UIMA_ERR_NONE) {
    getAnnotatorContext().getLogger().logError(
      _TEXT("Required option '" ANNOTATOR_DUMP_PARAM_OUTFILE "' not found"),
      (long)ANNOTATOR_DUMP_ERROR_OPEN);
    return(UIMA_ERR_USER_ANNOTATOR_CONFIG_INVALID_PARAM);
  }

  iv_clOutputFilename = strFileName.c_str();
  (void) rclAnnotatorContext.extractValue(ANNOTATOR_DUMP_PARAM_DUMP_DOCBUFFER, iv_bDumpDocBuffer);
  (void) rclAnnotatorContext.extractValue(ANNOTATOR_DUMP_PARAM_SAVE_DOCBUFFER, iv_bSaveDocBuffer);
  (void) rclAnnotatorContext.extractValue(ANNOTATOR_DUMP_PARAM_APPEND, iv_bAppendFile);

  // in append mode all data in a session/collection is dumped into one file
  // otherwise the same dump file is deleted and rewritten for each document
  // in the session/collection
  if (iv_bAppendFile) {
    tyErrId = openOutputFile();
    if (tyErrId != UIMA_ERR_NONE) {
      return tyErrId;
    }
  }

  //Output Style
  uiOutputStyle = 0;
  tyErrId = rclAnnotatorContext.extractValue(ANNOTATOR_DUMP_PARAM_STYLE,  uiOutputStyle);
  if (tyErrId != UIMA_ERR_CONFIG_OPTION_NOT_FOUND) {
    switch (uiOutputStyle) {
    case 0:
      iv_enOutputStyle = Xml;
      break;
    case 1:
      iv_enOutputStyle = XCas;
      break;
    default:
      getAnnotatorContext().getLogger().logWarning(
        "Invalid Output Style. Use Default",
        (long) ANNOTATOR_DUMP_MSG_STYLE);
      break;
    }
  }

  /*
     int iDummy;
     if (   rclAnnotatorContext.extractValue(ANNOTATOR_DUMP_OUTPUT_TYPES, iDummy)){
       getAnnotatorContext().getLogger().logWarning((long) ANNOTATOR_DUMP_MSG_TYPES,
         _TEXT("Specification of output types currently not suported. All types will be dumped."));
     }
  */

  // Test getting a multi-valued parameter

  vector<string*> vecOutputTypes;
  tyErrId = rclAnnotatorContext.extractValue(ANNOTATOR_DUMP_OUTPUT_TYPES,  vecOutputTypes);
  if (tyErrId != UIMA_ERR_CONFIG_OPTION_NOT_FOUND) {
    size_t i, len = 0;
    for (i=0; i<vecOutputTypes.size(); ++i) {
      string * rString = vecOutputTypes[i];
      len += rString->length();
    }
    cout << "  parameter OutputTypes has "<<i<<" values with a total of "<<len<<" characters." << endl;
    // Release contents of vector allocated by extractValue in case library uses a different heap.
    rclAnnotatorContext.release(vecOutputTypes);
  }

  // Release string buffer allocated by library in case it uses a different heap.
  usr.release(strFileName);

  return(TyErrorId)UIMA_ERR_NONE;
}
 TyErrorId initialize(AnnotatorContext &ctx)
 {
   outInfo("initialize");
   ctx.extractValue("test_param", test_param);
   return UIMA_ERR_NONE;
 }
示例#12
0
    TyErrorId
    extractConfigOptionListImpl(
            const AnnotatorContext& crclConfig,
            const UnicodeString* cpclConfigGroup,
            const ConfigOptionInfo::StOptionInfo& crclOptionInfo,
            ContainerType& rclTargetContainer,
            ElementType* /*not used, just for type information since ContainerType::value_type does not work with HP compiler*/
    ) {
        assert(crclOptionInfo.bOptionIsMultiValued);
        TyErrorId utErrId = UIMA_ERR_NONE;
        size_t i;
#if defined(__HPX_ACC__) || defined(__xlC__) || defined(__GNUC__)
        ElementType tTemp;
#else
    ContainerType::value_type tTemp;
#endif

#if defined(__SUNPRO_CC)
    std::vector<ContainerType::value_type> elements;
#else
        std::vector<ElementType> elements;
#endif

        if (EXISTS(cpclConfigGroup)) {
            crclConfig.extractValue(*cpclConfigGroup, crclOptionInfo.cpszOptionName, elements);
        } else {
            crclConfig.extractValue(crclOptionInfo.cpszOptionName, elements);
        }

        for (i = 0; i < elements.size(); ++i) {
            rclTargetContainer.insert(rclTargetContainer.end(), elements[i]);
        }

        if (utErrId != UIMA_ERR_NONE || (elements.size() == 0)) { // could not find option or value(s)
            if (crclOptionInfo.uiNbrOfValuesRequired != 0
                || crclOptionInfo.cpszDefaultValueAsString == NULL) {
                // required value not there: return error we got from config
                return utErrId;
            }
            std::vector<std::string> vecTmpStrings;
            delimitedString2Vector(
                    vecTmpStrings,
                    (std::string) crclOptionInfo.cpszDefaultValueAsString,
                    ",",
                    true,   // trim strings
                    false   // insert empty strings
            );
            // our default value too must have the required nbr of values
            assert(vecTmpStrings.size() >= crclOptionInfo.uiNbrOfValuesRequired);

            for (i = 0; i < vecTmpStrings.size(); ++i) {
                convertFromString(vecTmpStrings[i], tTemp);
                // assumes rclTargetContainer to be an STL container
                rclTargetContainer.insert(rclTargetContainer.end(), tTemp);
            }
        }
        if (i < crclOptionInfo.uiNbrOfValuesRequired) {
            /* taph 8/6/1999: ?? maybe we should have a more precise error id:
               UIMA_ERR_CONFIG_REQUIRED_OPTION_HAS_NOT_ENOUGH_VALUES
            */
            return UIMA_ERR_CONFIG_REQUIRED_OPTION_IS_EMPTY;
        }
        return utErrId;
    }