image_feature_detector 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

image_feature_detector #

A image feature detector using opencv for IOs and Android.

This plugin uses native versions of OpenCV to detect shapes in given images.

What does it do? #

For now it only detects rectangles in given images. It uses native implementations for both IOs and Android for this task.

Usage #

To use this package add following import to your file:

import 'package:image_feature_detector/image_feature_detector.dart';

The API for this package is fairly simple. We can only detect rectangles for now.

If you need more functionalities, feel free to contribute or open an issue in the code repository.

To detect a rectangle in an image save it to a local file and call the ImageFeatureDetector:

var rectangle = ImageFeatureDetector.detectRectangles(_filePath);

// Access the points of the contour
rectangle.contour[0].x; // Access X
rectangle.contour[0].y; // Access the y value.

To detect and transform the image into a normalized image use following api:

var imageData = ImageFeatureDetector.detectAndTransformRectangle(_filePath);

Quick Aside: Relative Coordiantes #

To be as size independent as possible this package uses relative coordinates.

Absolute coordinates would look likes this:

// This values are in Pixels.
var p = Point(x: 25, y: 25); 

This coordinates are only correct for the original width and height of the image.

If it gets scaled for some reason the above point won't be correct anymore.

To work around this we use relative coordinates. These are values between 0 and 1.

// Would be 25 in a image width 500 width or height
var relativePoint = Point(x: 0.05, y: 0.05);

RelativeCoordianteHelper #

To revert the relative coordinates back to absolute values we can use this helper.

Usage #

We have to easy methods. One for calculating a single value another for calculating a whole Point.

Calculating one point:

var p = Point(x: 0.05, y: 0.05);
var absoluteX = RelativeCoordianteHelper.calculateDistance(p.x, 500); // p.x = 0.05

// absolute value would be 25

Calculating a whole point:

var absolutePoint = RelativeCoordianteHelper.calculatePointDinstances(
          Point(x: 0.05, y: 0.05), ImageDimensions(500, 500));

// Result Point -> x = 25; y = 25;

0.2.1 #

  • Objective C: added helper to work with points to sort them and refactored opencvwrapper to be able to reuse contour logic for transformation
  • Java: refactored Opencvwrapper for upcomming image perspective wrapping function, started to add points helper to get list of points sorte
  • General: new Api has been added: detectAndTransformRectangle.

0.2.0 #

  • refactored image detection on java side to work with real images and fixed a logic bug, which found bigger objects that werent rectangles in the end
  • lifted the objective c code to the same functionality as the java side

0.1.1 #

Added longer description to pubspec and other fixes from pub

0.1.0 #

This is the initial release fo this package

Features #

  • Added detectRectangles to ImageFeatureDetector
  • Added getVersionStringto ImageFeatureDetector
  • Added RelativeCoordianteHelper to Plugin
  • Added example for basic usage.


import 'dart:io';

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

import 'package:flutter/services.dart';
import 'package:image_feature_detector/image_feature_detector.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _filePath;
  Contour _contour;
  Point _testPoint;
  TransformedImage _transfomed;

  void initState() {

    // Use the RelativeCoodrinateHelper to calculate a value for our point.
    setState(() {
      _testPoint = RelativeCoordianteHelper.calculatePointDinstances(
          Point(x: 0.05, y: 0.05), ImageDimensions(500, 500));

  // 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.
    try {
      platformVersion = await ImageFeatureDetector.getVersionString;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';

    try {
      var directory2 = await getApplicationDocumentsDirectory();

      var path = "${directory2.path}/images/tmp5.png";

      var file = File(path);
      if (!await file.exists()) {
        var data = await rootBundle.load("images/rectangle2.jpg");

        try {
          await file.create(recursive: true);
        } catch (e) {

            data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));

      setState(() {
        _filePath = path;
    } on PlatformException {}

    // 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;

  Widget build(BuildContext context) {
    // var image = _filePath == null ? Container() : Image.file(File(_filePath));
    Column c;
    Widget image;

    if (_contour != null) {
      c = Column(
        children: {
          return Text(
              "X: ${RelativeCoordianteHelper.calculateDistance(p.x, _contour.dimensions.width)}, Y: ${RelativeCoordianteHelper.calculateDistance(p.y, _contour.dimensions.height)}");
    } else {
      c = Column(
        children: <Widget>[Text("No contour calculated")],

    if (_transfomed != null) {
      image = Image.file(File(_transfomed.filePath));
    } else {
      image = Text("Press button to get transformed image");

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        body: Center(
            child: Column(
          children: <Widget>[
            Text('Running on: $_platformVersion\n'),
            Text("Example RelativePointHelper using Point:"),
                "Calculated values: x: ${_testPoint != null ? _testPoint.x : "-"}, y: ${_testPoint != null ? _testPoint.y : "-"}"),
        floatingActionButton: FloatingActionButton(
            child: Icon(Icons.image),
            onPressed: () async {
              try {
                // var c = await ImageFeatureDetector.detectRectangles(_filePath);
                var transformed =
                    await ImageFeatureDetector.detectAndTransformRectangle(
                setState(() {
                  _transfomed = transformed;
                // setState(() {
                //   _contour = c;
                // });
              } on PlatformException {
                print("error happened");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  image_feature_detector: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:image_feature_detector/image_feature_detector.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux


  • package:image_feature_detector/image_feature_detector.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web


  • package:image_feature_detector/image_feature_detector.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows


  • package:image_feature_detector/image_feature_detector.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS


  • package:image_feature_detector/image_feature_detector.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart


  • image_feature_detector that is a package requiring null.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (path_provider).

Package is getting outdated. (-19.18 points)

The package was last published 62 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
path_provider ^0.5.0+1 0.5.0+1 1.6.11
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies