diff --git a/Filter/IMG_23_05_2023_17_16_31.png b/Filter/IMG_23_05_2023_17_16_31.png new file mode 100644 index 0000000000000000000000000000000000000000..491007e4433cc27327fedb0af6cfba6f6fe8244d Binary files /dev/null and b/Filter/IMG_23_05_2023_17_16_31.png differ diff --git a/Filter/IMG_23_05_2023_17_26_27.png b/Filter/IMG_23_05_2023_17_26_27.png new file mode 100644 index 0000000000000000000000000000000000000000..451667bb69242f5c119c764d3d6fda3ff8561646 Binary files /dev/null and b/Filter/IMG_23_05_2023_17_26_27.png differ diff --git a/Filter/IMG_23_05_2023_17_32_16.png b/Filter/IMG_23_05_2023_17_32_16.png new file mode 100644 index 0000000000000000000000000000000000000000..2a71bd5eab336e954f0b998de6543b52b084e651 Binary files /dev/null and b/Filter/IMG_23_05_2023_17_32_16.png differ diff --git a/filter_pipeline.py b/filter_pipeline.py index c44ffcd19b0089d7b5177bc64463c813fac2f47d..1c22f6f55b7085e18485731827e67cea4ed6d971 100644 --- a/filter_pipeline.py +++ b/filter_pipeline.py @@ -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): diff --git a/filters.py b/filters.py index af1770aee55ce7515efb5fe0e9264cf69075872f..35e492903d0109339c1376a4bf5311b7b7aeea0c 100644 --- a/filters.py +++ b/filters.py @@ -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 @@ -73,10 +76,13 @@ def polyfit(n_list): return None -min_threshold = 30 -max_threshold = 110 +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: