Skip to content
Snippets Groups Projects
Commit 9781b4b5 authored by Joel Steffens's avatar Joel Steffens
Browse files

Filtereinstellungen und Multi-Diff-Filter hinzugefügt

parent 4f185e19
Branches
No related tags found
No related merge requests found
Filter/IMG_23_05_2023_17_16_31.png

8.22 KiB

Filter/IMG_23_05_2023_17_26_27.png

6.82 KiB

Filter/IMG_23_05_2023_17_32_16.png

7.49 KiB

......@@ -7,7 +7,7 @@ import pandas as pd
VIDEO = 'Videomaterial/WIN_20230414_13_41_55_Pro.mp4'
capture = cv2.VideoCapture(VIDEO)
capture.set(cv2.CAP_PROP_POS_FRAMES, 30 * 40) # skip 40 seconds
last = None
frame = None
......@@ -39,14 +39,16 @@ def nothing_cb(val):
# To control the Size of the Disply
cv2.namedWindow(window, cv2.WINDOW_AUTOSIZE)
cv2.createTrackbar('Line Threshold: ', window, line_threshold, 100, nothing_cb)
cv2.createTrackbar('Canny_Min', window, 50, 255, nothing_cb)
cv2.createTrackbar('Canny_Max', window, 100, 255, nothing_cb)
cv2.createTrackbar('Diff_Mix', window, 40, 100, nothing_cb)
import filters
pipeline = [
('Original', filters.none),
('Gray scale', filters.grayscale),
('Contrast and Blur', filters.medianBlur),
('Video Diff', filters.video_absdiff),
('Video Diff Multiple', filters.video_absdiff2),
('Canny edge detection', filters.filter_canny),
('Morph close', filters.filter_close),
#('Morph open', filters.filter_open),
......@@ -57,7 +59,7 @@ pipeline = [
state = {} # Empty dictionary to store filters state
info = {
'abs_diff': 5, # 5 images for difference,
'abs_diff': 3, # 3 images for difference,
'dim': (1920, 1080), #
'params': {}
}
......@@ -71,7 +73,9 @@ while capture.isOpened():
frame, _ = filters.resize(None, frame, None)
# Apply
info['params']['line'] = cv2.getTrackbarPos('Line Threshold: ', window)
info['params']['mix'] = cv2.getTrackbarPos('Diff_Mix', window) / 100.0
info['params']['canny_min'] = cv2.getTrackbarPos('Canny_Min', window)
info['params']['canny_max'] = cv2.getTrackbarPos('Canny_Max', window)
result = frame
for i, (name, filter) in enumerate(pipeline):
......
......@@ -2,6 +2,9 @@ import cv2 as cv
import numpy as np
import pandas as pd
from collections import deque
def none(info, image, state):
return image, False
......@@ -77,6 +80,9 @@ min_threshold = 30
max_threshold = 110
def filter_canny(info, image, state):
min_threshold = info['params']['canny_min']
max_threshold = info['params']['canny_max']
image = cv.Canny(image, min_threshold, max_threshold)
return image, False
......@@ -99,6 +105,9 @@ def filter_close(info, image, state):
def points_extract(info, image, state):
points = find_points(image)
if points is None:
return None, False
overlay = np.zeros((image.shape[0], image.shape[1], 3), np.uint8)
for y, x in points:
......@@ -151,6 +160,24 @@ def filter_all(info, image, state):
cv.polylines(overlay, [points], False, (255, 0, 0), thickness=6)
return overlay, True
def video_absdiff2(info, image, state):
if 'buffer' not in state:
state['buffer'] = deque(maxlen=info['abs_diff'])
buffer = state['buffer']
mix = info['params']['mix']
buffer.append(image)
if len(buffer) >= 2:
diff = np.zeros((image.shape[0], image.shape[1], 1), np.uint8)
for i in range(0, len(buffer) - 1):
diff_frame = cv.absdiff(buffer[i], buffer[i+1]) # Difference
diff = cv.addWeighted(diff, 1.0, diff_frame, 1.0 - mix, 0.0)
return diff, False
else:
return None, False
def video_absdiff(info, image, state):
if 'last' not in state or state['last'] is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment