我如何找到兔子?

时间:2022-07-03 00:24:34

I am trying to follow the rabbit in the game winterbells. Here are some screenshots我如何找到兔子?我如何找到兔子?我如何找到兔子?

我试图在游戏winterbells中跟随兔子。这是一些截图

Originally I thought that I could follow a color that only the rabbit had, but it seems that all the objects (i.e. 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? 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.

但我无法弄清楚如何找到兔子。我必须使用opencv吗?我用过的唯一模块就是检测像素的颜色。这似乎是一项简单的任务,但我不知道如何做到这一点。

2 个解决方案

#1


14  

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()

#2


0  

i think, you can try to use svm to classify rabbit and bell. First, you can detect all objects, and then classify them with svm.

我想,你可以尝试使用svm来分类兔子和铃铛。首先,您可以检测所有对象,然后使用svm对它们进行分类。

#1


14  

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()

#2


0  

i think, you can try to use svm to classify rabbit and bell. First, you can detect all objects, and then classify them with svm.

我想,你可以尝试使用svm来分类兔子和铃铛。首先,您可以检测所有对象,然后使用svm对它们进行分类。