gpt4 book ai didi

c++ - 如何将Mat图像转换为vector

转载 作者:行者123 更新时间:2023-11-28 00:13:14 25 4
gpt4 key购买 nike

有什么方法可以将Mat图像转换为 vector 吗?

这行不通:

Mat input = imread("image.png");
vector<Point> points;

points = input;

最佳答案

您可以轻松地手动完成,直接使用垫子的行/列索引创建点:

//Create a blank mat of size 3x3 and an empty point vector
cv::Mat img = cv::Mat::zeros(cv::Size(3, 3), CV_8UC3);
std::vector<cv::Point> points;

//Loop over each pixel and create a point
for (int x = 0; x < img.cols; x++)
for (int y = 0; y < img.rows; y++)
points.push_back(cv::Point(x, y));

//Print out results
for (cv::Point p : points)
std::cout << p << "\n";

enter image description here

但我不明白你为什么需要这样做,因为你已经知道矩阵中的点,因为你可以访问它的大小。

关于c++ - 如何将Mat图像转换为vector<Point>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31944013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com