Monday, March 28, 2011

Read from a file and create opencv matrix

파일에서숫자들을읽어서 opencv타입의 행렬로 만든다.

void artificialpt(CvMat* points1, CvMat* points2)
{
FILE * file1;
file1 = fopen("pt_2D_1.txt","r");
FILE * file2;
file2 = fopen("pt_2D_2.txt","r");
int rows = 37;
int columns =2;

float mat1[37][2]; float mat2[37][2];
char linebuf[256];

for (int i=0; i {
for (int j=0; j< columns; j++)
{
fscanf(file1,"%f",&mat1[i][j]);
fscanf(file2,"%f",&mat2[i][j]);

}
for (int j=0; j< columns; j++)
{
cvmSet(points1,i,j, mat1[i][1-j]);
cvmSet(points2,i,j, mat2[i][1-j]);
}
}
fclose(file1); fclose(file2);
}

No comments:

Post a Comment