Pygame Segmentation error when using the SimpleCV library findBlob function
Asked Answered
V

4

5

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)
Vanillin answered 8/10, 2011 at 20:51 Comment(0)
A
5

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)
Ajar answered 10/10, 2011 at 19:29 Comment(0)
P
2

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

Poyang answered 10/10, 2011 at 19:9 Comment(0)
C
0

Fatal Python error: (pygame parachute) Segmentation Fault

This means that some code crashed, and now you need to debug it to find the problem. I assume you are learning something; might as well learn how to debug ;-)

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.

These are classic symptoms of heap corruption, or a data race.

I have re-installed and fixed many problems in SimpleCV and tried re-installing Pygame and it doesn't seem to help.

Why did you think it would? Your problem does not at all look like an installation problem.

So here is what you do: the tool for debugging heap corruption problems on Linux is valgrind. Run it like this:

  valgrind python your-code.py

Unfortunately, default Python installation is not Valgrind-friendly, and above command will likely produce a lot of "uninitialized memory read" errors. You'll want to suppress most of them using this suppression file.

It may be possible to concentrate on errors that contain non-Python parts (and SimpleCV in particular). You are looking for invalid {read,write} ... N bytes after block ....

If you find such an error, you can try to debug it further with GDB, or report it to SimpleCV developers and hope for the best.

If you don't find the error, you can build a Valgrind-friendly version of Python (instructions), and try again.

If above run is Valgrind-clean, then you may have a race rather than heap corruption. Repeat with ThreadSanitizer.

Column answered 9/10, 2011 at 15:11 Comment(0)
S
0

Just replace your blob threshold with "-1"; I had the same problem and this fixed it.

Suiting answered 31/1, 2012 at 10:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.