Changeset 683
- Timestamp:
- 02/20/10 14:47:47 (2 years ago)
- Location:
- branches/2010-image-rec
- Files:
-
- 3 added
- 4 modified
-
README (added)
-
docs/report.pdf (modified) (previous)
-
docs/report.tex (modified) (1 diff)
-
hist_test.m (modified) (11 diffs)
-
images/elphel/cam-000084.jpeg-sobel-v-5.png (added)
-
run.sh (added)
-
sobel.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/2010-image-rec/docs/report.tex
r681 r683 14 14 15 15 \begin{document} 16 \title{ TODO: Pick a title}16 \title{Vision-based obstacle recognition for an autonomous mobile robot in a grassy, outdoor environment} 17 17 \author{Thomas W. Most \and Trenton S. Tabor} 18 18 \date{\today} -
branches/2010-image-rec/hist_test.m
r682 r683 1 function hist_test(fn )1 function hist_test(fn, show_images) 2 2 3 3 % Test how well histogramming works with our test images … … 37 37 38 38 39 fsobel = fspecial('sobel');40 hedges = filter2(fsobel , imbig(:,:,texture_band));41 vedges = filter2(fsobel', imbig(:,:,texture_band));42 edges = sqrt(hedges .^ 2 + vedges .^ 2);43 edges =double(imread([fn '-sobel-v-5.png']))/255;39 %fsobel = fspecial('sobel'); 40 %hedges = filter2(fsobel , imbig(:,:,texture_band)); 41 %vedges = filter2(fsobel', imbig(:,:,texture_band)); 42 %edges = sqrt(hedges .^ 2 + vedges .^ 2); 43 edges = double(imread([fn '-sobel-v-5.png']))/255; 44 44 texture = filter2(fspecial('average', 10), edges); 45 45 texture = filter2(fspecial('average', 10), texture); … … 56 56 57 57 figure(1); 58 im show([edges; texture]);59 60 texture =imresize(texture,.25);58 imwrite(texture, [fn '-texture-full.png']); 59 60 texture = imresize(texture, .25); 61 61 62 62 im(:,:,1:3) = rgb2hsv(im_rgb); … … 65 65 66 66 % Area at the bottom of the image assumed to be grass, clear of obstacles 67 clear_area = im(round(clear_area_top * rows):end -20, ...67 clear_area = im(round(clear_area_top * rows):end, ... 68 68 round(clear_area_left * cols): ... 69 69 round((1 - clear_area_left) * cols), :); … … 91 91 grass_v_mask = grass_v_hist; 92 92 grass_v_mask(grass_v_hist < mean(grass_v_hist) * v_mean_factor) = 0; 93 grass_t_mask = grass_t_hist;94 grass_t_mask(grass_t_hist < mean(grass_t_hist) * t_mean_factor) = 0;93 %grass_t_mask = grass_t_hist; 94 %grass_t_mask(grass_t_hist < mean(grass_t_hist) * t_mean_factor) = 0; 95 95 96 96 % Ungodly slow loop through the pixels … … 99 99 for c = 1:cols 100 100 if grass_h_mask(h(r,c)) && grass_s_mask(s(r,c)) && ... 101 grass_v_mask(v(r,c)) && grass_t_mask(t(r,c))101 grass_v_mask(v(r,c)) ... && grass_t_mask(t(r,c)) 102 102 mask(r,c) = 1; 103 103 end … … 105 105 end 106 106 107 imwrite(mask, [fn '-mask-raw.png']); 108 107 109 % Clean things up a bit 108 110 se = strel('square', 6); 109 111 mask = imclose(mask, se); 112 113 imwrite(mask, [fn, '-mask-closed.png']); 110 114 111 115 tempMask=mask*-1+1; … … 114 118 hold on; 115 119 scatter(bottomlist(:,1),-bottomlist(:,2)); 116 120 print('-depsc', [fn '-obstacle-points.png']); 117 121 118 122 line_mask = texture; 119 for threshold = .42 120 line_mask(texture > threshold & mask == 0) = 1; 121 line_mask(texture <= threshold | mask ~= 0) = 0; 122 figure; 123 imshow(line_mask); 124 end 125 %keyboard; 123 threshold = .42; 124 line_mask(texture > threshold & mask == 0) = 1; 125 line_mask(texture <= threshold | mask ~= 0) = 0; 126 imwrite(line_mask, [fn '-line-mask.png']); 127 126 128 % Display 127 129 figure(2); … … 130 132 % Draw a box over the "clear" area 131 133 top_y = round(clear_area_top * rows); 132 bottom_y = rows -20;134 bottom_y = rows; 133 135 left_x = round(clear_area_left * cols); 134 136 right_x = round((1 - clear_area_left) * cols); … … 136 138 [top_y top_y bottom_y bottom_y top_y],'LineWidth',4,'Color','red'); 137 139 138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 139 140 figure(3); 141 142 [H,T,R] = hough(line_mask); 143 imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit'); 144 xlabel('\theta'), ylabel('\rho'); 145 axis on, axis normal, hold on; 146 P = houghpeaks(H,5,'NHoodSize',[161,161])%ceil(0.3*max(H(:)))); 147 x = T(P(:,2)); 148 y = R(P(:,1)); 149 plot(x,y,'s','color','white'); 150 151 lines = houghlines(line_mask,T,R,P,'FillGap',5,'MinLength',7); 152 figure, imshow(im_rgb), hold on 153 max_len = 0; 154 for k = 1:length(lines) 155 xy = [lines(k).point1; lines(k).point2]; 156 plot(xy(:,1),xy(:,2),'LineWidth',8,'Color','blue'); 157 158 % plot beginnings and ends of lines 159 plot(xy(1,1),xy(1,2),'x','LineWidth',8,'Color','yellow'); 160 plot(xy(2,1),xy(2,2),'x','LineWidth',8,'Color','red'); 161 162 % determine the endpoints of the longest line segment 163 len = norm(lines(k).point1 - lines(k).point2); 164 if ( len > max_len) 165 max_len = len; 166 xy_long = xy; 167 end 168 end 169 170 % highlight the longest line segment 171 plot(xy_long(:,1),xy_long(:,2),'LineWidth',8,'Color','cyan'); 172 173 174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 141 142 figure(3); 143 144 [H,T,R] = hough(line_mask); 145 imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit'); 146 xlabel('\theta'), ylabel('\rho'); 147 axis on, axis normal, hold on; 148 P = houghpeaks(H,5,'NHoodSize',[161,161]); %ceil(0.3*max(H(:)))); 149 x = T(P(:,2)); 150 y = R(P(:,1)); 151 plot(x,y,'s','color','white'); 152 print('-depsc', [fn '-hough-peaks.eps']); 153 154 lines = houghlines(line_mask,T,R,P,'FillGap',5,'MinLength',7); 155 figure, imshow(im_rgb), hold on 156 max_len = 0; 157 for k = 1:length(lines) 158 xy = [lines(k).point1; lines(k).point2]; 159 plot(xy(:,1),xy(:,2),'LineWidth',8,'Color','blue'); 160 161 % plot beginnings and ends of lines 162 plot(xy(1,1),xy(1,2),'x','LineWidth',8,'Color','yellow'); 163 plot(xy(2,1),xy(2,2),'x','LineWidth',8,'Color','red'); 164 165 % determine the endpoints of the longest line segment 166 len = norm(lines(k).point1 - lines(k).point2); 167 if ( len > max_len) 168 max_len = len; 169 xy_long = xy; 170 end 171 end 172 173 % highlight the longest line segment 174 plot(xy_long(:,1),xy_long(:,2),'LineWidth',8,'Color','cyan'); 175 print('-depsc', [fn '-hough-lines.eps']); 176 177 178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 175 179 176 180 fprintf('Done\n'); … … 179 183 180 184 function rgb = bw2rgb(bw) 181 182 rgb = zeros(size(bw, 1), size(bw, 2), 3); 183 rgb(:,:,1) = bw; 184 rgb(:,:,2) = bw; 185 rgb(:,:,3) = bw; 186 187 end 185 rgb = zeros(size(bw, 1), size(bw, 2), 3); 186 rgb(:,:,1) = bw; 187 rgb(:,:,2) = bw; 188 rgb(:,:,3) = bw; 189 end 190 188 191 function bottomlist = bottomFind(bw) 189 list=zeros(size(bw,2),2);190 temp=bw;191 for i = 1:size(bw,2)192 temp(1,:)=1;193 list(i,2)=find(temp(:,i)==1,1,'last');194 list(i,1)=i;195 end196 bottomlist=list;197 end 192 list = zeros(size(bw,2),2); 193 temp = bw; 194 for i = 1:size(bw,2) 195 temp(1,:) = 1; 196 list(i,2) = find(temp(:,i)==1,1,'last'); 197 list(i,1) = i; 198 end 199 bottomlist = list; 200 end -
branches/2010-image-rec/sobel.py
r669 r683 5 5 import cv 6 6 7 fn = sys.argv[1] 7 try: 8 fn = sys.argv[1] 9 operations = [(5, c) for c in sys.argv[2:]] or [(5, 'v')] 10 except IndexError: 11 sys.stderr.write('usage: {0} image-fn [channel...]') 12 sys.exit(2) 8 13 14 # Load the image and split its channels out 9 15 im = cv.LoadImage(fn) 10 16 hsv = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 3) 11 17 cv.CvtColor(im, hsv, cv.CV_BGR2HSV) 12 im = hsv 18 channels = { 19 'h': cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1), 20 's': cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1), 21 'v': cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1), 22 } 23 cv.Split(hsv, channels['h'], channels['s'], channels['v'], None) 13 24 14 for sobel_aperture in (3, 5, 7): 25 # Preallocate buffers 26 27 # The output buffer for the sobel operation 28 sobel = cv.CreateMat(im.height, im.width, cv.CV_32FC1) 29 # 8-bit scaled version of sobel that can be saved to a file 30 sobel_img = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 31 32 # Loop through the operations 33 for (sobel_aperture, channel) in operations: 15 34 print "sobelizing", 16 35 start = time.time() 17 sobel = cv.CreateMat(im.height, im.width, cv.CV_32FC3) 18 #sobel_x = cv.CreateMat(im.height, im.width, cv.CV_32FC3) 19 #sobel_y = cv.CreateMat(im.height, im.width, cv.CV_32FC3) 20 #cv.Sobel(im, sobel_x, 1, 0, 3) 21 #cv.Sobel(im, sobel_y, 0, 1, 3) 22 cv.Sobel(im, sobel, 1, 1, sobel_aperture) 36 cv.Sobel(channels[channel], sobel, 1, 1, sobel_aperture) 23 37 print "took %.2fs" % (time.time() - start) 24 38 25 #cv.ShowImage('window', sobel)26 #cv.WaitKey()27 sobel_img = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 3)28 39 cv.ConvertScale(sobel, sobel_img, 8.0) 29 sobel_h = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 30 sobel_s = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 31 sobel_v = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1) 32 cv.Split(sobel_img, sobel_h, sobel_s, sobel_v, None) 33 cv.SaveImage('%s-sobel-h-%s.png' % (fn, sobel_aperture), sobel_h) 34 cv.SaveImage('%s-sobel-s-%s.png' % (fn, sobel_aperture), sobel_s) 35 cv.SaveImage('%s-sobel-v-%s.png' % (fn, sobel_aperture), sobel_v) 36 print "wrote %s-sobel-[hsv]-%s.png" % (fn, sobel_aperture) 37 sys.exit(0) 40 41 out_fn = '{fn}-sobel-{channel}-{aperture}.png'.format(fn=fn, channel=channel, aperture=sobel_aperture) 42 cv.SaveImage(out_fn, sobel_img) 43 print "wrote {0}".format(out_fn) 38 44 39 45 #print "median"

