Initial commit with project files
This commit is contained in:
32
4_Farbrepräsentationen/ü2/README.md
Normal file
32
4_Farbrepräsentationen/ü2/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Übung 2: BGR zu HSV
|
||||
|
||||
In dieser Übung wird der HSV Farbraum betrachtet. Die Information der Farbe wird
|
||||
durch die drei Werte
|
||||
|
||||
- H: Helligkeit (Hue)
|
||||
- S: Sättigung (Saturation)
|
||||
- V: Value (Helligkeit)
|
||||
|
||||
repräsentiert.
|
||||
|
||||
In der folgenden Abbildung wird der Farbraum visuell dargestellt:
|
||||
|
||||

|
||||
|
||||
|
||||
## Aufgabe a)
|
||||
Lesen Sie Ihre Kamera aus und geben Sie das Bild "live" wieder.
|
||||
Konvertieren Sie den eingelesenen Videostream aus Aufgabe in den HSV Farbraum.
|
||||
Reduzieren Sie die Helligkeit, indem Sie einen der drei Farbkanäle um 30% reduzieren.
|
||||
Konvertieren Sie das Bild daraufhin zurück in den RGB Farbraum.
|
||||
|
||||
Die Lösung findet sich in der Datei [l_a.py](l_a.py).
|
||||
|
||||
## Aufgabe b)
|
||||
Modifizieren Sie Aufgabe a) so, dass die Helligkeit zyklisch zwischen 0% und 100%
|
||||
variiert.
|
||||
Die Lösung findet sich in der Datei [l_b.py](l_b.py).
|
||||
|
||||
|
||||
|
||||
|
||||
0
4_Farbrepräsentationen/ü2/a.py
Normal file
0
4_Farbrepräsentationen/ü2/a.py
Normal file
24
4_Farbrepräsentationen/ü2/l_a.py
Normal file
24
4_Farbrepräsentationen/ü2/l_a.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
camera = cv2.VideoCapture(0)
|
||||
|
||||
signum = 1
|
||||
factor = 0.3
|
||||
while True:
|
||||
ret, bgr = camera.read()
|
||||
|
||||
''' Aufgabe a) '''
|
||||
hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)
|
||||
hsv[:, :, 2] = np.round(hsv[:, :, 2] * factor)
|
||||
bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
||||
|
||||
''' Visualisierung '''
|
||||
# Display the resulting frame
|
||||
cv2.imshow('frame', bgr)
|
||||
if 27 == cv2.waitKey(1): # Taste "q"
|
||||
break
|
||||
|
||||
# When everything done, release the capture
|
||||
camera.release()
|
||||
cv2.destroyAllWindows()
|
||||
33
4_Farbrepräsentationen/ü2/l_b.py
Normal file
33
4_Farbrepräsentationen/ü2/l_b.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
camera = cv2.VideoCapture(0)
|
||||
|
||||
signum = 1
|
||||
factor = 0.3
|
||||
while True:
|
||||
ret, bgr = camera.read()
|
||||
|
||||
''' Aufgabe a) '''
|
||||
hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)
|
||||
hsv[:, :, 2] = np.round(hsv[:, :, 2] * factor)
|
||||
bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
|
||||
|
||||
''' Aufgabe b) '''
|
||||
if factor == 0:
|
||||
signum = 1
|
||||
elif factor == 1:
|
||||
signum = -1
|
||||
factor += signum * 0.02
|
||||
factor = min(1, factor)
|
||||
factor = max(0, factor)
|
||||
|
||||
''' Visualisierung '''
|
||||
# Display the resulting frame
|
||||
cv2.imshow('frame', bgr)
|
||||
if 27 == cv2.waitKey(1): # Taste "q"
|
||||
break
|
||||
|
||||
# When everything done, release the capture
|
||||
camera.release()
|
||||
cv2.destroyAllWindows()
|
||||
Reference in New Issue
Block a user