From 88559f8a201b33727d54afc0b3f0952e1f512428 Mon Sep 17 00:00:00 2001 From: Midras Lappe <midras.lappe@hs-bochum.de> Date: Fri, 23 Jun 2023 15:28:08 +0200 Subject: [PATCH] Gitter erweitert sodass Felder mit weniger als zwei Nnachbarn entfernt werden --- filter_pipeline.py | 4 ++- filters.py | 63 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) mode change 100644 => 100755 filters.py diff --git a/filter_pipeline.py b/filter_pipeline.py index a1d7fee..c2a9a59 100644 --- a/filter_pipeline.py +++ b/filter_pipeline.py @@ -7,6 +7,7 @@ import pandas as pd import filters VIDEO = 'Videomaterial/WIN_20230602_14_45_52_Pro.mp4' +#VIDEO = 'Videomaterial/WIN_20230414_13_41_55_Pro.mp4' capture = cv2.VideoCapture(VIDEO) capture.set(cv2.CAP_PROP_POS_FRAMES, 30 * 0) # skip 40 seconds @@ -57,8 +58,9 @@ pipeline = [ ('Green filter abs', filters.green_absfilter), ('Canny edge detection', filters.filter_canny), ('Morph close', filters.filter_close), - ('gitter_filter', filters.gitter), + # ('gitter_filter', filters.gitter), #('Morph open', filters.filter_open), + ('Einzelne Rauswerfen', filters.sortOut), ('Point extraction', filters.points_extract), ('Polyfit lines', filters.points_overlay) ] diff --git a/filters.py b/filters.py old mode 100644 new mode 100755 index 3b344d5..fdd1487 --- a/filters.py +++ b/filters.py @@ -2,6 +2,7 @@ import cv2 as cv import numpy as np import pandas as pd import matplotlib.pyplot as plt +from scipy import signal from collections import deque currentfig = None @@ -39,16 +40,26 @@ def gitter(info, image, state): ax.grid(True, which='major') diff_x = 40 diff_y = 40 - treshold = 30 + treshold = 5 + haspoints = np.zeros([(int)(1280/diff_x),(int)(720/diff_y)]) ax.set_xticks(range(0,1280, diff_x)) ax.set_yticks(range(0,720, diff_y)) - + for x in range(0,1280,diff_x): for y in range(0,720,diff_y): subimg = image[y:y+diff_y,x:x+diff_x] indices = np.where(subimg > 0) if (indices[1].size > treshold): + haspoints[(int)(x/diff_x),(int)(y/diff_y)]=1 + neighbours= findneighbours(haspoints) + + for x in range(0,1280,diff_x): + for y in range(0,720,diff_y): + subimg = image[y:y+diff_y,x:x+diff_x] + indices = np.where(subimg > 0) + if (neighbours[(int)(x/diff_x),(int)(y/diff_y)]>2): + x_so = indices[1] + x y_so = indices[0] + y @@ -68,8 +79,56 @@ def gitter(info, image, state): + + return image, False +def sortOut(info, image, state): + + + # image Range ((1280, 720)) + + + diff_x = 40 + diff_y = 40 + treshold = 30 + haspoints = np.zeros([(int)(1280/diff_x),(int)(720/diff_y)]) + + + for x in range(0,1280,diff_x): + for y in range(0,720,diff_y): + subimg = image[y:y+diff_y,x:x+diff_x] + indices = np.where(subimg > 0) + if (indices[1].size > treshold): + haspoints[(int)(x/diff_x),(int)(y/diff_y)]=1 + neighbours= findneighbours(haspoints) + + for x in range(0,1280,diff_x): + for y in range(0,720,diff_y): + if (neighbours[(int)(x/diff_x),(int)(y/diff_y)]<3): + image[y:y+diff_y,x:x+diff_x] = 0 + + + return image, False + + +def findneighbours(haspoints): + #print(haspoints) + #flat = np.ravel(haspoints) + # Definition des Kernel-Filters für die Nachbarschaft (umliegenden Felder) + #kernel = np.ones((3, 3)) # 3x3 Kernel aus Einsen + + # Berechnung der Summe der umliegenden Felder + #sum_neighbors = np.convolve2d(haspoints, kernel, mode='same') + + kernel = np.ones([3,3]) # 3x3 Kernel aus Einsen + result = signal.convolve2d(haspoints, kernel, mode='same') + result[result < 3] = 0 + result = result * haspoints + return result + + + # Cut green kanal def greenfilter(info, image, state): # Umwandeln des Bildes in den Farbraum HSV -- GitLab