Algorithm参数记录

一、vector<Point2f>

vector是一个存储二维点坐标的容器,其中每个元素都是一个Point2f类型的对象。在OpenCV中,Point2f表示一个由两个单精度浮点数构成的二维点坐标。

你可以使用vector来存储一些二维坐标信息,比如图像中的关键点或轮廓点等。具体用法可以参考下面的示例:

#include <opencv2/core.hpp>
#include <vector>

using namespace cv;
using namespace std;

int main()
{
    vector<Point2f> pointList;
    // 添加几个二维点到容器中
    pointList.push_back(Point2f(10, 20));
    pointList.push_back(Point2f(30, 40));
    pointList.push_back(Point2f(50, 60));
    // 遍历容器中的所有点
    for (int i = 0; i < pointList.size(); i++)
    {
        // 输出每个点的坐标值
        Point2f pt = pointList[i];
        cout << "Point " << i + 1 << ": (" << pt.x << ", " << pt.y << ")" << endl;
    }
    return 0;
}

在上述示例中,定义了一个存储二维点坐标的vector对象pointList,并向其中添加了三个二维点坐标。然后通过遍历容器中的每个元素,输出每个点的坐标值。

二、Rect2i

可以通过以下示例代码来创建和操作一个Rect2i对象:

#include <opencv2/core.hpp>
#include <iostream>

int main()
{
    cv::Rect2i rect(10, 20, 100, 50);    // 创建一个矩形,左上角坐标为(10, 20),宽为100,高为50
    std::cout << "rect: (" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ")" << std::endl;

    cv::Point2i pt = rect.tl();     // 获取矩形左上角点
    std::cout << "top left: (" << pt.x << ", " << pt.y << ")" << std::endl;

    return 0;
}

在上述示例中,定义了一个Rect2i类对象rect,表示一个左上角坐标为(10, 20),宽为100,高为50的矩形,并获取了矩形左上角点的坐标并输出。

posted @ 2023-04-07 08:50  share0956  阅读(35)  评论(0编辑  收藏  举报