Changeset 479
- Timestamp:
- 04/02/09 01:07:42 (3 years ago)
- Location:
- trunk/software
- Files:
-
- 13 modified
-
Makefile (modified) (1 diff)
-
rb/vision/_vision.c (modified) (3 diffs)
-
rb/vision/classify.c (modified) (3 diffs)
-
rb/vision/classify.h (modified) (3 diffs)
-
rb/vision/classify_dtree.cpp (modified) (1 diff)
-
rb/vision/classify_dtree.h (modified) (1 diff)
-
rb/vision/classify_hard.c (modified) (1 diff)
-
rb/vision/classify_hard.h (modified) (1 diff)
-
rb/vision/main.c (modified) (1 diff)
-
rb/vision/makefile (modified) (1 diff)
-
rb/vision/vision.c (modified) (3 diffs)
-
rb/vision/vision.h (modified) (1 diff)
-
setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/Makefile
r469 r479 16 16 17 17 clean: 18 rm -f *.so 19 rm -fR rb/*.so 20 rm -fR rb/*/*.so 21 rm -f *.pyc 22 rm -fR rb/*.pyc 23 rm -fR rb/*/*.pyc 18 rm -rf build/* 19 rm -f *.{o,so,pyc} 20 rm -f rb/*.{o,so,pyc} 21 rm -f rb/*/*.{o,so,pyc} 24 22 25 23 rungui: -
trunk/software/rb/vision/_vision.c
r469 r479 23 23 24 24 #include "vision.h" 25 #include "classify.h" 25 26 26 27 /* TODO: define some constants for the types of points */ … … 32 33 PyObject *points = PyList_New(0); 33 34 35 36 classifier_t *classifier = classifier_new(RB_DTREE); 37 classifier_add_data_from_files(classifier, 38 "rb/vision/data/classes/input.jpeg", 39 "rb/vision/data/classes/classes.png"); 40 classifier_train(classifier); 41 34 42 IplImage *input = get_image(); 35 IplImage *transformed = transform_image(input, 0. 25);36 CvMat *classes = classif y_image(transformed);43 IplImage *transformed = transform_image(input, 0.50); 44 CvMat *classes = classifier_predict(classifier, transformed); 37 45 CvSeq *seq = get_points(classes); 38 46 … … 42 50 int data[3]; 43 51 CV_READ_SEQ_ELEM(data, reader); 44 PyObject *point = Py_BuildValue("iii", data[0], data[1], data[2]); 52 PyObject *point = Py_BuildValue("iii", 53 data[0], data[1], data[2]); 45 54 PyList_Append(points, point); 46 55 } -
trunk/software/rb/vision/classify.c
r476 r479 3 3 #include <opencv/highgui.h> 4 4 5 #include "vision.h" 5 6 #include "classify.h" 6 7 #include "classify_dtree.h" … … 12 13 for (int type = 0; type < RB_NUM_CLASSES; type++) { 13 14 const double *px = class_colors[type].val; 14 if (in[0]==px[0] && in[1]==px[1] && in[2]==px[2]) {15 if (in[0]==px[0] && in[1]==px[1] && in[2]==px[2]) 15 16 return type; 16 }17 17 } 18 18 printf("Warning, unknown type: (%f,%f,%f)\n", in[0], in[1], in[2]); … … 20 20 } 21 21 22 void parse_files(const char *input_file, const char *desired_file, 23 CvMat **input, CvMat **desired) 22 #define COPY_PX(row, col, px_num) { \ 23 CvScalar input_px = cvGet2D(hsv, row, col); \ 24 cvSet2D(input, out_row, (px_num*3)+0, cvRealScalar(input_px.val[0])); \ 25 cvSet2D(input, out_row, (px_num*3)+1, cvRealScalar(input_px.val[1])); \ 26 cvSet2D(input, out_row, (px_num*3)+2, cvRealScalar(input_px.val[2])); \ 27 } 28 /* Convert a raw RGB input image to a CvMat suitable for learning algorithms */ 29 CvMat *image_to_input(IplImage *image) 24 30 { 25 /* Load training data */ 26 fprintf(stderr, "Loading training images\n"); 27 IplImage *_input_img = cvLoadImage(input_file, 1); 28 IplImage *_desired_img = cvLoadImage(desired_file, 1); 31 CvSize size = {image->width, image->height}; 29 32 30 /* Scaling input */ 31 CvSize size = {_input_img->width*0.25, _input_img->height*0.25}; 32 IplImage *input_img = cvCreateImage(size, _input_img->depth, _input_img->nChannels); 33 IplImage *desired_img = cvCreateImage(size, _desired_img->depth, _desired_img->nChannels); 34 cvResize(_input_img, input_img, CV_INTER_LINEAR); 35 cvResize(_desired_img, desired_img, CV_INTER_NN); 33 /* Smooth image */ 34 print_time("Smoothing"); 35 IplImage *smoothed = cvCreateImage(size, image->depth, image->nChannels); 36 cvSmooth(image, smoothed, CV_BLUR, 3, 3, 0, 0); 36 37 37 /* Blur */ 38 cvSmooth(input_img, input_img, CV_BLUR, 3, 3, 0, 0); 38 /* Convert image to HSV */ 39 print_time("To HSV"); 40 IplImage *hsv = cvCreateImage(size, image->depth, image->nChannels); 41 cvCvtColor(smoothed, hsv, CV_BGR2HSV); 39 42 40 /* Convert to HSV */ 41 fprintf(stderr, "Preprocessing training images\n"); 42 cvCvtColor(input_img, input_img, CV_BGR2HSV); 43 44 /* Convert IplImage to DTree input format */ 45 fprintf(stderr, "Parsing training images to DTree input\n"); 43 /* Create matrix from image */ 46 44 int out_rows = size.height * size.width; 47 45 fprintf(stderr, "Creating %dx%d = %d input\n", size.width, size.height, out_rows); 48 *input = cvCreateMat(out_rows, RB_NUM_CLASSES, CV_32F); 49 *desired = cvCreateMat(out_rows, 1, CV_32F); 46 CvMat *input = cvCreateMat(out_rows, 3*1, CV_32F); 50 47 int row, col; 51 48 for (row = 0; row < size.height; row++) { 52 49 for (col = 0; col < size.width; col++) { 53 50 int out_row = row*size.width + col; 54 CvScalar input_px = cvGet2D(input_img, row, col); 55 CvScalar desired_px = cvGet2D(desired_img, row, col); 56 int desired_type = get_type(desired_px); 57 cvSet2D(*input, out_row, 0, cvRealScalar(input_px.val[0])); 58 cvSet2D(*input, out_row, 1, cvRealScalar(input_px.val[1])); 59 cvSet2D(*input, out_row, 2, cvRealScalar(input_px.val[2])); 60 cvSet2D(*desired, out_row, 0, cvRealScalar(desired_type)); 51 COPY_PX(row, col, 0); 52 //if (col-5 >= 0 ) COPY_PX(row, col-5, 1); 53 //if (col+5 < size.width ) COPY_PX(row, col+5, 2); 54 //if (row-5 >= 0 ) COPY_PX(row-5, col, 3); 55 //if (row+5 < size.height) COPY_PX(row+5, col, 4); 61 56 } 57 } 58 59 /* Done */ 60 cvReleaseImage(&smoothed); 61 cvReleaseImage(&hsv); 62 return input; 63 } 64 /* Convert a hand classified RGB input image to a CvMat suitable for learning algorithms */ 65 CvMat *image_to_desired(IplImage *image) 66 { 67 /* Create matrix from image */ 68 CvMat *desired = cvCreateMat(image->height, image->width, CV_32F); 69 for (int row = 0; row < image->height; row++) 70 for (int col = 0; col < image->width; col++) 71 cvSet2D(desired, row, col, 72 cvRealScalar(get_type(cvGet2D(image, row, col)))); 73 74 cvReshape(desired, desired, 1, image->height * image->width); 75 return desired; 76 } 77 78 79 classifier_t *classifier_new(int type) 80 { 81 classifier_t *classifier = malloc(sizeof(classifier_t)); 82 classifier->type = type; 83 classifier->train_input = cvCreateMat(1, 3, CV_32F); // FIXME: number of pixles may change 84 classifier->train_desired = cvCreateMat(1, 1, CV_32F); 85 switch (type) { 86 case RB_DTREE: classifier->classifier = dtree_create(); break; 87 case RB_HARD: break; 88 } 89 return classifier; 90 } 91 92 void classifier_add_data(classifier_t *classifier, CvMat *input, CvMat *desired) 93 { 94 // FIXME: This currently wipes out any existing data 95 cvReleaseMat(&classifier->train_input); 96 cvReleaseMat(&classifier->train_desired); 97 classifier->train_input = cvCloneMat(input); 98 classifier->train_desired = cvCloneMat(desired); 99 } 100 101 // "data/classes/input.jpeg" 102 // "data/classes/classes.png" 103 void classifier_add_data_from_files(classifier_t *classifier, const char *input_file, const char *desired_file) 104 { 105 IplImage *input_img = cvLoadImage(input_file, 1); 106 IplImage *desired_img = cvLoadImage(desired_file, 1); 107 108 CvSize size = cvSize(input_img->width*0.25, input_img->height*0.25); 109 IplImage *input_img_s = cvCreateImage(size, input_img->depth, input_img->nChannels); 110 IplImage *desired_img_s = cvCreateImage(size, desired_img->depth, desired_img->nChannels); 111 cvResize(input_img, input_img_s, CV_INTER_LINEAR); 112 cvResize(desired_img, desired_img_s, CV_INTER_NN); 113 cvReleaseImage(&input_img); 114 cvReleaseImage(&desired_img); 115 116 CvMat *input_mat = image_to_input(input_img_s); 117 CvMat *desired_mat = image_to_desired(desired_img_s); 118 cvReleaseImage(&input_img_s); 119 cvReleaseImage(&desired_img_s); 120 121 classifier_add_data(classifier, input_mat, desired_mat); 122 cvReleaseMat(&input_mat); 123 cvReleaseMat(&desired_mat); 124 } 125 126 void classifier_add_data_class(classifier_t *classifier, CvMat *input, int desired) 127 { 128 // TODO 129 } 130 131 void classifier_train(classifier_t *classifier) 132 { 133 switch (classifier->type) { 134 case RB_DTREE: dtree_train(classifier->classifier, classifier->train_input, classifier->train_desired); break; 135 case RB_HARD: /* no training */ break; 62 136 } 63 137 } 64 138 65 CvMat *classif y(IplImage *image)139 CvMat *classifier_predict(classifier_t *classifier, IplImage *image) 66 140 { 67 fprintf(stderr, "Starting classificaiton\n"); 68 CvMat *input, *desired; 69 parse_files("data/classes/input.jpeg", "data/classes/classes.png", 70 &input, &desired); 71 CvCDTree *dtree = dtree_create(); 72 dtree_train(dtree, input, desired); 73 CvMat *predictions = dtree_predict(dtree, image); 74 fprintf(stderr, "Finished classificaiton\n"); 141 CvMat *predictions = NULL; 142 CvMat *input = image_to_input(image); 143 144 switch (classifier->type) { 145 case RB_DTREE: predictions = dtree_predict(classifier->classifier, input); break; 146 case RB_HARD: predictions = hard_predict(classifier->classifier, image); break; 147 } 148 149 cvReleaseMat(&input); 150 cvReshape(predictions, predictions, 1, image->height); 75 151 return predictions; 76 //return classify_old(image);77 152 } -
trunk/software/rb/vision/classify.h
r476 r479 4 4 * The classified image will be represented by these colors 5 5 */ 6 typedef enum rb_classes_t{6 enum { 7 7 RB_GRASS, 8 8 RB_OBSTICLE, … … 10 10 RB_IGNORE , 11 11 RB_NUM_CLASSES 12 } rb_classes_t;12 }; 13 13 const static CvScalar class_colors[] = { 14 14 {{0*255, 1*255, 0*255, 0}}, // Green … … 18 18 }; 19 19 20 enum { 21 RB_DTREE, // Decision tree 22 RB_HARD, // Hard coded classifier 23 RB_NUM_CLASSIFIERS 24 }; 25 20 26 /** 21 * Do pixel classifications using a decision tree 27 * Classifiers, these store the actual OpenCV classifier along with some 28 * additional stuff for adding/removing data from them. 22 29 */ 23 CvMat *classify(IplImage *hsv); 30 typedef struct { 31 /* Type of classifier */ 32 int type; 33 34 /* The a classifier itself */ 35 void *classifier; 36 37 /* Training data */ 38 CvMat *train_input; // Nx3 (HSV values) 39 CvMat *train_desired; // Nx1 (classes) 40 } classifier_t; 41 42 43 /** 44 * Create a new classifier of the given type 45 */ 46 classifier_t *classifier_new(int type); 47 48 49 /** 50 * Append data to the train_input and train_desired fields 51 */ 52 void classifier_add_data(classifier_t *classifier, CvMat *input, CvMat *desired); 53 /** 54 * Loads data from input files before appending it to the training data 55 */ 56 void classifier_add_data_from_files(classifier_t *classifier, const char *input, const char *desired); 57 /** 58 * Adds training data that is all of the same class 59 */ 60 void classifier_add_data_class(classifier_t *classifier, CvMat *input, int desired); 61 62 63 /** 64 * Train the classifier based on the data store within it 65 */ 66 void classifier_train(classifier_t *classifier); 67 68 69 /** 70 * Train the classifier based on the data store within it 71 */ 72 CvMat *classifier_predict(classifier_t *classifier, IplImage *image); -
trunk/software/rb/vision/classify_dtree.cpp
r476 r479 26 26 dtree->train(input, CV_ROW_SAMPLE, desired, 0, 0, var_type, NULL, 27 27 CvDTreeParams( 28 1 7,// Max depth29 10,// min sample count30 0, // regression accuracy: N/A here31 false, // no not compute surrogate split32 5,// max number of categories (use sub-optimal algorithm for larger numbers)33 10,// the number of cross-validation folds34 false, // use 1SE rule => smaller tree35 true, // throw away the pruned tree branches36 priors // the array of priors , the bigger p_weight, the more attention28 15, // Max depth 29 50, // min sample count 30 0, // regression accuracy: N/A here 31 false, // no not compute surrogate split 32 RB_NUM_CLASSES, // max number of categories (use sub-optimal algorithm for larger numbers) 33 20, // the number of cross-validation folds 34 false, // use 1SE rule => smaller tree 35 true, // throw away the pruned tree branches 36 priors // the array of priors , the bigger p_weight, the more attention 37 37 ) 38 38 ); 39 39 } 40 CvMat *dtree_predict(CvCDTree *_dtree, IplImage *input) 40 /* todo, return a 1xN matrix and let the caller reshape it */ 41 CvMat *dtree_predict(CvCDTree *_dtree, CvMat *input) 41 42 { 42 43 CvDTree *dtree = (CvDTree *)_dtree; 43 44 fprintf(stderr, "Predicting using DTree\n"); 44 45 45 CvSize size = {input->width, input->height}; 46 47 CvMat *output = cvCreateMat(size.height, size.width, CV_8U); 48 int row, col; 49 for (row = 0; row < size.height; row++) { 50 for (col = 0; col < size.width; col++) { 51 CvMat *sample = cvCreateMat(1, RB_NUM_CLASSES, CV_32F); 52 CvScalar input_px = cvGet2D(input, row, col); 53 54 cvSet2D(sample, 0, 0, cvScalar(input_px.val[0])); 55 cvSet2D(sample, 0, 1, cvScalar(input_px.val[1])); 56 cvSet2D(sample, 0, 2, cvScalar(input_px.val[2])); 57 58 double predicted_px = dtree->predict(sample, NULL)->value; 59 60 cvSet2D(output, row, col, cvScalar(predicted_px)); 61 } 46 CvMat *output = cvCreateMat(input->height, 1, CV_8U); 47 CvMat *sample = cvCreateMat(1, RB_NUM_CLASSES, CV_32F); 48 for (int row = 0; row < input->height; row++) { 49 sample = cvGetRow(input, sample, row); 50 double predicted_px = dtree->predict(sample, NULL)->value; 51 cvSet2D(output, row, 0, cvScalar(predicted_px)); 62 52 } 63 53 -
trunk/software/rb/vision/classify_dtree.h
r476 r479 9 9 CvCDTree *dtree_create(); 10 10 void dtree_train(CvCDTree *dtree, CvMat *input, CvMat *desired); 11 CvMat *dtree_predict(CvCDTree *dtree, IplImage*input);11 CvMat *dtree_predict(CvCDTree *dtree, CvMat *input); 12 12 13 13 #ifdef __cplusplus -
trunk/software/rb/vision/classify_hard.c
r476 r479 4 4 #include "classify_hard.h" 5 5 6 CvMat *classify_old(IplImage *image) 6 // /* Morphological operations */ 7 // int rad = (int)size.width*0.005; 8 // IplConvKernel *se = cvCreateStructuringElementEx(rad, rad, rad/2, rad/2, CV_SHAPE_RECT, NULL); 9 // cvDilate(line_mask, line_mask, se, 2); 10 // cvReleaseStructuringElement(&se); 11 12 CvMat *hard_predict(classifier_t *classifier, IplImage *image) 7 13 { 14 /* TODO: convert to using CvMat* */ 15 /* Smooth image */ 8 16 CvSize size = {image->width, image->height}; 17 IplImage *smoothed = cvCreateImage(size, image->depth, image->nChannels); 18 cvSmooth(image, smoothed, CV_BLUR, 3, 3, 0, 0); 19 20 /* Convert image to HSV */ 21 IplImage *hsv = cvCreateImage(size, image->depth, image->nChannels); 22 cvCvtColor(smoothed, hsv, CV_BGR2HSV); 23 24 /* Masks */ 9 25 CvMat *grass_mask = cvCreateMat(size.height, size.width, CV_8U); 10 26 CvMat *line_mask = cvCreateMat(size.height, size.width, CV_8U); 11 cvInRangeS(image, cvScalar(30, 0, 80, 0), cvScalar(120,90,180,0), grass_mask); 12 cvInRangeS(image, cvScalar(100,60,140,0), cvScalar(120,90,254,0), line_mask); 13 // TODO, mark obstacles separately 14 15 /* Morphological operations */ 16 int rad = (int)size.width*0.005; 17 IplConvKernel *se = cvCreateStructuringElementEx(rad, rad, rad/2, rad/2, CV_SHAPE_RECT, NULL); 18 cvDilate(line_mask, line_mask, se, 2); 19 cvReleaseStructuringElement(&se); 27 cvInRangeS(hsv, cvScalar(30, 0, 80, 0), cvScalar(120,90,180,0), grass_mask); 28 cvInRangeS(hsv, cvScalar(100,60,140,0), cvScalar(120,90,254,0), line_mask); 20 29 21 30 /* Mark outputs */ 22 31 CvMat *output = cvCreateMat(size.height, size.width, CV_8U); 23 //cvSet(output, cvRealScalar(RB_IGNORE), NULL);24 cvSet(output, cvRealScalar(RB_GRASS), grass_mask);25 cvSet(output, cvRealScalar(RB_LINE ), line_mask);32 cvSet(output, cvRealScalar(RB_OBSTICLE), NULL); 33 cvSet(output, cvRealScalar(RB_GRASS), grass_mask); 34 cvSet(output, cvRealScalar(RB_LINE ), line_mask); 26 35 27 36 /* Release temporary data */ -
trunk/software/rb/vision/classify_hard.h
r476 r479 1 1 /* Hard coded classifier */ 2 CvMat * classify_old(IplImage *image);2 CvMat *hard_predict(classifier_t *classifier, IplImage *image); -
trunk/software/rb/vision/main.c
r474 r479 41 41 42 42 /* Process */ 43 print_time("Training classifier"); 44 classifier_t *classifier = classifier_new(RB_DTREE); 45 classifier_add_data_from_files(classifier, 46 "data/classes/input.jpeg", 47 "data/classes/classes.png"); 48 classifier_train(classifier); 49 43 50 print_time("Processing images"); 44 IplImage *transformed = transform_image(input, 0. 25);45 CvMat *classes = classif y_image(transformed);51 IplImage *transformed = transform_image(input, 0.50); 52 CvMat *classes = classifier_predict(classifier, transformed); 46 53 IplImage *colors = color_mat(classes); 47 54 -
trunk/software/rb/vision/makefile
r476 r479 1 CFLAGS =-p -pg -g -Wall -pedantic --std=gnu99 -fgnu89-inline -O3 $(shell pkg-config --cflags opencv gsl) 2 CPPFLAGS=-p -pg -g -Wall -pedantic -O3 $(shell pkg-config --cflags opencv gsl) 3 LDFLAGS =-lpython2.5 $(shell pkg-config --libs opencv gsl) 4 DLFLAGS =-shared -nostartfiles -fPIC 1 CFLAGS = -p -pg -g -Wall -pedantic --std=gnu99 -fgnu89-inline -O3 $(shell pkg-config --cflags opencv gsl) 2 CPPFLAGS = -p -pg -g -Wall -pedantic -O3 $(shell pkg-config --cflags opencv gsl) 3 LDFLAGS = $(shell pkg-config --libs opencv gsl) 4 DLFLAGS = -shared -nostartfiles -fPIC 5 PYFLAGS = -I/usr/include/python2.5/ 6 PYLIBS = -lpython2.5 5 7 8 SRCS=vision.c classify.c classify_hard.c classify_dtree.c 9 OBJS=$(subst .c,.o,$(SRCS)) 6 10 PROG=main 7 CPROG=$(PROG) 8 PPROG=$(PROG).py 11 LIB=_vision.so 9 12 10 #test:VQ: _ml 11 # ./_ml data/both.log 12 # #./_hough ../../training_course/cam-000077.jpeg 13 default: $(PROG) $(LIB) test 13 14 14 test: $(CPROG) 15 #./$CPROG ./line.jpeg 16 # #./$CPROG ./grass.jpeg 17 # #./$CPROG ./notgrass.jpeg 18 ./$(CPROG) ./data/classes/input.jpeg ./data/classes/classes.png 19 # ./$(CPROG) ./tile.png 20 # #./$CPROG ./lines.jpeg 21 # #./$CPROG ./lines.jpeg 22 # #for (i in 00*.jpeg) ./$CPROG $i 23 # #python $PROG.py test_image2.jpeg 15 test: $(PROG) 16 ./$(PROG) ./data/images/cam-000043.jpeg 17 #./$(PROG) ./data/classes/input.jpeg 24 18 25 main: main.o vision.o classify.o classify_hard.o classify_dtree.o 26 gcc -o $@ $+ $(LDFLAGS) 19 # Python rules 20 %.so: %.o $(OBJS) 21 gcc $(CFLAGS) $(DLFLAGS) -o $@ $+ $(LDFLAGS) $(PYLIBS) 22 _%.o: _%.c 23 gcc $(CFLAGS) $(PYFLAGS) -c -o $@ $+ 27 24 28 %.o: %.cpp 29 g++ $(CPPFLAGS) -c -o $@ $< 30 31 %.o: %.c 32 gcc $(CFLAGS) -c -o $@ $< 33 34 _%: _%.c 25 # C rules 26 main: main.o $(OBJS) 35 27 gcc $(CFLAGS) -o $@ $+ $(LDFLAGS) 36 28 37 _%.so: _%.c 38 gcc $(CFLAGS) $(DLFLAGS) -o $@ $+ $(LDFLAGS) 29 # Object rules 30 %.o: %.cpp 31 g++ $(CPPFLAGS) -c -o $@ $+ 32 %.o: %.c 33 gcc $(CFLAGS) -c -o $@ $+ 39 34 35 # Misc 40 36 tags: 41 37 ctags -R 42 43 38 clean: 44 rm -f $( CPROG) *.o *.so *.pyc core out*.jpeg *.out tags39 rm -f $(PROG) *.o *.so *.pyc core out*.jpeg *.out tags -
trunk/software/rb/vision/vision.c
r476 r479 31 31 IplImage *get_image() 32 32 { 33 c har *file = "rb/vision/data/classes/input.jpeg";33 const char *file = "rb/vision/data/classes/input.jpeg"; 34 34 IplImage *image = cvLoadImage(file, 1); 35 35 if (!image) { … … 67 67 cvReleaseImage(&img); 68 68 return transformed; 69 }70 71 CvMat *classify_image(IplImage *input)72 {73 CvSize size = {input->width, input->height};74 IplImage *img = cvCreateImage(size, input->depth, input->nChannels);75 cvCopy(input, img, NULL);76 77 /* Smooth image */78 print_time("Smoothing");79 cvSmooth(img, img, CV_BLUR, 3, 3, 0, 0);80 81 /* Convert image to HSV */82 print_time("To HSV");83 IplImage *hsv = cvCreateImage(size, img->depth, img->nChannels);84 cvCvtColor(img, hsv, CV_BGR2HSV);85 86 /* Threshold image */87 print_time("Marking types");88 CvMat *classes = classify(hsv);89 //CvMat *grass_mask = cvCreateMat(size.height, size.width, CV_8U);90 //CvMat *line_mask = cvCreateMat(size.height, size.width, CV_8U);91 //cvInRangeS(hsv, cvScalar(30, 0, 80, 0), cvScalar(120,90,180,0), grass_mask);92 //cvInRangeS(hsv, cvScalar(100,60,140,0), cvScalar(120,90,254,0), line_mask);93 // TODO, mark obstacles separately94 95 /* Morphological operations */96 //print_time("Expanding lines");97 //int rad = (int)size.width*0.005;98 //IplConvKernel *se = cvCreateStructuringElementEx(rad, rad, rad/2, rad/2, CV_SHAPE_RECT, NULL);99 //cvDilate(line_mask, line_mask, se, 2);100 //cvReleaseStructuringElement(&se);101 102 /* Mark outputs */103 //CvMat *output = cvCreateMat(input->height, input->width, CV_8U);104 //cvSet(output, cvRealScalar(RB_IGNORE), NULL);105 //cvSet(output, cvRealScalar(RB_GRASS), grass_mask);106 //cvSet(output, cvRealScalar(RB_LINE ), line_mask);107 108 /* Release temporary data */109 //cvReleaseMat(&grass_mask);110 //cvReleaseMat(&line_mask);111 cvReleaseImage(&hsv);112 cvReleaseImage(&img);113 114 return classes;115 69 } 116 70 … … 248 202 } 249 203 250 void print_time(c har *label)204 void print_time(const char *label) 251 205 { 252 206 struct timeb tp; -
trunk/software/rb/vision/vision.h
r474 r479 96 96 * This is used for profiling the software 97 97 */ 98 void print_time(c har *label);98 void print_time(const char *label); 99 99 100 100 #endif -
trunk/software/setup.py
r469 r479 27 27 vision_module = Extension( 28 28 'rb.vision._vision', 29 ['rb/vision/_vision.c', 'rb/vision/vision.c', 'rb/vision/main.c'], 29 ['rb/vision/_vision.c', 30 'rb/vision/vision.c', 31 'rb/vision/classify.c', 32 'rb/vision/classify_hard.c', 33 'rb/vision/classify_dtree.cpp'], 30 34 libraries=['cv', 'highgui', 'gsl'], 31 extra_compile_args=['- -std=c99']35 extra_compile_args=['-I/usr/include/opencv -lcv -lhighgui -lgsl'] 32 36 ); 33 37

