computer vision - Edge following with camera -


i want follow rightmost edge in following picture line following robot.

source9

i tried simple "thresholding", unfortunately, includes blurry white halo:

posterized9

the reason threshold obtain clean line sobel edge detector:

edge9

is there algorithm can use isolate edge/move along edge? 1 using seems error prone, it's best 1 i've been able figure out far.

note: edge may curve or aligned in direction, point on edge lie close center of image. here's video of i'm trying do. doesn't follow edge after (1:35) due halo screwing thresholding.


here's sample:

source6

posterized6

edge6

here, floodfill centermost edge separate little bump in bottom right corner:

final6

simplest method (vertical line)

if know image have black on right side of line, here's simple method:

1) apply sobel operator find first derivative in x direction. result image negative gradient strongest. (use large kernel size average out halo effect. can apply gaussian blur image first, more averaging if 7x7 kernel isn't enough.)

2) each row of image, find index of minimum (i.e. negative) value. that's estimate of line position in row.

3) whatever want that. (maybe take median of line positions, on top half , bottom half of image, estimate of 2 points describe line.)

slightly more advanced (arbitrary line)

use if don't know direction of line, know it's straight enough can approximate straight line.

1)

dx = cv2.sobel(grayscaleimg,cv2.cv.cv_32f,1,0,ksize=7) dy = cv2.sobel(grayscaleimg,cv2.cv.cv_32f,0,1,ksize=7) angle = np.atan2(dy,dx) magnitudesquared = np.square(dx)+np.square(dy) 

you have angle (in radians) , magnitude of gradient @ each point in image.

2) here can use basic numpy operations find line: filter points keep points magnitudesquared > threshold. grab common angle (np.bincount() useful that). know line's angle.

3) further filter points keep points close angle. have points on line. fit line through coordinates of points.

most advanced , brittle (arbitrary curve)

if really need handle curve, here's 1 way:

1) use method above threshold image. manually tune threshold until white/black division happens want it. (probably 127 not right threshold. if lighting conditions consistent, might able find threshold works. confirm works across multiple images.)

2) use opencv's findcontours() fit curve white/black boundary. if it's choppy, use approxpolydp() simplify it.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -