Changeset 474
- Timestamp:
- 03/26/09 05:58:24 (3 years ago)
- Location:
- trunk/software/rb/vision
- Files:
-
- 3 added
- 5 modified
-
classify.cpp (added)
-
classify.h (added)
-
examples/dtree.cpp (added)
-
examples/mkfile (modified) (1 diff)
-
main.c (modified) (2 diffs)
-
makefile (modified) (3 diffs)
-
vision.c (modified) (3 diffs)
-
vision.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/rb/vision/examples/mkfile
r372 r474 13 13 14 14 %.o: %.cpp 15 g++ $C PPFLAGS -c -o $target $prereq15 g++ $CFLAGS -c -o $target $prereq 16 16 17 17 %.o: %.c -
trunk/software/rb/vision/main.c
r469 r474 23 23 24 24 #include "vision.h" 25 #include "classify.h" 25 26 26 27 int main(int argc, char **argv) { … … 53 54 int data[3]; 54 55 CV_READ_SEQ_ELEM(data, reader); 55 printf("read: (%d, %d, %d)\n", data[0], data[1], data[2]);56 56 cvCircle(transformed, 57 57 cvPoint(data[1], data[2]), -
trunk/software/rb/vision/makefile
r469 r474 1 CFLAGS=-p -pg -g -Wall -pedantic --std=gnu99 -fgnu89-inline -O3 $(shell pkg-config --cflags opencv gsl) 2 LDFLAGS=-lpython2.5 $(shell pkg-config --libs opencv gsl) 3 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 =-lpython2.5 $(shell pkg-config --libs opencv gsl) 4 DLFLAGS =-shared -nostartfiles -fPIC 4 5 5 6 PROG=main … … 15 16 # #./$CPROG ./grass.jpeg 16 17 # #./$CPROG ./notgrass.jpeg 17 ./$(CPROG) ./data/ images/cimg4753.jpg18 ./$(CPROG) ./data/classes/input.jpeg ./data/classes/classes.png 18 19 # ./$(CPROG) ./tile.png 19 20 # #./$CPROG ./lines.jpeg … … 22 23 # #python $PROG.py test_image2.jpeg 23 24 24 main: main.o vision.o 25 main: main.o vision.o classify.o 25 26 gcc -o $@ $+ $(LDFLAGS) 26 27 28 %.o: %.cpp 29 g++ $(CPPFLAGS) -c -o $@ $< 30 27 31 %.o: %.c 28 gcc $(CFLAGS) -c -o $@ $ *.c32 gcc $(CFLAGS) -c -o $@ $< 29 33 30 34 _%: _%.c -
trunk/software/rb/vision/vision.c
r469 r474 27 27 28 28 #include "vision.h" 29 #include "classify.h" 29 30 30 31 IplImage *get_image() 31 32 { 32 char *file = "rb/vision/data/ images/cimg4753.jpg";33 char *file = "rb/vision/data/classes/input.jpeg"; 33 34 IplImage *image = cvLoadImage(file, 1); 34 35 if (!image) { … … 48 49 49 50 /* transform image */ 50 IplImage *transformed = cvCreateImage(size, img->depth, img->nChannels); 51 CvMat* mat= cvCreateMat( 3, 3, CV_32F ); 52 CvPoint2D32f from[] = { 53 cvPoint2D32f(0 , size.height*0.12), 54 cvPoint2D32f(0 , size.height-1), 55 cvPoint2D32f(size.width-1, size.height-1), 56 cvPoint2D32f(size.width-1, size.height*0.12) 57 }; 58 CvPoint2D32f to[] = { 59 cvPoint2D32f(0 , -62 ), 60 cvPoint2D32f(size.width*0.33, size.height-1), 61 cvPoint2D32f(size.width*0.67, size.height-1), 62 cvPoint2D32f(size.width-1 , -62 ) 63 }; 64 cvGetPerspectiveTransform(from, to, mat); 65 cvWarpPerspective(img, transformed, mat, CV_WARP_FILL_OUTLIERS, cvScalarAll(0)); 66 cvReleaseImage(&img); 67 return transformed; 51 //IplImage *transformed = cvCreateImage(size, img->depth, img->nChannels); 52 //CvMat* mat= cvCreateMat( 3, 3, CV_32F ); 53 //CvPoint2D32f from[] = { 54 // cvPoint2D32f(0 , size.height*0.12), 55 // cvPoint2D32f(0 , size.height-1), 56 // cvPoint2D32f(size.width-1, size.height-1), 57 // cvPoint2D32f(size.width-1, size.height*0.12) 58 //}; 59 //CvPoint2D32f to[] = { 60 // cvPoint2D32f(0 , -62 ), 61 // cvPoint2D32f(size.width*0.33, size.height-1), 62 // cvPoint2D32f(size.width*0.67, size.height-1), 63 // cvPoint2D32f(size.width-1 , -62 ) 64 //}; 65 //cvGetPerspectiveTransform(from, to, mat); 66 //cvWarpPerspective(img, transformed, mat, CV_WARP_FILL_OUTLIERS, cvScalarAll(0)); 67 //cvReleaseImage(&img); 68 //return transformed; 69 return img; 68 70 } 69 71 … … 84 86 85 87 /* Threshold image */ 86 print_time("Marking grass"); 87 CvMat *grass_mask = cvCreateMat(size.height, size.width, CV_8U); 88 CvMat *line_mask = cvCreateMat(size.height, size.width, CV_8U); 89 cvInRangeS(hsv, cvScalar(30, 0, 80, 0), cvScalar(120,90,180,0), grass_mask); 90 cvInRangeS(hsv, cvScalar(100,60,140,0), cvScalar(120,90,254,0), line_mask); 88 print_time("Marking types"); 89 CvMat *classes = classify(hsv); 90 //CvMat *grass_mask = cvCreateMat(size.height, size.width, CV_8U); 91 //CvMat *line_mask = cvCreateMat(size.height, size.width, CV_8U); 92 //cvInRangeS(hsv, cvScalar(30, 0, 80, 0), cvScalar(120,90,180,0), grass_mask); 93 //cvInRangeS(hsv, cvScalar(100,60,140,0), cvScalar(120,90,254,0), line_mask); 91 94 // TODO, mark obstacles separately 92 95 93 96 /* Morphological operations */ 94 print_time("Expanding lines");95 int rad = (int)size.width*0.005;96 IplConvKernel *se = cvCreateStructuringElementEx(rad, rad, rad/2, rad/2, CV_SHAPE_RECT, NULL);97 cvDilate(line_mask, line_mask, se, 2);98 cvReleaseStructuringElement(&se);97 //print_time("Expanding lines"); 98 //int rad = (int)size.width*0.005; 99 //IplConvKernel *se = cvCreateStructuringElementEx(rad, rad, rad/2, rad/2, CV_SHAPE_RECT, NULL); 100 //cvDilate(line_mask, line_mask, se, 2); 101 //cvReleaseStructuringElement(&se); 99 102 100 103 /* Mark outputs */ 101 CvMat *output = cvCreateMat(input->height, input->width, CV_8U);102 cvSet(output, cvRealScalar(RB_IGNORE), NULL);103 cvSet(output, cvRealScalar(RB_GRASS), grass_mask);104 cvSet(output, cvRealScalar(RB_LINE ), line_mask);104 //CvMat *output = cvCreateMat(input->height, input->width, CV_8U); 105 //cvSet(output, cvRealScalar(RB_IGNORE), NULL); 106 //cvSet(output, cvRealScalar(RB_GRASS), grass_mask); 107 //cvSet(output, cvRealScalar(RB_LINE ), line_mask); 105 108 106 109 /* Release temporary data */ 107 cvReleaseMat(&grass_mask);108 cvReleaseMat(&line_mask);110 //cvReleaseMat(&grass_mask); 111 //cvReleaseMat(&line_mask); 109 112 cvReleaseImage(&hsv); 110 113 cvReleaseImage(&img); 111 114 112 return output;115 return classes; 113 116 } 114 117 115 118 CvSeq *get_points(CvMat *classes) 116 119 { 117 int test_data[][3] = {118 {RB_SKY,100,100}, {RB_GRASS,200,100}, {RB_OBSTICLE,300,100},119 {RB_SKY,100,200}, {RB_GRASS,200,200}, {RB_OBSTICLE,300,200},120 {RB_SKY,100,300}, {RB_GRASS,200,300}, {RB_OBSTICLE,300,300},121 };120 //int test_data[][3] = { 121 // {RB_SKY,100,100}, {RB_GRASS,200,100}, {RB_OBSTICLE,300,100}, 122 // {RB_SKY,100,200}, {RB_GRASS,200,200}, {RB_OBSTICLE,300,200}, 123 // {RB_SKY,100,300}, {RB_GRASS,200,300}, {RB_OBSTICLE,300,300}, 124 //}; 122 125 123 126 CvMemStorage *storage = cvCreateMemStorage(0); -
trunk/software/rb/vision/vision.h
r469 r474 27 27 CvPoint end; 28 28 } CvLine; 29 30 /**31 * Standard pixel values32 *33 * The classified image will be represented by these colors34 */35 typedef enum rb_classes_t {36 RB_SKY ,37 RB_GRASS ,38 RB_LINE ,39 RB_OBSTICLE,40 RB_PATH ,41 RB_IGNORE ,42 RB_NUM_CLASSES43 } rb_classes_t;44 const static CvScalar class_colors[256] = {45 [RB_SKY ] = {{0*255, 0*255, 1*255, 0}}, // Blue46 [RB_GRASS ] = {{0*255, 1*255, 0*255, 0}}, // Green47 [RB_LINE ] = {{1*255, 1*255, 1*255, 0}}, // White48 [RB_OBSTICLE] = {{1*255, 0*255, 0*255, 0}}, // Red49 [RB_PATH ] = {{1*255, 0*255, 1*255, 0}}, // Purple50 [RB_IGNORE ] = {{0*255, 0*255, 0*255, 0}} // Black51 };52 29 53 30 /** … … 121 98 void print_time(char *label); 122 99 123 124 100 #endif

