[TASK] Finish sorting the hough lines.

This commit is contained in:
Jan Philipp Timme 2016-01-08 13:52:58 +01:00
parent 85f2dd2824
commit 7f186fa4e9

View File

@ -11,10 +11,10 @@
#include "lazy_image.cpp" #include "lazy_image.cpp"
struct houghdot { struct hparam {
double point;
double theta; double theta;
double r; double r;
int value;
}; };
class HoughMachine { class HoughMachine {
@ -113,13 +113,41 @@ class HoughMachine {
}; };
void drawLines(int n) { void drawLines(int n) {
// TODO: Sort stuff in hough_arr by value, get the n top values and draw them using bresenham. n += 1;
// for each value: if == 0 ignore
// put all of them into a custom struct (a, r, value). Now sort these fuckers! // 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) { void setPixelDebug(int x, int y, int color=0) {
int our_color = QColor::fromRgb(0, 255, 0).rgb(); int our_color = QColor::fromRgb(0, 255, 0).rgb();