Structure      Contains  Represents
CvPoint      int x, y  Point in image
CvPoint2D32f   float x, y  Points in R 2
CvPoint3D32f   float x, y, z  Points in R 3
CvSize       int width, height  Size of image
CvRect       int x, y, width, height  Portion of image
CvScalar      double val[4]  RGBA value

cvScalar() , takes one, two, three, or four arguments and assigns those arguments to the corresponding elements of val[] .  set四个值

cvRealScalar() ; it takes one argument, which it assigns to val[0] while setting the other entries to 0.            set第一个值,其余为0

cvScalarAll() , which takes a single argument but sets all four elements of val[] to that same argument.            全set成同一个值

For all intents andpurposes, an IplImage can be thought of as being derived from CvMat . Therefore, it is best to understand the (would-be) base class before attempting to understand the added complexities of the derived class. A third class, called CvArr , can be thought of as an abstract base class from which CvMat is itself derived. You will oft en see CvArr (or, more accurately, CvArr* ) in function prototypes. When it appears, it is acceptable to pass CvMat* or IplImage* to the routine.

32-bit floats ( CV_32FC1 ),

unsigned integer 8-bit triplets ( CV_8UC3 )

typedef struct CvMat {
int type;
int step;
int* refcount; // for internal use only
union {
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data;
union {
int rows;
int height;
};
union {
int cols;
int width;
};
} CvMat;

cvCreateMatHeader() creates the CvMat structure without allocating memory for the data.
cvCreateData() handles the data allocation.

cvCreateMat()  =  cvCreateMatHeader() + cvCreateData() .

cvCloneMat(CvMat*) creates a new matrix from an existing one.*

cvReleaseMat(CvMat**)  release.

* cvCloneMat() and other OpenCV functions containing the word “clone” not only create a new header that
is identical to the input header, they also allocate a separate data area and copy the data from the source to
the new object.

* For the regular two-dimensional matrices discussed here, dimension zero (0) is always the “width” and dimension one (1) is always the height.

二维矩阵中,维度0通常是宽,维度1通常是高。

矩阵某个位置的元素:the location of any given point is given by the formula:

δ = ( row ) ⋅ N cols ⋅ N channels + ( col ) ⋅ N channels + ( channel)  通道

IplImage header structure

typedef struct _IplImage {
int nSize;
int ID;
int nChannels;
int alphaChannel;
int depth;
char colorModel[];
char channelSeq[];
int dataOrder;
int origin;
int align;
int width;
int height;
struct _IplROI* roi;
struct _IplImage* maskROI;
void* imageId;
struct _IplTileInfo* tileInfo;
int imageSize;
char* imageData;
int widthStep;
int BorderMode[];
int BorderConst[];
char* imageDataOrigin;
} IplImage;

Th e possible values for nChannels are 1, 2, 3, or 4.

origin : IPL_ORIGIN_TL or IPL_ORIGIN_BL (the origin of coordinates being located in either the upper-left or lower-left corners of the image, respectively.)

dataOrder: IPL_DATA_ORDER_PIXEL or IPL_DATA_ORDER_PLANE .(whether the data should be packed with multiple channels one aft er the other for each pixel (interleaved, the usual case), or rather all of the channels clustered into image planes with the planes placed one aft er another.)

ROI:感兴趣的区域

COI:感兴趣的通道 channel of interest

矩阵和图像操作的方法

cvAbs  计算数组中所有元素的绝对值

cvAbsDiff  计算两个数组差值的绝对值

cvXXX      对两个数组作XXX操作

cvXXXS    对数组和一个固定值作XXX操作

cvXXXRS   对固定值和数组作XXX操作(和cvXXXS相反)

void cvCvtColor(

  const CvArr* src,
  CvArr* dst,
  int code
);

code转换方式

RGB555

RGB555是另一种16位的RGB格式,RGB分量都用5位表示(剩下的1位不用)。使用一个字读出一个像素后,这个字的各个位意义如下:
高字节 低字节
X R R R R R G G G G G B B B B B (X表示不用,可以忽略)
可以组合使用屏蔽字和移位操作来得到RGB各分量的值:
#define RGB555_MASK_RED 0x7C00
#define RGB555_MASK_GREEN 0x03E0
#define RGB555_MASK_BLUE 0x001F
R = (wPixel & RGB555_MASK_RED) >> 10; // 取值范围0-31
G = (wPixel & RGB555_MASK_GREEN) >> 5; // 取值范围0-31
B = wPixel & RGB555_MASK_BLUE; // 取值范围0-31
 

RGB565

RGB565使用16位表示一个像素,这16位中的5位用于R,6位用于G,5位用于B。程序中通常使用一个字(WORD,一个字等于两个字节)来操作一个像素。当读出一个像素后,这个字的各个位意义如下:
高字节 低字节
R R R R R G G G G G G B B B B B
可以组合使用屏蔽字和移位操作来得到RGB各分量的值:
#define RGB565_MASK_RED 0xF800
#define RGB565_MASK_GREEN 0x07E0
#define RGB565_MASK_BLUE 0x001F
R = (wPixel & RGB565_MASK_RED) >> 11; // 取值范围0-31
G = (wPixel & RGB565_MASK_GREEN) >> 5; // 取值范围0-63
B = wPixel & RGB565_MASK_BLUE; // 取值范围0-31
#define RGB(r,g,b) (unsigned int)( (r|0x08 << 11) | (g|0x08 << 6) | b|0x08 )
#define RGB(r,g,b) (unsigned int)( (r|0x08 << 10) | (g|0x08 << 5) | b|0x08 )
该代码可以解决24位与16位相互转换的问题

RGB24

RGB24使用24位来表示一个像素,RGB分量都用8位表示,取值范围为0-255。注意在内存中RGB各分量的排列顺序为:BGR BGR BGR…。通常可以使用RGBTRIPLE数据结构来操作一个像素,它的定义为:
typedef struct tagRGBTRIPLE {
  BYTE rgbtBlue; // 蓝色分量
  BYTE rgbtGreen; // 绿色分量
  BYTE rgbtRed; // 红色分量
} RGBTRIPLE;

RGB32

RGB32使用32位来表示一个像素,RGB分量各用去8位,剩下的8位用作Alpha通道或者不用。(ARGB32就是带Alpha通道的RGB24。)注意在内存中RGB各分量的排列顺序为:BGRA BGRA BGRA…。通常可以使用RGBQUAD数据结构来操作一个像素,它的定义为:
typedef struct tagRGBQUAD {
  BYTE rgbBlue; // 蓝色分量
  BYTE rgbGreen; // 绿色分量
  BYTE rgbRed; // 红色分量
  BYTE rgbReserved; // 保留字节(用作Alpha通道或忽略)
} RGBQUAD。
 

HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. Smith在1978年创建的一种颜色空间, 也称六角锥体模型(Hexcone Model)。

这个模型中颜色的参数分别是:色调(H),饱和度(S),亮度(V)。
 
 
 
 
 
画图

最新文章

  1. iOS开发之Runtime机制深入解析
  2. C#导出csv文件 支持中文的解决方案
  3. 设计js通用库
  4. 通过PLSQL Developer导入SQL文件
  5. Android TabHost中实现标签的滚动以及一些TabHost开发的奇怪问题
  6. Android 使用存放在存assets文件夹下的SQLite数据库
  7. 用DOS命令来运行Java代码
  8. iOS UITableView左滑操作功能的实现(iOS8-11)
  9. Chapter 1 Securing Your Server and Network(14):限制功能——xp_cmdshell 和OPENROWSET
  10. [jzoj]3875.【NOIP2014八校联考第4场第2试10.20】星球联盟(alliance)
  11. CodeMirror 在线代码编辑器
  12. 新装的MySQL没有密码怎么办
  13. [转] HTML5中meta属性的使用详解
  14. 在html的JavaScript部分计算,保留小数点后面的位数
  15. Canvas简述
  16. Java NIO使用及原理分析 (四)(转)
  17. jquery easy ui 简单字段选择搜索实现
  18. com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver
  19. cesium编程入门(八)设置材质
  20. js中的问题(this)(遍历对象中的属性)

热门文章

  1. EF-局部更新
  2. vue配置stylus
  3. mobiscroll时间控件
  4. hive 遇到的问题及解决方法
  5. Linux-压缩与解压缩命令
  6. nyoj-1011-So Easy[II] (多边形面积求解)
  7. 机器学习:YOLO for Object Detection (二)
  8. LeetCode Shopping Offers
  9. C#检查网络是否可以连接互联网
  10. LOJ 10189 仓库建设 ——斜率优化dp