Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Frank Tjado Ihmels
medienverarbeitung17.projectmood
Commits
55169ea5
Commit
55169ea5
authored
Nov 08, 2017
by
Arne Gerdes
Browse files
Histogram hinzugefügt
parent
fb016012
Changes
1
Hide whitespace changes
Inline
Side-by-side
projectmood/Haarcascade
View file @
55169ea5
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment