line 311: code fix suggestion for webcam input
existing code results in error: AttributeError: __enter__ INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
This commit is contained in:
parent
a92cff7a60
commit
a6fef0becb
|
@ -308,15 +308,13 @@ with mp_face_mesh.FaceMesh(
|
||||||
# For webcam input:
|
# For webcam input:
|
||||||
drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
|
drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
|
||||||
cap = cv2.VideoCapture(0)
|
cap = cv2.VideoCapture(0)
|
||||||
with mp_face_mesh.FaceMesh(
|
face_mesh = mp_face_mesh.FaceMesh(min_detection_confidence=0.5, min_tracking_confidence=0.5)
|
||||||
min_detection_confidence=0.5,
|
while cap.isOpened():
|
||||||
min_tracking_confidence=0.5) as face_mesh:
|
|
||||||
while cap.isOpened():
|
|
||||||
success, image = cap.read()
|
success, image = cap.read()
|
||||||
if not success:
|
if not success:
|
||||||
print("Ignoring empty camera frame.")
|
print("Ignoring empty camera frame.")
|
||||||
# If loading a video, use 'break' instead of 'continue'.
|
# If loading a video, use 'break' instead of 'continue'.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Flip the image horizontally for a later selfie-view display, and convert
|
# Flip the image horizontally for a later selfie-view display, and convert
|
||||||
# the BGR image to RGB.
|
# the BGR image to RGB.
|
||||||
|
@ -330,16 +328,16 @@ with mp_face_mesh.FaceMesh(
|
||||||
image.flags.writeable = True
|
image.flags.writeable = True
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
||||||
if results.multi_face_landmarks:
|
if results.multi_face_landmarks:
|
||||||
for face_landmarks in results.multi_face_landmarks:
|
for face_landmarks in results.multi_face_landmarks:
|
||||||
mp_drawing.draw_landmarks(
|
mp_drawing.draw_landmarks(
|
||||||
image=image,
|
image=image,
|
||||||
landmark_list=face_landmarks,
|
landmark_list=face_landmarks,
|
||||||
connections=mp_face_mesh.FACE_CONNECTIONS,
|
connections=mp_face_mesh.FACE_CONNECTIONS,
|
||||||
landmark_drawing_spec=drawing_spec,
|
landmark_drawing_spec=drawing_spec,
|
||||||
connection_drawing_spec=drawing_spec)
|
connection_drawing_spec=drawing_spec)
|
||||||
cv2.imshow('MediaPipe FaceMesh', image)
|
cv2.imshow('MediaPipe FaceMesh', image)
|
||||||
if cv2.waitKey(5) & 0xFF == 27:
|
if cv2.waitKey(5) & 0xFF == 27:
|
||||||
break
|
break
|
||||||
cap.release()
|
cap.release()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user