Skip to content

This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.

License

Notifications You must be signed in to change notification settings

farmako/edge_detection

 
 

Repository files navigation

edge_detection

A flutter plugin to detect edges of objects, scan paper, detect corners, detect rectangles. It allows cropping of the detected object image and returns the path of the cropped image.

Usage:

iOS

iOS 10.0 or higher is needed to use the plugin. If compiling for any version lower than 10.0 make sure to check the iOS version before using the plugin. Change the minimum platform version to 10 (or higher) in your ios/Podfile file.

Add below permission to the ios/Runner/Info.plist:

  • one with the key Privacy - Camera Usage Description and a usage description.

Or in text format add the key:

<key>NSCameraUsageDescription</key>
<string>Can I use the camera please?</string>

Add to your need localizations to your app through XCode for localize actions buttons from WeScan (https://github.com/WeTransfer/WeScan/tree/master/WeScan/Resources/Localisation)

Android

The plugin code is written in kotlin 1.5.31 so the same has to be set to the android project of yours for compilation. Change the kotlin_version to 1.5.31 in your android/build.gradle file.

ext.kotlin_version = '1.5.31'

Change the minimum Android SDK version to 21 (or higher) in your android/app/build.gradle file.

minSdkVersion 21

Add dependency:

Please check the latest version before installation.

dependencies:
  flutter:
    sdk: flutter
  edge_detection: ^1.1.0
  permission_handler: ^10.0.0
  path_provider: ^2.0.11
  path: ^1.8.2

Add the following imports to your Dart code:

import 'package:edge_detection/edge_detection.dart';
// Check permissions and request its
bool isCameraGranted = await Permission.camera.request().isGranted;
if (!isCameraGranted) {
    isCameraGranted = await Permission.camera.request() == PermissionStatus.granted;
}

if (!isCameraGranted) {
    // Have not permission to camera
    return;
}

// Generate filepath for saving
String imagePath = join((await getApplicationSupportDirectory()).path,
    "${(DateTime.now().millisecondsSinceEpoch / 1000).round()}.jpeg");
        
try {
    //Make sure to await the call to detectEdge.
    bool success = await EdgeDetection.detectEdge(imagePath,
        canUseGallery: false,
        androidScanTitle: 'Сканирование', // use custom localizations for android
        androidCropTitle: 'Редактирование',
        androidCropBlackWhiteTitle: 'Ч/Б',
        androidCropReset: 'Отменить',
    );
} catch (e) {
    print(e);
}

Screenshots

Android

iOS

Using these native implementation
https://github.com/WeTransfer/WeScan

https://github.com/KePeng1019/SmartPaperScan

About

This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 68.6%
  • Swift 22.7%
  • Dart 4.9%
  • Ruby 2.9%
  • Objective-C 0.9%