Ask Your Question

Looking for just square blobs

asked 2013-03-13 02:48:30 -0500

decrot gravatar image

is it possible to create a list of blobs that are just square? I tried playing around with isSquare to no avail. I wanted something similar to

squareblobs = img.findBlobs().isSquare()

obviously this doesn't work, but its the general idea, I am only interested in square blobs.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-03-13 10:10:40 -0500

kscottz gravatar image

Actually it does work. Twiddle the tolerances to get the results you would like. FeatureSets and python lists are interchangeable, so you can use list comprehension to filter them.

SimpleCV:30> squares = Image('./squares.png')
SimpleCV:31> blobs = squares.findBlobs()
SimpleCV:32> blobs.draw(width=-1)
SimpleCV:33> test = [b for b in blobs if b.isSquare(0.1,0.1)]
SimpleCV:34> test = FeatureSet([b for b in blobs if b.isSquare(0.1,0.1)])
SimpleCV:36> test.draw(color=Color.RED,width=-1)
SimpleCV:37: <SimpleCV.Display Object resolution:((640, 480)), Image Resolution: (640, 480) at memory location: (0x107048710)>
SimpleCV:38> squares.applyLayers().save('squaresout.png')

Here are the results

edit flag offensive delete link more

answered 2013-03-13 13:02:38 -0500

decrot gravatar image

updated 2013-03-13 14:00:42 -0500

I dunno why I can't reply to your answer, but I hope you see this. my code is:

while disp.isNotDone():
    img2 = cam.getImage()

    imgBin = img_hsv.binarize(75).morphOpen().invert()
    blobs = imgBin.findBlobs(minsize=30)
    #blobs.draw(color=Color.PUCE, width=3)
    count = 1
    textLayer = DrawingLayer(img2.size())
    squares = blobs.filter([b.isSquare(0.1, 0.1) for b in blobs])
    print squares.coordinates()
    if squares:
        textLayer.text(str(count), squares.coordinates(), color=Color.RED)
        squares.draw(color=Color.PUCE, width=3)

        count += 1
    print len(squares)


My problem here is trying to number all the squares according to their count. It seems using 'squares.coordinates()' for the location of the text is invalid here, but it seems to work if I'm using blobs.

EDIT: Nevermind, I figured out that I needed to put for squares in squares: to break that list up

edit flag offensive delete link more


nevermind, I found out that I needed to put

decrot gravatar imagedecrot ( 2013-03-13 13:59:06 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-13 02:48:30 -0500

Seen: 2,331 times

Last updated: Mar 13 '13