iOS 解析AR人体姿势识别数据

iOS 解析AR人体姿势识别数据

个人兴趣,研究了一下iOS的人体姿势识别,遇到一些问题,最终进行了解决,下面分享出来

问题

Apple开发网站上提供了demo,
demo地址
但是纯Swift语言的,并且使用的模型是其自己的模型,我是想将识别到的姿势应用到自己的模型上的。,所以需要姿势的原始数据,于是做了研究。

我是用Objective-C语言解析的,进行了简单的封装,如果需要可以使用。

方法

@interface ARBodyInfo : NSObject
@property(nonatomic,assign)SCNVector3 positions;
@property(nonatomic,assign)SCNVector4 orientation;

//身体
@property(nonatomic,assign)SCNMatrix4 hips_Transform;
@property(nonatomic,assign)SCNMatrix4 spine_1_Transform;
@property(nonatomic,assign)SCNMatrix4 spine_2_Transform;
@property(nonatomic,assign)SCNMatrix4 spine_3_Transform;
@property(nonatomic,assign)SCNMatrix4 spine_4_Transform;
@property(nonatomic,assign)SCNMatrix4 spine_5_Transform;
@property(nonatomic,assign)SCNMatrix4 spine_6_Transform;
@property(nonatomic,assign)SCNMatrix4 spine_7_Transform;

//脖子
@property(nonatomic,assign)SCNMatrix4 neck_1_Transform;
@property(nonatomic,assign)SCNMatrix4 neck_2_Transform;
@property(nonatomic,assign)SCNMatrix4 neck_3_Transform;
@property(nonatomic,assign)SCNMatrix4 neck_4_Transform;

//头
@property(nonatomic,assign)SCNMatrix4 head_Transform;
@property(nonatomic,assign)SCNMatrix4 nose_Transform;
@property(nonatomic,assign)SCNMatrix4 jaw_Transform;
@property(nonatomic,assign)SCNMatrix4 chin_Transform;

//手
@property(nonatomic,assign)SCNMatrix4 right_shoulder_1_Transform;
@property(nonatomic,assign)SCNMatrix4 right_arm_Transform;
@property(nonatomic,assign)SCNMatrix4 right_forearm_Transform;
@property(nonatomic,assign)SCNMatrix4 right_hand_Transform;

@property(nonatomic,assign)SCNMatrix4 left_shoulder_1_Transform;
@property(nonatomic,assign)SCNMatrix4 left_arm_Transform;
@property(nonatomic,assign)SCNMatrix4 left_forearm_Transform;
@property(nonatomic,assign)SCNMatrix4 left_hand_Transform;

//脚
@property(nonatomic,assign)SCNMatrix4 right_upLeg_Transform;
@property(nonatomic,assign)SCNMatrix4 right_leg_Transform;
@property(nonatomic,assign)SCNMatrix4 right_foot_Transform;
@property(nonatomic,assign)SCNMatrix4 right_toes_Transform;
@property(nonatomic,assign)SCNMatrix4 right_toesEnd_Transform;

@property(nonatomic,assign)SCNMatrix4 left_upLeg_Transform;
@property(nonatomic,assign)SCNMatrix4 left_leg_Transform;
@property(nonatomic,assign)SCNMatrix4 left_foot_Transform;
@property(nonatomic,assign)SCNMatrix4 left_toes_Transform;
@property(nonatomic,assign)SCNMatrix4 left_toesEnd_Transform;

@end

@interface ARBodyParsingTool : NSObject
/**
 传入监听到的ARBodyAnchor数据,会返回解析的ARBodyInfo
 */
+(ARBodyInfo*)parsingForAr:(ARBodyAnchor*)bodyInfo;

说明

ARBodyInfo是我自己封装的类,里面是解析后的数据,包括整个身体的位置positions和朝向orientation信息,和身体具体部位的位置信息Transform

使用

-(void)session:(ARSession *)session didUpdateAnchors:(NSArray<__kindof ARAnchor *> *)anchors{
    dispatch_async(dispatch_get_main_queue(), ^{
        for (ARAnchor * object in anchors) {
            if([object isKindOfClass:[ARBodyAnchor class]]){
                ARBodyAnchor * bodyClass = (ARBodyAnchor *)object;
               ARBodyInfo * info =  [ARBodyParsingTool parsingForAr:bodyClass];
               //根据info,部署自己模型各个位置的姿势
            }
        }
    });
}

文件

iOSAR人体姿势识别解析

联系作者

期待你的点赞和关注!如有疑问,联系作者。
在这里插入图片描述

posted @ 2021-12-24 18:17  这个我知道  阅读(177)  评论(0编辑  收藏  举报