OPencv study eleven - a little summary (programming mistakes, data types, common classes)

tiny error:

1. Do not misuse identifiers as variables (eg: threshold)

2. The window name of the displayed image and the name of the tracking bar should be in English as much as possible. The lower version is not compatible with Chinese (compatible with 2.4 and above).


type of data

Please refer to: https://blog.csdn.net/u010368556/article/details/79179669

 vector: 

<1> Explanation:The container, which can store various types of objects, is a dynamic array that stores various types of data;
         Note: If the length of the vector to be represented is long (a lot of numbers need to be stored inside the vector), it is easy to Causes memory leaks, and the efficiency will be very low;

<2> method:
        vector<Point2f> ---- used to store data of type float, here is a two-dimensional point vector, you can also replace Point2f with other types such as int;
        vector <Point2i> ---- used to store data of type int;
        vector<Point2d> ---- used to store data of type double;
        vector<vector<Point2f>> points;---- means to define a two-dimensional array ,
                where points[0].size() represents the number of columns in the first row;

<3>Basically know:
 (1) Header file #include<vector>;
 (2) Create a vector object, vector<int> vec;
 (3) Insert numbers at the end: vec.push_back(a);
 (4) Use subscripts to access elements, cout<<vec[0]<<endl; remember that subscripts start from 0.
 (5) Use an iterator to access elements:
  vector<int>::iterator it;
   for(it=vec.begin();it!=vec.end();it++)
        cout<<*it<<endl;
 (6) Insert elements: vec.insert(vec.begin()+i,a); insert a before the i+1th element;
 (7) Delete elements:    
    vec.erase(vec.begin()+2); delete the third element
    vec.erase(vec.begin()+i,vec.end()+j); delete interval [i,j-1]; interval starts from 0
 (8) Vector size: vec.size();
 (9) Clear: vec.clear();
 (10) The begin() and end() functions indicate the beginning of the first and the last;

       front() and back() mean starting from the front and starting from the back;

<4> Simple usage:
        (1) vecor<int> data; indicates that a vector array is created, int is the data type of the array element, and data is the dynamic array name;
        (2) data.push_back(m); stored in data The input data m, m can be a single number, an array: such as (2,3), a pointer, an address, etc., and it is stored from data[0], and then stored in sequence.
           For example: data.push_back(23);data.push_back( 45); ------Then: data[0]=23;data[1]=45;
        (3)data.pop_back(m); Efficiently remove the last data in the vector in data, m can be For single numbers, arrays: such as (2,3), pointers, addresses, structures, etc., and remove from the last one, and remove them in turn;
        (4) When Vector is used as a parameter or return value of a function, you need to pay attention to the "&" must not be missing:  
            double Distance(vector<int>&a, vector<int>&b) ! ! !

<5> Complex usage: (Note: Header file #include<algorithm> is required)
        (1) reverse---- flip the element;
             reverse(vec.begin(),vec.end()); flip the element, that is Reverse order!
        (2)sort----sort;
             sort(vec.begin(), vec.end()); (the default is to sort in ascending order, that is, from small to large).  
             可以通过重写排序比较函数按照降序比较,如下:         
             bool Comp(const int &a,const int &b)//定义排序比较函数:
{return a>b;}
            调用时:sort(vec.begin(),vec.end(),Comp),这样就降序排序。 
       (3)insert()----插入;函数有以下三种用法: 
                 a.在指定位置loc前插入值为val的元素,返回指向这个元素的迭代器
       b.在指定位置loc前插入num个值为val的元素 
                 c.在指定位置loc前插入区间[start, end)的所有元素 

        (4)Vector中元素的输入输出 :http://blog.csdn.net/duan19920101/article/details/50617190

 

Matx类和Vec类:https://blog.csdn.net/qq_37871032/article/details/69487334


绘图

参考:https://blog.csdn.net/ubunfans/article/details/24421981


数据处理(浮点型转换为整型

参考:https://blog.csdn.net/u013829933/article/details/50471227

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324847390&siteId=291194637