// setup from cv::Filestorage object
void TransientAreasSegmentationModuleImpl::setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure)
{
    try
    {
        // read parameters file if it exists or apply default setup if asked for
        if (!fs.isOpened())
        {
            std::cout<<"Retina::setup: provided parameters file could not be open... skeeping configuration"<<std::endl;
            return;
            // implicit else case : retinaParameterFile could be open (it exists at least)
        }
        // OPL and Parvo init first... update at the same time the parameters structure and the retina core
        cv::FileNode rootFn = fs.root(), currFn=rootFn["SegmentationModuleSetup"];
        currFn["thresholdON"]>>_segmentationParameters.thresholdON;
        currFn["thresholdOFF"]>>_segmentationParameters.thresholdOFF;
        currFn["localEnergy_temporalConstant"]>>_segmentationParameters.localEnergy_temporalConstant;
        currFn["localEnergy_spatialConstant"]>>_segmentationParameters.localEnergy_spatialConstant;
        currFn["neighborhoodEnergy_temporalConstant"]>>_segmentationParameters.neighborhoodEnergy_temporalConstant;
        currFn["neighborhoodEnergy_spatialConstant"]>>_segmentationParameters.neighborhoodEnergy_spatialConstant;
        currFn["contextEnergy_temporalConstant"]>>_segmentationParameters.contextEnergy_temporalConstant;
        currFn["contextEnergy_spatialConstant"]>>_segmentationParameters.contextEnergy_spatialConstant;
        setup(_segmentationParameters);

    }catch(const cv::Exception &e)
    {
        std::cout<<"Retina::setup: resetting retina with default parameters"<<std::endl;
        if (applyDefaultSetupOnFailure)
        {
            struct cv::bioinspired::SegmentationParameters defaults;
            setup(defaults);
        }
        std::cout<<"SegmentationModule::setup: wrong/unappropriate xml parameter file : error report :`n=>"<<e.what()<<std::endl;
        std::cout<<"=> keeping current parameters"<<std::endl;
    }
}
Beispiel #2
0
void RetinaImpl::setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure)
{
    try
    {
        // read parameters file if it exists or apply default setup if asked for
        if (!fs.isOpened())
        {
            printf("Retina::setup: provided parameters file could not be open... skeeping configuration\n");
            return;
            // implicit else case : retinaParameterFile could be open (it exists at least)
        }
                // OPL and Parvo init first... update at the same time the parameters structure and the retina core
        cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"];
        currFn["colorMode"]>>_retinaParameters.OPLandIplParvo.colorMode;
        currFn["normaliseOutput"]>>_retinaParameters.OPLandIplParvo.normaliseOutput;
        currFn["photoreceptorsLocalAdaptationSensitivity"]>>_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity;
        currFn["photoreceptorsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant;
        currFn["photoreceptorsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant;
        currFn["horizontalCellsGain"]>>_retinaParameters.OPLandIplParvo.horizontalCellsGain;
        currFn["hcellsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.hcellsTemporalConstant;
        currFn["hcellsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.hcellsSpatialConstant;
        currFn["ganglionCellsSensitivity"]>>_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity;
        setupOPLandIPLParvoChannel(_retinaParameters.OPLandIplParvo.colorMode, _retinaParameters.OPLandIplParvo.normaliseOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant, _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant, _retinaParameters.OPLandIplParvo.horizontalCellsGain, _retinaParameters.OPLandIplParvo.hcellsTemporalConstant, _retinaParameters.OPLandIplParvo.hcellsSpatialConstant, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity);

        // init retina IPL magno setup... update at the same time the parameters structure and the retina core
        currFn=rootFn["IPLmagno"];
        currFn["normaliseOutput"]>>_retinaParameters.IplMagno.normaliseOutput;
        currFn["parasolCells_beta"]>>_retinaParameters.IplMagno.parasolCells_beta;
        currFn["parasolCells_tau"]>>_retinaParameters.IplMagno.parasolCells_tau;
        currFn["parasolCells_k"]>>_retinaParameters.IplMagno.parasolCells_k;
        currFn["amacrinCellsTemporalCutFrequency"]>>_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency;
        currFn["V0CompressionParameter"]>>_retinaParameters.IplMagno.V0CompressionParameter;
        currFn["localAdaptintegration_tau"]>>_retinaParameters.IplMagno.localAdaptintegration_tau;
        currFn["localAdaptintegration_k"]>>_retinaParameters.IplMagno.localAdaptintegration_k;

        setupIPLMagnoChannel(_retinaParameters.IplMagno.normaliseOutput, _retinaParameters.IplMagno.parasolCells_beta, _retinaParameters.IplMagno.parasolCells_tau, _retinaParameters.IplMagno.parasolCells_k, _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency,_retinaParameters.IplMagno.V0CompressionParameter, _retinaParameters.IplMagno.localAdaptintegration_tau, _retinaParameters.IplMagno.localAdaptintegration_k);

    }
    catch(Exception &e)
    {
        printf("RetinaImpl::setup: resetting retina with default parameters\n");
        if (applyDefaultSetupOnFailure)
        {
            setupOPLandIPLParvoChannel();
            setupIPLMagnoChannel();
        }
        printf("Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>%s\n", e.what());
        printf("=> keeping current parameters\n");
    }

    // report current configuration
    printf("%s\n", printSetup().c_str());
}
Beispiel #3
0
bool MarkupEditor::readSessionData( 
  cv::FileStorage& fs, 
  vector< FrameData >& frames,
  int& start_frame
  )
{
  if (!fs.isOpened())
    return __false("Attempt to read from not open storage");


  cv::FileNode last_session_node = fs["LastMarkupSession"];
  if (!last_session_node.empty())
  {
    if (start_frame < 0)
    try {  
      last_session_node["LastVisitedFrame"] >> start_frame;
    }
    catch (...)
    {
      cout << "no StartFrame specified" << endl;
      start_frame = -1;
    }

    string activeObjectType;
    last_session_node[ "ActiveObjectType" ] >> activeObjectType;
    if (!activeObjectType.empty()) // setup iObjType
      for (iObjType = int(afoTypes.objTypes.size()-1); iObjType >=0; iObjType-- ) // if not found -- set to 0
        if ( afoTypes.objTypes[iObjType] == activeObjectType )
          break;
  }
  return true;
}
Beispiel #4
0
void readFile(cv::FileStorage &fs) {
    if (!fs.isOpened()) {
       std::cout << "Empty File..." << std::endl;
       return;
    }
    cv::FileNode n = fs["TrainerInfo"];
    std::string ttype = n["trainer_type"];
    std::string tpath = n["trainer_path"];
    std::cout << ttype << std::endl;
    std::cout << tpath << std::endl;

    n = fs["FeatureInfo"];
    int hog = n["HOG"];
    int lbp = n["LBP"];
    std::cout << hog << std::endl;
    std::cout << lbp << std::endl;
    
    
    n = fs["SlidingWindowInfo"];
    int swindow_x = static_cast<int>(n["window_x"]);
    int swindow_y = static_cast<int>(n["window_y"]);

    n = fs["TrainingDatasetDirectory"];
    std::string pfile = n["object_dataset"];
    std::string nfile = n["nonobject_dataset"];

    std::cout << swindow_x << " " << swindow_y << std::endl;
    std::cout << pfile << " \n" << nfile << std::endl;
}
Beispiel #5
0
void EventType::writeKeypoints(cv::FileStorage outfile) throw(runtime_error) {
    if(outfile.isOpened()) {
        outfile << getId() + "_pts" << getKeypoints();
    } else {
        throw runtime_error("File is not open for writing");
    }
}
Beispiel #6
0
void EventType::writeDescriptors(cv::FileStorage outfile) throw(runtime_error) {
    if(outfile.isOpened()) {
        outfile << getId() + "_desc" << getDescriptors();
    } else {
        throw runtime_error("File is not open for writing");
    }
}
void TransientAreasSegmentationModuleImpl::write( cv::FileStorage& fs ) const
{
    if (!fs.isOpened())
        return; // basic error case
    fs <<"SegmentationModuleSetup"<<"{";
    fs <<"thresholdON" << _segmentationParameters.thresholdON;
    fs <<"thresholdOFF" << _segmentationParameters.thresholdOFF;
    fs <<"localEnergy_temporalConstant" << _segmentationParameters.localEnergy_temporalConstant;
    fs <<"localEnergy_spatialConstant" << _segmentationParameters.localEnergy_spatialConstant;
    fs <<"neighborhoodEnergy_temporalConstant" << _segmentationParameters.neighborhoodEnergy_temporalConstant;
    fs <<"neighborhoodEnergy_spatialConstant" << _segmentationParameters.neighborhoodEnergy_spatialConstant;
    fs <<"contextEnergy_temporalConstant" << _segmentationParameters.contextEnergy_temporalConstant;
    fs <<"contextEnergy_spatialConstant" << _segmentationParameters.contextEnergy_spatialConstant;
    fs <<"}";
}
Beispiel #8
0
bool MarkupEditor::writeSessionData( 
  cv::FileStorage& fs, 
  vector< FrameData >& frames,  
  int start_frame
  )
{
  if (!fs.isOpened())
    return __false("Attempt to write to not open storage");

  fs << "LastMarkupSession" << "{";
  fs << "LastVisitedFrame" << start_frame;
  fs << "ActiveObjectType" << objType();
  fs << "}";
  
  return true;
}
Beispiel #9
0
void readImageToVector(
    cv::FileStorage imageListFs, 
    std::vector<cv::Mat> &images
    ) {
  cv::FileNode n = imageListFs.getFirstTopLevelNode();
  if (n.type() != cv::FileNode::SEQ) {
    std::cout << "Image List file is not sequential.\n";
    exit(0);
  }
  cv::FileNodeIterator it       = n.begin();
  cv::FileNodeIterator it_end   = n.end();
  for (; it != it_end; it++) {
    cv::Mat tempImage = cv::imread(std::string(*it));
    cv::Mat tempGrayImage;
    cv::cvtColor(tempImage, tempGrayImage, cv::COLOR_BGR2GRAY);
    images.push_back(tempGrayImage);
  }
}
Beispiel #10
0
void EventType::read(cv::FileStorage infile, cv::Rect_<float> bounds) throw(runtime_error) {
    cv::Mat descriptors, new_descriptors;
    vector<cv::Point2f> keypoints, new_keypoints;
    if(infile.isOpened()) {
        cv::read(infile[getId() + "_desc"], descriptors); // infile[getId()] >> descriptors;
        cv::read(infile[getId() + "_pts"], keypoints); // infile[getId()] >> keypoints;
        if(keypoints.size() > 0) {
            for(int i=0; i<keypoints.size(); i++) {
                if(bounds.contains(keypoints[i])) {
                    new_descriptors.push_back(descriptors.row(i));
                    new_keypoints.push_back(keypoints.at(i));
                }
            }
            addDescriptors(new_descriptors);
            addKeypoints(new_keypoints);
        } else {
            addDescriptors(descriptors);
            addKeypoints(keypoints);
        }
    } else {
        throw runtime_error("File is not open for reading");
    }
}
Beispiel #11
0
 void write_to_yaml(cv::FileStorage& output_file, const std::string& name, const cv::Mat& matrix)
 {
   CvMat m = matrix;
   output_file.writeObj(name, &m);
 }