【发布时间】:2023-03-21 22:35:01
【问题描述】:
我正在尝试使用 C++ 语言中的 openCV 从图像上的线条中提取点。线被编程显示在图像上,但我需要知道如何从线中提取点并将其输入到文本文件中?
【问题讨论】:
-
是要检测线,还是知道线在哪里?
-
你真的应该澄清你的问题。输入是什么?里面有线条的图片?您所说的“线被编程为在图像上显示”是什么意思?
我正在尝试使用 C++ 语言中的 openCV 从图像上的线条中提取点。线被编程显示在图像上,但我需要知道如何从线中提取点并将其输入到文本文件中?
【问题讨论】:
您可以使用cv::LineIterator 类获取光栅线的每个点,例如:
// grabs pixels along the line (pt1, pt2)
// from 8-bit 3-channel image to the buffer
LineIterator it(img, pt1, pt2, 8);
LineIterator it2 = it;
vector<Vec3b> buf(it.count);
for(int i = 0; i < it.count; i++, ++it)
buf[i] = *(const Vec3b)*it;
// alternative way of iterating through the line
for(int i = 0; i < it2.count; i++, ++it2)
{
Vec3b val = img.at<Vec3b>(it2.pos());
CV_Assert(buf[i] == val);
}
【讨论】: