AdityaMulgundkar / flutter_opencv

Flutter plug-in providing (a few) basic bindings to OpenCV-4.x. OpenCV methods implemented without the Core packages. WIP.
https://pub.dev/packages/opencv
Other
125 stars 55 forks source link

[BUG] I/System.out(11892): OpenCV Error: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer #18

Open marcoramosw opened 3 years ago

marcoramosw commented 3 years ago

Describe the bug the following error occurs when using the warpPerspectiveTransform function I/System.out(11892): OpenCV Error: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer

To Reproduce

Future<dynamic> WarpPerspective() async {
    Uint8List image = widget.file.readAsBytesSync();
    List<dynamic> sourcepoints = [
      tl_x,
      tl_y,
      tr_x,
      tr_y,
      bl_x,
      bl_y,
      br_x,
      br_y
    ];
    double tld_x = widget.tl.dx;
    double tld_y = widget.tl.dy;
    double trd_x = widget.tr.dx;
    double trd_y = widget.tr.dy;
    double bld_x = widget.bl.dx;
    double bld_y = widget.bl.dy;
    double brd_x = widget.br.dx;
    double brd_y = widget.br.dy;
    List<dynamic> destinationpoints = [
      tld_x,
      tld_y,
      trd_x,
      trd_y,
      bld_x,
      bld_y,
      brd_x,
      brd_y
    ];
    List<double> size = [100.0, 200.0];
    print(sourcepoints);
    print(destinationpoints);
    var bytesArray = await ImgProc.warpPerspectiveTransform(image,
        sourcePoints: sourcepoints,
        destinationPoints: destinationpoints,
        outputSize: size);
    setState(() {
      bytes = bytesArray;
    });
    return await bytesArray;
  }
AdityaMulgundkar commented 3 years ago

Hey @marcoramosw You're passing the size variable as a double... List<double> size = [100.0, 200.0];

You'll have to pass an integer instead. List<int> size = [100, 200];

marcoramosw commented 3 years ago

Hey, @AdityaMulgundkar , thank you for the reply but that would be a simple fix that I indeed tried already,

If I pass as integer:

the Function's Parameter outputSize is a double and you can't pass an int:

The argument type 'List<int>' can't be assigned to the parameter type 'List<double>'.

but if you try to use double you get the already mentioned error:

OpenCV Error: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer"

AdityaMulgundkar commented 3 years ago

Hey @marcoramosw Sorry for making that assumption... Many people miss out on such stuff and create issues, hence the quick response from my end.

I just tried to replicate the error, but couldn't on my end. I think it might be because of casting and autoboxing in java at the same time (at the platform channel level), so I have changed the cast for this one function (warpPerspectiveTransform) and pushed this new version to another branch at https://github.com/AdityaMulgundkar/flutter_opencv/tree/java-cast-test

Could you please help me out by testing this? In case it works out, I can replace all such casts.

You can simply change the version of opencv you're using in your pubspec.yaml as such:

opencv:
     git:
          url: git://github.com/AdityaMulgundkar/flutter_opencv.git
          ref: java-cast-test

Awaiting your response.

marcoramosw commented 3 years ago

Thank you for answering, I will test it as soon as possible!

Aditya Mulgundkar notifications@github.com escreveu no dia segunda, 14/12/2020 à(s) 18:16:

Reopened #18 https://github.com/AdityaMulgundkar/flutter_opencv/issues/18.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AdityaMulgundkar/flutter_opencv/issues/18#event-4110678620, or unsubscribe https://github.com/notifications/unsubscribe-auth/APILA5HZ5MP77SCZRRD5X6DSUZI6RANCNFSM4UW3U6KA .

marcoramosw commented 3 years ago

still unable to get it to work :( unfortunetly I am a beginner in dart and flutter and can't help you resolve it, here is the error message:

C:\Users\mramos\AppData\Local\flutter\.pub-cache\git\flutter_opencv-046ca6ee193e13ace10d11885638a3d75645687b\android\src\main\java\com\mulgundkar\opencv\core\CVCore.java:748: error: cannot find symbol
            Imgproc.warpPerspective(input, destImage, warpMat, new Size(outputSize.get(0).doubleValue(), outputSize.get(1).doubleValue()));
                                                                                         ^
  symbol:   method doubleValue()
  location: class Object
C:\Users\mramos\AppData\Local\flutter\.pub-cache\git\flutter_opencv-046ca6ee193e13ace10d11885638a3d75645687b\android\src\main\java\com\mulgundkar\opencv\core\CVCore.java:748: error: cannot find symbol
            Imgproc.warpPerspective(input, destImage, warpMat, new Size(outputSize.get(0).doubleValue(), outputSize.get(1).doubleValue()));
                                                                                                                          ^
  symbol:   method doubleValue()
  location: class Object
Note: C:\Users\mramos\AppData\Local\flutter\.pub-cache\git\flutter_opencv-046ca6ee193e13ace10d11885638a3d75645687b\android\src\main\java\com\mulgundkar\opencv\OpenCV4Plugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':opencv:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
marcoramosw commented 3 years ago

hey, any new ideas regarding this issue?

Soham-Rakhunde commented 3 years ago

Did it get solved