From 3619b9796b70592d80fcb234f9bf2e9267fbbd6f Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 8 Jan 2016 17:31:43 +0100 Subject: [PATCH] [BUGFIX] Fix overshoot on array index. --- hough_machine.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hough_machine.cpp b/hough_machine.cpp index 4c6a252..fa161ac 100644 --- a/hough_machine.cpp +++ b/hough_machine.cpp @@ -118,7 +118,7 @@ class HoughMachine { // if so, put it in the list struct hparam* lines = (struct hparam*) malloc(sizeof(struct hparam) * this->n_ang * this->n_rad); int line = 0; - for(int i=0; i<=this->n_ang*this->n_rad; i++) { + for(int i=0; in_ang*this->n_rad; i++) { int value = this->hough_arr[i]; if(value <= 5) continue; // Ignore small values // TODO: Check neighbours and compare! @@ -142,15 +142,15 @@ class HoughMachine { int quadrant = floor(theta / pi_half); std::cout << "Top " << i << ": " << lines[i].value << ", r: " << r << ", theta: " << theta << " quadrand: " << quadrant; - // cos(pi/8) -sin(pi/8) - // sin(pi/8) cos(pi/8) + // cos() -sin() + // sin() cos() // Do matrix multiplication // Turn r into a x/y vector double vec_x = r * cos(theta) + 0 * -sin(theta); double vec_y = r * sin(theta) + 0 * cos(theta); // find point in image - int x = vec_x + this->x_center; - int y = vec_y + this->y_center; + double x = vec_x + this->x_center; + double y = vec_y + this->y_center; std::cout << " vec x: " << x << ", vec y: " << y << std::endl; // create vector for line double vec_target_x = vec_y; @@ -159,13 +159,14 @@ class HoughMachine { double vec_target_len = sqrt(pow(vec_target_x, 2) + pow(vec_target_y, 2)); vec_target_x = vec_target_x / vec_target_len; vec_target_y = vec_target_y / vec_target_len; - // find first out of bounds condition + // find first border double i = x; double j = y; while(i < this->working_copy->width() && i > 0 && j < this->working_copy->height() && j > 0) { i += vec_target_x; j += vec_target_y; } + // find second border int x1 = i; int y1 = j; i = x;