#include "stdafx.h" #include "highgui.h" #include "cv.h" #include "iostream" using namespace std; void PrintMat2(CvMat*target, char * name)//第一个参数为cvMat矩阵指针,第二个参数为输出的矩阵的名字 { printf("%s:\n", name); for (int i=0; i<target->rows; i++) { for (int j=0; j<target->cols;j++) { printf("%f\t", cvmGet(target, i,j)); } printf("\n"); } } int main() { float vals1[]={1,2,3,4}; CvMat src1; //cvInitMatHeader(CvMat矩阵指针,行数,列数,数据类型,一维矩阵指针) cvInitMatHeader(&src1,2,2,CV_32FC1,vals1); PrintMat2(&src1,"src1"); float vals2[]={2,3,4,5}; CvMat src2; //cvInitMatHeader(CvMat矩阵指针,行数,列数,数据类型,一维矩阵指针) cvInitMatHeader(&src2,2,2,CV_32FC1,vals2); PrintMat2(&src2,"src2"); CvMat* src[2]; src[0]=&src1; src[1]=&src2; CvMat* mat=cvCreateMat(2,2,CV_32FC1); CvMat* avg=cvCreateMat(2,2,CV_32FC1); cvCalcCovarMatrix(( const CvArr **)src,2,mat,avg,CV_COVAR_NORMAL); PrintMat2(mat,"mat"); PrintMat2(avg,"avg"); return 0; }
时间: 2024-10-28 10:41:10