Ejemplo n.º 1
0
void Write_Vignette(string aDir, string aNameOut,vector<double> aParam,string aDirOut, Pt2di aSz){

    //Bulding the output file system
    ELISE_fp::MkDirRec(aDir + aDirOut);

    //Reading the image and creating the objects to be manipulated
    aNameOut=aDir + aDirOut + aNameOut;
    Tiff_Im aTF=Tiff_Im(aNameOut.c_str(), aSz, GenIm::real4, Tiff_Im::No_Compr, Tiff_Im::BlackIsZero);

    Im2D_REAL4  aIm(aSz.x,aSz.y);

    ELISE_COPY
    (
        aTF.all_pts(),
        aTF.in(),
        aIm.out()
    );

    REAL4 ** aData = aIm.data();

    for (int aY=0 ; aY<aSz.y  ; aY++)
        {
            for (int aX=0 ; aX<aSz.x  ; aX++)
            {
                double x0=aSz.x/2;
                double y0=aSz.y/2;
                double D=pow(aX-x0,2)+pow(aY-y0,2);
                double aCor=1+aParam[0]*D+aParam[1]*pow(D,2)+aParam[2]*pow(D,3);
                if(aCor<1){aData[aY][aX]=1;}else{aData[aY][aX]=aCor;}
            }
        }

        Tiff_Im  aTOut
        (
            aNameOut.c_str(),
            aSz,
            GenIm::real4,
            Tiff_Im::No_Compr,
            Tiff_Im::BlackIsZero
        );

        ELISE_COPY
            (
                aTOut.all_pts(),
                aIm.in(),
                aTOut.out()
            );

}
int ApplyParralaxCor_main(int argc, char ** argv)
{
	//std::string aNameIm, aNameIm2, aNameParallax, aNameDEM;
	std::string aNameIm, aNameParallax;
	std::string aNameOut = "";
	//Reading the arguments
	ElInitArgMain
		(
		argc, argv,
		LArgMain()
		<< EAMC(aNameIm, "Image to be corrected", eSAM_IsPatFile)
		//<< EAMC(aNameIm2, "Other image", eSAM_IsPatFile)
		<< EAMC(aNameParallax, "Paralax correction file", eSAM_IsPatFile),
		//<< EAMC(aNameDEM, "DEM file", eSAM_IsPatFile),
		LArgMain()
		<< EAM(aNameOut, "Out", true, "Name of output image (Def=ImName_corrected.tif")
		);

	std::string aDir, aPatIm;
	SplitDirAndFile(aDir, aPatIm, aNameIm);

	cout << "Correcting " << aNameIm << endl;
	if (aNameOut == "")
		aNameOut = aNameIm + "_corrected.tif";

	//Reading the image and creating the objects to be manipulated
	Tiff_Im aTF = Tiff_Im::StdConvGen(aDir + aNameIm, 1, false);

	Pt2di aSz = aTF.sz(); cout << "size of image = " << aSz << endl;
	Im2D_U_INT1  aIm(aSz.x, aSz.y);

	ELISE_COPY
		(
		aTF.all_pts(),
		aTF.in(),
		aIm.out()//Virgule(aImR.out(),aImG.out(),aImB.out())
		);

	U_INT1 ** aData = aIm.data();

	//Reading the parallax correction file
	Tiff_Im aTFPar = Tiff_Im::StdConvGen(aDir + aNameParallax, 1, false);
	Im2D_REAL8  aPar(aSz.x, aSz.y);
	ELISE_COPY
		(
		aTFPar.all_pts(),
		aTFPar.in(),
		aPar.out()//Virgule(aImR.out(),aImG.out(),aImB.out())
		);
	REAL8 ** aDatPar = aPar.data();
	

	//Output container
	Im2D_U_INT1  aImOut(aSz.x, aSz.y);
	U_INT1 ** aDataOut = aImOut.data();

	/*Things needed for RPC angle computation, not main goal of this function
	
	//Read RPCs
	RPC aRPC;
	string aNameRPC1 = "RPC_" + StdPrefix(aNameIm) + ".xml";
	aRPC.ReadDimap(aNameRPC1);
	cout << "Dimap File " << aNameRPC1 << " read" << endl;
	RPC aRPC2;
	string aNameRPC2 = "RPC_" + StdPrefix(aNameIm2) + ".xml";
	aRPC2.ReadDimap(aNameRPC2);
	cout << "Dimap File " << aNameRPC2 << " read" << endl;
	
	//Reading the DEM file
	Tiff_Im aTFDEM = Tiff_Im::StdConvGen(aDir + aNameDEM, 1, false);
	Im2D_REAL8  aDEM(aSz.x, aSz.y);
	ELISE_COPY
	(
	aTFDEM.all_pts(),
	aTFDEM.in(),
	aDEM.out()
	);
	REAL8 ** aDatDEM = aDEM.data();

	//Output angle container 1
	Im2D_REAL8  aAngleBOut(aSz.x, aSz.y);
	REAL8 ** aDataAngleBOut = aAngleBOut.data();
	string aNameAngleB = "AngleB.tif";

	//Output angle container 2
	Im2D_REAL8  aAngleNOut(aSz.x, aSz.y);
	REAL8 ** aDataAngleNOut = aAngleNOut.data();
	string aNameAngleN = "AngleN.tif";
	*/
	//Pt3dr PBTest(1500,3000, 0);
	//Pt3dr PWTest = aRPC.DirectRPC(PBTest);
	//Pt3dr PNTest = aRPC2.InverseRPC(PWTest);
	//cout << "PB0 = " << PBTest << endl;
	//cout << "PW0 = " << PWTest << endl;
	//cout << "PN0 = " << PNTest << endl;
	//cout << aRPC.height_scale << " " << aRPC.height_off << endl;
	//PBTest.z=1000;
	//PWTest = aRPC.DirectRPC(PBTest);
	//PNTest = aRPC2.InverseRPC(PWTest);
	//cout << "PB1 = " << PBTest << endl;
	//cout << "PW1 = " << PWTest << endl;
	//cout << "PN1 = " << PNTest << endl;


	cout << "size of image = " << aSz << endl;
	//Computing output data
	for (int aX = 0; aX < aSz.x; aX++)
	{
		for (int aY = 0; aY < aSz.y; aY++)
		{
			/*
			Pt3dr P0B(aX, aY, aDatDEM[aY][aX]);
			Pt3dr PW0 = aRPC.DirectRPC(P0B);
			Pt3dr PW1 = PW0, PW2 = PW0;
			PW1.z = PW1.z - 1;
			PW2.z = PW2.z + 1;
			Pt3dr P1B = aRPC.InverseRPC(PW1);
			Pt3dr P2B = aRPC.InverseRPC(PW2);
			Pt3dr P1N = aRPC2.InverseRPC(PW1);
			Pt3dr P2N = aRPC2.InverseRPC(PW2);
			//Pt3dr P1B(aX, aY, 0);
			//Pt3dr P2B(aX, aY, 10000);
			//Pt3dr P1N = aRPC2.InverseRPC(aRPC.DirectRPC(P1B));
			//Pt3dr P2N = aRPC2.InverseRPC(aRPC.DirectRPC(P2B));
			double aAngleB = atan((P2B.x - P1B.x) / (P2B.y - P1B.y));
			aDataAngleBOut[aY][aX] = aAngleB;
			double aAngleN = atan((P2N.x - P1N.x) / (P2N.y - P1N.y));
			aDataAngleNOut[aY][aX] = aAngleN;
			//cout << aX << " " << aY << " " << aAngle << endl;
			//cout << P1N << " " << P2N << " " << aAngle << endl;

			*/
			//THE THINGS COMPUTED ABOVE WILL BE USED IN A FURTHER UPDATE

			Pt2dr ptOut;
			ptOut.x = aX - aDatPar[aY][aX];// * cos(aAngleB);
			ptOut.y = aY - aDatPar[aY][aX];// * sin(aAngleB);
			aDataOut[aY][aX] = Reechantillonnage::biline(aData, aSz.x, aSz.y, ptOut);
		}
	}
	cout << "size of image = " << aSz << endl;
	Tiff_Im  aTOut
		(
		aNameOut.c_str(),
		aSz,
		GenIm::u_int1,
		Tiff_Im::No_Compr,
		Tiff_Im::BlackIsZero
		);


	ELISE_COPY
		(
		aTOut.all_pts(),
		aImOut.in(),
		aTOut.out()
		);
	/*
	Tiff_Im  aTAngleBOut
		(
		aNameAngleB.c_str(),
		aSz,
		GenIm::real8,
		Tiff_Im::No_Compr,
		Tiff_Im::BlackIsZero
		);


	ELISE_COPY
		(
		aTAngleBOut.all_pts(),
		aAngleBOut.in(),
		aTAngleBOut.out()
		);


	Tiff_Im  aTAngleNOut
		(
		aNameAngleN.c_str(),
		aSz,
		GenIm::real8,
		Tiff_Im::No_Compr,
		Tiff_Im::BlackIsZero
		);


	ELISE_COPY
		(
		aTAngleNOut.all_pts(),
		aAngleNOut.in(),
		aTAngleNOut.out()
		);
*/
	return 0;
}
int Luc_main_truc(int argc, char ** argv)
{
    /*
    std::string aFullPattern, aOri, aNameOut="PointsCordinates.txt";
    //Reading the arguments
    ElInitArgMain
        (
        argc, argv,
        LArgMain()  << EAMC(aFullPattern, "Images Pattern 1", eSAM_IsPatFile)
                    << EAMC(aOri, "Orientation", eSAM_IsPatFile),
        LArgMain()  << EAM(aNameOut, "Out", true, "Output file (txt)")
        );

    string aPattern, aNameDir;
    SplitDirAndFile(aNameDir, aPattern, aFullPattern);

    //Reading input files
    list<string> ListIm = RegexListFileMatch(aNameDir, aPattern, 1, false);
    int nbIm = ListIm.size();

    string oriFileName = aNameDir + aNameOut;
    FILE *f = fopen(oriFileName.c_str(), "w");

    for (int i = 1; i <= nbIm; i++)
    {
        //Processing the image
        string aNameIm = ListIm.front();
        ListIm.pop_front();
        string aNameOut = aNameDir + aNameIm + ".tif";

        //Loading the camera
        string aNameCam = "Ori-" + aOri + "/Orientation-" + aNameIm + ".xml";
        cInterfChantierNameManipulateur * anICNM = cInterfChantierNameManipulateur::BasicAlloc(aNameDir);
        CamStenope * aCam = CamOrientGenFromFile(aNameCam, anICNM);
        cout << aNameIm << " [ " << aCam->VraiOpticalCenter().x << " , " << aCam->VraiOpticalCenter().y << " , " << aCam->VraiOpticalCenter().z << " ]" << endl;
        fprintf(f, "%s %0.6f %0.6f %0.6f\n", aNameIm, aCam->VraiOpticalCenter().x, aCam->VraiOpticalCenter().y, aCam->VraiOpticalCenter().z);

    }
    fclose(f);



    */

    std::string aFullPattern1, aFullPattern2, aFile3D1, aFile3D2, aOri, aDirOut = "Visualisation/";
    int aSzW = 1;
    double aSzMovArea = 5;
    //Reading the arguments
    ElInitArgMain
        (
        argc, argv,
        LArgMain()	<< EAMC(aFullPattern1, "Images Pattern 1", eSAM_IsPatFile)
                    << EAMC(aFullPattern2, "Images Pattern 2", eSAM_IsPatFile)
                    << EAMC(aFile3D1, "File 3D 1", eSAM_IsPatFile)
                    << EAMC(aFile3D2, "File 3D 2", eSAM_IsPatFile)
                    << EAMC(aOri, "Orientation", eSAM_IsPatFile),
        LArgMain()	<< EAM(aDirOut, "Out", true, "Output folder (end with /) and/or prefix (end with another char)")
                    << EAM(aSzMovArea, "SzMovArea", true, "Max magnitude of movement in meters (def=5)")
        );

    //Creating vector of images
    std::string aDir, aPatIm1, aPatIm2;
    SplitDirAndFile(aDir, aPatIm1, aFullPattern1);
    SplitDirAndFile(aDir, aPatIm2, aFullPattern2);
    cInterfChantierNameManipulateur * aICNM = cInterfChantierNameManipulateur::BasicAlloc(aDir);
    const std::vector<std::string> * aSetIm1 = aICNM->Get(aPatIm1);
    const std::vector<std::string> * aSetIm2 = aICNM->Get(aPatIm2);
    std::vector<std::string> aVectIm1 = *aSetIm1;
    std::vector<std::string> aVectIm2 = *aSetIm2;

    cout << "Set 1 size : " << aVectIm1.size() << endl;
    cout << "Set 1 : " << aVectIm1 << endl;
    cout << "Set 2 size : " << aVectIm2.size() << endl;
    cout << "Set 2 : " << aVectIm2 << endl;

    //loading 3D models
    cElNuage3DMaille * info3D1 = cElNuage3DMaille::FromFileIm(aFile3D1);
    cElNuage3DMaille * info3D2 = cElNuage3DMaille::FromFileIm(aFile3D2);
    cout << "Sz geom 1: " << info3D1->SzGeom() << endl;
    cout << "Sz geom 2: " << info3D2->SzGeom() << endl;
    cout << "Resol geom 1: " << info3D1->ResolSolGlob() << endl;
    cout << "Resol geom 2: " << info3D2->ResolSolGlob() << endl;

    //Loading images
    vector<SpatioTempImage> aGrIm1 = LoadGrpImages(aDir, aPatIm1, aOri);
    vector<SpatioTempImage> aGrIm2 = LoadGrpImages(aDir, aPatIm2, aOri);
    cout << "Loaded " << aGrIm1.size() << " images for group 1 and " << aGrIm2.size() << " for group 2" << endl;


    //Bulding the output file system
    ELISE_fp::MkDirRec(aDir + aDirOut);
    std::string aNameOut = "banane.tif";
    //Reading the image and creating the objects to be manipulated
    aNameOut = aDir + aDirOut + aNameOut;

    Pt2di aSz( info3D1->SzGeom().x , info3D1->SzGeom().y );

    Tiff_Im aTF = Tiff_Im(aNameOut.c_str(), aSz, GenIm::real4, Tiff_Im::No_Compr, Tiff_Im::BlackIsZero);

    Im2D_REAL4  aIm(aSz.x, aSz.y);

    ELISE_COPY
        (
        aTF.all_pts(),
        aTF.in(),
        aIm.out()
        );

    REAL4 ** aData = aIm.data();


    for (int aY = aSzW; aY < aSz.y - aSzW; aY++)
    {
        for (int aX = aSzW; aX < aSz.x - aSzW; aX++)
        {
            /*******************************
            HOW TO
            //transform XY pixel coordinates to terrain coordinates
            Pt2dr pos2DPtIm1; pos2DPtIm1.x = 10050 + aX*0.14999999999999999*2; pos2DPtIm1.y = 10350 - aY*0.14999999999999999*2;
            //Go back to pix coordinates
            pos2DPtIm1 = info3D->Plani2Index(pos2DPtIm1);
            ********************************/
            Pt2dr pos2DMNT( aX , aY );
            //Test if there is data
            if (info3D1->CaptHasData(pos2DMNT)){
                //Get 3D info at XY
                Pt3d<double> pos3DMNT = info3D1->PreciseCapteur2Terrain(pos2DMNT);
                //cout << "pos3DMNT1 = " << pos3DMNT << endl;
                //Get Im1(i,j)
                Pt2di pos2DIm1( int(aGrIm1[0].aCamera->Ter2Capteur(pos3DMNT).x) , int(aGrIm1[0].aCamera->Ter2Capteur(pos3DMNT).y) );
                cout << "pos2DIm1 = " << pos2DIm1 << endl;
                //Extracting window from Im1
                Im2D_U_INT1 aWindow1 = Window_Maker(aGrIm1[0], pos2DIm1, 1);

                Fonc_Num aScoreMin = 100;
                /*
                for (int bX = pos3DMNT.x - aSzMovArea; bX <= pos3DMNT.x + aSzMovArea; bX++)
                {
                    for (int bY = pos3DMNT.y - aSzMovArea; bY <= pos3DMNT.y + aSzMovArea; bY++)
                    {
                        Pt2di aPos(int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).x), int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).y));
                        //Extracting window from Im2
                        Im2D_U_INT1 aWindow2 = Window_Maker(aGrIm2[0], aPos, 1);
                        double aScore = Correlator(&aWindow1, &aWindow2);
                        if (aScore < aScoreMin)
                        {
                            //CACACACACACACACCACACACACA TESTER SI PT EXIST DANS INFO3D2=====================================================================================
                            aScoreMin = aScore;
                            Pt2dr aPos2D(bX, bY);
                            Pt3dr aPos3D = info3D2->PreciseCapteur2Terrain(info3D2->Plani2Index(aPos2D));
                            cout << "pos set 1 = " << pos3DMNT << endl;
                            cout << "pos set 2 = " << aPos3D << endl;
                            aData[aY][aX] = square_euclid(pos3DMNT, aPos3D);
                            cout << aData[aY][aX] << endl;
                        }
                    }
                }


                //Get Im2(i,j)
                Pt2di pos2DIm2( int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).x) , int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).y) );
                cout << "pos2DIm2 = " << pos2DIm2 << endl;
                //Define researsh area in pixels from input info in meters
                int aSzMovAreaPix = aSzMovArea / aGrIm2[0].aCamera->ResolutionSol();
                cout <<"Pouet"<<endl;
                double aScoreMin = 100;
                for (int bX = pos2DIm2.x - aSzMovAreaPix; bX <= pos2DIm2.x + aSzMovAreaPix; bX++)
                {
                    for (int bY = pos2DIm2.y - aSzMovAreaPix; bY <= pos2DIm2.y + aSzMovAreaPix; bY++)
                    {
                        Pt2di aPos( bX, bY );
                        //Extracting window from Im2
                        vector<vector<float> > aWindow2 = Window_Maker(aGrIm2[0], aPos, 1);
                        cout << aWindow2 << endl;
                        double aScore = Correlator(aWindow1, aWindow2);
                        cout << aScore << endl;
                        if (aScore < aScoreMin)
                        {
                            aScoreMin = aScore;
                            Pt2dr aPosR(aPos.x, aPos.y);
                            cout << "aPos " << aPos << endl;
                            cout << "aPosR " << aPosR << endl;

                            Pt3dr aPosPt3D = aGrIm2[0].aCamera->PreciseCapteur2Terrain(aPosR);
                            cout << aPosPt3D << endl;
                            Pt2dr aPos2DPtIm2 = info3D2->Plani2Index(aPosR);
                            cout << aPos2DPtIm2 << endl;
                            aData[aY][aX] = square_euclid(pos3DMNT, info3D2->PreciseCapteur2Terrain(aPos2DPtIm2));
                            cout << aData[aY][aX] << endl;
                        }
                    }
                }
                */

            }
            else
            {
                aData[aY][aX] = 1;
                //cout << "not in Masq" << endl;
            }
        }
    }

    Tiff_Im  aTOut
        (
        aNameOut.c_str(),
        aSz,
        GenIm::real4,
        Tiff_Im::No_Compr,
        Tiff_Im::BlackIsZero
        );

    ELISE_COPY
        (
        aTOut.all_pts(),
        aIm.in(),
        aTOut.out()
        );

    return 0;

}