如何使用opencv在图像上添加边缘?

时间:2014-07-02 20:35:19

标签: c++ opencv image-processing

我在c ++中使用opencv,我有一个带有一个对象的二进制图像(图像1)。

我想在图像的上,左,右和下添加像素(图像3),因为我使用Zhang-Suen算法(图像2)获取对象的骨架,并在顶部,左侧,右侧添加像素,然后我修复了图像2中可见的错误,如何在边缘添加5 px?

imagen

我想将image1转换为image3。

2 个答案:

答案 0 :(得分:2)

输入图片:

enter image description here

// Load input image
cv::Mat input = cv::imread("zero.png");
if (input.empty())
{
    std::cout << "!!! Failed imread\n";
    return -1;
}

// Create a larger output image to store the end result
cv::Mat output(input.rows+10, input.cols+10, input.type(), cv::Scalar(0));

// Specify the size of the copy and its offset 
cv::Rect offset_rect = cv::Rect(5, 5, input.cols, input.rows);

// Copy to the output Mat
input.copyTo(output(offset_rect));

//cv::imwrite("output.png", output);

输出图片:

enter image description here

此技术之前已described here

答案 1 :(得分:2)

使用以下方法可以轻松获得相同的输出。

void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int     right, int borderType, const Scalar& value=Scalar() )

可以在opencv文档here

中找到示例实现
相关问题