diff --git a/filter_pipeline.py b/filter_pipeline.py index 8dae2467f95e0d22723959d472689b5605494fb0..a1d7feeabddbd48321ee94878f58df1bc5fb1558 100644 --- a/filter_pipeline.py +++ b/filter_pipeline.py @@ -44,8 +44,8 @@ cv2.namedWindow(window, cv2.WINDOW_NORMAL) cv2.createTrackbar('Canny_Min', window, 90, 255, nothing_cb) cv2.createTrackbar('Canny_Max', window, 150, 255, nothing_cb) cv2.createTrackbar('Diff_Mix', window, 40, 100, nothing_cb) -cv2.createTrackbar('HSV_Min', window, 40, 255, nothing_cb) -cv2.createTrackbar('HSV_Max', window, 100, 255, nothing_cb) +cv2.createTrackbar('HSV_Min', window, 50, 180, nothing_cb) +cv2.createTrackbar('HSV_Max', window, 100, 180, nothing_cb) pipeline = [ diff --git a/filters.py b/filters.py index d7437714b3d43f971bc28814acad37dad85f151c..d6151b9e24a7e276a92ded7562b078aa18ba2f63 100644 --- a/filters.py +++ b/filters.py @@ -31,9 +31,9 @@ def gitter(info, image, state): ax.set_ylim([720, 0]) ax.grid(True, which='major') - diff_x = 50 - diff_y = 50 - treshold = 50 + diff_x = 40 + diff_y = 40 + treshold = 30 ax.set_xticks(range(0,1280, diff_x)) ax.set_yticks(range(0,720, diff_y)) @@ -47,17 +47,21 @@ def gitter(info, image, state): y_so = indices[0] + y list_xy = np.column_stack((x_so, y_so)).astype(np.int32) - poly_xy = polyfit2(list_xy, x, x + diff_x, y, y + diff_y) + complete, poly_xy = trendline(list_xy, x, x + diff_x, y, y + diff_y) list_of_lines.append(poly_xy) ax.scatter(x_so, y_so, c='r') + #ax.plot(complete[:,0], complete[:,1], 'g') ax.plot(poly_xy[:,0], poly_xy[:,1], 'b') - #fig.show() + #print(complete) + if complete is None or poly_xy is None: + print('Poly xy none') #plot_points(poly_xy[:,0], poly_xy[:,1], x_so, y_so) - plt.show() + + return image, False # Cut green kanal @@ -174,6 +178,55 @@ def polyfit2(n_list, xs, xe, ys, ye): return None +def trendline(n_list, x1, x2, y1, y2): + if n_list is not None and len(n_list) >= 2: + m, b = np.polyfit(n_list[:,0], n_list[:,1], 1) + + # f_n(x) = m*x+b + # f_i(y) = (y-b)/m + + # x1 < x2 and y1 < y2 + + # Ersten beide Punkte (links x1 und rechts x2) + y_f1 = m*x1+b # (x1, y_f1) + y_f2 = m*x2+b # (x2, y_f2) + + # Letzten beide Punkte (oben y1 und unten y2) + if m != 0: + x_f1 = (y1-b)/m # (x_f1, y1) + x_f2 = (y2-b)/m # (x_f2, y2) + else: + x_f1 = x1 + x_f2 = x2 + + # Schnittpunkt mit vertikaler Grenze (links) + if y_f1 >= y1 and y_f1 <= y2: + p1 = [x1, y_f1] + # Schnittpunkt mit horizontaler Grenze (oben) + elif x_f1 >= x1 and x_f1 <= x2: + p1 = [x_f1, y1] + # Schnittpunkt mit horizontaler Grenze (unten) + elif x_f2 >= x1 and x_f2 <= x2: + p1 = [x_f2, y2] + else: + raise ValueError('Not possible') + + # Schnittpunkt mit vertikaler Grenze (rechts) + if y_f2 >= y1 and y_f2 <= y2: + p2 = [x2, y_f2] + # Schnittpunkt mit horizontaler Grenze (oben) + elif x_f1 >= x1 and x_f1 <= x2: + p2 = [x_f1, y1] + # Schnittpunkt mit horizontaler Grenze (unten) + elif x_f2 >= x1 and x_f2 <= x2: + p2 = [x_f2, y2] + else: + raise ValueError('Not possible') + + return [np.array([[x1, y_f1], [x2, y_f2], [x_f1, y1], [x_f2, y2]]), np.array([p1, p2])] + + return None + def polyfit(n_list,n=4): if n_list is not None: p = np.polyfit(n_list[:,0], n_list[:,1], n)