目标C——检测“路径”在地图图像内绘图

发布于 2024-11-18 09:33:12 字数 438 浏览 5 评论 0原文

我有一张物理地图(现实世界),例如一张小镇地图。 地图上画了一条“路径”线,想象一下“你在这里。这是到达火车站的方法”:) 现在,假设我可以获得该场景的图像(同样,来自照片)。 图像如下:

地图路径示例

我的目标并不容易!

我想获取图像的路径,即分离两层。

有没有办法从图像中提取那些红色标记?

也许使用 CoreGraphics?也许是外部图书馆? 这不是 Objective C 特定的问题,但我正在 Apple iOS 上工作。

我已经研究过类似的东西,即面部识别。 现在我期望的答案是:“你所说的 PATH 是什么意思?” 好吧,我真的不知道,也许是一条与背景中的“主要”颜色完全不同颜色的线(见上图)。 我们来谈谈吧。

I have a physical map (real world), for example, a little town map.
A "path" line is painted over the map, think about it like "you are here. here's how to reach the train station" :)
Now, let's suppose I can get an image of that scenario (likewise, coming from a photo).
An image that looks like:

Map path example

My goal is not easy way out!

I want to GET the path OUT of the image, i.e., separate the two layers.

Is there a way to extract those red marks from the image?

Maybe using CoreGraphics? Maybe an external library?
It's not an objective C specific question, but I am working on Apple iOS.

I already worked with something similar, the face-recognition.
Now the answer I expect is: "What do you mean by PATH?"
Well, I really don't know, maybe a line (see above image) of a completely different color from the 'major' colors in the background.
Let's talk about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请持续率性 2024-11-25 09:33:12

如果你会使用OpenCV那就变得更简单了。这是一个通用方法:

  1. 将图像分为色调、饱和度和变化(HSV 颜色空间)

    这是 OpenCV 代码:

    // 计算HSV图像并分离成颜色
    IplImage* hsv = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );

    cvCvtColor(img, hsv, CV_BGR2HSV);

    IplImage* h_plane = cvCreateImage( cvGetSize( img ), 8, 1 );

    IplImage* s_plane = cvCreateImage( cvGetSize( img ), 8, 1 );

    IplImage* v_plane = cvCreateImage( cvGetSize( img ), 8, 1 );

    cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );

  2. 仅处理色调 (h_plane) 图像,因为它只提供色调,而相同颜色的较浅或较暗阴影的值没有任何变化

  3. 检查哪些像素具有红色色调(我认为 HSV 的红色为 0 度,但请检查 OpenCV 值)

  4. 将这些像素复制到单独的图像中

我强烈建议如果可能的话使用 OpenCV 库,它基本上是为此类而设计的任务。

If you can use OpenCV then it becomes simpler. Here's a general method:

  1. Separate the image into Hue, Saturation and Variation (HSV colorspace)

    Here's the OpenCV code:

    // Compute HSV image and separate into colors
    IplImage* hsv = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );

    cvCvtColor( img, hsv, CV_BGR2HSV );

    IplImage* h_plane = cvCreateImage( cvGetSize( img ), 8, 1 );

    IplImage* s_plane = cvCreateImage( cvGetSize( img ), 8, 1 );

    IplImage* v_plane = cvCreateImage( cvGetSize( img ), 8, 1 );

    cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );

  2. Deal with the Hue (h_plane) image only as it gives just the hue without any change in value for a lighter or darker shade of the same color

  3. Check which pixels have Red hue (i think red is 0 degree for HSV, but please check the OpenCV values)

  4. Copy these pixels into a separate image

I's strongly suggest using the OpenCV library if possible, which is basically made for such tasks.

む无字情书 2024-11-25 09:33:12

您可以过滤颜色,定义红色的阈值,然后将其他所有内容过滤为 alpha,然后您剩下的“路径”是什么?

You could filter the color, define a threshold for what the color red is, then filter everything else to alpha, and you have left over what your "path" is?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文