[BUGFIX] Fix overshoot on array index.

This commit is contained in:
Jan Philipp Timme 2016-01-08 17:31:43 +01:00
parent cc78822dfe
commit 3619b9796b

View File

@ -118,7 +118,7 @@ class HoughMachine {
// if so, put it in the list // if so, put it in the list
struct hparam* lines = (struct hparam*) malloc(sizeof(struct hparam) * this->n_ang * this->n_rad); struct hparam* lines = (struct hparam*) malloc(sizeof(struct hparam) * this->n_ang * this->n_rad);
int line = 0; int line = 0;
for(int i=0; i<=this->n_ang*this->n_rad; i++) { for(int i=0; i<this->n_ang*this->n_rad; i++) {
int value = this->hough_arr[i]; int value = this->hough_arr[i];
if(value <= 5) continue; // Ignore small values if(value <= 5) continue; // Ignore small values
// TODO: Check neighbours and compare! // TODO: Check neighbours and compare!
@ -142,15 +142,15 @@ class HoughMachine {
int quadrant = floor(theta / pi_half); int quadrant = floor(theta / pi_half);
std::cout << "Top " << i << ": " << lines[i].value << ", r: " << r << ", theta: " << theta << " quadrand: " << quadrant; std::cout << "Top " << i << ": " << lines[i].value << ", r: " << r << ", theta: " << theta << " quadrand: " << quadrant;
// cos(pi/8) -sin(pi/8) // cos() -sin()
// sin(pi/8) cos(pi/8) // sin() cos()
// Do matrix multiplication // Do matrix multiplication
// Turn r into a x/y vector // Turn r into a x/y vector
double vec_x = r * cos(theta) + 0 * -sin(theta); double vec_x = r * cos(theta) + 0 * -sin(theta);
double vec_y = r * sin(theta) + 0 * cos(theta); double vec_y = r * sin(theta) + 0 * cos(theta);
// find point in image // find point in image
int x = vec_x + this->x_center; double x = vec_x + this->x_center;
int y = vec_y + this->y_center; double y = vec_y + this->y_center;
std::cout << " vec x: " << x << ", vec y: " << y << std::endl; std::cout << " vec x: " << x << ", vec y: " << y << std::endl;
// create vector for line // create vector for line
double vec_target_x = vec_y; 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)); 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_x = vec_target_x / vec_target_len;
vec_target_y = vec_target_y / 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 i = x;
double j = y; double j = y;
while(i < this->working_copy->width() && i > 0 && j < this->working_copy->height() && j > 0) { while(i < this->working_copy->width() && i > 0 && j < this->working_copy->height() && j > 0) {
i += vec_target_x; i += vec_target_x;
j += vec_target_y; j += vec_target_y;
} }
// find second border
int x1 = i; int x1 = i;
int y1 = j; int y1 = j;
i = x; i = x;