◄home    

StereoFlow - File formats

Javier Sánchez Pérez

Computer Science Department

University of Las Palmas de Gran Canaria


All the output file formats are produced in ASCII. You may wonder why we do not use binary instead of ASCII. There is no good reasons for this. I do promise in future versions to use binary files.

 

2D file format

When you open a file like U.dat or V.dat (the resulting flow components of StereoFlow) you find somethig like:

 

    642 482

    45.759857 45.767181 45.774925 45.782612 45.790142 45.797768 ...

    44.676857 44.664951 44.653049 44.640945 44.629101 44.617294 ...

 

The first two digits are the size of the image ('nx' and 'ny'). Then you will find 'nx' rows with 'ny' columns

 

3D file format

When you open a file like Points3D.dat (the resulting 3D reconstruction given by StereoFlow) you find somethig like:  

   

    642 482

    -289.807617 814.512390 952.531860

    -289.025269 815.373596 950.343689

    -288.235626 816.242493 948.155884

    -287.446716 817.110596 945.966858

 

The first two digits are the size of the 2D image ('nx' and 'ny'). Then you will find 'nx*ny' registers each one representing a 3D point ('x', 'y' and 'z').

 

Following some C code for reading and writing files in this formats.

 

Reading code in C

 

/******************************************************************************/

/*** This function reads a                                                                                                                                ****/

/*** matrix from a file                                                                                                                                         ****/

/******************************************************************************/

void Read_Matrix(char *nomfich, float **m, int *nx, int *ny)

{

    FILE *fd;

    int i, j;

    float value;

 

    /* open the file */

    fd=fopen(nomfich, "r");

 

    /* read the number of registers */

    fscanf(fd, "%d %d\n", nx, ny);

 

    /* read the registers */

    for(i=0;i<*nx;i++){

        for(j=0;j<*ny;j++){

            fscanf(fd, "%f ", &value);

            m[i][j]=value;  

        }   

        fscanf(fd,"\n");

    }

  

 

Writing code in C

 

/******************************************************************************/

/*** This function saves a matrix in a file                                                                                                          ***/

/******************************************************************************/

void Keep_Matrix(char *nomfich, float **m, int nx, int ny)

{

    FILE *fd;

    int i, j;

 

    /* open the file */

    fd=fopen(nomfich, "w");

 

    /* write the number of registers */

    fprintf(fd, "%d %d\n", nx, ny);

 

    /* we write the registers */

    for(i=0;i<nx;i++){

        for(j=0;j<ny;j++)

            fprintf(fd, "%f ", m[i][j]);

            fprintf(fd,"\n");

    }

    fclose(fd);

}

 

/******************************************************************************/

/*** This function saves a 3D reconstruction in a file                                                                                  ***/

/******************************************************************************/

void Keep_3D(char *nomfich, float **x, float **y, float **z, int nx, int ny)

{

    FILE *fd;

    int i, j;

 

    /* open the file */

    fd=fopen(nomfich, "w");

 

    /* write the number of points to be processed */

    fprintf(fd, "%d %d\n", nx, ny);

 

    for(i=0;i<nx;i++)

        for(j=0;j<ny;j++){

            /* write the point into the file*/

            fprintf(fd, "%f %f %f\n",x[i][j], y[i][j], z[i][j] );

    }   

    fclose(fd);

}


 ◄home

  last update 24/12/2004