Thursday, March 03, 2011

Trials of pycam example code (2)

I've downloaded pycam and tested some of the sample codes. There were some errors when I tried to run the examples, such as and [1]. The error messages were as follows.

swig/python detected a memory leak of type 'int64 *', no destructor found.
Traceback (most recent call last):
  File "", line 50, in <module>
  File "/usr/local/lib/python2.6/dist-packages/pycam/", line 160, in main
  File "/usr/local/lib/python2.6/dist-packages/pycam/", line 126, in get_and_flip
    res = self.processFunction(self.snapshot)
  File "", line 36, in drawHatOnFaces
    faces = pygameFaceDetect.getFaces(surf)
  File "/usr/local/lib/python2.6/dist-packages/pycam/", line 51, in getFaces
    return faceDetect.detectObject(img)
  File "/usr/local/lib/python2.6/dist-packages/pycam/", line 130, in detectObject
    t = cvGetTickCount() - t
TypeError: unsupported operand type(s) for -: 'SwigPyObject' and 'SwigPyObject'
swig/python detected a memory leak of type 'int64 *', no destructor found.

This afternoon, I jumped into these examples again and tried to figure out what the messages meant. But I know nothing about the swig/python lines. Then, I found out that I should step into which is in charge of the detection of objects. The error messages said that the problems caused by something about types, and I found the cvGetTickCount() were used to get ticks for estimating fps, which is not crucial and can be isolated!

So I commented out the lines related to cvGetTickCount(), reinstalled the pycam library, and retried the example. It worked!

def detectObject(self,img):
        This should be pure opencv and reasonably quick.
        It carrys out the actual detection, and returns a list of objects found
        # Could this go into init?
        gray = cvCreateImage( cvSize(img.width,img.height), 8, 1 ) 
        small_img = cvCreateImage( cvSize( cvRound (img.width/self.image_scale),
                                           cvRound (img.height/self.image_scale)), 8, 1 ) 
        cvCvtColor( img, gray, CV_BGR2GRAY )
        cvResize( gray, small_img, CV_INTER_LINEAR )
        cvEqualizeHist( small_img, small_img )
        cvClearMemStorage( )

        if( self.cascade ):
            #t = cvGetTickCount()
            objects = cvHaarDetectObjects( small_img, self.cascade,,
                                         self.haar_scale, self.min_neighbors, self.haar_flags, self.min_size )
            #t = cvGetTickCount() - t
            #logging.debug( "%i objects found, detection time = %gms" % (,t/(cvGetTickFrequency()*1000.)) )
            return objects
            logging.error("no cascade")

Here are two funny trials. Spider-Man and Guy Fawkes:

[1] These examples are located in ``pycam-read-only/pycam/examples/opencv''

No comments:

Post a Comment