AdityaMulgundkar/flutter_opencv

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

Opened this issue · 7 comments

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

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

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"

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.

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.

hey, any new ideas regarding this issue?

Did it get solved