vector azaie.push_back
时间: 2024-06-15 17:03:09 浏览: 148
vector的push_back函数是用于向vector容器中添加元素的方法。在这个例子中,azaie是一个vector对象,通过调用push_back函数,可以将一个元素添加到azaie的末尾。
例如,如果我们有一个空的azaie vector,可以使用push_back函数将元素添加到其中:
azaie.push_back(10);
这将在azaie的末尾添加一个值为10的元素。如果azaie之前已经包含了其他元素,新的元素将被添加到已有元素的后面。
相关问题
//显示结果 imshow("轮廓绘制结果", edge); vector<Point2f>point_0; vector<Point2f>point_1; vector<Point2f>point_2; vector<Point2f>point_3; vector<Point2f>point_4; vector<Point2f>point_5; vector<Point2f>point_6; vector<Point2f>point_7; vector<Point2f>point_8; vector<Point2f>point_9; vector<Point2f>point_10; vector<Point2f>point_11; vector<Point2f>point_12; vector<Point2f>point_13; vector<Point2f>point_14; vector<Point2f>point_15; vector<Point2f>point_16; vector<Point2f>point_17; vector<Point2f>point_18; vector<Point2f>point_19; int m, n; for (m = 0; m < contours.size(); m++) { for (n = 0; n < contours[m].size(); n++) { switch (m) { case 0: point_0.push_back(contours[m][n]); break; case 1: point_1.push_back(contours[m][n]); break; case 2: point_2.push_back(contours[m][n]); break; case 3: point_3.push_back(contours[m][n]); break; case 4: point_4.push_back(contours[m][n]); break; case 5: point_5.push_back(contours[m][n]); break; case 6: point_6.push_back(contours[m][n]); break; case 7: point_7.push_back(contours[m][n]); break; case 8: point_8.push_back(contours[m][n]); break; case 9: point_9.push_back(contours[m][n]); break; case 10: point_10.push_back(contours[m][n]); break; case 11: point_11.push_back(contours[m][n]); break; case 12: point_12.push_back(contours[m][n]); break; case 13: point_13.push_back(contours[m][n]); break; case 14: point_14.push_back(contours[m][n]); break; case 15: point_15.push_back(contours[m][n]); break; case 16: point_16.push_back(contours[m][n]); break; case 17: point_17.push_back(contours[m][n]); break; case 18: point_18.push_back(contours[m][n]); break; case 19: point_19.push_back(contours[m][n]); break; default: cout << "input error" << endl; } } } Mat img(321, 432, CV_8UC1, cv::Scalar(0));
这段代码创建了一个大小为321x432的单通道图像img,并将所有像素值初始化为0。在之前的代码中,找到了一些轮廓(contours),然后将每个轮廓的所有点按照其所在的轮廓编号(m)分别存储到了对应的vector<Point2f>中。现在,这段代码的作用是根据这些点的坐标信息,在img图像上绘制出对应的轮廓线条。具体的绘制方法可以通过OpenCV的绘图函数实现,例如cv::line()和cv::polylines()等。
omp vector.push_back()
vector.push_back() is a member function of the C++ STL vector class that adds a new element at the end of the vector. The syntax for using this function is as follows:
vector.push_back(element);
Here, the "element" parameter is the value that needs to be added to the vector. The function increases the size of the vector by one and adds the element at the end.
For example, consider the following code snippet:
vector<int> v;
v.push_back(10);
v.push_back(20);
v.push_back(30);
for(int i=0; i<v.size(); i++) {
cout << v[i] << " ";
}
Output:
10 20 30
In this example, we create an empty vector "v" and then use the push_back() function to add three integers to the vector. Finally, we use a for loop to print the contents of the vector.
阅读全文