【OpenCV学习】多通道矩阵的赋值和取值
作者: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"); } }