bytedeco / javacpp-presets

The missing Java distribution of native C++ libraries
Other
2.63k stars 731 forks source link

OpenCV Fisheye Camera Functions Missing #1185

Closed calvertdw closed 1 year ago

calvertdw commented 2 years ago

The "undistort" function is missing:

https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga69f2545a8b62a6b0fc2ee060dc30559d

and the fisheye functions: https://docs.opencv.org/4.5.5/db/d58/group__calib3d__fisheye.html

Edit: I renamed this issue to be more general about needing functions relating to fisheye cameras. We are trying to accelerate our new Fisheye camera on our robot with OpenCV :slightly_smiling_face:

saudet commented 2 years ago

I see all of them: http://bytedeco.org/javacpp-presets/opencv/apidocs/org/bytedeco/opencv/global/opencv_calib3d.html#undistort-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat- http://bytedeco.org/javacpp-presets/opencv/apidocs/org/bytedeco/opencv/global/opencv_calib3d.html#undistortImage-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Size- http://bytedeco.org/javacpp-presets/opencv/apidocs/org/bytedeco/opencv/global/opencv_calib3d.html#undistortPoints-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-org.bytedeco.opencv.opencv_core.Mat-

calvertdw commented 2 years ago

Oh well that's great news! Thank you. I was expecting them to be in imgproc.

calvertdw commented 1 year ago

I finally got around to using these and I'm finding that the fisheye functions are missing the helper types, for instance the calibrate method has MatVector objectPoints instead of Point3fVectorVector objectPoints. This can be worked around but is not ideal. The pinhole model methods have the helper types, i.e. in calibrateCamera.

saudet commented 1 year ago

Right, that's easy enough to fix, see commit https://github.com/bytedeco/javacpp-presets/commit/86a78a6bca5cadc01d33933ce7a77fa6a29f1219. Please give it a try with the snapshots: http://bytedeco.org/builds/

calvertdw commented 1 year ago

Wow, thanks! I'll give it a shot. My code can be simpler now.

However, I think I ran into another issue. It seems that by chance the fisheye and non-fisheye method for calibrate and undistort are different. cv::fisheye has calibrate and undistortImage and calib3d (for pinhole/perspective cameras) has calibrateCamera and undistort. However, the functions for initUndistortRectifyMap have the same signature and the fisheye version is not accessible in the preset. The fisheye undistortImage was not working for me, see the weird trianglar output below. I was going to break it down into initUndistortRectifyMap and remap when I noticed the missing method.

Is it hard to fix? @ds58 or myself can try to fix, though some pointers might help. :smile:

image The code

calvertdw commented 1 year ago

I guess we could add something like

.put(new Info("cv::fisheye::initUndistortRectifyMap").javaText(
                        "@Namespace(\"cv::fisheye\") public static native void initUndistortRectifyMap
                        ...
calvertdw commented 1 year ago

Okay I did fix my issue with cv::fisheye::undistortImage. I was not calling estimateNewCameraMatrixForUndistortRectify first. image

saudet commented 1 year ago

I guess we could add something like

.put(new Info("cv::fisheye::initUndistortRectifyMap").javaText(
                        "@Namespace(\"cv::fisheye\") public static native void initUndistortRectifyMap
                        ...

If we don't need to change anything but the name, it's easier using Info.javaNames: https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#specifying-names-to-use-in-java

saudet commented 1 year ago

Version 1.5.9 has been released with the fixes! Thanks for contribution