Tuesday, November 06, 2007

OpenCV: print matrix

void PrintMat(CvMat *A)
{
int i, j;
for (i = 0; i < A->rows; i++)
{
printf("\n");
switch (CV_MAT_DEPTH(A->type))
{
case CV_32F:
case CV_64F:
for (j = 0; j < A->cols; j++)
printf ("%8.3f ", (float)cvGetReal2D(A, i, j));
break;
case CV_8U:
case CV_16U:
for(j = 0; j < A->cols; j++)
printf ("%6d",(int)cvGetReal2D(A, i, j));
break;
default:
break;
}
}
printf("\n");
}

Some matrix operations need to be updated.

7 comments:

  1. thanks Weis again!

    comes handy.

    ReplyDelete
  2. Thanks a lot!
    It also seems to support CV_8S, CV_16S for integer matrices.
    And it can be written with more arguments: (rowBeg, rowEnd, colBeg, colEnd) to set the printing range, with default arguments being the entire matrix.

    ReplyDelete
  3. Anonymous5:17 AM

    Thank you, this is useful

    ReplyDelete
  4. Anonymous10:57 PM

    very useful code! Thanks a lot.

    ReplyDelete
  5. Bui Van Thong7:24 AM

    thank you so much. Good code

    ReplyDelete