Changeset 508
- Timestamp:
- 06/03/09 18:09:23 (3 years ago)
- Location:
- trunk/software/rb
- Files:
-
- 1 added
- 8 modified
-
auto.py (modified) (4 diffs)
-
controller.py (modified) (1 diff)
-
gui/auto.py (added)
-
gui/gui.glade (modified) (2 diffs)
-
gui/gui.py (modified) (3 diffs)
-
gui/gui.xml (modified) (2 diffs)
-
vision/__init__.py (modified) (2 diffs)
-
vision/_vision.c (modified) (5 diffs)
-
vision/vision.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/rb/auto.py
r490 r508 24 24 from rb.core.logging import log_debug, log_info, log_warn, log_error, log_die 25 25 from rb.utils import points_to_vec, rad_delta 26 from rb.vision import Camera 26 27 27 28 from time import sleep … … 67 68 68 69 def navigate_course(self): 69 # TODO: import these from the C enum70 RB_GRASS = 071 RB_OBSTICLE = 172 RB_LINE = 273 RB_IGNORE = 374 70 values = [0.1, 0.1, 0.1, 0.1] 75 71 … … 79 75 values[point[2]] += 1 80 76 81 if (values[ RB_GRASS] < 10):77 if (values[Camera.GRASS] < 10): 82 78 print "Auto.navigate_course: Not enough data, aborting" 83 79 return False; … … 85 81 # If it's `mostly' clear 86 82 print "Auto.navigate_course: values = ", values 87 if (values[ RB_GRASS]/values[RB_OBSTICLE]) > 2:83 if (values[Camera.GRASS]/values[Camera.OBSTICLE]) > 2: 88 84 # go forward 89 85 print "Auto.navigate_course: Moving forward" -
trunk/software/rb/controller.py
r503 r508 43 43 self.data_queue = Queue() 44 44 self.init_drive() 45 #self.init_camera()45 self.init_camera() 46 46 #self.init_gps() 47 47 #self.init_microstrain() 48 48 49 self.transcript = TranscriptLogger('/tmp/rblog.txt',50 self.drive, self.gps, self.microstrain)49 #self.transcript = TranscriptLogger('/tmp/rblog.txt', 50 # self.drive, self.gps, self.microstrain) 51 51 52 52 self.set_navigator('laptop') -
trunk/software/rb/gui/gui.glade
r485 r508 1 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 2 2 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> 3 <!--Generated with glade3 3.4.5 on Wed May 6 22:08:342009 -->3 <!--Generated with glade3 3.4.5 on Wed Jun 3 20:52:53 2009 --> 4 4 <glade-interface> 5 5 <widget class="GtkWindow" id="window"> … … 277 277 </child> 278 278 <child> 279 <widget class="GtkLabel" id="auto_body"> 280 <property name="visible">True</property> 281 <property name="label" translatable="yes">TODO</property> 279 <widget class="GtkAlignment" id="auto_body"> 280 <property name="visible">True</property> 281 <child> 282 <placeholder/> 283 </child> 282 284 </widget> 283 285 <packing> 284 286 <property name="position">4</property> 285 <property name="tab_expand">True</property>286 287 </packing> 287 288 </child> -
trunk/software/rb/gui/gui.py
r482 r508 30 30 from rb.gui.speedgraph import SpeedGraph 31 31 from rb.gui.camera import Camera 32 from rb.gui.auto import Auto 32 33 33 34 … … 79 80 self.raw_orient_dir = self.compass.new_direction(RAW_ORIENT_BLUE, pi / 2) 80 81 self.speed_graph = SpeedGraph(self.controller.drive) 82 self.auto = Auto() 81 83 self.camera = Camera() 82 84 self.builder.get_object("speed_body").add(self.speed) 83 85 self.builder.get_object("compass_body").add(self.compass) 84 86 self.builder.get_object("speed_graph").add(self.speed_graph) 87 self.builder.get_object("auto_body").add(self.auto) 85 88 self.builder.get_object("camera_body").add(self.camera) 86 89 … … 108 111 elif type == 'vision_points': 109 112 points, pixbuf = data 113 self.auto.points = points 110 114 self.camera.pixbuf = pixbuf 111 115 self.camera.queue_draw() -
trunk/software/rb/gui/gui.xml
r485 r508 1 1 <?xml version="1.0"?> 2 <!--Generated with glade3 3.4.5 on Wed May 6 22:08:342009 -->2 <!--Generated with glade3 3.4.5 on Wed Jun 3 20:52:53 2009 --> 3 3 <interface> 4 4 <object class="GtkAdjustment" id="adjustment1"> … … 288 288 </child> 289 289 <child> 290 <object class="GtkLabel" id="auto_body"> 291 <property name="visible">True</property> 292 <property name="label" translatable="yes">TODO</property> 293 </object> 294 <packing> 295 <property name="position">4</property> 296 <property name="tab_expand">True</property> 297 </packing> 290 <object class="GtkAlignment" id="auto_body"> 291 <property name="visible">True</property> 292 <child> 293 <placeholder/> 294 </child> 295 </object> 298 296 </child> 299 297 <child type="tab"> -
trunk/software/rb/vision/__init__.py
r490 r508 1 1 from thread import start_new_thread 2 2 3 import rbconfig 3 4 from rb.vision import _vision 4 5 from time import sleep 5 6 6 7 class Camera(object): 8 # TODO: import these from the C enum 9 GRASS = 0 10 OBSTICLE = 1 11 LINE = 2 12 IGNORE = 3 13 14 DTREE = 0 15 HARD = 1 16 17 COLORS = { 18 GRASS : [0, 255, 0 ], 19 OBSTICLE : [255, 0, 0 ], 20 LINE : [255, 255, 255], 21 IGNORE : [0, 0, 255], 22 } 23 7 24 def __init__(self, controller): 8 25 self.running = True 9 26 self.controller = controller 10 _vision._init_classifier() 11 #_vision._init_capture() 27 _vision._init(rbconfig.fake_ccam, rbconfig.classifier) 12 28 start_new_thread(self._main, ()) 13 29 … … 30 46 win = gtk.Window() 31 47 image = gtk.Image() 32 _vision._init _classifier()48 _vision._init(TRUE, Camera.DTREE) 33 49 points, pixbuf = _vision._get_points() 34 50 image.set_from_pixbuf(pixbuf) -
trunk/software/rb/vision/_vision.c
r498 r508 65 65 } 66 66 67 static PyObject* 68 _init(PyObject *self, PyObject *args) 69 { 70 int fake_ccam, classifier_num; 71 if (!PyArg_ParseTuple(args, "bb", &fake_ccam, &classifier_num)) 72 return NULL; 67 73 68 /* TODO: define some constants for the types of points */ 69 static PyObject* 70 _init_classifier(PyObject *self, PyObject *args) 71 { 74 /* Init ccam */ 75 if (!fake_ccam) { 76 printf("Initializing capture\n"); 77 cam = cvCreateCameraCapture(0); 78 if (cam == NULL) 79 return PyErr_SetFromErrno(PyExc_IOError); 80 } 81 82 /* Init classifier */ 72 83 printf("Initialzing classifier\n"); 73 classifier = classifier_new( RB_DTREE);84 classifier = classifier_new(classifier_num); 74 85 classifier_add_data_from_files(classifier, 75 86 "rb/vision/data/classes/input.jpeg", … … 77 88 classifier_train(classifier); 78 89 return Py_None; 79 }80 81 static PyObject*82 _init_capture(PyObject *self, PyObject *args)83 {84 if (!PyArg_ParseTuple(args, "")) {85 return NULL;86 }87 printf("Initializing capture\n");88 cam = cvCreateCameraCapture(0);89 if (cam == NULL) {90 return PyErr_SetFromErrno(PyExc_IOError);91 }92 return Py_None;93 }94 95 IplImage *capture()96 {97 cvGrabFrame(cam);98 return cvRetrieveFrame(cam);99 90 } 100 91 … … 121 112 CvSeq *seq; 122 113 123 // Release the global interpreter lock. No messing with Python objects without it, though!124 // This creates a new block, so we need to declare variables above to access them after we125 // reacquire the GIL.114 // Release the global interpreter lock. No messing with Python objects 115 // without it, though! This creates a new block, so we need to declare 116 // variables above to access them after we reacquire the GIL. 126 117 Py_BEGIN_ALLOW_THREADS 127 118 128 //input = capture(); 129 input = get_image("rb/vision/data/classes/input.jpeg"); 119 input = get_image(cam); 130 120 transformed = transform_image(input, 0.25); 131 121 classes = classifier_predict(classifier, transformed); … … 150 140 151 141 cvReleaseMemStorage(&seq->storage); 152 //cvReleaseImage(&input); // Don't free captured images142 cvReleaseImage(&input); // Don't free captured images 153 143 cvReleaseImage(&transformed); 154 144 cvReleaseMat(&classes); … … 163 153 {"_get_points", _get_points, METH_VARARGS, 164 154 "Return a list of points corresponding to obstacles and lines"}, 165 {"_init_classifier", _init_classifier, METH_VARARGS, 166 "Initialize the classifier using predefined training images"}, 167 {"_init_capture", _init_capture, METH_VARARGS, 168 "Initialize the camera capture device"}, 155 {"_init", _init, METH_VARARGS, 156 "Initialize the classifier and camera capture device"}, 169 157 {NULL, NULL, 0, NULL} // sentinel 170 158 }; -
trunk/software/rb/vision/vision.c
r490 r508 29 29 #include "classify.h" 30 30 31 IplImage *get_image() 32 { 33 const char *file = "rb/vision/data/classes/input.jpeg"; 34 IplImage *image = cvLoadImage(file, 1); 35 if (!image) { 36 printf("Could not load image file: %s\n", file); 37 return NULL; 38 } 39 return image; 31 32 IplImage *get_image(CvCapture *cam) 33 { 34 if (cam) { 35 cvGrabFrame(cam); 36 return cvRetrieveFrame(cam); 37 } else { 38 const char *file = "rb/vision/data/classes/input.jpeg"; 39 IplImage *image = cvLoadImage(file, 1); 40 if (!image) { 41 printf("Could not load image file: %s\n", file); 42 return NULL; 43 } 44 return image; 45 } 40 46 } 41 47

