When I run the following Python file
import tensorflow as tf
import tensorflow_hub as hub
from tensorflow_docs.vis import embed
import numpy as np
import cv2
import json
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
mp_hands = mp.solutions.hands
def detectHands():
print("detect hands")
with mp_hands.Hands(
static_image_mode=True,
model_complexity=1,
min_detection_confidence=0.5,
max_num_hands=2) as hands:
image_path_1 = './210.jpg'
hands_image_input = tf.io.read_file(image_path_1)
hands_image_input = tf.image.decode_jpeg(hands_image_input)
# print(" read_file = cv2.imread(image_path_1);")
# read_file = cv2.imread(image_path_1)
# print("handsImage = cv2.flip(cv2.imread(input_image), 1)")
# print(hands_image_input)
# hands_image_input = cv2.flip(cv2.imread(image_path_1), 1)
# Convert the BGR image to RGB before processing.
# print("hands.process(read_file)",read_file)
# print("hands ")
print("hands ")
print(hands)
# flipped_image = cv2.cvtColor(read_file, cv2.COLOR_BGR2RGB)
print("flipped_image ")
# print(flipped_image)
results = hands.process(hands_image_input)
print('results!:', results)
# Print handedness and draw hand landmarks on the image.
print('Handedness:', results.multi_handedness)
if not results.multi_hand_landmarks:
return
image_height, image_width, _ = image.shape
annotated_image = image.copy()
for hand_landmarks in results.multi_hand_landmarks:
print('hand_landmarks:', hand_landmarks)
print(
f'Index finger tip coordinates: (',
f'{hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].x * image_width}, '
f'{hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].y * image_height})'
)
mp_drawing.draw_landmarks(
annotated_image,
hand_landmarks,
mp_hands.HAND_CONNECTIONS,
mp_drawing_styles.get_default_hand_landmarks_style(),
mp_drawing_styles.get_default_hand_connections_style())
# cv2.imwrite(
# './tmp/annotated_image.png', cv2.flip(annotated_image, 1))
# Draw hand world landmarks.
if not results.multi_hand_world_landmarks:
return
for hand_world_landmarks in results.multi_hand_world_landmarks:
mp_drawing.plot_landmarks(
hand_world_landmarks, mp_hands.HAND_CONNECTIONS, azimuth=5)
detectHands()
It shows the following output, but it never goes below the following line
results = hands.process(hands_image_input)
/Users/richardlindhout/PycharmProjects/pythonProject1/venv/bin/python /Users/richardlindhout/go/src/bitbucket.org/omoda-applicatiebeheer/media-service/external_helpers/pythonProject1/main.py
2022-03-02 16:33:52.222319: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
detect hands
hands
<mediapipe.python.solutions.hands.Hands object at 0x15902c2e0>
flipped_image
Why doesn't it timeout or why does it take extremely long for results?