Question

I am currently on a robotics team for my high school and my objective is to use our kinect to detect the balls in this year's game by using simplecv and openkinect. I am currently stuck on an issue that my mentors and I cannot seem to resolve. What the code does is it takes a live-depth map feed from the kinect and binarizes it, once it has done that it looks for blobs and tries to find the circular blobs. Finally it draws a circle over the circular blob. The issue is the code is able to find blobs no problem, but it's not able to find the circular ones. I am at a dead end and am hoping someone in the community will be able to please help me. Thank you, here's the code and an image of what is seen

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

Was it helpful?

Solution

I have solved the problem, here is the new version of the code that works. Sorry, no screen cap this time.

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top