Last active
November 23, 2016 08:21
-
-
Save maxbeutel/a6b60b04bfef954caa84647e7859dc51 to your computer and use it in GitHub Desktop.
Hough Transform - Voting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// calculate the longest line that can occur in the image (hypotenuse) | |
let max_line_length = (img_width as f64).hypot(img_height as f64).ceil(); | |
// Create the accumulator matrix, x-axis is angle theta, y-axis is distance rho | |
let mut accumulator: na::DMatrix<u64> = na::DMatrix::new_zeros(180, max_line_length as usize); | |
// Flip y axis when reading image, as the image has 0/0 at the top left, | |
// but it's easier for us to work with when the origin 0/0 is at the bottom left | |
for y in 0..img_height { | |
for x in 0..img_width { | |
if !detect_edge(x, y_flipped) { | |
continue; | |
} | |
for i in 0..3 { | |
let theta = (i as f64 + 1.0) * 30.0; | |
let rho = (x as f64) * theta.to_radians().cos() + (y_flipped as f64) * theta.to_radians().sin(); | |
let rho_rounded = rho.round(); | |
accumulator[(theta as usize, rho_rounded as usize)] += 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment