◄home    

OpticFlow - 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

 

 

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);

}

 


 ◄home

  last update 24/12/2004