Commit 55169ea5 authored by Arne Gerdes's avatar Arne Gerdes

Histogram hinzugefügt

parent fb016012
......@@ -8,19 +8,23 @@ detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# create the landmark predictor
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
cap = cv2.VideoCapture(0)
while (True):
while True:
# Read the Video
ret, img = cap.read()
# convert the video to grayscale
# convert the video to gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Contrast Limited Adaptive Histogram Equalization
clahe = cv2.createCLAHE(clipLimit=4.0, tileGridSize=(8, 8))
clahe_image = clahe.apply(gray)
# Detect faces in the video
faces = detector.detectMultiScale(
gray,
clahe_image,
scaleFactor=1.05,
minNeighbors=5,
minSize=(100, 100),
......@@ -29,16 +33,14 @@ while (True):
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(gray, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.rectangle(clahe_image, (x, y), (x + w, y + h), (255, 0, 0), 2)
# Converting the OpenCV rectangle coordinates to Dlib rectangle
dlib_rect = dlib.rectangle(int(x), int(y), int(x + w), int(y + h))
print
dlib_rect
# use that rectangle as the bounding box to detect the face landmarks,
# and extract out the coordinates of the landmarks so OpenCV can use them
detected_landmarks = predictor(gray, dlib_rect).parts()
detected_landmarks = predictor(clahe_image, dlib_rect).parts()
landmarks = np.matrix([[p.x, p.y] for p in detected_landmarks])
# enumerate through the landmark coordinates and mark them on the image
......@@ -46,16 +48,16 @@ while (True):
pos = (point[0, 0], point[0, 1])
# annotate the positions
cv2.putText(gray, str(idx), pos,
cv2.putText(clahe_image, str(idx), pos,
fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=0.4,
color=(0, 0, 255))
# draw points on the landmark positions
cv2.circle(gray, pos, 3, color=(0, 255, 255))
cv2.circle(clahe_image, pos, 3, color=(0, 255, 255))
# draw the annotated image on an OpenCV window
cv2.imshow('Window', gray)
cv2.imshow('Window', clahe_image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment