chore: move code to main function
This commit is contained in:
parent
434cea77c1
commit
0ed01b9172
36
src/main.py
36
src/main.py
|
@ -1,14 +1,19 @@
|
|||
import logging
|
||||
|
||||
import cv2
|
||||
import mediapipe as mp
|
||||
|
||||
mp_drawing = mp.solutions.drawing_utils # type: ignore
|
||||
mp_drawing_styles = mp.solutions.drawing_styles # type: ignore
|
||||
mp_holistic = mp.solutions.holistic # type: ignore
|
||||
|
||||
# open webcam
|
||||
cap = cv2.VideoCapture(0)
|
||||
def main() -> None:
|
||||
"""Main function."""
|
||||
mp_drawing = mp.solutions.drawing_utils # type: ignore
|
||||
mp_drawing_styles = mp.solutions.drawing_styles # type: ignore
|
||||
mp_holistic = mp.solutions.holistic # type: ignore
|
||||
|
||||
with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
|
||||
# open webcam
|
||||
cap = cv2.VideoCapture(0)
|
||||
|
||||
with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
|
||||
while cap.isOpened():
|
||||
# read webcam
|
||||
success, image = cap.read()
|
||||
|
@ -22,6 +27,10 @@ with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=
|
|||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
results = holistic.process(image)
|
||||
|
||||
# log landmarks
|
||||
logging.debug(results.face_landmarks)
|
||||
logging.debug(results.pose_landmarks)
|
||||
|
||||
# draw landmark annotation on the image
|
||||
image.flags.writeable = True
|
||||
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
||||
|
@ -44,5 +53,16 @@ with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=
|
|||
if cv2.waitKey(5) & 0xFF == 27:
|
||||
break
|
||||
|
||||
# close webcam
|
||||
cap.release()
|
||||
# close webcam
|
||||
cap.release()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# setup logging format
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format="%(asctime)s %(name)s %(levelname)-8s %(message)s",
|
||||
datefmt="(%F %T)",
|
||||
)
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue