我在C++中使用opencv,我有一个对象的二进制图像(图像1)。因为我使用Zhang-Suen算法(图2)获得了对象的骨架,并且在顶部,左侧和右侧添加了像素,因此我们需要在顶部,左侧,右侧和下部添加像素(图像3)正确,然后我修复了图像2中可见的错误,我如何在边缘上添加5个像素?如何使用opencv在图像上添加边缘?
我想转换到此搜索的Image3。
我在C++中使用opencv,我有一个对象的二进制图像(图像1)。因为我使用Zhang-Suen算法(图2)获得了对象的骨架,并且在顶部,左侧和右侧添加了像素,因此我们需要在顶部,左侧,右侧和下部添加像素(图像3)正确,然后我修复了图像2中可见的错误,我如何在边缘上添加5个像素?如何使用opencv在图像上添加边缘?
我想转换到此搜索的Image3。
输入图像:
// 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);
输出图像:
这种技术已先前described here一直。
只是完美的解决方案! – user3779874
使用以下方法可以轻松获得相同的输出。
void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar& value=Scalar())
的示例性实现可以OpenCV的文档here
我不使用下,在下蟒找到++但是,在OpenCV中,该图像是只是数字的阵列。添加边框与向数组添加行或列是一回事。它使用正常的数组操作完成。很可能,在C++下的OpenCV的行为是相似的。 – John1024