aihot  2017-05-18 01:46:51  图像处理 |   查看评论   
for (int col = 0; col < img->width; col++) { b = ((uchar *)(img->imageData + row * img->widthStep))[col * img->nChannels + 0];  g = ((uchar *)(img->imageData + row * img->widthStep))[col * img->nChannels + 1];  r = ((uchar *)(img->imageData + row * img->widthStep))[col * img->nChannels + 2]; } }

 初始化使用IplImage *,是一个指向结构体IplImage的指针: 

View Code
IplImage * cvLoadImage(const char * filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); //load images from specified image  IplImage * cvCreateImage(CvSize size, int depth, int channels); //allocate memory

 

2.CvMat

首先,我们需要知道,第一,在OpenCV中没有向量(vector)结构。任何时候需要向量,都只需要一个列矩阵(如果需要一个转置或者共轭向量,则需要一个行矩阵)。第二,OpenCV矩阵的概念与我们在线性代数课上学习的概念相比,更抽象,尤其是矩阵的元素,并非只能取简单的数值类型,可以是多通道的值。CvMat 的结构: 

View Code
typedef struct CvMat  {  int type;  int step;  int* refcount;  union { uchar* ptr; short* s; int* i; float* fl; double* db; } data;  union { int rows; int height; }; union { int cols;  int width; }; } CvMat;

 创建CvMat数据: 

View Code
CvMat * cvCreateMat(int rows, int cols, int type);  CV_INLine CvMat cvMat((int rows, int cols, int type, void* data CV_DEFAULT);  CvMat * cvInitMatHeader(CvMat * mat, int rows, int cols, int type, void * data CV_DEFAULT(NULL), int step CV_DEFAULT(CV_AUTOSTEP));

 对矩阵数据进行访问: 

View Code
 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自IplImage, CvMat, Mat 的关系和相互转换

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]