Rose-Hulman Robotics Team

Changeset 484

Show
Ignore:
Timestamp:
05/06/09 22:27:01 (3 years ago)
Author:
spenceal
Message:

Fixing memory leaks mostly

Location:
trunk/software
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/software/rb/gui/camera.py

    r482 r484  
    3232                gc = gtk.gdk.GC(drawable) 
    3333                alloc = self.get_allocation() 
    34                 self.pixbuf.render_to_drawable( 
    35                                 drawable, gc, 
     34                drawable.draw_pixbuf( 
     35                                gc, self.pixbuf, 
    3636                                0, 0, # src_x, src_y, 
    3737                                alloc.x, alloc.x, 
  • trunk/software/rb/vision/__init__.py

    r482 r484  
    1818                        print "done getting points" 
    1919                        self.controller.send("vision_points", data) 
    20                         sleep(10) 
     20                        sleep(1) 
     21 
     22def key_press_cb(widget, event): 
     23        import gtk 
     24        if event.keyval in (gtk.keysyms.Escape, gtk.keysyms.q): 
     25                gtk.main_quit()  
    2126 
    2227def test(): 
     
    2833        image.set_from_pixbuf(pixbuf) 
    2934        win.add(image) 
     35        win.connect("key-press-event", key_press_cb) 
     36        win.connect("destroy", gtk.main_quit) 
    3037        win.show_all() 
    3138        gtk.main() 
  • trunk/software/rb/vision/_vision.c

    r482 r484  
    3737        IplImage *rgb = cvCreateImage(size, image->depth, image->nChannels); 
    3838        cvCvtColor(image, rgb, CV_BGR2RGB); 
    39         return gdk_pixbuf_new_from_data( 
     39        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data( 
    4040                (guchar*)rgb->imageData,  
    4141                GDK_COLORSPACE_RGB,  
     
    4848                NULL 
    4949        );  
     50        cvReleaseImageHeader(&rgb); 
     51        return pixbuf; 
    5052}  
    5153 
     
    7577 
    7678        IplImage *input       = get_image(); 
    77         IplImage *transformed = transform_image(input, 0.50); 
     79        IplImage *transformed = transform_image(input, 0.25); 
    7880        CvMat    *classes     = classifier_predict(classifier, transformed); 
    7981        CvSeq    *seq         = get_points(classes); 
     
    8890                PyList_Append(points, point); 
    8991        } 
     92 
     93        GdkPixbuf *pixbuf = ipl_image_to_gtk_pixbuf(transformed); 
     94        PyObject  *py_pixbuf  = pygobject_new((GObject*)pixbuf); 
     95 
    9096        cvReleaseMemStorage(&seq->storage); 
    91  
    92         GdkPixbuf *pixbuf = ipl_image_to_gtk_pixbuf(input); 
    93         PyObject  *py_pixbuf  = pygobject_new((GObject*)pixbuf); 
     97        cvReleaseImage(&input); 
     98        cvReleaseImage(&transformed); 
     99        cvReleaseMat(&classes); 
    94100 
    95101        return Py_BuildValue("(OO)", points, py_pixbuf); 
  • trunk/software/rb/vision/classify.c

    r479 r484  
    9090} 
    9191 
     92void classifier_free(classifier_t *classifier) 
     93{ 
     94        cvReleaseMat(&classifier->train_input); 
     95        cvReleaseMat(&classifier->train_desired); 
     96        switch (classifier->type) { 
     97        case RB_DTREE: dtree_free(classifier->classifier); break; 
     98        case RB_HARD:  break; 
     99        } 
     100        free(classifier); 
     101} 
     102 
    92103void classifier_add_data(classifier_t *classifier, CvMat *input, CvMat *desired) 
    93104{ 
  • trunk/software/rb/vision/classify.h

    r479 r484  
    4545 */ 
    4646classifier_t *classifier_new(int type); 
     47void classifier_free(classifier_t *classifier); 
    4748 
    4849 
  • trunk/software/rb/vision/classify_dtree.cpp

    r479 r484  
    1010        CvDTree *dtree = new CvDTree; 
    1111        return dtree; 
     12} 
     13 
     14void dtree_free(CvCDTree *_dtree) 
     15{ 
     16        CvDTree *dtree = (CvDTree *)_dtree; 
     17        delete dtree; 
    1218} 
    1319 
     
    2632        dtree->train(input, CV_ROW_SAMPLE, desired, 0, 0, var_type, NULL, 
    2733                CvDTreeParams( 
    28                         15,             // Max depth 
    29                         50,             // min sample count 
     34                        5,  // 15,             // Max depth 
     35                        10, // 50,             // min sample count 
    3036                        0,              // regression accuracy: N/A here 
    3137                        false,          // no not compute surrogate split 
    3238                        RB_NUM_CLASSES, // max number of categories (use sub-optimal algorithm for larger numbers) 
    33                         20,             // the number of cross-validation folds 
     39                        4, // 20,             // the number of cross-validation folds 
    3440                        false,          // use 1SE rule => smaller tree 
    3541                        true,           // throw away the pruned tree branches 
  • trunk/software/rb/vision/classify_dtree.h

    r479 r484  
    88/* Decision tree classifier */ 
    99CvCDTree *dtree_create(); 
     10void dtree_free(CvCDTree *); 
    1011void dtree_train(CvCDTree *dtree, CvMat *input, CvMat *desired); 
    1112CvMat *dtree_predict(CvCDTree *dtree, CvMat *input); 
  • trunk/software/rb/vision/main.c

    r482 r484  
    6969        /* Display images */ 
    7070        print_time("Displaying images"); 
    71         cvNamedWindow("input", 0); 
    72         cvMoveWindow ("input", 100, 100); 
    73         cvShowImage  ("input", input); 
    74         cvNamedWindow("transformed", 0); 
    75         cvMoveWindow ("transformed", 100, 100); 
    76         cvShowImage  ("transformed", transformed); 
    77         cvNamedWindow("colors", 0); 
    78         cvMoveWindow ("colors", 100, 100); 
    79         cvShowImage  ("colors", colors); 
     71        //cvNamedWindow("input", 0); 
     72        //cvMoveWindow ("input", 100, 100); 
     73        //cvShowImage  ("input", input); 
     74        //cvNamedWindow("transformed", 0); 
     75        //cvMoveWindow ("transformed", 100, 100); 
     76        //cvShowImage  ("transformed", transformed); 
     77        //cvNamedWindow("colors", 0); 
     78        //cvMoveWindow ("colors", 100, 100); 
     79        //cvShowImage  ("colors", colors); 
    8080 
    81         while (cvWaitKey(0) != XK_q); 
     81        //while (cvWaitKey(0) != XK_q); 
    8282 
    8383        /* Release temp data */ 
     
    8686        cvReleaseMat(&classes); 
    8787        cvReleaseImage(&colors); 
     88        classifier_free(classifier); 
    8889 
    8990        return 0; 
  • trunk/software/rb/vision/makefile

    r482 r484  
    11CFLAGS   = -p -pg -g -Wall -Werror -pedantic -fPIC --std=gnu99 -fgnu89-inline -O3 $(shell pkg-config --cflags opencv gsl) 
     2#CFLAGS   = -p -pg -g -Wall -Werror -pedantic -fPIC -O3 $(shell pkg-config --cflags opencv gsl) 
    23CPPFLAGS = -p -pg -g -Wall -Werror -pedantic -fPIC -O3 $(shell pkg-config --cflags opencv gsl) 
    34LDFLAGS  = $(shell pkg-config --libs opencv gsl) 
  • trunk/software/rb/vision/vision.c

    r479 r484  
    8181        for(int x = 0; x < classes->cols; x+=10) { 
    8282                for(int y = 0; y < classes->rows; y+=10) { 
    83                         CvScalar class = cvGet2D(classes, y, x); 
    84                         int data[3] = {class.val[0], x, y}; 
     83                        CvScalar klass = cvGet2D(classes, y, x); 
     84                        int data[3] = {klass.val[0], x, y}; 
    8585                        CV_WRITE_SEQ_ELEM(data, writer); 
    8686                } 
  • trunk/software/setup.py

    r479 r484  
    3030         'rb/vision/vision.c', 
    3131         'rb/vision/classify.c', 
    32          'rb/vision/classify_hard.c', 
    33          'rb/vision/classify_dtree.cpp'], 
     32         'rb/vision/classify_hard.c'], 
     33         #'rb/vision/classify_dtree.cpp'], 
    3434        libraries=['cv', 'highgui', 'gsl'], 
    35         extra_compile_args=['-I/usr/include/opencv -lcv -lhighgui -lgsl'] 
     35        extra_compile_args=['-I/usr/include/opencv -lcv -lhighgui -lgsl'], 
     36        language="c++", 
    3637); 
    3738