示例#1
0
文件: b_0_38.cpp 项目: jakexie/micmac
void bench_Proj32()
{
    Pt2di aSz(200,300);
    Pt2di aC = aSz/2;
    double aR = 50;
    Fonc_Num aF = Square(FX-aC.x)+Square(FY-aC.y) < ElSquare(aR);
    // aF = 0;

    Im2D_INT2 aI1(aSz.x,aSz.y);
    ELISE_COPY
    (
        aI1.all_pts(),
          aF * Polar_Def_Opun::polar(Virgule(FX-aC.x,FY-aC.y),0).v1()*(255.0/(2.0*PI))
        + (1-aF) * (frandr() * 255),
        aI1.out()
    );

   Video_Win aW= Video_Win::WStd(aSz,1.0);
   ELISE_COPY(aI1.all_pts(),aI1.in(),aW.ocirc());

   getchar();
   cResProj32  aR32 = Projection32(aF,aSz);
   ELISE_COPY
   (
         aI1.all_pts(),
         aI1.in()[Virgule(aR32.PX().in(),aR32.PY().in())],
         aW.ocirc()
   );
   getchar();
}
void Test_Arrondi_LG()
{
    Pt2di aSz(100,100);
    double aVTest = 117;

    Im2D_REAL16 anIm(aSz.x,aSz.y);
    TIm2D<REAL16,REAL16> aTIm(anIm);

    ELISE_COPY(anIm.all_pts(),aVTest,anIm.out());

    while (1)
    {
         Pt2dr aP0 = Pt2dr(10,10) + Pt2dr(NRrandom3(),NRrandom3()) *50.123456701765;
         double aV0 = aTIm.getr(aP0);
         double aV1 = Reechantillonnage::biline(anIm.data(),aSz.x,aSz.y,aP0);

         std::cout << " TEST " << (aV0-aVTest) * 1e50 << " " << (aV1-aVTest) * 1e50  << " " << aP0 << "\n";
         getchar();
    }
}
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;

}