I have this code where I label fingers using MediaPipe and OpenCV:
import cv2
import mediapipe as mp
from mediapipe import solutions
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(
static_image_mode=False,
max_num_hands=2,
min_detection_confidence=0.5,
min_tracking_confidence=0.5,
)
mp_drawing = mp.solutions.drawing_utils
finger_indices = [
mp_hands.HandLandmark.THUMB_TIP,
mp_hands.HandLandmark.INDEX_FINGER_TIP,
mp_hands.HandLandmark.MIDDLE_FINGER_TIP,
mp_hands.HandLandmark.RING_FINGER_TIP,
mp_hands.HandLandmark.PINKY_TIP,
]
def label_fingers(frame, fingers, hand_landmarks, frame_width, frame_height):
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 1.0
color = (255, 0, 0)
thickness = 2
line_type = cv2.LINE_AA
for idx, finger in enumerate(finger_indices):
landmark = hand_landmarks.landmark[finger]
x = int(landmark.x * frame_width)
y = int(landmark.y * frame_height)
text = str(fingers[idx])
org = (x, y)
cv2.putText(frame, text, org, font, font_scale, color, thickness, line_type)
async def process_video_stream(frame, fingers):
frame = cv2.resize(frame, (600, 400))
frame = cv2.flip(frame, 1)
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
result = hands.process(rgb_frame)
if result.multi_hand_landmarks:
frame_height, frame_width = frame.shape[:2]
for hand_landmarks in result.multi_hand_landmarks:
mp_drawing.draw_landmarks(
frame,
hand_landmarks,
mp_hands.HAND_CONNECTIONS,
solutions.drawing_styles.get_default_hand_landmarks_style(),
solutions.drawing_styles.get_default_hand_connections_style(),
)
label_fingers(frame, fingers, hand_landmarks, frame_width, frame_height)
return frame
The code works well, but I get the following warning message:
/home/khalid/.local/lib/python3.10/site-packages/google/protobuf/symbol_database.py:55: UserWarning: SymbolDatabase.GetPrototype() is deprecated. Please use message_factory.GetMessageClass() instead. SymbolDatabase.GetPrototype() will be removed soon.
warnings.warn('SymbolDatabase.GetPrototype() is deprecated. Please '
I don’t know where in the code the deprecated SymbolDatabase.GetPrototype()
function is being called so I can replace it with the new message_factory.GetMessageClass()
method. How can I locate and update this deprecated function usage?