我正在开发一个基于安卓的跟踪系统,使用安卓上的摄像头和其他传感器。我有兴趣从 AndAR 读取转换矩阵,而不是在检测到标记时显示某些对象(例如立方体)。我有另一个使用 ARToolkit 开发的跟踪系统,称为 jARToolkit,它在台式机上运行,并提供网络摄像头和图案之间的转换矩阵。现在我从 AndAR 获得了转换矩阵,但是如果我们将它与我从 jARToolkit 获得的转换矩阵进行比较,它就完全不同了。原因可能是以下问题 -
- 我在 android 上看到的表面预览总是旋转 90 度。所以我在平移矩阵中的 X 和 Y 坐标交换了它们的位置。
- 我不确定翻译矩阵的单位。在物理世界中每厘米大约有 4 个单位,但我无法验证这一点。
如果有人能帮助我解决这些问题或让我知道我是否遗漏了什么,我将不胜感激。提前致谢。
以下是我正在使用的代码。它与 AndAR 文档中的内容几乎相同。
boolean keepRunning = true;
try {
ARToolkit artoolkit = getArtoolkit();
CustomObject object_hiro = new CustomObject("test_hiro", "hiro.patt", 80.0,new double[] { 0, 0 });
artoolkit.registerARObject(object_hiro);
}
catch (AndARException ex)
{
System.out.println("");
}
while(keepRunning)
{
double[] transMatrix = (double[]) object_hiro.getTransMatrix();
}
这是 CustomObject.java -
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
import edu.dhbw.andar.ARObject;
import edu.dhbw.andar.pub.SimpleBox;
import edu.dhbw.andar.util.GraphicsUtil;
/**
* An example of an AR object being drawn on a marker.
* @author tobi
*
*/
public class CustomObject extends ARObject {
public CustomObject(String name, String patternName,
double markerWidth, double[] markerCenter) {
super(name, patternName, markerWidth, markerCenter);
float mat_ambientf[] = {0f, 1.0f, 0f, 1.0f};
float mat_flashf[] = {0f, 1.0f, 0f, 1.0f};
float mat_diffusef[] = {0f, 1.0f, 0f, 1.0f};
float mat_flash_shinyf[] = {50.0f};
mat_ambient = GraphicsUtil.makeFloatBuffer(mat_ambientf);
mat_flash = GraphicsUtil.makeFloatBuffer(mat_flashf);
mat_flash_shiny = GraphicsUtil.makeFloatBuffer(mat_flash_shinyf);
mat_diffuse = GraphicsUtil.makeFloatBuffer(mat_diffusef);
}
public CustomObject(String name, String patternName,
double markerWidth, double[] markerCenter, float[] customColor) {
super(name, patternName, markerWidth, markerCenter);
float mat_flash_shinyf[] = {50.0f};
mat_ambient = GraphicsUtil.makeFloatBuffer(customColor);
mat_flash = GraphicsUtil.makeFloatBuffer(customColor);
mat_flash_shiny = GraphicsUtil.makeFloatBuffer(mat_flash_shinyf);
mat_diffuse = GraphicsUtil.makeFloatBuffer(customColor);
}
private SimpleBox box = new SimpleBox();
private FloatBuffer mat_flash;
private FloatBuffer mat_ambient;
private FloatBuffer mat_flash_shiny;
private FloatBuffer mat_diffuse;
/**
* Everything drawn here will be drawn directly onto the marker,
* as the corresponding translation matrix will already be applied.
*/
@Override
public final void draw(GL10 gl) {
super.draw(gl);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR,mat_flash);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, mat_flash_shiny);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mat_diffuse);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mat_ambient);
//draw cube
gl.glColor4f(1.0f, 0f, 0, 1.0f);
gl.glTranslatef( 0.0f, 0.0f, 12.5f );
box.draw(gl);
}
@Override
public void init(GL10 gl) {
// TODO Auto-generated method stub
}
}
如果我需要提供更多信息,请告诉我。谢谢