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 cv2
|
||||||
import mediapipe as mp
|
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
|
def main() -> None:
|
||||||
cap = cv2.VideoCapture(0)
|
"""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():
|
while cap.isOpened():
|
||||||
# read webcam
|
# read webcam
|
||||||
success, image = cap.read()
|
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)
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||||
results = holistic.process(image)
|
results = holistic.process(image)
|
||||||
|
|
||||||
|
# log landmarks
|
||||||
|
logging.debug(results.face_landmarks)
|
||||||
|
logging.debug(results.pose_landmarks)
|
||||||
|
|
||||||
# draw landmark annotation on the image
|
# draw landmark annotation on the image
|
||||||
image.flags.writeable = True
|
image.flags.writeable = True
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
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:
|
if cv2.waitKey(5) & 0xFF == 27:
|
||||||
break
|
break
|
||||||
|
|
||||||
# close webcam
|
# close webcam
|
||||||
cap.release()
|
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