基于MediaPipe的手部特征点识别
MediaPipe简介
MediaPipe Solutions 提供了一套库和工具,可以在安卓或者windows应用中快速应用人工智能 (AI) 和机器学习 (ML) 技术。
MediaPipe 手部地标任务可检测图片中手部的特征点。识别效果如下
环境配置
python -m pip install mediapipe
运行代码
import mediapipe as mp
from mediapipe.tasks import python
BaseOptions = mp.tasks.BaseOptions
HandLandmarker = mp.tasks.vision.HandLandmarker
HandLandmarkerOptions = mp.tasks.vision.HandLandmarkerOptions
VisionRunningMode = mp.tasks.vision.RunningMode
# 加载模型
options = HandLandmarkerOptions(
base_options=BaseOptions(model_asset_path='model/hand_landmarker.task'),
running_mode=VisionRunningMode.IMAGE)
with HandLandmarker.create_from_options(options) as landmarker:
mp_image = mp.Image.create_from_file('./image/a.jpg')
# 检测图片
hand_landmarker_result = landmarker.detect(mp_image)
# 输出手的关键点
print(hand_landmarker_result)
输出结果
HandLandmarkerResult(handedness=[[Category(index=1, score=0.9459662437438965, display_name='Left', category_name='Left')]], hand_landmarks=[[NormalizedLandmark(x=0.5290346741676331, y=0.8187840580940247, z=3.174700680119713e-07, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.4484105110168457, y=0.7732243537902832, z=-0.03075455315411091, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.3810454308986664, y=0.6866939067840576, z=-0.052056632936000824, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.33181697130203247, y=0.6147985458374023, z=-0.07278180122375488, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.28900274634361267, y=0.560761034488678, z=-0.09389756619930267, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.43227246403694153, y=0.4703798294067383, z=-0.029644589871168137, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.39301061630249023, y=0.33941853046417236, z=-0.05450108274817467, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.3721613883972168, y=0.2534501552581787, z=-0.07634947448968887, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.35551917552948, y=0.17865553498268127, z=-0.09304636716842651, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.4823477864265442, y=0.43757355213165283, z=-0.03536772355437279, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.47116559743881226, y=0.2744345963001251, z=-0.055556535720825195, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.4666796326637268, y=0.17104032635688782, z=-0.07358471304178238, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.46402132511138916, y=0.08638948202133179, z=-0.08801455050706863, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.53156578540802, y=0.4503312110900879, z=-0.04591694474220276, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.5318034291267395, y=0.29948270320892334, z=-0.0690978467464447, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.5335848927497864, y=0.20017921924591064, z=-0.09021823108196259, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.5348951816558838, y=0.1156383752822876, z=-0.10539528727531433, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.5789802074432373, y=0.4953954815864563, z=-0.059340327978134155, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.6133036613464355, y=0.3942757844924927, z=-0.07918249815702438, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.638502836227417, y=0.3260626494884491, z=-0.092025525867939, visibility=0.0, presence=0.0), NormalizedLandmark(x=0.6581178903579712, y=0.2595255970954895, z=-0.10176999866962433, visibility=0.0, presence=0.0)]], hand_world_landmarks=[[Landmark(x=0.012887902557849884, y=0.08369775116443634, z=0.02169019542634487, visibility=0.0, presence=0.0), Landmark(x=-0.01810395158827305, y=0.06716234982013702, z=0.005550411995500326, visibility=0.0, presence=0.0), Landmark(x=-0.03653212636709213, y=0.05187749117612839, z=-0.0053679971024394035, visibility=0.0, presence=0.0), Landmark(x=-0.0606301873922348, y=0.03301876038312912, z=-0.01467543002218008, visibility=0.0, presence=0.0), Landmark(x=-0.08052900433540344, y=0.011681696400046349, z=-0.020814580842852592, visibility=0.0, presence=0.0), Landmark(x=-0.028123382478952408, y=0.0011320854537189007, z=0.0022898740135133266, visibility=0.0, presence=0.0), Landmark(x=-0.03646745905280113, y=-0.024606864899396896, z=-0.007287601940333843, visibility=0.0, presence=0.0), Landmark(x=-0.04623487591743469, y=-0.045148856937885284, z=-0.01855948381125927, visibility=0.0, presence=0.0), Landmark(x=-0.05742239952087402, y=-0.05820189416408539, z=-0.04638492316007614, visibility=0.0, presence=0.0), Landmark(x=-0.005197027698159218, y=-0.005314752459526062, z=0.005884634796530008, visibility=0.0, presence=0.0), Landmark(x=-0.0045807939022779465, y=-0.043435558676719666, z=-0.005011055618524551, visibility=0.0, presence=0.0), Landmark(x=-0.013069529086351395, y=-0.06594625860452652, z=-0.025721462443470955, visibility=0.0, presence=0.0), Landmark(x=-0.01720215007662773, y=-0.08636726438999176, z=-0.047411683946847916, visibility=0.0, presence=0.0), Landmark(x=0.01882200874388218, y=-0.0035621775314211845, z=-0.0010493824956938624, visibility=0.0, presence=0.0), Landmark(x=0.0158691443502903, y=-0.03264676779508591, z=-0.01168868038803339, visibility=0.0, presence=0.0), Landmark(x=0.01356110256165266, y=-0.05471034720540047, z=-0.029167117550969124, visibility=0.0, presence=0.0), Landmark(x=0.010571113787591457, y=-0.07351168990135193, z=-0.04976153373718262, visibility=0.0, presence=0.0), Landmark(x=0.029267607256770134, y=0.011042852886021137, z=-0.004063688218593597, visibility=0.0, presence=0.0), Landmark(x=0.044259436428546906, y=-0.008888565935194492, z=-0.00678011542186141, visibility=0.0, presence=0.0), Landmark(x=0.0552644208073616, y=-0.029306873679161072, z=-0.016462478786706924, visibility=0.0, presence=0.0), Landmark(x=0.05928361415863037, y=-0.042335450649261475, z=-0.02878321148455143, visibility=0.0, presence=0.0)]])
解码对应点
根据图片自行解码图片数据