apple_vision_pose_3d 0.0.1 apple_vision_pose_3d: ^0.0.1 copied to clipboard
A Flutter plugin to use Apple Vision Pose Detection to detect the pose of a subject's body in real time from a continuous video or static image.
apple_vision_pose_3d #
Apple Vision Pose Detection is a Flutter plugin that enables Flutter apps to use Apple Vision Pose Detection 3D.
- This plugin is not sponsor or maintained by Apple. The authors are developers who wanted to make a similar plugin to Google's ml kit for macos.
Requirements #
MacOS
- Minimum osx Deployment Target: 14.0
- Xcode 13 or newer
- Swift 5
- ML Kit only supports 64-bit architectures (x86_64 and arm64).
iOS
- Minimum ios Deployment Target: 17.0
- Xcode 13 or newer
- Swift 5
- ML Kit only supports 64-bit architectures (x86_64 and arm64).
Getting Started #
You need to first import 'package:apple_vision/apple_vision.dart';
final GlobalKey cameraKey = GlobalKey(debugLabel: "cameraKey");
late AppleVisionPose3DController visionController = AppleVisionPose3DController();
InsertCamera camera = InsertCamera();
Size imageSize = const Size(640,640*9/16);
String? deviceId;
bool loading = true;
List<PoseData3D>? poseData;
late double deviceWidth;
late double deviceHeight;
@override
void initState() {
camera.setupCameras().then((value){
setState(() {
loading = false;
});
camera.startLiveFeed((InputImage i){
if(i.metadata?.size != null){
imageSize = i.metadata!.size;
}
if(mounted) {
Uint8List? image = i.bytes;
visionController.processImage(image!, i.metadata!.size).then((data){
poseData = data;
setState(() {
});
});
}
});
});
super.initState();
}
@override
void dispose() {
camera.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
deviceWidth = MediaQuery.of(context).size.width;
deviceHeight = MediaQuery.of(context).size.height;
return Stack(
children:<Widget>[
SizedBox(
width: imageSize.width,
height: imageSize.height,
child: loading?Container():CameraSetup(camera: camera, size: imageSize)
),
]+showPoints()
);
}
List<Widget> showPoints(){
if(poseData == null || poseData!.isEmpty) return[];
Map<Joint3D,Color> colors = {
Joint3D.rightAnkle: Colors.orange,
Joint3D.rightKnee: Colors.orange,
Joint3D.rightHip: Colors.orange,
Joint3D.rightWrist: Colors.purple,
Joint3D.rightElbow: Colors.purple,
Joint3D.rightShoulder: Colors.pink,
Joint3D.leftShoulder: Colors.pink,
Joint3D.leftElbow: Colors.indigo,
Joint3D.leftWrist: Colors.indigo,
Joint3D.leftHip: Colors.grey,
Joint3D.leftKnee: Colors.grey,
Joint3D.leftAnkle: Colors.grey,
Joint3D.root: Colors.yellow,
Joint3D.centerShoulder: Colors.yellow,
Joint3D.spine: Colors.yellow,
Joint3D.centerHead: Colors.cyanAccent,
Joint3D.topHead: Colors.cyanAccent
};
List<Widget> widgets = [];
for(int j = 0; j < poseData!.length;j++){
for(int i = 0; i < poseData![j].poses.length; i++){
widgets.add(
Positioned(
top: imageSize.height-poseData![j].poses[i].location.y * imageSize.height,
left: poseData![j].poses[i].location.x * imageSize.width,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: colors[poseData![j].poses[i].joint],
borderRadius: BorderRadius.circular(5)
),
)
)
);
}
}
return widgets;
}
Example #
Find the example for this API here.
Contributing #
Contributions are welcome. In case of any problems look at existing issues, if you cannot find anything related to your problem then open an issue. Create an issue before opening a pull request for non trivial fixes. In case of trivial fixes open a pull request directly.