MarchingCubes::MarchingCubes( const char* filePath )
{
	MappedData paramFile( filePath );

	position = paramFile.getData("base","position").getVec3();	
	scale = paramFile.getData("base","scale").getVec3();	
		
	dataWidth = paramFile.getData("base","dataWidth").get<int>();
	dataHeight = paramFile.getData("base","dataHeight").get<int>();
	dataDepth = paramFile.getData("base","dataDepth").get<int>();
	dataWidth = dataWidth<DATA_CHANGE_DIV ? DATA_CHANGE_DIV : dataWidth;
	dataHeight = dataHeight<DATA_CHANGE_DIV ? DATA_CHANGE_DIV : dataHeight;
	dataDepth = dataDepth<DATA_CHANGE_DIV ? DATA_CHANGE_DIV : dataDepth;
	dataSize = dataWidth * dataHeight * dataDepth;
	dataField = new char[ dataSize ];

	dataChanged = new bool[ DATA_CHANGE_SIZE ];
	dataChangedWidth = (dataWidth/DATA_CHANGE_DIV);
	dataChangedHeight = (dataHeight/DATA_CHANGE_DIV);
	dataChangedDepth = (dataDepth/DATA_CHANGE_DIV);
	dataChangedGlobal = false;
	
	dataMax = paramFile.getData("base","maxValue").get<int>();
	treshold = 0;
	useInterpolated = true;

	trianglesCount = 0;
	trianglesSize = TRIANGLE_COUNT_INCREASE;
	triangles = new glm::vec3[ trianglesSize ];
	normals = new glm::vec3[trianglesSize];

	pointGrid = 0;

	clear();
}
//-------------------------------------------------------------------------------------
//constructeur avec une initialisation USER
//-------------------------------------------------------------------------------------
XEMGaussianGeneralParameter::XEMGaussianGeneralParameter(int64_t  iNbCluster, int64_t  iPbDimension, XEMModelType * iModelType, string & iFileName) : XEMGaussianEDDAParameter(iNbCluster, iPbDimension, iModelType){
  int64_t  k;
  __storeDim           = _pbDimension * (_pbDimension + 1) / 2;
  _tabShape           = new XEMDiagMatrix*[_nbCluster];
  _tabOrientation     = new XEMGeneralMatrix*[_nbCluster];
  _tabLambda          = new double [_nbCluster];

  for (k=0; k<_nbCluster; k++){
    _tabShape[k]     = new XEMDiagMatrix(_pbDimension); //Id
    _tabOrientation[k] = new XEMGeneralMatrix(_pbDimension); //Id
    _tabLambda[k]      = 1.0;

    // _tabSigma, _tabInvSigma, _tabWk will be initialized in XEMGaussianEDDAparameter
    _tabInvSigma[k] = new XEMSymmetricMatrix(_pbDimension);  //Id
    _tabSigma[k]    = new XEMSymmetricMatrix(_pbDimension); // Id
    _tabWk[k]       = new XEMSymmetricMatrix(_pbDimension); //Id
    *_tabWk[k]      = 1.0;
  }
  _W = new XEMSymmetricMatrix(_pbDimension); //Id

  // read parameters in file iFileName//
  if (iFileName.compare("") != 0){
    ifstream paramFile(iFileName.c_str(), ios::in);
    if (! paramFile.is_open()){
      throw wrongParamFileName;
    }
    input(paramFile);
    paramFile.close();
  }

  updateTabInvSigmaAndDet(); // method of XEMGaussianParameter

}
Example #3
0
int main(int argc, char** argv) {

    // read parameters and image names
    array<double, 6> params;
    ifstream paramFile(argv[1]);
    cout << argv[1] << endl;
    cout << "EU Camera model parameters :" << endl;
    for (auto & p: params) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    array<double, 3> params2;
    cout << "Pinhole rectified camera parameters :" << endl;
    for (auto & p: params2) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    array<double, 3> rotation;
    cout << "Rotation of the pinhole camera :" << endl;
    for (auto & p: rotation) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    Mat32f  mapX, mapY;
    initRemap(params, params2, mapX, mapY, rotation);
    
    string dirName, fileName;
    getline(paramFile, dirName);
    while (getline(paramFile, fileName))
    {
        Mat32f img = imread(dirName + fileName, 0);
        Mat32f img2;
        remap(img, img2, mapX, mapY, cv::INTER_LINEAR);
        imshow("orig", img/255);
        imshow("res", img2/255);
        waitKey();
    }

    return 0;


}
Example #4
0
//-------------------
// set init parameter
//-------------------
void XEMStrategyInit::setInitParam(string & paramFileName, int64_t position){
  ifstream paramFile(paramFileName.c_str(), ios::in);
  if (! paramFile.is_open()){
    throw wrongParamFileName;
  }
  if (_tabInitParameter != NULL){
    _tabInitParameter[position]->input(paramFile);
    _tabInitParameter[position]->setFilename(paramFileName);
    paramFile.close();
  }
  else{
    throw internalMixmodError;
  }
}
Example #5
0
void AbacusGlobal::readParameters(const string &fileName)
{
	string line;
	string name;
	string value;

	// open the parameter file \a fileName
	/* CHANGED  ifstream paramFile(fileName, ios::in \a  ios::nocreate);*/
	ifstream paramFile(OGDF_STRING_OPEN(fileName), ios::in);

	if (!paramFile) {
		Logger::ifout() << "AbacusGlobal::readParameters(): opening file " << fileName << " failed\n";
		OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::afcGlobal);
	}
	// read the parameter file line by line
	/* Lines in a parameter file starting with \a '#' are comments and hence they
	*   are skipped. Every other non-void line must contain two strings. The
	*   first one is the name of the parameter, the second one its value.
	*/
	std::stringstream is;
	while( std::getline(paramFile, line) ) {
		if (line.empty() || line[0] == '#')
			continue;

		is.str(line);
		is.clear();

		if( !(is >> name) )
			continue; // empty line

		if( !(is >> value) ) {
			Logger::ifout() << "AbacusGlobal::readParameters " << fileName << " value missing for parameter " << name << "\n";
			OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::afcGlobal);
		}
		else {
			paramTable_.overWrite(name, value);
		}
	}
Example #6
0
int main(int argc, char** argv)
{	
    /*Polynomial2 poly2;
    poly2.kuu = -1; 
    poly2.kuv = 1; 
    poly2.kvv= -1; 
    poly2.ku = 0.25; 
    poly2.kv = 0.25; 
    poly2.k1 = 5;
    
    CurveRasterizer<Polynomial2> raster(1, 1, -100, 100, poly2);
    CurveRasterizer2<Polynomial2> raster2(1, 1, -100, 100, poly2);

    auto tr0 = clock();
    int x1 = 0;
    int x2 = 0;
    for (int i = 0; i < 10000000; i++)
    {
        raster.step();
        x1 += raster.x;
    }
    auto tr1 = clock();
    
    for (int i = 0; i < 10000000; i++)
    {
        raster2.step();
        x2 += raster2.x;
    }
    auto tr2 = clock();
    
    cout << "optimized " << double(tr1 - tr0) / CLOCKS_PER_SEC << endl;
    cout << "simple " << double(tr2 - tr1) / CLOCKS_PER_SEC << endl;
    cout << x1 << " " << x2 << endl;
    return 0;*/
    ifstream paramFile(argv[1]);
    if (not paramFile.is_open())
    {
        cout << argv[1] << " : ERROR, file is not found" << endl;
        return 0;
    }
    
    array<double, 6> params1;
    array<double, 6> params2;
    
    cout << "First EU Camera model parameters :" << endl;
    for (auto & p: params1) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    cout << "Second EU Camera model parameters :" << endl;
    for (auto & p: params2) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    array<double, 6> cameraPose;
    cout << "Camera pose wrt the robot :" << endl;
    for (auto & e: cameraPose) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    paramFile.ignore();
    Transformation<double> TbaseCamera(cameraPose.data());
    
    array<double, 6> robotPose1, robotPose2;
    cout << "First robot's pose :" << endl;
    for (auto & e: robotPose1) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    cout << "Second robot's pose :" << endl;
    for (auto & e: robotPose2) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    paramFile.ignore();
    Transformation<double> T01(robotPose1.data()), T02(robotPose2.data());
    
    Transformation<double> TleftRight = T01.compose(TbaseCamera).inverseCompose(T02.compose(TbaseCamera));
    
    SGMParameters stereoParams;
    stereoParams.flawCost = 5;
    stereoParams.verbosity = 0;
    stereoParams.hypMax = 1;
//    stereoParams.salientPoints = false;
    paramFile >> stereoParams.u0;
    paramFile >> stereoParams.v0;
    paramFile >> stereoParams.dispMax;
    paramFile >> stereoParams.scale;
    paramFile.ignore();
//    stereoParams.lambdaStep = 3;
//    stereoParams.lambdaJump = 15;
    string fileName1, fileName2;
    while(getline(paramFile, fileName1))
    {
        getline(paramFile, fileName2);
        
        Mat8u img1 = imread(fileName1, 0);
        Mat8u img2 = imread(fileName2, 0);
        Mat16s img1lap, img2lap;

        stereoParams.uMax = img1.cols;
        stereoParams.vMax = img1.rows;
        stereoParams.setEqualMargin();
    //    
    //    Laplacian(img1, img1lap, CV_16S, 3);
    //    Laplacian(img2, img2lap, CV_16S, 3);
    //    
    //    GaussianBlur(img1, img1, Size(3, 3), 0, 0);
    //    GaussianBlur(img2, img2, Size(3, 3), 0, 0);
    //    
    //    img1lap = img1lap + 128;
    //    img2lap = img2lap + 128;
    //    img1lap.copyTo(img1);
    //    img2lap.copyTo(img2);
    ////    
        
        Timer timer;
        EnhancedCamera camera1(params1.data()), camera2(params2.data());
        EnhancedSGM stereo(TleftRight, &camera1, &camera2, stereoParams);
        cout << "    initialization time : " << timer.elapsed() << endl;
        Mat8u out1, out2;
        
        img1.copyTo(out1);
        img2.copyTo(out2);
        
    //    
    //    for (auto & x : {Point(320, 300), Point(500, 300), Point(750, 300), Point(350, 500), Point(600, 450)})
    //    {
    //        out1(x) = 0;
    //        out1(x.y + 1, x.x) = 0;
    //        out1(x.y, x.x + 1) = 255;
    //        out1(x.y + 1, x.x + 1) = 255;
    //        stereo.traceEpipolarLine(x, out2);
    //    }
        

    //    Mat32f res;
    //    timer.reset();
    //    stereo.computeCurveCost(img1, img2);
    //    cout << timer.elapsed() << endl;
    //    timer.reset();
    //    stereo.computeDynamicProgramming();
    //    cout << timer.elapsed() << endl;
    //    timer.reset();
    //    stereo.reconstructDisparity();
    //    cout << timer.elapsed() << endl;
    //    timer.reset();
    //    stereo.computeDepth(res);
    //    cout << timer.elapsed() << endl;
        
        DepthMap depth;
        Mat32f depthMat;
        timer.reset();
        
    //    stereo.computeStereo(img1, img2, depthMat);
        stereo.computeStereo(img1, img2, depth);
        cout << "    stereo total time : " << timer.elapsed() << endl;
        
        depth.toInverseMat(depthMat);
        
        imshow("out1", out1);
        imshow("out2", out2);
        imshow("res", depthMat/ 3);
        imshow("disp", stereo.disparity() * 256);
        cout << stereo.disparity()(350, 468) << " " << stereo.disparity()(350, 469) << endl;
        waitKey(); 
    }
    return 0;
}
Example #7
0
int main(int argc, char** argv)
{	
    ifstream paramFile(argv[1]);
    if (not paramFile.is_open())
    {
        cout << argv[1] << " : ERROR, file is not found" << endl;
        return 0;
    }
    
    array<double, 6> params1;
    array<double, 6> params2;
    
    cout << "First EU Camera model parameters :" << endl;
    for (auto & p: params1) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    cout << "Second EU Camera model parameters :" << endl;
    for (auto & p: params2) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    array<double, 6> cameraPose;
    cout << "Camera pose wrt the robot :" << endl;
    for (auto & e: cameraPose) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    paramFile.ignore();
    Transformation<double> TbaseCamera(cameraPose.data());
    
    array<double, 6> robotPose1, robotPose2;
    cout << "First robot's pose :" << endl;
    for (auto & e: robotPose1) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    cout << "Second robot's pose :" << endl;
    for (auto & e: robotPose2) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    paramFile.ignore();
    Transformation<double> T01(robotPose1.data()), T02(robotPose2.data());
    
    Transformation<double> TleftRight = T01.compose(TbaseCamera).inverseCompose(T02.compose(TbaseCamera));
    
    EnhancedCamera cam1(params1.data()), cam2(params2.data());
    
    EnhancedEpipolar epipolar(&cam1, &cam2, TleftRight, 2000);
    
    string fileName1, fileName2;
    
    getline(paramFile, fileName1); //to SGM parameters
    
    const int LENGTH = 5;
    //TODO fix the constructor to avoid NULL 
    EpipolarDescriptor epipolarDescriptor(LENGTH, 3, {1, 2, 3, 5, 7, 9});
    StereoEpipoles epipoles(&cam1, &cam2, TleftRight);
    
    while(getline(paramFile, fileName1))
    {
        getline(paramFile, fileName2);
        
        img1 = imread(fileName1, 0);
        img2 = imread(fileName2, 0);
        
        Mat8u descStepMat(img1.size());
        
        for (int v = 0; v < img1.rows; v++)
        {
            for (int u = 0; u < img1.cols; u++)
            {
                Vector3d X;
                
                cam1.reconstructPoint(Vector2d(u, v), X);
                CurveRasterizer<int, Polynomial2> raster(Vector2i(u, v), epipoles.getFirstPx(),
                                         epipolar.getFirst(X));
                if (epipoles.firstIsInverted()) raster.setStep(-1);
                vector<uint8_t> descriptor;
                const int step = epipolarDescriptor.compute(img1, raster, descriptor);
                if (step > 0)  descStepMat(v, u) = (10 - step) * 25; 
                else descStepMat(v, u) = 0;
            }
        }
        
        imshow("out1", img1);
        imshow("out2", img2);
        imshow("descStep", descStepMat);
        waitKey(); 
    }
    return 0;
}
Example #8
0
int main(int argc, char** argv)
{	
    /*Polynomial2 poly2;
    poly2.kuu = -1; 
    poly2.kuv = 1; 
    poly2.kvv= -1; 
    poly2.ku = 0.25; 
    poly2.kv = 0.25; 
    poly2.k1 = 5;
    
    CurveRasterizer<Polynomial2> raster(1, 1, -100, 100, poly2);
    CurveRasterizer2<Polynomial2> raster2(1, 1, -100, 100, poly2);

    auto tr0 = clock();
    int x1 = 0;
    int x2 = 0;
    for (int i = 0; i < 10000000; i++)
    {
        raster.step();
        x1 += raster.x;
    }
    auto tr1 = clock();
    
    for (int i = 0; i < 10000000; i++)
    {
        raster2.step();
        x2 += raster2.x;
    }
    auto tr2 = clock();
    
    cout << "optimized " << double(tr1 - tr0) / CLOCKS_PER_SEC << endl;
    cout << "simple " << double(tr2 - tr1) / CLOCKS_PER_SEC << endl;
    cout << x1 << " " << x2 << endl;
    return 0;*/
    ifstream paramFile(argv[1]);
    if (not paramFile.is_open())
    {
        cout << argv[1] << " : ERROR, file is not found" << endl;
        return 0;
    }
    
    array<double, 6> params;
    
    cout << "EU Camera model parameters :" << endl;
    for (auto & p: params) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    array<double, 6> cameraPose;
    cout << "Camera pose wrt the robot :" << endl;
    for (auto & e: cameraPose) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    paramFile.ignore();
    Transformation<double> TbaseCamera(cameraPose.data());
    
    array<double, 6> robotPose1, robotPose2;

    
    
    SGMParameters stereoParams;
    stereoParams.verbosity = 3;
    stereoParams.salientPoints = false;
    paramFile >> stereoParams.u0;
    paramFile >> stereoParams.v0;
    paramFile >> stereoParams.dispMax;
    paramFile >> stereoParams.scale;
    paramFile.ignore();
    string imageDir;
    getline(paramFile, imageDir);
    string imageInfo, imageName;
    getline(paramFile, imageInfo);
    istringstream imageStream(imageInfo);
    imageStream >> imageName;
    for (auto & x : robotPose1) imageStream >> x;

    Mat8u img1 = imread(imageDir + imageName, 0);
    stereoParams.uMax = img1.cols;
    stereoParams.vMax = img1.rows;
    stereoParams.setEqualMargin();
    
    int counter = 2;
    EnhancedCamera camera(params.data());
    while (getline(paramFile, imageInfo))
    {
        istringstream imageStream(imageInfo);
        
        imageStream >> imageName;
        for (auto & x : robotPose2) imageStream >> x;
    
        Transformation<double> T01(robotPose1.data()), T02(robotPose2.data());
        Transformation<double> TleftRight = T01.compose(TbaseCamera).inverseCompose(T02.compose(TbaseCamera));
        
        Mat8u img2 = imread(imageDir + imageName, 0);

        EnhancedSGM stereo(TleftRight, &camera, &camera, stereoParams);

        DepthMap depth;
        auto t2 = clock();
        stereo.computeStereo(img1, img2, depth);
        auto t3 = clock();
        cout << double(t3 - t2) / CLOCKS_PER_SEC << endl;
        
        Mat32f dMat;
        depth.toInverseMat(dMat);
//        imwrite(imageDir + "res" + to_string(counter++) + ".png", depth*200);
        imwrite(imageDir + "res" + to_string(counter++) + ".png", dMat*30);
    }
    return 0;
}
Example #9
0
bool NEAT::load_neat_params(const char *filename, bool output) {

    std::ifstream paramFile(filename);

	if(!paramFile) {
		return false;
	}
	char curword[128];
	//char delimiters[] = " \n"; // tab = bad, CR(int 13) = bad in the file
	//char delimiters[] = " \t\n";
	//char delimiters[] = {' ', '\n', (char)13};
	//int curwordnum = 1;
	//char filestring[1000000];
	//paramFile.read(sizeof(filestring), filestring);

	// **********LOAD IN PARAMETERS*************** //
    if(output)
	    printf("NEAT READING IN %s", filename);

	paramFile>>curword;
	paramFile>>NEAT::trait_param_mut_prob;

	//strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::trait_param_mut_prob = atof(curword);
	//curwordnum += 2;

	paramFile>>curword;
	paramFile>>NEAT::trait_mutation_power;

	//strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::trait_mutation_power = atof(curword);
	//curwordnum += 2;

	paramFile>>curword;
	paramFile>>NEAT::linktrait_mut_sig;

	//strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::linktrait_mut_sig = atof(curword);
	//curwordnum += 2;

	paramFile>>curword;
	paramFile>>NEAT::nodetrait_mut_sig;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::nodetrait_mut_sig = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::weight_mut_power;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::weight_mut_power = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::recur_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::recur_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::disjoint_coeff;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::disjoint_coeff = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::excess_coeff;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::excess_coeff = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutdiff_coeff;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutdiff_coeff = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::compat_threshold;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::compat_threshold = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::age_significance;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::age_significance = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::survival_thresh;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::survival_thresh = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_only_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_only_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_random_trait_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_random_trait_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_link_trait_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_link_trait_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_node_trait_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_node_trait_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_link_weights_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_link_weights_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_toggle_enable_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_toggle_enable_prob = atof(curword);
	//curwordnum += 2;

	paramFile>>curword;
	paramFile>>NEAT::mutate_gene_reenable_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_gene_reenable_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_add_node_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_add_node_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mutate_add_link_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mutate_add_link_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::interspecies_mate_rate;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::interspecies_mate_rate = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mate_multipoint_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mate_multipoint_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mate_multipoint_avg_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mate_multipoint_avg_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mate_singlepoint_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mate_singlepoint_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::mate_only_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::mate_only_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::recur_only_prob;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::recur_only_prob = atof(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::pop_size;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::pop_size = atoi(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::dropoff_age;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::dropoff_age = atoi(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::newlink_tries;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::newlink_tries = atoi(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::print_every;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::print_every = atoi(curword);
	//curwordnum += 2;
	
    paramFile>>curword;
	paramFile>>NEAT::babies_stolen;
	
    //strcpy(curword, getUnit(filestring, curwordnum, delimiters));
	//NEAT::babies_stolen = atoi(curword);
	//curwordnum += 2;

    paramFile>>curword;
	paramFile>>NEAT::num_runs;
	

    if(output) {
	    printf("trait_param_mut_prob=%f\n",trait_param_mut_prob);
	    printf("trait_mutation_power=%f\n",trait_mutation_power);
	    printf("linktrait_mut_sig=%f\n",linktrait_mut_sig);
	    printf("nodetrait_mut_sig=%f\n",nodetrait_mut_sig);
	    printf("weight_mut_power=%f\n",weight_mut_power);
	    printf("recur_prob=%f\n",recur_prob);
	    printf("disjoint_coeff=%f\n",disjoint_coeff);
	    printf("excess_coeff=%f\n",excess_coeff);
	    printf("mutdiff_coeff=%f\n",mutdiff_coeff);
	    printf("compat_threshold=%f\n",compat_threshold);
	    printf("age_significance=%f\n",age_significance);
	    printf("survival_thresh=%f\n",survival_thresh);
	    printf("mutate_only_prob=%f\n",mutate_only_prob);
	    printf("mutate_random_trait_prob=%f\n",mutate_random_trait_prob);
	    printf("mutate_link_trait_prob=%f\n",mutate_link_trait_prob);
	    printf("mutate_node_trait_prob=%f\n",mutate_node_trait_prob);
	    printf("mutate_link_weights_prob=%f\n",mutate_link_weights_prob);
	    printf("mutate_toggle_enable_prob=%f\n",mutate_toggle_enable_prob);
	    printf("mutate_gene_reenable_prob=%f\n",mutate_gene_reenable_prob);
	    printf("mutate_add_node_prob=%f\n",mutate_add_node_prob);
	    printf("mutate_add_link_prob=%f\n",mutate_add_link_prob);
	    printf("interspecies_mate_rate=%f\n",interspecies_mate_rate);
	    printf("mate_multipoint_prob=%f\n",mate_multipoint_prob);
	    printf("mate_multipoint_avg_prob=%f\n",mate_multipoint_avg_prob);
	    printf("mate_singlepoint_prob=%f\n",mate_singlepoint_prob);
	    printf("mate_only_prob=%f\n",mate_only_prob);
	    printf("recur_only_prob=%f\n",recur_only_prob);
	    printf("pop_size=%d\n",pop_size);
	    printf("dropoff_age=%d\n",dropoff_age);
	    printf("newlink_tries=%d\n",newlink_tries);
	    printf("print_every=%d\n",print_every);
	    printf("babies_stolen=%d\n",babies_stolen);
	    printf("num_runs=%d\n",num_runs);
    }

	paramFile.close();
	return true;
}
Example #10
0
// Main program
int main(int argc, char** argv) {

    // Overall program timer
    auto overallstart = std::chrono::steady_clock::now();

    // Print program header
    std::cout<<std::endl;
    std::cout<<"PGURE-SVT Denoising"<<std::endl;
    std::cout<<"Author: Tom Furnival"<<std::endl;
    std::cout<<"Email:  [email protected]"<<std::endl<<std::endl;
    std::cout<<"Version 0.3.0 - April 2016"<<std::endl<<std::endl;

    /////////////////////////////
    //                           //
    //    PARAMETER IMPORT     //
    //                           //
    /////////////////////////////

    // Read in the parameter file name
    if( argc != 2) {
        std::cout<<"  Usage: ./PGURE-SVT paramfile"<<std::endl;
        return -1;
    }
    std::map<std::string, std::string> programOptions;
    std::ifstream paramFile(argv[1], std::ios::in);

    // Parse the parameter file
    ParseParameters(paramFile, programOptions);

    // Check all required parameters are specified
    if(programOptions.count("filename") == 0 || programOptions.count("start_image") == 0 || programOptions.count("end_image") == 0) {
        std::cout<<"**WARNING** Required parameters not specified"<<std::endl;
        std::cout<<"            You must specify filename, start and end frame"<<std::endl;
        return -1;
    }

    // Extract parameters
    // File path
    std::string filename = programOptions.at("filename");
    int lastindex = filename.find_last_of(".");
    std::string filestem = filename.substr(0, lastindex);

    // Frames to process
    int startimg = std::stoi(programOptions.at("start_image"));
    int endimg = std::stoi(programOptions.at("end_image"));
    int num_images = endimg - startimg + 1;

    // Move onto optional parameters
    // Patch size and trajectory length
    // Check sizes to ensure SVD is done right way round
    int Bs = (programOptions.count("patch_size") == 1) ? std::stoi(programOptions.at("patch_size")) : 4;
    //int Overlap = (programOptions.count("patch_overlap") == 1) ? std::stoi(programOptions.at("patch_overlap")) : 1;
    int T = (programOptions.count("trajectory_length") == 1) ? std::stoi(programOptions.at("trajectory_length")) : 15;
    T = (Bs*Bs<T) ? (Bs*Bs)-1 : T;
    std::string casoratisize = std::to_string(Bs*Bs) + "x" + std::to_string(T);

    // Noise parameters initialized at -1 unless user-defined
    double alpha = (programOptions.count("alpha") == 1) ? std::stod(programOptions.at("alpha")) : -1.;
    double mu = (programOptions.count("mu") == 1) ? std::stod(programOptions.at("mu")) : -1.;
    double sigma = (programOptions.count("sigma") == 1) ? std::stod(programOptions.at("sigma")) : -1.;

    // SVT thresholds and noise parameters initialized at -1 unless user-defined
    bool pgureOpt = (programOptions.count("pgure") == 1) ? strToBool(programOptions.at("pgure")) : true;
    double lambda;
    if(!pgureOpt) {
        if(programOptions.count("lambda") == 1) {
            lambda = std::stod(programOptions.at("lambda"));
        }
        else {
            std::cout<<"**WARNING** PGURE optimization is turned OFF but no lambda specified in parameter file"<<std::endl;
            return -1;
        }
    }

    // Move onto advanced parameters
    // Motion neigbourhood size
    int MotionP = (programOptions.count("motion_neighbourhood") == 1) ? std::stoi(programOptions.at("motion_neighbourhood")) : 7;

    // Size of median filter
    int MedianSize = (programOptions.count("median_filter") == 1) ? std::stoi(programOptions.at("median_filter")) : 5;

    // PGURE tolerance
    double tol = 1E-7;
    if(programOptions.count("tolerance") == 1) {
        std::istringstream osTol(programOptions.at("tolerance"));
        double tol;
        osTol >> tol;
    }
Example #11
0
int main(int argc, char** argv)
{	
    /*Polynomial2 poly2;
    poly2.kuu = -1; 
    poly2.kuv = 1; 
    poly2.kvv= -1; 
    poly2.ku = 0.25; 
    poly2.kv = 0.25; 
    poly2.k1 = 5;
    
    CurveRasterizer<Polynomial2> raster(1, 1, -100, 100, poly2);
    CurveRasterizer2<Polynomial2> raster2(1, 1, -100, 100, poly2);

    auto tr0 = clock();
    int x1 = 0;
    int x2 = 0;
    for (int i = 0; i < 10000000; i++)
    {
        raster.step();
        x1 += raster.x;
    }
    auto tr1 = clock();
    
    for (int i = 0; i < 10000000; i++)
    {
        raster2.step();
        x2 += raster2.x;
    }
    auto tr2 = clock();
    
    cout << "optimized " << double(tr1 - tr0) / CLOCKS_PER_SEC << endl;
    cout << "simple " << double(tr2 - tr1) / CLOCKS_PER_SEC << endl;
    cout << x1 << " " << x2 << endl;
    return 0;*/
    ifstream paramFile(argv[1]);
    if (not paramFile.is_open())
    {
        cout << argv[1] << " : ERROR, file is not found" << endl;
        return 0;
    }
    
    array<double, 6> params;
    
    cout << "EU Camera model parameters :" << endl;
    for (auto & p: params) 
    {
        paramFile >> p;
        cout << setw(10) << p;
    }
    cout << endl;
    paramFile.ignore();
    
    array<double, 6> cameraPose;
    cout << "Camera pose wrt the robot :" << endl;
    for (auto & e: cameraPose) 
    {
        paramFile >> e;
        cout << setw(10) << e;
    }
    cout << endl;
    paramFile.ignore();
    Transformation<double> TbaseCamera(cameraPose.data());
    
    array<double, 6> robotPose1, robotPose2;

    
    
    
    
    SGMParameters stereoParams2;
    stereoParams2.salientPoints = false;
    stereoParams2.verbosity = 3;
    stereoParams2.hypMax = 1;
//    stereoParams.salientPoints = false;
    paramFile >> stereoParams2.u0;
    paramFile >> stereoParams2.v0;
    paramFile >> stereoParams2.dispMax;
    paramFile >> stereoParams2.scale;
    
    paramFile.ignore();
    string imageDir;
    getline(paramFile, imageDir);
    string imageInfo, imageName;
    getline(paramFile, imageInfo);
    istringstream imageStream(imageInfo);
    imageStream >> imageName;
    for (auto & x : robotPose1) imageStream >> x;

    Mat8u img1 = imread(imageDir + imageName, 0);
    cout << "Image name: "<< imageDir + imageName << endl;
    cout << "Image size: "<<img1.size()<<endl;;
    
    stereoParams2.u0 = 50;
    stereoParams2.v0 = 50;
    stereoParams2.uMax = img1.cols;
    stereoParams2.vMax = img1.rows;
    stereoParams2.setEqualMargin();
//    stereoParams2.salientPoints = true;
    
    int counter = 2;
    EnhancedCamera camera(params.data());
    DepthMap depth;
    depth.setDefault();
    
//    stereoParams2.dispMax = 40;
//    stereoParams2.descRespThresh = 2;
//    stereoParams2.scaleVec = vector<int>{1};
    
    MotionStereoParameters stereoParams(stereoParams2);
    stereoParams.verbosity = 1;
    stereoParams.descLength = 5;
//    stereoParams.descRespThresh = 2;
//    stereoParams.scaleVec = vector<int>{1};
    
    MotionStereo stereo(&camera, &camera, stereoParams);
    stereo.setBaseImage(img1);
    
    
    //do SGM to init the depth
    getline(paramFile, imageInfo);
    getline(paramFile, imageInfo);
    getline(paramFile, imageInfo);
    imageStream.str(imageInfo);
    imageStream.clear();
    imageStream >> imageName;
    for (auto & x : robotPose2) imageStream >> x;
    Mat8u img2 = imread(imageDir + imageName, 0);
    Transformation<double> T01(robotPose1.data()), T02(robotPose2.data());
    Transformation<double> TleftRight = T01.compose(TbaseCamera).inverseCompose(T02.compose(TbaseCamera));
    EnhancedSGM stereoSG(TleftRight, &camera, &camera, stereoParams2);
    
    Timer timer;
    stereoSG.computeStereo(img1, img2, depth);
    depth.filterNoise();
    cout << timer.elapsed() << endl; 
    Mat32f res, sigmaRes;
    Mat32f res2, sigmaRes2;
    depth.toInverseMat(res2);
    depth.sigmaToMat(sigmaRes2);
    imshow("res" + to_string(counter), res2 *0.12);
    imshow("sigma " + to_string(counter), sigmaRes2*20);
    cv::waitKey(0);
    
    counter++;
    while (getline(paramFile, imageInfo))
    {
        istringstream imageStream(imageInfo);
        
        imageStream >> imageName;
        for (auto & x : robotPose2) imageStream >> x;
    
        Transformation<double> T01(robotPose1.data()), T02(robotPose2.data());
        Transformation<double> TleftRight = T01.compose(TbaseCamera).inverseCompose(T02.compose(TbaseCamera));
        
        Mat8u img2 = imread(imageDir + imageName, 0);

//        depth.setDefault();
        timer.reset();
        cout << TleftRight << endl;
        DepthMap depth2 = stereo.compute(TleftRight, img2, depth, counter - 3);
        depth = depth2;
        depth.filterNoise();
        cout << timer.elapsed() << endl; 
        depth.toInverseMat(res);
        depth.sigmaToMat(sigmaRes);
//        imwrite(imageDir + "res" + to_string(counter++) + ".png", depth*200);
        
        imshow("sigma " + to_string(counter), sigmaRes*20);
        imshow("d sigma " + to_string(counter), (sigmaRes - sigmaRes2)*20  + 0.5);
//        cout << (sigmaRes - sigmaRes2)(Rect(150, 150, 15, 15)) << endl;
        imshow("res " + to_string(counter), res *0.12);
        counter++; 
        waitKey();
    }
    waitKey();
    return 0;
}