作者:gnuhpc
出處:http://www.cnblogs.com/gnuhpc/
#pragma comment( lib, "cxcore.lib" ) #include "cv.h" #include <stdio.h> void main() { //矩陣元素為三通道浮點數 CvMat* mat = cvCreateMat(3,3,CV_32FC3); cvZero(mat);//將矩陣置0 //為矩陣元素賦值 //獲得矩陣元素(0,0)的指標 float *p = (float*)cvPtr2D(mat, 0, 0); //為矩陣賦值 for(int i = 0; i < 9; i++) { //為每個通道賦值 *p = (float)i*10; p++; *p = (float)i*10+1; p++; *p = (float)i*10+2; p++; } //列印矩陣的值 p = (float*)cvPtr2D(mat, 0, 0); for(i = 0; i < 9; i++) { printf("%2.1f,%2.1f,%2.1f/t",*p,*(p+1),*(p+2)); p+=3; if((i+1) % 3 == 0) printf("/n"); } }