From 7f186fa4e968a28ccb8157c3ad6e8955370937ec Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 8 Jan 2016 13:52:58 +0100 Subject: [PATCH] [TASK] Finish sorting the hough lines. --- hough_machine.cpp | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/hough_machine.cpp b/hough_machine.cpp index 7a78450..bd4bdec 100644 --- a/hough_machine.cpp +++ b/hough_machine.cpp @@ -11,10 +11,10 @@ #include "lazy_image.cpp" -struct houghdot { - double point; +struct hparam { double theta; double r; + int value; }; class HoughMachine { @@ -113,13 +113,41 @@ class HoughMachine { }; void drawLines(int n) { - // TODO: Sort stuff in hough_arr by value, get the n top values and draw them using bresenham. - - // put all of them into a custom struct (a, r, value). Now sort these fuckers! - + n += 1; + // for each value: if == 0 ignore + // else check if bigger than all neighbours + // 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++) { + int value = this->hough_arr[i]; + if(value == 0) continue; // Ignore zeros + // TODO: Check neighbours and compare! + // Store value if bigger than neighbours + int a = i / this->n_ang; + int r = i - (a*this->n_ang); + double theta = this->d_ang * a; + //std::cout << "[" << theta << ", " << r << "] " << value << std::endl; + lines[line].r = r; + lines[line].theta = theta; + lines[line].value = value; + line++; + } + // Now sort it + qsort((void*) lines, line, sizeof(struct hparam), HoughMachine::comp); + for(int i=0; i<10; i++) std::cout << "Top " << i << ": " << lines[i].value << std::endl; }; + static int comp(const void* a, const void* b) { + struct hparam param_a = *((struct hparam*) a); + struct hparam param_b = *((struct hparam*) b); + int f = param_a.value; + int s = param_b.value; + if (f > s) return -1; + if (f < s) return 1; + return 0; + } void setPixelDebug(int x, int y, int color=0) { int our_color = QColor::fromRgb(0, 255, 0).rgb();