Пример #1
0
int main(int argc, char **argv)
{

  double * rodriguez = (double*) malloc(sizeof(double) * 3 );
  double * translation = (double*) malloc(sizeof(double) * 3 );
  double * camera = (double*) malloc(sizeof(double) * 9 );



 //Internal calibration
 camera[0]=535.784106;   camera[1]=0.0;         camera[2]=312.428312;
 camera[3]=0.0;          camera[4]=534.223354;  camera[5]=243.889369;
 camera[6]=0.0;          camera[7]=0.0;         camera[8]=1.0;

 #define USE_CAMERA_CALIBRATION 0
 #define USE_TEST 0

 #if   USE_TEST == 0
  translation[0]=0.0;  translation[1]=0.0; translation[2]=0.0;
  rodriguez[0]=0.0;    rodriguez[1]=0.0;    rodriguez[2]=0.0;
 #elif USE_TEST == 1
  //box0603 Calib
  translation[0]=0.215793; translation[1]=-0.137982; translation[2]=0.767494;
  rodriguez[0]=0.029210; rodriguez[1]=-2.776582; rodriguez[2]=1.451629;
 #elif USE_TEST == 2
  //boxNew Calib
  translation[0]=-0.062989;  translation[1]=0.159865; translation[2]=0.703045;
  rodriguez[0]=1.911447;     rodriguez[1]=0.000701;   rodriguez[2]=-0.028548;
 #elif USE_TEST == 3
  //Test Calib
  translation[0]=0.056651;  translation[1]=-0.000811; translation[2]=0.601942;
  rodriguez[0]=0.829308;    rodriguez[1]=2.251753;    rodriguez[2]=-1.406462;
 #elif USE_TEST == 4
 //Test Calib
  translation[0]=-0.041674;  translation[1]=-0.076036; translation[2]=2.355294;
  rodriguez[0]=-0.733111;    rodriguez[1]=0.155142;    rodriguez[2]=0.172950;
 #elif USE_TEST == 5
  // ARTest
  translation[0]=-0.413148;  translation[1]=0.208111; translation[2]=1.987205;
  rodriguez[0]=2.052258;    rodriguez[1]=0.642598;    rodriguez[2]=-0.246993;
 #endif // USE_TEST


 #if USE_TEST == 0
  setOpenGLNearFarPlanes(1,5000);
  #if USE_CAMERA_CALIBRATION
   setOpenGLIntrinsicCalibration( (double*) camera);
  #endif
 #else
  setOpenGLNearFarPlanes(0.1,100);
  setOpenGLIntrinsicCalibration( (double*) camera);
  setOpenGLExtrinsicCalibration( (double*) rodriguez, (double*) translation );
 #endif



  int i=0;
  for (i=0; i<argc; i++)
  {
    if (strcmp(argv[i],"-size")==0) {
                                        if (i+2<argc)
                                        {
                                         width=atof(argv[i+1]);
                                         height=atof(argv[i+2]);
                                        }
                                     } else
    if (
         (strcmp(argv[i],"-photo")==0) ||
         (strcmp(argv[i],"-photoshoot")==0)
        )
                                     {
                                        if (i+4<argc)
                                        {
                                         photoShootOBJ=atoi(argv[i+1]);
                                         angleX=atof(argv[i+2]);
                                         angleY=atof(argv[i+3]);
                                         angleZ=atof(argv[i+4]);
                                        }
                                     } else
    if (strcmp(argv[i],"-from")==0) {
                                        if (i+1<argc)
                                          { readFromArg = i+1 ; }
                                    }
  }

 if (readFromArg!=0) {   startOGLRendererSandbox(width,height,1 /*View OpenGL Window*/,argv[readFromArg]); } else
                     {   startOGLRendererSandbox(width,height,1 /*View OpenGL Window*/,0); /*0 defaults to scene.conf*/ }


  if (photoShootOBJ)
   {
     float angXVariance=60,angYVariance=60,angZVariance=30;
     //fprintf(stderr,"Making a photoshoot of object %u",photoShootOBJ);

     void * oglPhotoShoot = createOGLRendererPhotoshootSandbox( photoShootOBJ,columns,rows,distance,angleX,angleY,angleZ,angXVariance,angYVariance,angZVariance );

     snapOGLRendererPhotoshootSandbox(oglPhotoShoot , photoShootOBJ,columns,rows,distance,angleX,angleY,angleZ,angXVariance,angYVariance,angZVariance);
     writeOpenGLColor("color.pnm",0,0,width,height);
     writeOpenGLDepth("depth.pnm",0,0,width,height);

     destroyOGLRendererPhotoshootSandbox( oglPhotoShoot );
     return 0;
   }


  snapOGLRendererSandbox(); // Snap a frame
  writeOpenGLColor("color.pnm",0,0,width,height);
  writeOpenGLDepth("depth.pnm",0,0,width,height);

   while (1)
    {
      snapOGLRendererSandbox();
    }


  free(rodriguez);
  free(translation);
  free(camera);

  stopOGLRendererSandbox();
  return 0;
}
Пример #2
0
int main(int argc, char **argv)
{

    double * rodriguez = (double*) malloc(sizeof(double) * 3 );
    double * translation = (double*) malloc(sizeof(double) * 3 );
    double * camera = (double*) malloc(sizeof(double) * 9 );
    double scaleToDepthUnit = 1.0;



//Internal calibration
    camera[0]=535.784106;
    camera[1]=0.0;
    camera[2]=312.428312;
    camera[3]=0.0;
    camera[4]=534.223354;
    camera[5]=243.889369;
    camera[6]=0.0;
    camera[7]=0.0;
    camera[8]=1.0;

    translation[0]=0.0;
    translation[1]=0.0;
    translation[2]=0.0;
    rodriguez[0]=0.0;
    rodriguez[1]=0.0;
    rodriguez[2]=0.0;

    setOpenGLNearFarPlanes(1,15000);

    int i=0;
    for (i=0; i<argc; i++)
    {

        if (strcmp(argv[i],"-test")==0)
        {
            internalTest();
            exit(0);
        }
        else if (strcmp(argv[i],"-intrinsics")==0)
        {
            if (i+8<argc)
            {
                int z=0;
                for (z=0; z<9; z++)
                {
                    camera[z]=atof(argv[z+i+1]);
                }
                setOpenGLIntrinsicCalibration( (double*) camera);
            }
        }
        else if (strcmp(argv[i],"-extrinsics")==0)
        {
            if (i+7<argc)
            {
                translation[0]=atof(argv[i+1]);
                translation[1]=atof(argv[i+2]);
                translation[2]=atof(argv[i+3]);
                rodriguez[0]=atof(argv[i+4]);
                rodriguez[1]=atof(argv[i+5]);
                rodriguez[2]=atof(argv[i+6]);
                scaleToDepthUnit = atof(argv[i+7]);
                setOpenGLExtrinsicCalibration( (double*) rodriguez, (double*) translation , scaleToDepthUnit);
            }
        }
        else if ( (strcmp(argv[i],"-resolution")==0) ||
                  (strcmp(argv[i],"-size")==0) )
        {
            if (i+2<argc)
            {
                width=atof(argv[i+1]);
                height=atof(argv[i+2]);
            }
        }
        else if (
            (strcmp(argv[i],"-photo")==0) ||
            (strcmp(argv[i],"-photoshoot")==0)
        )
        {
            if (i+4<argc)
            {
                photoShootOBJ=atoi(argv[i+1]);
                angleX=atof(argv[i+2]);
                angleY=atof(argv[i+3]);
                angleZ=atof(argv[i+4]);
                columns=atoi(argv[i+5]);
                rows=atoi(argv[i+6]);
            }
        }
        else if (strcmp(argv[i],"-from")==0)
        {
            if (i+1<argc)
            {
                readFromArg = i+1 ;
            }
        }
        else if (strcmp(argv[i],"-to")==0)
        {
            if (i+1<argc)
            {
                writeToArg = i+1 ;
                doFileOutput=1;
                fprintf(stderr,"Will write data to %s\n",argv[writeToArg]);
            }
        }
        else if (strcmp(argv[i],"-shader")==0)
        {
            enableShaders(argv[i+1],argv[i+2]);
        }
        else if (strcmp(argv[i],"-keyboard")==0)
        {
            forceKeyboardControl=1;
        }
        else if (strcmp(argv[i],"-maxFrames")==0)
        {
            maxFrames=atoi(argv[i+1]);
        }
    }


    int started = 0;
    if (readFromArg!=0)
    {
        started=startOGLRendererSandbox(width,height,1 /*View OpenGL Window*/,argv[readFromArg]);
    }
    else
    {
        started=startOGLRendererSandbox(width,height,1 /*View OpenGL Window*/,0); /*0 defaults to scene.conf*/
    }


    if (!started)
    {
        fprintf(stderr,"Could not start OpenGL Renderer Sandbox , please see log to find the exact reason of failure \n");
        return 0;
    }

    if (photoShootOBJ)
    {
        float angXVariance=60,angYVariance=60,angZVariance=30;
        //fprintf(stderr,"Making a photoshoot of object %u",photoShootOBJ);

        void * oglPhotoShoot = createOGLRendererPhotoshootSandbox( photoShootOBJ,columns,rows,distance,angleX,angleY,angleZ,angXVariance,angYVariance,angZVariance );

        snapOGLRendererPhotoshootSandbox(oglPhotoShoot , photoShootOBJ,columns,rows,distance,angleX,angleY,angleZ,angXVariance,angYVariance,angZVariance);
        writeOpenGLColor("color.pnm",0,0,width,height);
        writeOpenGLDepth("depth.pnm",0,0,width,height);

        destroyOGLRendererPhotoshootSandbox( oglPhotoShoot );
        return 0;
    }

    if ( forceKeyboardControl )
    {
        setKeyboardControl(1);
    }

    char filename[FILENAME_MAX]= {0};
    if (doFileOutput)
    {
        myMkdir("frames",argv[writeToArg]);
    }



    unsigned int snappedFrames=0;
    while (1)
    {
        snapOGLRendererSandbox();


        if (doFileOutput)
        {
            snprintf(filename,FILENAME_MAX,"frames/%s/colorFrame_0_%05u.pnm",argv[writeToArg],snappedFrames);
            writeOpenGLColor(filename,0,0,width,height);


            snprintf(filename,FILENAME_MAX,"frames/%s/depthFrame_0_%05u.pnm",argv[writeToArg],snappedFrames);
            writeOpenGLDepth(filename,0,0,width,height);

            ++snappedFrames;
        }


        if (maxFrames!=0)
        {
          if (maxFrames==snappedFrames)
          {
            fprintf(stderr,"Reached target of %u frames , stopping\n",maxFrames);
            break;
          }
        }
    }


    free(rodriguez);
    free(translation);
    free(camera);

    stopOGLRendererSandbox();
    return 0;
}