gpt4 book ai didi

objective-c - 使用 opencv 或其他技术识别出现在图像 ios 四个角上的黑色图案

转载 作者:可可西里 更新时间:2023-11-01 05:42:01 28 4
gpt4 key购买 nike

我遇到了一个问题,即如何识别图像中的某些模式。

图像为纯白色纸张图像,四个角的图案为黑色。我想识别图像上的黑色图案?

我在网上冲浪了很多,发现 opencv 作为答案。但是没有提供任何内容来描述如何使用 opencv 来实现所需的功能。

请帮助我提供一些编码观点或提供一些我应该遵循的链接或我应该用来实现此功能的任何开源库的任何名称。图案图像如下:- enter image description here

图像由纯白色背景和角落的四个黑色图案组成。我需要识别所有四个角中的这些黑色图案,然后对图像进行处理。一个角以椭圆形显示以突出​​显示。

我们将不胜感激任何建议。

提前致谢!

最佳答案

我真的不明白你的问题 - 如果你说:

The image is the image of paper which is pure white and the patterns are in four corners are in black.

那么只屏蔽图像中的这四个轮廓有什么问题呢?用 4 个长度为 40 像素的正方形蒙版后,我得到了这个:

enter image description here

要删除小区域,您可以使用形态学操作。我明白了:

enter image description here

然后将它们(可选)绘制在输入图像上。结果如下:

enter image description here

为了实现这个算法,我使用了 OpenCV 库。我 100% 确定它适用于 IOS - OpenCV 团队终于 published IOS version .所以如果你说:

I tried running the OpenCV-iOS link but the project does not run, it is showing errors.

那我们就帮不了你了,因为我们不是心灵感应者,无法看到你的问题。只是一个小建议 - 尝试用谷歌搜索你的问题。我 99% 确定它应该有所帮助。

以免我忘记 - 这是 C++ 代码:

Mat src = imread("input.png"), tmp;

//convert image to 1bit
cvtColor(src, tmp, CV_BGR2GRAY);
threshold(tmp, tmp, 200, 255, THRESH_OTSU);

//do masking
#define DELTA 40
for (size_t i=0; i<tmp.rows; i++)
{
for (size_t j=0; j<tmp.cols; j++)
{
if(!((i < DELTA && j < DELTA)
|| (i < DELTA && j > tmp.cols - DELTA)
|| (i > tmp.rows - DELTA && j < DELTA)
|| (i > tmp.rows - DELTA && j > tmp.cols - DELTA)))
{
//set color to black
tmp.at<uchar>(i, j) = 255;
}
}
}

bitwise_not(tmp,tmp);

//erosion and dilatation:
Mat element = getStructuringElement(MORPH_RECT, Size(2, 2), Point(1, 1));

erode(tmp, tmp, element);
dilate(tmp, tmp, element);

//(Optional) find contours and draw them:
vector<Vec4i> hierarchy;
vector<vector<Point2i> > contours;

findContours(tmp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

for (size_t i=0; i<contours.size(); i++)
{
drawContours(src, contours, i, Scalar(0, 0, 255), 1);
}

关于objective-c - 使用 opencv 或其他技术识别出现在图像 ios 四个角上的黑色图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11913911/

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