OPENCV Basic data types

Source: Internet
Author: User


OpenCV provides a variety of basic data types. Although these data types are not basic in the C language, they are simple in structure and can be used as atomic types. You can view its detailed definition in the Cxtypes.h file under the ".../opencv/cxcore/include" directory.



The simplest of the data types is cvpoint. Cvpoint is a simple struct that contains integer type members x and Y. Cvpoint has two variant types: cvpoint2d32f and cvpoint3d32f. The former also has two members, X, Y, but they are floating-point types, while the latter is a member of the floating-point type Z.



The cvsize type is very similar to Cvpoint, but its data member is the width and height of the integer type. If you want to use floating-point types, choose Cvsize Variant type cvsize2d32f.



The Cvrect type is derived from Cvpoint and Cvsize, which contains 4 data members: X,y,width and height. (As you might think, the type is a composite type).



The next (but not the last) is a cvscalar type that contains 4 integral members, and when memory is not a problem, cvscalar is often used in place of the 3 real members (in this case, the unwanted components are ignored). The Cvscalar has a separate member Val, which is a pointer to 4 double-precision floating-point array.



All of these data types have constructors defined with their names, such as Cvsize (). (constructors usually have the same name as the struct type, except that the initial letter is not very written). Remember, this is C and not C + +, so these constructors are just inline functions that first fetch the parameter list and then return the structure that is assigned the relevant value.



Inline constructors for each data type are listed in the following table: Cvpoint (), Cvsize (), Cvrect (), and Cvscalar (). These structures are useful because they not only make the code easier to write, but are also easier to read. Suppose you want to draw a white rectangle between (5,10) and (20,30), simply call:



Cvrectangle (



Myimg,



Cvpoint (5,10),



Cvpoint (20,30),



Cvscalar (255,255,255)



);



Table 3-1:points, size, rectangles and calar structure of ternary group


td>

Cvpoint

Structure

Member

Meaning

int x, y

Point in image

Cvpoint2d 32f

Float x, y

A point in two-dimensional space

cvpoint3d32f

Float x, y, z

Points in three-dimensional space

Cvsize

int width, height

Image size

Cvrect

int x, y, width, height

Partial area of image

Cvscalar

Double val[4]

RGBA value


Cvscalar is a special example: it has 3 constructors. The first is Cvscalar (), which requires one, two, three, or four parameters and passes these parameters to the corresponding element in the array val[]. The second constructor is Cvrealscalar (), which requires a parameter, which is passed to val[0], and the value of the val[group is assigned to 0. The last Change is Cvscalarall (), which requires a parameter and the 4 elements in val[] will be set to this parameter.

  matrix and image types



The following figure shows a class or structure hierarchy of three images. When using OPENCV, the Iplimage data type is frequently encountered, and iplimage is the basic structure that we use to encode what is commonly referred to as "images". These images may be grayscale, color, 4-channel (Rgb+alpha), where each channel can contain any integer or floating-point number. Therefore, this type is more common than common, easy-to-understand 3-Channel 8-bit RGB images.



OPENCV provides a number of useful image operators, including scaling images, single channel extraction, to find the maximum minimum value of a specific channel, two image summation, image threshold operation, and so on.



Figure 3-1: Although OpenCV is implemented by the C language, the structure it uses is also designed to follow object-oriented thinking. In fact, Iplimage is derived from Cvmat, and Cvmat is derived from Cvarr



Before we start exploring the details of the image, we need to understand the matrix structure of the other data type CVMAT,OPENCV. Although OPENCV is implemented entirely by the C language, the relationship between Cvmat and Iplimage is like an inheritance relationship in C + +. In essence, iplimage can be considered derived from the Cvmat. Therefore, before trying to understand complex derived classes, it is a good idea to understand the basic classes first. The third class, Cvarr, can be considered an abstract base class, Cvmat derived from it. In a function prototype, you will often see Cvarr (more precisely, cvarr*), and when it appears, you can pass cvmat* or iplimage* to the program. 

Cvmat Matrix Structure



Before we start learning about the matrix, we need to know two things. First, there is no vector structure in OPENCV. Any time you need a vector, you need only one column matrix (a row matrix if you need one transpose or conjugate vector). Second, the concept of the OpenCV matrix is more abstract than the concept of our learning in the linear algebra class, especially the elements of matrices, not only the simple numeric types. For example, a routine for creating a new two-dimensional matrix has the following prototype:



cvmat* cvcreatemat (int rows, int cols, int type);



Here type can be any predefined type, the structure of the predefined type is as follows:cv_<bit_depth> (s| u| F) c<number_of_channels>. Thus, the elements of the matrix can be 32-bit floating-point data (CV_32FC1), or an unsigned 8-bit ternary array of integer data (CV_8UC3), or an infinite number of other types of elements. A CVMAT element is not necessarily a single number. Multiple values can be represented in a matrix by a single (simple) input, so that we can depict multiple color channels on a three-color image. For a simple image that contains an RGB channel, most image operations will be applied to each channel individually (unless otherwise noted). 

iplimage Data Structure



Essentially, it is a Cvmat object, but it has other member variables that interpret the matrix as an image. This structure was originally defined as part of the Intel Image Processing Library (IPL). The exact definition of the IPLIMAGE structure is shown in example 3-10.



Example 3-10:iplimage 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;



We tried to discuss some of the functions of these variables. Some variables are not important, but some variables are important to help us understand how OPENCV interprets and processes images.


The two variables

Width and height are important, followed by depth and nchannals. The value of the depth variable is taken from a set of data defined in Ipl.h, but differs from the corresponding variable seen in the matrix. Because in the image, we tend to separate the depth and the number of channels, and in the matrix, we tend to represent them at the same time. The available depth values are shown in table 3-2.                                                                                                       table 3-2:OPENCV Image type


Macro

Image pixel Type

ipl_depth_8u

Unsigned 8-bit integer (8u)

Ipl_depth_8s

Signed 8-bit integer (8s)

Ipl_depth_16s

Signed 16-bit integer (16s)

Ipl_depth_32s

Signed 32-bit integer (32s)

ipl_depth_32f

32-bit floating point single precision (32f)

ipl_depth_64f

64-bit floating point double precision (64f)


Number of channels nchannels the desirable value is 4.



The next two important members are Origin and Dataorder. The origin variable can have two values: Ipl_origin_tl or IPL_ORIGIN_BL, setting the origin of the coordinates to the upper-left or lower-left corner of the image, respectively. In the field of computer vision, an important source of error is that the definition of Origin location is not uniform. In particular, the source of the image, operating system, codec and storage format and other factors can affect the selection of the origin of the image coordinates. For example, you might think you're taking a sample from the face near the image, but you're actually sampling it near the skirt below the image. The best way to avoid this kind of phenomenon is to check the system at the very beginning and try to draw something in the area of the image block you are manipulating.



The value of Dataorder can be either Ipl_data_order_pixel or Ipl_data_order_plane, which indicates that the data is staggered together (this is a common staggered arrangement) of the values of the different channels of the pixel points, which are the same as the channel values of all pixels. , forming the channel plane, and then arranging the plane together.



The parameter widthstep is similar to the step parameter in the Cvmat discussed earlier, including the number of bytes between the same column points of adjacent rows. This value cannot be computed with variable width alone, because each row is aligned with a fixed number of bytes in order to process more efficiently, so it may be somewhat redundant at the beginning of line I and i+1. The parameter imagedata contains a pointer to the first row of image data. If there are separate planes in the image (such as when dataorder = Ipl_data_order_plane), they are placed continuously as separate images, with the total number of rows being the product of height and nchannels. Typically, however, they are interleaved, making the number of rows equal to the height, and each row contains an orderly interleaved channel.



Finally, there is a practical and important parameter-the area of interest (ROI), which is actually an example of another IPL/IPP structure Iplroi. The Iplroi contains xoffset,yoffset,height,width and COI member variables, where COI represents channel of interest (channels of interest). The idea of ROI is that once the ROI is set, the function that normally acts on the entire image will only manipulate the sub-image represented by the ROI. If the ROI is set in the Iplimage variable, the ROI variable is used by all OPENCV functions. If the COI is set to a value other than 0, the operation on the image is only used on the specified channel. Unfortunately, many OPENCV functions ignore parameter COI.









Transferred from: http://blog.csdn.net/xiazhaoqiang/article/details/6254547


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.