diff --git a/CV-App/README.md b/CV-App/README.md index 035b46d..5a6238d 100644 --- a/CV-App/README.md +++ b/CV-App/README.md @@ -13,6 +13,15 @@ Abbildungen dargestellt. ## Anleitung +### Kurzanleitung Verwendung magischer Umhang + +1. Programm starten via PyCharm und Strg+Shift+F10 +2. Umschalten auf "invis_cloak" Skript mit Taste "7" +3. Kamera positionieren, Hintergrund leeren, Hintergrund aufnehmen mit mittlerer Maustaste +4. Roten Gegenstand vor Körper halten. Körper sollte nun verschwinden. Linke Maustaste drücken um Bilder aufzunehmen +5. Die Ergebnisse landen im Ordner results/ und werden beim Programm-Neustart gelöscht! + + ### Treiber virtuelle Kamera Die Grundfunktion der CV-App ist einsatzbereit, sobald dieses Repository erfolgreich installiert ist. Sie können Ihre Webcam einlesen und CV-Algorithmen auf den Videostream anwenden. diff --git a/CV-App/algorithms/invis_cloak.py b/CV-App/algorithms/invis_cloak.py index 82c4c9d..04d74fd 100644 --- a/CV-App/algorithms/invis_cloak.py +++ b/CV-App/algorithms/invis_cloak.py @@ -63,7 +63,7 @@ class InvisCloak (Algorithm): # Stores the current image to data folder cv2.imwrite(f"results/{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}_original_image.png", - self.picture_buffer[4]) + self.picture_buffer[self.n - 1]) # Create RGB histogram self._221_RGB(self.middle_value_picture) @@ -71,6 +71,14 @@ class InvisCloak (Algorithm): # Create HSV histogram self._222_HSV(self.middle_value_picture) + # Get binary mask and write it to file + binary_mask = self._23_SegmentUndBildmodifizierung(self.middle_value_picture, True) + cv2.imwrite(f"results/{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}_binary_mask.png", + binary_mask) + elif event == cv2.EVENT_MBUTTONUP: + # Save current image as background + cv2.imwrite(f"results/background.png", self.picture_buffer[self.n - 1]) + def _plotNoise(self, img, name:str): height, width = np.array(img.shape[:2]) @@ -136,14 +144,16 @@ class InvisCloak (Algorithm): Hier steht Ihr Code zu Aufgabe 2.2.1 (RGB) - Histogrammberechnung und Analyse """ - # Names of the color spectrums + # Names of the colors in histogram channels = ["b", "g", "r"] + # Calc histogram for index, channel_name in enumerate(channels): hist = cv2.calcHist([img], [index], None, [256], [0, 256]) plt.plot(hist, color=channel_name) plt.xlim([0, 256]) + # Save histogram, clear cache plt.savefig(f"results/{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}_histogram_{colorspectrum}.png") plt.clf() @@ -153,14 +163,37 @@ class InvisCloak (Algorithm): Hier steht Ihr Code zu Aufgabe 2.2.2 (HSV) - Histogrammberechnung und Analyse im HSV-Raum """ + # Convert image to hsv, call _221_RGB to create histogram self._221_RGB(cv2.cvtColor(img, cv2.COLOR_BGR2HSV), "hsv") - def _23_SegmentUndBildmodifizierung (self, img): + def _23_SegmentUndBildmodifizierung (self, img, save_binary_mask = False): """ Hier steht Ihr Code zu Aufgabe 2.3.1 (StatischesSchwellwertverfahren) - Binärmaske erstellen """ + # 0 = blue, 1 = green, 2 = red + selected_color_channel = 2 + + # Color threshold values for color deletion + lower_bound, upper_bound = 100, 255 + + # Creating binary mask + binary_mask = (lower_bound < img[:, :, selected_color_channel]) * (img[:, :, selected_color_channel] < upper_bound) + + # Store binary mask to results folder + if save_binary_mask: + cv2.imwrite(f"results/{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}_binary_mask.png", + binary_mask * 256) + + try: + # Get background image + background = cv2.imread("results/background.png") + + # Apply mask to image + img[binary_mask] = background[binary_mask] + except: + print("No background image") """