vision 0.0.5 copy "vision: ^0.0.5" to clipboard
vision: ^0.0.5 copied to clipboard

A new plugin for offline image labeling in flutter

example/lib/main.dart

import 'dart:convert';
import 'dart:typed_data';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:vision/vision.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _vision = Vision();
  final ImagePicker picker = ImagePicker();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      var initialed = await Vision.initial();
      platformVersion = (initialed).toString();
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            // Pick an image
            final XFile? image = await picker.pickImage(source: ImageSource.gallery);
            if (image != null){
              var bytes = await image.readAsBytes();
              String jsonLabels = await Vision.runModelOnByteArray(Uint8List.fromList(bytes.toList()), 0.3);
              var labels = List<Map<String, dynamic>>.from(json.decode(jsonLabels));
              if (kDebugMode){
                print(labels);
              }
            }
          },
          child: const Icon(Icons.transfer_within_a_station),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}
11
likes
140
points
24
downloads

Publisher

verified publishersensifai.com

Weekly Downloads

A new plugin for offline image labeling in flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on vision

Packages that implement vision