Changeset 716
- Timestamp:
- 03/03/10 04:04:50 (2 years ago)
- Location:
- trunk/software/rb/vision
- Files:
-
- 2 modified
-
_processing.c (modified) (7 diffs)
-
makefile (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/rb/vision/_processing.c
r714 r716 25 25 #include "_camera.h" 26 26 27 // The following macros return pointers to pixels in 1- and 3-channel images, respectively. 28 #define IMAGE_PIXEL_C1(image, x, y) ((guint8*) (image->imageData + image->widthStep * y + x)) 29 #define IMAGE_PIXEL_C3(image, x, y) ((guint8*) (image->imageData + image->widthStep * y + x * 3)) 30 31 27 32 static PyTypeObject *PyGObjectType = NULL; 28 33 static PyTypeObject *IplImageObjectType = NULL; … … 85 90 int sobel_aperture = 5; 86 91 int blur_aperture = 3; 92 int hist_bins = 100; 93 // Histogram bins below these thresholds are zeroed. 94 int hist_s_low = 50; 95 int hist_v_low = 100; 96 97 inline int hist_bin(guint8 pixel_value) { 98 return pixel_value * hist_bins / 255.0; 99 } 87 100 88 101 // Calculate the "working" image size … … 99 112 CvMat *sobel; 100 113 IplImage *texture; 114 int *hist_h; 115 int *hist_s; 116 int *hist_v; 101 117 102 118 hsv_full = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3); … … 107 123 texture = cvCreateImage(cvSize(working_width, working_height), IPL_DEPTH_8U, 1); 108 124 output = cvCreateImage(cvSize(working_width, working_height), IPL_DEPTH_8U, 3); 125 hist_h = malloc(sizeof(int) * hist_bins); // TODO: Check this return value 126 hist_s = malloc(sizeof(int) * hist_bins); // TODO: Check this return value 127 hist_v = malloc(sizeof(int) * hist_bins); // TODO: Check this return value 109 128 110 129 // Colorspace conversion and scaling … … 112 131 cvSplit(hsv_full, NULL, NULL, v_full, NULL); 113 132 cvResize(hsv_full, hsv, CV_INTER_AREA); 133 134 // Create the output image 135 cvResize(input, output, CV_INTER_AREA); 114 136 115 137 // Calculate "texture" channel … … 119 141 cvSmooth(texture, texture, CV_BLUR, blur_aperture, 0, 0, 0); 120 142 143 // Calculate the location of the "safe region", which will be histogrammed in 144 // order to determine what the grass looks like. 145 int tl_x = working_width * 0.2; 146 int tl_y = working_height * 0.8; 147 int br_x = working_width - tl_x - 1; 148 int br_y = working_height - 1; 149 150 // Generate the ground histogram 151 for (int x = tl_x; x <= br_x; x++) { 152 for (int y = tl_y; y <= br_y; y++) { 153 guint8 *pixel = IMAGE_PIXEL_C3(hsv, x, y); 154 hist_h[hist_bin(pixel[0])]++; 155 hist_s[hist_bin(pixel[1])]++; 156 hist_v[hist_bin(pixel[2])]++; 157 } 158 } 159 160 // Low-pass filter the histograms 161 for (int i = 0; i < hist_bins; i++) { 162 if (hist_s[i] < hist_s_low) hist_s[i] = 0; 163 if (hist_v[i] < hist_v_low) hist_v[i] = 0; 164 } 165 166 for (int x = 0; x < working_width; x++) { 167 for (int y = 0; y < working_height; y++) { 168 guint8 *hsv_pixel = IMAGE_PIXEL_C3(hsv, x, y); 169 guint8 *out_pixel = IMAGE_PIXEL_C3(output, x, y); 170 if (hist_h[hist_bin(hsv_pixel[0])] && 171 hist_s[hist_bin(hsv_pixel[1])] && 172 hist_v[hist_bin(hsv_pixel[2])]) { 173 out_pixel[0] = 0; 174 out_pixel[1] = 255; 175 out_pixel[2] = 0; 176 } 177 } 178 } 179 180 121 181 // Create output image 122 cvCvtColor(texture, output, CV_GRAY2BGR);182 //cvCvtColor(texture, output, CV_GRAY2BGR); 123 183 124 184 cvReleaseImage(&hsv_full); … … 128 188 cvReleaseMat(&sobel); 129 189 cvReleaseImage(&texture); 190 free(hist_h); 191 free(hist_s); 192 free(hist_v); 130 193 Py_END_ALLOW_THREADS 131 194 -
trunk/software/rb/vision/makefile
r713 r716 1 CFLAGS := -p -pg -g -Wall -Werror -Wno-unused - pedantic -fPIC --std=gnu99 -fgnu89-inline -O3 $(shell pkg-config --cflags opencv gsl glib-2.0 gobject-2.0)1 CFLAGS := -p -pg -g -Wall -Werror -Wno-unused -fPIC --std=gnu99 -fgnu89-inline -O3 $(shell pkg-config --cflags opencv gsl glib-2.0 gobject-2.0) 2 2 #CFLAGS := -p -pg -g -Wall -Werror -pedantic -fPIC -O3 $(shell pkg-config --cflags opencv gsl) 3 3 CPPFLAGS := -p -pg -g -Wall -Werror -Wno-unused -pedantic -fPIC -O3 $(shell pkg-config --cflags opencv gsl)

