Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame Segmentation error when using the SimpleCV library findBlob function

I have been using SimpleCV for find blobs to be used with a self-driving robot. The problem is when I call the findBlobs command in SimpleCV. When I completely block the lens of the Kinect Camera, PyGame crashes giving me this error:

Fatal Python error: (pygame parachute) Segmentation Fault

Sometimes it works and other times it just crashes, even when the lens is unblocked. It will almost always crash when i run it for longer than about thirty seconds. I have re-installed and fixed many problems in SimpleCV and tried re-installing Pygame and it doesn't seem to help at all. Also, I am using the X-Box kinect as my camera source. I'm using Ubuntu 11.04.

Here is my exact code:

from SimpleCV import *
from SimpleCV.Display import *
from time import sleep
k = Kinect()
dis = Display()

while 1:
    depth = k.getDepth()
    depth = depth.invert()
    depth = depth.erode()
    blobs = depth.findBlobs(threshval=127, minsize=10, maxsize=0)
    if blobs:
        blobs.draw()
    depth.save(dis)
    sleep(0)
like image 469
HuntR2 Avatar asked Oct 08 '11 20:10

HuntR2


2 Answers

Kat here, I wrote the SimpleCV blob library.

There were a couple issues with the blob library that we found after we shipped the 1.1 release. The two big ones were that the blob library would hit the python max recursion depth and bail out. The second one stems from the actual underlying OpenCV wrapper and causes the pygame error when there are no blobs are detected by the blob maker.

The solution right now is to use the version that is in the master branch of our github repo. The patched version will also be available in the new SimpleCV 1.2 release which is slated for later this month. If you want to manually fix the code I have pasted the fixed snippet below:

In BlobMaker.py around line 55

    def extractFromBinary(self,binaryImg,colorImg, minsize = 5, maxsize = -1):
        #fix recursion limit bug
        sys.setrecursionlimit(1000000)

        if (maxsize <= 0):  
        maxsize = colorImg.width * colorImg.height 

       retVal = []
       #fix all black image bug
       test = binaryImg.meanColor()
       if( test[0]==0.00 and test[1]==0.00 and test[2]==0.00):
           return FeatureSet(retVal)


       seq = cv.FindContours( binaryImg._getGrayscaleBitmap(), self.mMemStorage, cv.CV_RETR_TREE, cv.CV_CHAIN_APPROX_SIMPLE)

       retVal = self._extractFromBinary(seq,False,colorImg,minsize,maxsize)
       del seq
       return FeatureSet(retVal)
like image 126
kscottz Avatar answered Oct 13 '22 14:10

kscottz


Anthony one of the SimpleCV developers here: Can you try changing the last line:

sleep(0.01)

Just to see if there is some type of issue going on where it can't process fast enough. I recently upgraded to Ubuntu 11.04 and I think there are a couple of python bugs I need to squash that popped up since 10.10.

Also if you could post this to our issue queue I would appreciate it: http://github.com/ingenuitas/SimpleCV/issues

like image 24
xamox Avatar answered Oct 13 '22 16:10

xamox