C++ 如何将坐标数组推广到像素宽的直线

C++ 如何将坐标数组推广到像素宽的直线,c++,graphics,C++,Graphics,我所说的标题的意思是,我有一个结构的std::vector,称为Coord: struct Coord { int x; int y; }; 它包含图像上特定颜色的像素坐标。这里它们是蓝色的(不要介意红色的线条和文本) 我想从那个数组中删除像素,这样我们就只剩下前面像素集中的像素宽的行了。在这张照片上,它看起来像这样(我可怕的素描): 以下是我查找像素的函数: std::vector<Coord> findPathIn(const std::vector<

我所说的标题的意思是,我有一个结构的
std::vector
,称为Coord:

struct Coord
{
    int x;
    int y;
};
它包含图像上特定颜色的像素坐标。这里它们是蓝色的(不要介意红色的线条和文本)

<>我想从那个数组中删除像素,这样我们就只剩下前面像素集中的像素宽的行了。在这张照片上,它看起来像这样(我可怕的素描):


以下是我查找像素的函数:

std::vector<Coord> findPathIn(const std::vector< std::vector<Color> >& image, const Color& pathColor, double threshold)
{
    int maxError = ceil(threshold * 255.0);

    std::vector<Coord> path;

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            auto& current = image[x][y];
            if (abs(pathColor - current) <= maxError)
                path.push_back({ x, y });
        }
    }

    return path;
}
为了找到这幅图像中的路径,我使用了
findPathIn(image,{0,0,0},0.48)
其中image是一个2d颜色向量。我正在使用机顶盒库读写图像


提前感谢。

什么不起作用,或者问题是什么?@acraig5075我的问题是如何做(删除像素,这样我们就剩下线条)。我已经在上面坐了几天了,但我想不出一个算法。我想你在寻找一个“骨架化”算法。您可以使用ImageMagick从命令行轻松完成此操作。。。另请参见此处的
中轴线
。。。另一个答案是使用OpenCV的
findContours()
struct Color
{
private:
    friend int operator - (const Color& a, const Color& b);

public:
    int red;
    int green;
    int blue;
};

int operator - (const Color& a, const Color& b)
{
    int sum = 0;
    sum += a.red - b.red;
    sum += a.green - b.green;
    sum += a.blue - b.blue;

    int avg = int(sum / 3);

    return avg;
}