opencv求取RGB分量
2016-04-10 14:01 GarfieldEr007 阅读(616) 评论(0) 编辑 收藏 举报需要注意的是下面r,b,g的类型和顺序
须用IPL_DEPTH_8U类型创建图像且[0][1][2]分量分别是b,g,r.
另外多谢郑乾师兄帮我发现了IPL_DEPTH_8U问题
- uchar r,b,g;//notice 'uchar' type must be used instead of double
- int h=workImg->height;
- int w=workImg->width;
- IplImage *D=cvCreateImage(cvGetSize(workImg),IPL_DEPTH_8U,workImg->nChannels);
- CvScalar s,s1;
- for(int x=0;x<workImg->height;x++)
- {
- for(int y=0;y<workImg->width;y++)
- {
- b=((uchar*)(workImg->imageData+x*workImg->widthStep))[y*3+0];
- g=((uchar*)(workImg->imageData+x*workImg->widthStep))[y*3+1];
- r=((uchar*)(workImg->imageData+x*workImg->widthStep))[y*3+2];
- }
- }
若用IPL_DEPTH_64U类型赋值会导致图片出现如下情况:
这里大家一定要小心哦~
from: http://blog.csdn.net/abcjennifer/article/details/7385672