Skip to content

Commit

Permalink
Draft of grabCut wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Railean @xlippery committed Jun 22, 2020
1 parent 6ceaeae commit 4571102
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Expand Up @@ -138,6 +138,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
case "houghCircles":
result.success(core.houghCircles((byte[]) call.argument("byteData"), (int) call.argument("method"), (double) call.argument("dp"), (double) call.argument("minDist"), (double) call.argument("param1"), (double) call.argument("param2"), (int) call.argument("minRadius"), (int) call.argument("maxRadius"), (int) call.argument("centerWidth"), (String) call.argument("centerColor"), (int) call.argument("circleWidth"), (String) call.argument("circleColor")));
break;
case "grabCut":
result.success(core.grabCut((byte[]) call.argument("byteData"), (int) call.argument("itercount")));
break;
default:
result.notImplemented();
break;
Expand Down
33 changes: 33 additions & 0 deletions android/src/main/java/com/mulgundkar/opencv/core/CVCore.java
Expand Up @@ -7,6 +7,7 @@
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.core.MatOfByte;
Expand Down Expand Up @@ -647,4 +648,36 @@ public byte[] houghCircles(byte[] byteData, int method, double dp, double minDis
}
return byteArray;
}

@SuppressLint("MissingPermission")
public byte[] grabCut(byte[] byteData, int itercount) {
byte[] byteArray = new byte[0];
try {
System.out.println("###########################");
Mat dst = new Mat();
Mat background = new Mat();
Mat foreground = new Mat();
// Decode image from input byte array

System.out.println("grabCut start imdecode:");
Mat src = Imgcodecs.imdecode(new MatOfByte(byteData), Imgcodecs.IMREAD_UNCHANGED);
System.out.println("grabCut end imdecode:");

Rect rect = new Rect(5,5,20,20);

System.out.println("grabCut start:");
Imgproc.grabCut(src, dst, rect, background, foreground, 1, 2);
System.out.println("grabCut end ...");

//instantiating an empty MatOfByte class
MatOfByte matOfByte = new MatOfByte();
//Converting the Mat object to MatOfByte
Imgcodecs.imencode(".jpg", dst, matOfByte);
byteArray = matOfByte.toArray();
System.out.println("###########################");
} catch (Exception e) {
System.out.println("OpenCV Error: " + e.toString());
}
return byteArray;
}
}
4 changes: 4 additions & 0 deletions example/lib/main.dart
Expand Up @@ -68,6 +68,10 @@ class _MyAppState extends State<MyApp> {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
switch (functionName) {
case 'grabCut':
print('grabcut selected');
res = await ImgProc.grabCut(await file.readAsBytes(), 1);
break;
case 'blur':
res = await ImgProc.blur(
await file.readAsBytes(), [45, 45], [20, 30], Core.borderReflect);
Expand Down
12 changes: 12 additions & 0 deletions lib/core/imgproc.dart
Expand Up @@ -840,4 +840,16 @@ class ImgProc {
/// Function returns the set String as result, use for debugging
return result;
}

static Future<dynamic> grabCut(
Uint8List byteData, int itercount) async {
/// Variable to store operation result
final dynamic result = await _channel.invokeMethod('grabCut', {
'byteData': byteData,
'itercount': itercount
});

/// Function returns the set String as result, use for debugging
return result;
}
}

0 comments on commit 4571102

Please sign in to comment.