Simplecv和openkinect blob检测问题

时间:2014-02-05 04:38:25

标签: python robotics simplecv openkinect

我目前正在上高中的机器人团队,我的目标是使用我们的kinect通过使用simplecv和openkinect来检测今年游戏中的球。我目前陷入一个问题,我的导师和我似乎无法解决。代码所做的是它需要来自kinect的实时深度地图输入并对其进行二值化,一旦完成,它就会查找blob并尝试查找圆形blob。最后,它在圆形斑点上绘制一个圆圈。问题是代码能够找到blob没问题,但它无法找到循环的。我走到了尽头,我希望社区中的某个人能够帮助我。谢谢,这是代码和所见内容的图像

from SimpleCV import *
cam = Kinect()
display = SimpleCV.Display()
while display.isNotDone():
    depth = cam.getDepth().flipHorizontal()
    img2 = cam.getImage().flipHorizontal()

    filtered = depth.stretch(200,255)
    segmented = filtered.binarize(200)
    blobs = segmented.findBlobs()
    if blobs:
        circles = blobs.filter([b.isCircle() for b in blobs])
        if circles:
            img2.drawCircle((circles[-1].x, circles[-1].y), circles[-1].radius(),SimpleCV.Color.RED,3)
            img2.drawText("FOUND A BALL", 50,50,color=Color.RED,fontsize=48)

    img2.sideBySide(segmented).show()

enter image description here

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,这里是新版本的代码。对不起,这次没有屏幕上限。

import SimpleCV
from SimpleCV import *
display = SimpleCV.Display()
cam = Kinect()
normaldisplay = True

while display.isNotDone():

    if display.mouseRight:
        normaldisplay = not(normaldisplay)
        print "Display Mode:", "Normal" if normaldisplay else "Segmented" 

    img = cam.getDepth().flipHorizontal()
    img2 = cam.getImage().flipHorizontal()
    dist = img.colorDistance(SimpleCV.Color.BLACK).dilate(2)
    segmented = dist.stretch(200,255)
    binar = segmented.binarize(200)
    erode = binar.erode(2)
    blobs = erode.findBlobs()
    if blobs:
        circles = blobs.filter([b.isCircle(0.2) for b in blobs])
        if circles:
            img.drawCircle((circles[-1].x, circles[-1].y), circles[-1].radius(),SimpleCV.Color.BLUE,3)

    if normaldisplay:
        img.show()

    else:
        segmented.show()