Changeset 489
- Timestamp:
- 05/14/09 00:13:53 (3 years ago)
- Location:
- trunk/software/rb/vision
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/rb/vision/__init__.py
r485 r489 9 9 self.controller = controller 10 10 _vision._init_classifier() 11 _vision._init_capture() 11 12 start_new_thread(self._main, ()) 12 13 13 14 def _main(self): 14 15 sleep(2) 15 while (self.running == True):16 while self.running: 16 17 print "getting points" 17 18 data = _vision._get_points() -
trunk/software/rb/vision/_vision.c
r488 r489 25 25 26 26 #include <opencv/cv.h> 27 #include <opencv/highgui.h> 27 28 28 29 #include "vision.h" … … 31 32 static PyTypeObject *PyGObject_Type=NULL; 32 33 classifier_t *classifier = NULL; 34 CvCapture *cam = NULL; 33 35 34 36 void free_pixbuf_data(guchar *pixels, gpointer _ipl_image) … … 78 80 79 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 } 100 101 static PyObject* 80 102 _get_points(PyObject *self, PyObject *args) 81 103 { 82 104 if (classifier == NULL) { 83 printf("Error: you must call _init_classifier first\n"); 105 PyErr_SetString(PyExc_RuntimeError, "_init_classifier must be called first"); 106 return NULL; 107 } else if (cam == NULL) { 108 PyErr_SetString(PyExc_RuntimeError, "_init_capture must be called first"); 84 109 return NULL; 85 110 } … … 89 114 PyObject *points = PyList_New(0); 90 115 91 IplImage *input = get_image(); 92 IplImage *transformed = transform_image(input, 0.25); 93 CvMat *classes = classifier_predict(classifier, transformed); 94 CvSeq *seq = get_points(classes); 116 IplImage *input; 117 IplImage *transformed; 118 CvMat *classes; 119 CvSeq *seq; 120 121 // Release the global interpreter lock. No messing with Python objects without it, though! 122 // This creates a new block, so we need to declare variables above to access them after we 123 // reacquire the GIL. 124 Py_BEGIN_ALLOW_THREADS 95 125 126 input = capture(); 127 transformed = transform_image(input, 0.25); 128 classes = classifier_predict(classifier, transformed); 129 seq = get_points(classes); 130 131 Py_END_ALLOW_THREADS 132 96 133 CvSeqReader reader; 97 134 cvStartReadSeq(seq, &reader, 0); … … 110 147 111 148 cvReleaseMemStorage(&seq->storage); 112 cvReleaseImage(&input);149 //cvReleaseImage(&input); // Don't free captured images 113 150 cvReleaseImage(&transformed); 114 151 cvReleaseMat(&classes); … … 125 162 {"_init_classifier", _init_classifier, METH_VARARGS, 126 163 "Initialize the classifier using predefined training images"}, 164 {"_init_capture", _init_capture, METH_VARARGS, 165 "Initialize the camera capture device"}, 127 166 {NULL, NULL, 0, NULL} // sentinel 128 167 }; -
trunk/software/rb/vision/vision.c
r488 r489 69 69 } 70 70 71 int [3]point_to_71 //int [3]point_to_ 72 72 73 73 CvSeq *get_points(CvMat *classes)

