Skip to content
Snippets Groups Projects
Commit 88559f8a authored by Midras Lappe's avatar Midras Lappe
Browse files

Gitter erweitert sodass Felder mit weniger als zwei Nnachbarn entfernt werden

parent 5fd72477
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import pandas as pd ...@@ -7,6 +7,7 @@ import pandas as pd
import filters import filters
VIDEO = 'Videomaterial/WIN_20230602_14_45_52_Pro.mp4' VIDEO = 'Videomaterial/WIN_20230602_14_45_52_Pro.mp4'
#VIDEO = 'Videomaterial/WIN_20230414_13_41_55_Pro.mp4'
capture = cv2.VideoCapture(VIDEO) capture = cv2.VideoCapture(VIDEO)
capture.set(cv2.CAP_PROP_POS_FRAMES, 30 * 0) # skip 40 seconds capture.set(cv2.CAP_PROP_POS_FRAMES, 30 * 0) # skip 40 seconds
...@@ -57,8 +58,9 @@ pipeline = [ ...@@ -57,8 +58,9 @@ pipeline = [
('Green filter abs', filters.green_absfilter), ('Green filter abs', filters.green_absfilter),
('Canny edge detection', filters.filter_canny), ('Canny edge detection', filters.filter_canny),
('Morph close', filters.filter_close), ('Morph close', filters.filter_close),
('gitter_filter', filters.gitter), # ('gitter_filter', filters.gitter),
#('Morph open', filters.filter_open), #('Morph open', filters.filter_open),
('Einzelne Rauswerfen', filters.sortOut),
('Point extraction', filters.points_extract), ('Point extraction', filters.points_extract),
('Polyfit lines', filters.points_overlay) ('Polyfit lines', filters.points_overlay)
] ]
......
filters.py 100644 → 100755
...@@ -2,6 +2,7 @@ import cv2 as cv ...@@ -2,6 +2,7 @@ import cv2 as cv
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from scipy import signal
from collections import deque from collections import deque
currentfig = None currentfig = None
...@@ -39,7 +40,8 @@ def gitter(info, image, state): ...@@ -39,7 +40,8 @@ def gitter(info, image, state):
ax.grid(True, which='major') ax.grid(True, which='major')
diff_x = 40 diff_x = 40
diff_y = 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_xticks(range(0,1280, diff_x))
ax.set_yticks(range(0,720, diff_y)) ax.set_yticks(range(0,720, diff_y))
...@@ -49,6 +51,15 @@ def gitter(info, image, state): ...@@ -49,6 +51,15 @@ def gitter(info, image, state):
subimg = image[y:y+diff_y,x:x+diff_x] subimg = image[y:y+diff_y,x:x+diff_x]
indices = np.where(subimg > 0) indices = np.where(subimg > 0)
if (indices[1].size > treshold): 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 x_so = indices[1] + x
y_so = indices[0] + y y_so = indices[0] + y
...@@ -68,8 +79,56 @@ def gitter(info, image, state): ...@@ -68,8 +79,56 @@ def gitter(info, image, state):
return image, False 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 # Cut green kanal
def greenfilter(info, image, state): def greenfilter(info, image, state):
# Umwandeln des Bildes in den Farbraum HSV # Umwandeln des Bildes in den Farbraum HSV
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment