Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marcoramosw opened this issue Dec 11, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@marcoramosw
Copy link

marcoramosw commented Dec 11, 2020

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;
  }
@marcoramosw marcoramosw added the bug Something isn't working label Dec 11, 2020
@AdityaMulgundkar
Copy link
Owner

AdityaMulgundkar commented Dec 11, 2020

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
Copy link
Author

marcoramosw commented Dec 14, 2020

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
Copy link
Owner

AdityaMulgundkar commented Dec 14, 2020

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
Copy link
Author

marcoramosw commented Dec 15, 2020 via email

@marcoramosw
Copy link
Author

marcoramosw commented Dec 15, 2020

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
Copy link
Author

hey, any new ideas regarding this issue?

@Soham-Rakhunde
Copy link

Did it get solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants