zoukankan      html  css  js  c++  java
  • OpenCV笔记 1

    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;                        
    View Code

    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[4];
    char channelSeq[4];
    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[4];
    int BorderConst[4];
    char* imageDataOrigin;
    } IplImage;
    View Code

    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)。
     
     
     
     
     
    画图
  • 相关阅读:
    【POJ3069】Saruman's Army
    【POJ2453】An Easy Problem
    【POJ2386】Lake Counting
    【POJ2251】Dungeon Master
    【POJ1664】放苹果
    【基础】枚举学习笔记
    算法时空复杂度【OI缩水版】
    【POJ2018】Best Cow Fences
    【POJ3889】Fractal Streets(分形图)
    【BZOJ2296】随机种子(构造)
  • 原文地址:https://www.cnblogs.com/maxiaodoubao/p/4603029.html
Copyright © 2011-2022 走看看