1.
void PrintCvMatElements(CvMat* mat,int nRows,int nCols,int nArg,char* strMatName,float fVal)//nArg是用来指示数据类型的,float类型4字节,double类型8字节,uchar类型1字节
{
printf("%s:\n",strMatName);
for(int i=0;i<nRows;i++)
{
//double* pLine = (double*)dict_hires.ptr(80);
double* pLine = mat->data.db + i*(mat->step/nArg);
//uchar* pLine = mat->data.ptr + i*(mat->step/nArg);
for(int j=0;j<nCols;j++)
{
printf(" %f ",pLine[j]);
}
printf("\n");
}
}
2.
void PrintCvMatElements(CvMat* mat,int nRows,int nCols,int nArg,char* strMatName,int nVal)//nArg是用来指示数据类型的,float类型4字节,double类型8字节,uchar类型1字节
{
printf("%s:\n",strMatName);
for(int i=0;i<nRows;i++)
{
//double* pLine = (double*)dict_hires.ptr(80);
//double* pLine = mat->data.db + i*(mat->step/nArg);
uchar* pLine = mat->data.ptr + i*(mat->step/nArg);
for(int j=0;j<nCols;j++)
{
printf(" %u ",pLine[j]);
}
printf("\n");
}
}
3.应用举例:
PrintCvMatElements(conf.filterLT,7,1,8,"conf.filterLT",0.0f);//打印double类型数据的CvMat
PrintCvMatElements(conf.window,1,2,1,"conf.window",0);//打印uchare类型数据的CvMat