gpt4 book ai didi

java - 在棋盘上绘制 3D 框 - OpenCV、LibGdx 和 java

转载 作者:太空宇宙 更新时间:2023-11-03 21:36:05 25 4
gpt4 key购买 nike

我是 opencv 的新手。我在 Java 中使用它,这很痛苦,因为互联网上的大多数示例和资源都是用 C++ 编写的。

目前我的项目涉及识别棋盘,然后能够在棋盘的特定部分上绘图。

到目前为止,我已经通过库的 Calib3d 部分获得了角落。但这就是我卡住的地方。我的问题是如何将我得到的角信息(这是 2D 图像上的角位置)转换为我可以在 3D 空间中使用以使用 LibGdx 绘制的信息?

以下是我的代码(片段):

public class chessboardDrawer implements ApplicationListner{
... //Fields are here

MatOfPoint2f corners = new MatOfPoint2f();
MatOfPoint3f objectPoints = new MatOfPoint3f();

public void create(){
webcam = new VideoCapture(0);
... //Program sleeps to make sure camera is ready

}

public void render(){
//Fetch webcam image
webcam.read(webcamImage);
//Grayscale the image
Imgproc.cvtColor(webcamImage, greyImage, Imgproc.COLOR_BGR2GRAY);
//Check if image contains a chessboard of with 9x6 corners
boolean foundCorners = Calib3d.findChessboardCorners(greyImage,
new Size(9,6),
corners, Calib3d.CALIB_CB_FAST_CHECK | Calib3d.CALIB_CB_ADAPTIVE_THRESH);

if(foundCorners){
for(int i = 0; i < corners.height; i++){
//This is where i have to convert the corners
//to something i can use in libGdx to draw boxes
//And insert them into the objectPoints variable
}
}
//Show the corners on the webcamIamge
Calib3d.drawChessboardCorners(webcamImage, new Size(9,6), corners, true);
//Helper library to show the webcamImage
UtilAR.imDrawBackground(webcamImage);
}
}

有什么帮助吗?

最佳答案

  1. 您实际上需要使用这些坐标来定位(物理)相机。

    幸运的是,如果是棋盘,这真的很容易。

    Camera pose estimation

    Note:
    The current implementation in OpenCV may not satisfy you in terms of accuracy (at least for a monocular camera). A good AR experience demands nice accuracy.

  2. (可选)使用一些噪声过滤方法/估计算法来稳定跨时间/帧的姿态估计(最好是 Kalman Filter)。

    这会减少抽搐和摇晃。

  3. 控制 PerspectiveCamera 的姿势(位置 + 方向)使用上述姿势估计。

  4. 根据您提供给相机校准方法的 objPoints 使用比例和初始方向绘制 3D 东西。

    可以关注这个nice blog post去做。

您现在渲染的所有 3D 模型都将位于棋盘的引用系中。

希望这对您有所帮助。
祝你好运。

关于java - 在棋盘上绘制 3D 框 - OpenCV、LibGdx 和 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28500110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com