【发布时间】:2015-02-13 12:54:06
【问题描述】:
我是opencv的新手。我在 java 中使用它,这很痛苦,因为互联网上的大多数示例和资源都是用 C++ 编写的。
目前我的项目涉及识别棋盘,然后能够在棋盘的特定部分上绘图。
到目前为止,我已经通过库的 Calib3d 部分获得了角落。但这是我卡住的地方。我的问题是如何将我得到的角点信息(2D 图像上的角点位置)转换为我可以在 3D 空间中使用 LibGdx 绘制的东西?
以下是我的代码(在 sn-ps 中):
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);
}
}
有什么帮助吗?
【问题讨论】:
标签: java opencv libgdx computer-vision augmented-reality