手势检测是MNNKit提供的移动端AI解决方案SDK,在端上提供了精准实时的手势检测和识别能力,基于它应用可以拓展丰富的业务场景和玩法。
异步创建HandGestureDetector实例,主线程中回调。
context:上下文环境
createConfig:创建时的配置参数,可用来配置是视频检测还是图片检测
listener:创建完成后的回调
public static void createInstanceAsync (Context context, HandCreateConfig createConfig, InstanceCreatedListener<HandGestureDetector> listener)
检测器会同时进行人手检测和手势识别,人手检测包含检测和跟踪两个动作,检测就是找到人手的位置,跟踪就是人手移动时重新定位其位置。视频模式下并不是每一帧都检测,默认每20帧检测一次,其余帧只做跟踪,适合视频流输入的场景;而图片模式下每一次调用都会进行检测,适合图片检测的场景。
通用数据的推理,支持多种数据格式输入。视频流检测场景中,可以使用摄像头的回调数据作为该接口的输入。
检测对象,可能包含多个手势的检测结果,详见HandGestureDetectionReport
public synchronized HandGestureDetectionReport[] inference(byte[] data, int width, int height, MNNCVImageFormat format, int inAngle, int outAngle, MNNFlipType flipType)
Bitmap检测接口,除了输入数据为bitmap,其余参数一样。
注意:如检测单个图片,创建时需配置为图片检测模式。
public synchronized HandGestureDetectionReport[] inference(Bitmap bitmap, int inAngle, int outputAngle, MNNFlipType outputFlip)
HandGestureDetector实例用完之后需要手动释放,否则会产生native的内存泄露。
public synchronized void release()
public enum MNNCVImageFormat {
RGBA(0),
RGB(1),
BGR(2),
GRAY(3),
BGRA(4),
YUV_NV21(11);
...
}
public class HandGestureDetectionReport {
public enum HandGestureType {
HAND_GESTURE_TYPE_FINGER_HEART(0), // 比心
HAND_GESTURE_TYPE_HAND_OPEN(1), // 五指张开
HAND_GESTURE_TYPE_INDEX_FINGER(2), // 竖食指
HAND_GESTURE_TYPE_FIST(3), // 握拳
HAND_GESTURE_TYPE_THUMB_UP(4), // 竖大拇指
HAND_GESTURE_TYPE_OTHER(5); // 其他
public int label;
HandGestureType(int t) {
label = t;
}
}
// 手势类型
public HandGestureType type;
// 手的区域
public RectF rect;
public final float score; // score of dtected object
public final int id; // id for each detected object
...
}
异步创建MNNHandGestureDetector实例
+ (void)createInstanceAsync:(MNNHandGestureDetectorCreateConfig*)config Callback:(void(^)(NSError *error, MNNHandGestureDetector *handgestureDetector))block CallbackQueue:(dispatch_queue_t)callbackQueue;
默认主线程中回调,其他参数一样
+ (void)createInstanceAsync:(MNNHandGestureDetectorCreateConfig*)config Callback:(void(^)(NSError *error, MNNHandGestureDetector *handgestureDetector))block;
检测器会同时进行人手检测和手势识别,人手检测包含检测和跟踪两个动作,检测就是找到人手的位置,跟踪就是人手移动时重新定位其位置。视频模式下并不是每一帧都检测,默认每20帧检测一次,其余帧只做跟踪,适合视频流输入的场景;而图片模式下每一次调用都会进行检测,适合图片检测的场景。
使用系统相机作为输入检测时可使用该接口
检测结果对象,可能包含多个手势检测的结果,详见MNNHandGestureDetectionReport
- (NSArray<MNNHandGestureDetectionReport *> *)inference:(CVPixelBufferRef)pixelBuffer Angle:(float)inAngle OutAngle:(float)outAngle FlipType:(MNNFlipType)flipType error:(NSError *__autoreleasing *)error;
图片检测接口,除了输入数据为UIImage,其余参数一样。
注意:如检测单个图片,创建时需配置为图片检测模式。
- (NSArray<MNNHandGestureDetectionReport *> *)inferenceImage:(UIImage*)image Angle:(float)inAngle OutAngle:(float)outAngle FlipType:(MNNFlipType)flipType error:(NSError *__autoreleasing *)error;
通用数据的推理接口
检测结果对象,可能包含多个手势检测的结果,详见MNNHandGestureDetectionReport
- (NSArray<MNNHandGestureDetectionReport *> *)inference:(unsigned char*)data Width:(float)w Height:(float)h Format:(MNNCVImageFormat)format Angle:(float)inAngle OutAngle:(float)outAngle FlipType:(MNNFlipType)flipType error:(NSError *__autoreleasing *)error;
MNNHandGestureDetector实例生命周期结束后会自动触发相关内存的释放,无需调用方手动释放
typedef NS_ENUM(NSUInteger, MNNCVImageFormat) {
RGBA = 0,
RGB = 1,
BGR = 2,
GRAY = 3,
BGRA = 4,
YUV_NV21 = 11,
};
typedef NS_ENUM(NSUInteger, MNNHandGestureType) {
MNN_HAND_GESTURE_TYPE_FINGER_HEART = 0, // 比心
MNN_HAND_GESTURE_TYPE_HAND_OPEN = 1, // 五指张开
MNN_HAND_GESTURE_TYPE_INDEX_FINGER = 2, // 竖食指
MNN_HAND_GESTURE_TYPE_FIST = 3, // 握拳
MNN_HAND_GESTURE_TYPE_THUMB_UP = 4, // 竖大拇指
MNN_HAND_GESTURE_TYPE_OTHER = 5, // 其他
};
@interface MNNHandGestureDetectionReport : NSObject
@property (nonatomic, assign) MNNHandGestureType type;
@property (nonatomic, assign) float score;
@property (nonatomic, assign) int handID;
@property (nonatomic, assign) CGRect rect;
@end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。