Finish 2.3.1 exercise 1
This commit is contained in:
@@ -13,6 +13,15 @@ Abbildungen dargestellt.
|
|||||||
|
|
||||||
|
|
||||||
## Anleitung
|
## 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
|
### Treiber virtuelle Kamera
|
||||||
Die Grundfunktion der CV-App ist einsatzbereit, sobald dieses Repository erfolgreich installiert ist. Sie können Ihre
|
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.
|
Webcam einlesen und CV-Algorithmen auf den Videostream anwenden.
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class InvisCloak (Algorithm):
|
|||||||
|
|
||||||
# Stores the current image to data folder
|
# Stores the current image to data folder
|
||||||
cv2.imwrite(f"results/{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}_original_image.png",
|
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
|
# Create RGB histogram
|
||||||
self._221_RGB(self.middle_value_picture)
|
self._221_RGB(self.middle_value_picture)
|
||||||
@@ -71,6 +71,14 @@ class InvisCloak (Algorithm):
|
|||||||
# Create HSV histogram
|
# Create HSV histogram
|
||||||
self._222_HSV(self.middle_value_picture)
|
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):
|
def _plotNoise(self, img, name:str):
|
||||||
height, width = np.array(img.shape[:2])
|
height, width = np.array(img.shape[:2])
|
||||||
@@ -136,14 +144,16 @@ class InvisCloak (Algorithm):
|
|||||||
Hier steht Ihr Code zu Aufgabe 2.2.1 (RGB)
|
Hier steht Ihr Code zu Aufgabe 2.2.1 (RGB)
|
||||||
- Histogrammberechnung und Analyse
|
- Histogrammberechnung und Analyse
|
||||||
"""
|
"""
|
||||||
# Names of the color spectrums
|
# Names of the colors in histogram
|
||||||
channels = ["b", "g", "r"]
|
channels = ["b", "g", "r"]
|
||||||
|
|
||||||
|
# Calc histogram
|
||||||
for index, channel_name in enumerate(channels):
|
for index, channel_name in enumerate(channels):
|
||||||
hist = cv2.calcHist([img], [index], None, [256], [0, 256])
|
hist = cv2.calcHist([img], [index], None, [256], [0, 256])
|
||||||
plt.plot(hist, color=channel_name)
|
plt.plot(hist, color=channel_name)
|
||||||
plt.xlim([0, 256])
|
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.savefig(f"results/{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}_histogram_{colorspectrum}.png")
|
||||||
plt.clf()
|
plt.clf()
|
||||||
|
|
||||||
@@ -153,14 +163,37 @@ class InvisCloak (Algorithm):
|
|||||||
Hier steht Ihr Code zu Aufgabe 2.2.2 (HSV)
|
Hier steht Ihr Code zu Aufgabe 2.2.2 (HSV)
|
||||||
- Histogrammberechnung und Analyse im HSV-Raum
|
- 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")
|
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)
|
Hier steht Ihr Code zu Aufgabe 2.3.1 (StatischesSchwellwertverfahren)
|
||||||
- Binärmaske erstellen
|
- 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")
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user