Opencv中将CvMat转为IplImage,并在内存获得起头指针,而不用cvSaveImage(),贴上代码
IplImage * imgg = NULL; imgg = cvCreateImage(cvSize(modelF[0].Matrix->cols,modelF[0].Matrix->rows),IPL_DEPTH_8U,1); float ve; for(int n = 0; n < modelF[0].Matrix->rows; n++){ for(int m = 0; m < modelF[0].Matrix->cols; m++){ ve = CV_MAT_ELEM(*(modelF[0].Matrix),float,n,m); CV_IMAGE_ELEM(imgg,uchar,n,m) = (uchar)cvRound(ve); } }
cvNamedWindow("imgg",CV_WINDOW_AUTOSIZE);
cvShowImage("imgg",imgg);
cvWaitKey(0);
注意这里的cvSize类的用法,cvSize(int width,int height) 是先输入图像矩阵的列,再输入行