Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ example/.idea

.idea

android/.cxx
android/.cxx

ios/opencv2.framework
android/src/main/jniLibs
182 changes: 91 additions & 91 deletions example/lib/edge_detector.dart
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
import 'dart:async';
import 'dart:isolate';

import 'package:simple_edge_detection/edge_detection.dart';

class EdgeDetector {
static Future<void> startEdgeDetectionIsolate(EdgeDetectionInput edgeDetectionInput) async {
EdgeDetectionResult result = await EdgeDetection.detectEdges(edgeDetectionInput.inputPath);
edgeDetectionInput.sendPort.send(result);
}

static Future<void> processImageIsolate(ProcessImageInput processImageInput) async {
EdgeDetection.processImage(processImageInput.inputPath, processImageInput.edgeDetectionResult);
processImageInput.sendPort.send(true);
}

Future<EdgeDetectionResult> detectEdges(String filePath) async {
final port = ReceivePort();

_spawnIsolate<EdgeDetectionInput>(
startEdgeDetectionIsolate,
EdgeDetectionInput(
inputPath: filePath,
sendPort: port.sendPort
),
port
);

return await _subscribeToPort<EdgeDetectionResult>(port);
}

Future<bool> processImage(String filePath, EdgeDetectionResult edgeDetectionResult) async {
final port = ReceivePort();

_spawnIsolate<ProcessImageInput>(
processImageIsolate,
ProcessImageInput(
inputPath: filePath,
edgeDetectionResult: edgeDetectionResult,
sendPort: port.sendPort
),
port
);

return await _subscribeToPort<bool>(port);
}

void _spawnIsolate<T>(Function function, dynamic input, ReceivePort port) {
Isolate.spawn<T>(
function,
input,
onError: port.sendPort,
onExit: port.sendPort
);
}

Future<T> _subscribeToPort<T>(ReceivePort port) async {
StreamSubscription sub;
var completer = new Completer<T>();
sub = port.listen((result) async {
await sub?.cancel();
completer.complete(await result);
});
return completer.future;
}
}

class EdgeDetectionInput {
EdgeDetectionInput({
this.inputPath,
this.sendPort
});

String inputPath;
SendPort sendPort;
}

class ProcessImageInput {
ProcessImageInput({
this.inputPath,
this.edgeDetectionResult,
this.sendPort
});

String inputPath;
EdgeDetectionResult edgeDetectionResult;
SendPort sendPort;
}
// import 'dart:async';
// import 'dart:isolate';
//
// import 'package:simple_edge_detection/edge_detection.dart';
//
// class EdgeDetector {
// static Future<void> startEdgeDetectionIsolate(EdgeDetectionInput edgeDetectionInput) async {
// EdgeDetectionResult result = await EdgeDetection.detectEdges(edgeDetectionInput.inputPath);
// edgeDetectionInput.sendPort.send(result);
// }
//
// static Future<void> processImageIsolate(ProcessImageInput processImageInput) async {
// EdgeDetection.processImage(processImageInput.inputPath, processImageInput.edgeDetectionResult);
// processImageInput.sendPort.send(true);
// }
//
// Future<EdgeDetectionResult> detectEdges(String filePath) async {
// final port = ReceivePort();
//
// _spawnIsolate<EdgeDetectionInput>(
// startEdgeDetectionIsolate,
// EdgeDetectionInput(
// inputPath: filePath,
// sendPort: port.sendPort
// ),
// port
// );
//
// return await _subscribeToPort<EdgeDetectionResult>(port);
// }
//
// Future<bool> processImage(String filePath, EdgeDetectionResult edgeDetectionResult) async {
// final port = ReceivePort();
//
// _spawnIsolate<ProcessImageInput>(
// processImageIsolate,
// ProcessImageInput(
// inputPath: filePath,
// edgeDetectionResult: edgeDetectionResult,
// sendPort: port.sendPort
// ),
// port
// );
//
// return await _subscribeToPort<bool>(port);
// }
//
// void _spawnIsolate<T>(Function function, dynamic input, ReceivePort port) {
// Isolate.spawn<T>(
// function,
// input,
// onError: port.sendPort,
// onExit: port.sendPort
// );
// }
//
// Future<T> _subscribeToPort<T>(ReceivePort port) async {
// StreamSubscription sub;
//
// var completer = new Completer<T>();
//
// sub = port.listen((result) async {
// await sub?.cancel();
// completer.complete(await result);
// });
//
// return completer.future;
// }
// }
//
// class EdgeDetectionInput {
// EdgeDetectionInput({
// this.inputPath,
// this.sendPort
// });
//
// String inputPath;
// SendPort sendPort;
// }
//
// class ProcessImageInput {
// ProcessImageInput({
// this.inputPath,
// this.edgeDetectionResult,
// this.sendPort
// });
//
// String inputPath;
// EdgeDetectionResult edgeDetectionResult;
// SendPort sendPort;
// }
4 changes: 2 additions & 2 deletions example/lib/scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:path_provider/path_provider.dart';
import 'package:simple_edge_detection_example/cropping_preview.dart';

import 'camera_view.dart';
import 'edge_detector.dart';
import 'image_view.dart';

class Scan extends StatefulWidget {
Expand Down Expand Up @@ -180,7 +179,8 @@ class _ScanState extends State<Scan> {
return;
}

bool result = await EdgeDetector().processImage(filePath, edgeDetectionResult);
double rotation=0;
bool result = await EdgeDetector().processImage(filePath, edgeDetectionResult,rotation);

if (result == false) {
return;
Expand Down
Loading