From fada1f1b858110374853ddfaed676a0c869c76ac Mon Sep 17 00:00:00 2001 From: Bene Date: Mon, 3 Jul 2023 15:50:17 +0200 Subject: [PATCH] second commit --- .idea/.gitignore | 3 ++ .idea/WebcamTest.iml | 10 +++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ subtract_mask.py | 40 +++++++++++++++++++ 7 files changed, 77 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/WebcamTest.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 subtract_mask.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/WebcamTest.iml b/.idea/WebcamTest.iml new file mode 100644 index 0000000..aee9ef2 --- /dev/null +++ b/.idea/WebcamTest.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a971a2c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0187264 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/subtract_mask.py b/subtract_mask.py new file mode 100644 index 0000000..3155b62 --- /dev/null +++ b/subtract_mask.py @@ -0,0 +1,40 @@ +import cv2 + +# Lade das erste Frame und bestimme seine Größe +cap = cv2.VideoCapture(0) +ret, frame = cap.read() +height, width, channels = frame.shape + +# Definiere einen Bereich, der ausgeschlossen werden soll +exclude_area = [[0, 0], [0, 100], [width, 100], [width, 0]] + +# Erstelle eine Maske +mask = np.zeros((height, width), np.uint8) +pts = np.array([exclude_area], np.int32) +cv2.fillPoly(mask, pts, 255) + +# Initialisiere den Hintergrundsubtraktor +fgbg = cv2.createBackgroundSubtractorMOG2() + +while True: + # Lese das nächste Frame + ret, frame = cap.read() + if not ret: + break + + # Wende die Maske auf das Frame an + masked_frame = cv2.bitwise_and(frame, frame, mask=mask) + + # Subtrahiere das Hintergrund-Modell von dem aktuellen Frame + fgmask = fgbg.apply(masked_frame) + + # Wende eine Schwellenwertbildung auf das Differenzbild an + thresh = cv2.threshold(fgmask, 127, 255, cv2.THRESH_BINARY)[1] + + # Zeige das Ergebnis an + cv2.imshow('frame', thresh) + if cv2.waitKey(1) & 0xFF == ord('q'): + break + +cap.release() +cv2.destroyAllWindows() \ No newline at end of file