简体   繁体   English

我如何找到兔子?

[英]How do I locate the rabbit?

I am trying to follow the rabbit in the game winterbells. 我试图在游戏winterbells中跟随兔子。 Here are some screenshots 这是一些截图 兔子兔子兔子

Originally I thought that I could follow a color that only the rabbit had, but it seems that all the objects (ie the bells and dove) have the same colors. 最初我以为我可以按照只有兔子的颜色,但似乎所有的物体(即铃铛和鸽子)都有相同的颜色。 I can detect all the objects by just searching for white (see results) 我可以通过搜索白色来检测所有对象(参见结果) 结果

but I can't figure out how to find the rabbit. 但我无法弄清楚如何找到兔子。 Would I have to use opencv? 我必须使用opencv吗? The only module I've used is pil to detect the colors of the pixels. 我用过的唯一模块就是检测像素的颜色。 It seems like an easy task but I just don't see how I can do it. 这似乎是一项简单的任务,但我不知道如何做到这一点。

The simplest way would be to just classify the shapes by area. 最简单的方法是按区域对形状进行分类。 Here's one solution with SimpleCV: 这是SimpleCV的一个解决方案:

>>> from SimpleCV import *
>>> image = Image('image.png')
>>> binarized = image.binarize(220).invert()
>>> binarized.show()

在此输入图像描述

Now, this is much easier to work with. 现在,这更容易使用。 You can use simple blob detection to filter out the bells and the bird: 您可以使用简单的斑点检测来过滤掉铃铛和鸟类:

>>> blobs = binarized.findBlobs()
>>> for blob in blobs:
...    blob.draw()
...    print blob
...    binarized.show()
...    raw_input()

After pressing Enter 50 times and looking at the areas of the blobs, you'll notice that the bells have an area between 630 and 660. The bird has an area of 540 and the rabbit has an area of about 750. 按下Enter键 50次并观察斑点的区域后,你会发现铃铛的面积在630到660之间。这只鸟的面积为540,兔子的面积约为750。

Now, it's just a matter of filtering out the blobs you don't want: 现在,只需要过滤掉你不想要的blob:

>>> rabbit = next(b for b in blobs if abs(750 - b.area()) < 60)
>>> rabbit.draw()
>>> binarized.show()
>>> rabbit
    SimpleCV.Features.Blob.Blob object at (381, 445) with area 754

在此输入图像描述

There's your rabbit. 有你的兔子。

So to wrap things up, your script would look like: 所以为了包装起来,你的脚本看起来像:

from SimpleCV import *

image = Image('image.png')
binarized = image.binarize(220).invert()
blobs = binarized.findBlobs()
rabbit = next(b for b in blobs if abs(750 - b.area()) < 60)

print rabbit.coordinates()

i think, you can try to use svm to classify rabbit and bell. 我想,你可以尝试用svm来分类兔子和铃铛。 First, you can detect all objects, and then classify them with svm. 首先,您可以检测所有对象,然后使用svm对它们进行分类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM