apple_vision_saliency 0.0.2 copy "apple_vision_saliency: ^0.0.2" to clipboard
apple_vision_saliency: ^0.0.2 copied to clipboard

PlatformiOSmacOS

A Flutter plugin to use Apple Vision Saliency Segmentation Detection to detect the person in real time from a continuous video or static image.

apple_vision_saliency #

Pub Version analysis Star on Github License: MIT

Apple Vision Saliency Detection is a Flutter plugin that enables Flutter apps to use Apple Vision Saliency Segmentation.

  • 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: 10.15
  • Xcode 13 or newer
  • Swift 5
  • ML Kit only supports 64-bit architectures (x86_64 and arm64).

iOS

  • In develpoment not yet supported
  • Minimum ios Deployment Target: 13.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 AppleVisionSaliencyController visionController = AppleVisionSaliencyController();
  InsertCamera camera = InsertCamera();
  Size imageSize = const Size(640,640*9/16);
  String? deviceId;
  bool loading = true;

  List<Uint8List?>? saliencyImage;
  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, PictureFormat.png).then((data){
            saliencyImage = 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)
        ),
        if(saliencyImage?[0] != null) SizedBox(
          width: imageSize.width, 
          height: imageSize.height, 
          child: Image.memory(saliencyImage![0]!, fit: BoxFit.fill,)
        )
      ]
    );
  }

  Widget loadingWidget(){
    return Container(
      width: deviceWidth,
      height: deviceHeight,
      color: Theme.of(context).canvasColor,
      alignment: Alignment.center,
      child: const CircularProgressIndicator(color: Colors.blue)
    );
  }

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.

0
likes
150
points
38
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to use Apple Vision Saliency Segmentation Detection to detect the person in real time from a continuous video or static image.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

apple_vision_commons, flutter

More

Packages that depend on apple_vision_saliency