Java 在Metaio图像跟踪器上显示多个图像

Java 在Metaio图像跟踪器上显示多个图像,java,augmented-reality,metaio,Java,Augmented Reality,Metaio,我的想法是显示Metaio图像跟踪器识别的图像名称。我成功地显示了为第一个COS动态创建的图像,但它没有显示为第二个COS动态创建的图像。它确实检测到第二个图像(它进入if块,记录了-->Java代码),但我不明白为什么它不显示第二个图像。它肯定会检测到第二个图像,因为当我将相机拉回第一个图像仅几毫秒时,第二个图像的名称会反射,并再次更改为第一个图像的名称 我使用了广告牌的方法来创建动态图像。为此感谢metaio开发人员 正在等待答复。。提前谢谢各位 Java代码 public类标识扩展了AR

我的想法是显示Metaio图像跟踪器识别的图像名称。我成功地显示了为第一个COS动态创建的图像,但它没有显示为第二个COS动态创建的图像。它确实检测到第二个图像(它进入if块,记录了-->Java代码),但我不明白为什么它不显示第二个图像。它肯定会检测到第二个图像,因为当我将相机拉回第一个图像仅几毫秒时,第二个图像的名称会反射,并再次更改为第一个图像的名称

我使用了广告牌的方法来创建动态图像。为此感谢metaio开发人员

正在等待答复。。提前谢谢各位

Java代码

public类标识扩展了ARViewActivity{
/*
*此方法定期调用,计算手机之间的距离
*并根据距离确定目标并执行操作
*/
专用void checkDistanceToTarget(){
TrackingValuesVector poses=metaioSDK.getTrackingValues();
如果(poses.size()!=0){
Log.e(“METAIO”,“发现了什么”);
对于(int i=0;i
//metaioSDK.set }

@覆盖
几何接触的受保护空隙(最终Igometry几何){
}
私有字符串GetAnnotationImageFortile(字符串标题){
位图billboard=null;
试一试{
最后一个字符串texturepath=getCacheDir()+“/”+title+“.png”;
Paint mPaint=新油漆();
//加载背景图像并制作可变副本
float dpi=SystemInfo.getDisplayDensity(getApplicationContext());
int scale=dpi>240?2:1;
字符串filepath=AssetManager.getAssetPath(
getApplicationContext(),“POI_bg”
+(比例==2?”@2x:“)+”.png”);
位图mBackgroundImage=BitmapFactory.decodeFile(文件路径);
billboard=mBackgroundImage.copy(Bitmap.Config.ARGB_8888,true);
画布c=新画布(广告牌);
mPaint.setColor(Color.WHITE);
mPaint.setTextSize(24);
mPaint.setTypeface(Typeface.DEFAULT);
mPaint.setTextAlign(Paint.Align.CENTER);
浮动y=40*刻度;
浮动x=30*刻度;
//绘制POI名称
如果(title.length()>0){
字符串n=title.trim();
最终整数最大宽度=160*刻度;
int i=mPaint.breakText(n,true,maxWidth,null);
int xPos=(c.getWidth()/2);
intypos=(int)((c.getHeight()/2)-((mpain.descent()+mpain
.上升())/2);
c、 drawText(n.substring(0,i)、xPos、yPos、mPaint);
//如果有效,画第二条线
如果(i
}

XML文件


特色
 public class Identify extends ARViewActivity {

/*
 * This method is regularly called, calculates the distance between phone
 * and target and performs actions based on the distance
 */
private void checkDistanceToTarget() {

    TrackingValuesVector poses = metaioSDK.getTrackingValues();

    if (poses.size() != 0) {


        Log.e("METAIO", "FOUND SOMETHING");
        for (int i = 0; i < poses.size(); i++) {

            TrackingValues pose = poses.get(i);
            String cosName = pose.getCosName();
            if (cosName.equalsIgnoreCase("MarkerlessCOS1")) {
                String title = "MYSELF";
                String texturePath = getAnnotationImageForTitle(title);
                metaioSDK.createGeometryFromImage(texturePath, true, true);
                System.out.println("MYSELF");
            } else if (cosName.equalsIgnoreCase("MarkerlessCOS2")) {
                System.out.println("TIGER");
                String title = "TIGER";
                String texturePath = getAnnotationImageForTitle(title);
                metaioSDK.createGeometryFromImage(texturePath, true, true); // THIS DOESN'T WORK!! :(
            } else {

            }

        }
    }

}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}

@Override
protected void onDestroy() {
    super.onDestroy();
}

@Override
protected int getGUILayout() {
    // TODO: return 0 in case of no GUI overlay
    return R.layout.identify_national_personality;
}

@Override
protected IMetaioSDKCallback getMetaioSDKCallbackHandler() {
    return null;
}

@Override
public void onDrawFrame() {

    super.onDrawFrame();

    try {
        checkDistanceToTarget();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public void onButtonClick(View v) {
    finish();
}

@Override
protected void loadContents() {

    String trackingConfigFile = AssetsManager.getAssetPath(
            getApplicationContext(),
            "TrackingDataXML/TrackingData_MarkerlessFast.xml");
    // Assigning tracking configuration
    boolean result = metaioSDK.setTrackingConfiguration(trackingConfigFile);
@Override
protected void onGeometryTouched(final IGeometry geometry) {

}

private String getAnnotationImageForTitle(String title) {

    Bitmap billboard = null;

    try {
        final String texturepath = getCacheDir() + "/" + title + ".png";
        Paint mPaint = new Paint();

        // Load background image and make a mutable copy

        float dpi = SystemInfo.getDisplayDensity(getApplicationContext());
        int scale = dpi > 240 ? 2 : 1;
        String filepath = AssetsManager.getAssetPath(
                getApplicationContext(), "POI_bg"
                        + (scale == 2 ? "@2x" : "") + ".png");
        Bitmap mBackgroundImage = BitmapFactory.decodeFile(filepath);

        billboard = mBackgroundImage.copy(Bitmap.Config.ARGB_8888, true);

        Canvas c = new Canvas(billboard);

        mPaint.setColor(Color.WHITE);
        mPaint.setTextSize(24);
        mPaint.setTypeface(Typeface.DEFAULT);
        mPaint.setTextAlign(Paint.Align.CENTER);

        float y = 40 * scale;
        float x = 30 * scale;

        // Draw POI name
        if (title.length() > 0) {
            String n = title.trim();

            final int maxWidth = 160 * scale;

            int i = mPaint.breakText(n, true, maxWidth, null);

            int xPos = (c.getWidth() / 2);
            int yPos = (int) ((c.getHeight() / 2) - ((mPaint.descent() + mPaint
                    .ascent()) / 2));
            c.drawText(n.substring(0, i), xPos, yPos, mPaint);

            // Draw second line if valid
            if (i < n.length()) {
                n = n.substring(i);
                y += 20 * scale;
                i = mPaint.breakText(n, true, maxWidth, null);

                if (i < n.length()) {
                    i = mPaint.breakText(n, true, maxWidth - 20 * scale,
                            null);
                    c.drawText(n.substring(0, i) + "...", x, y, mPaint);
                } else {
                    c.drawText(n.substring(0, i), x, y, mPaint);
                }
            }
        }

        // Write texture file
        try {
            FileOutputStream out = new FileOutputStream(texturepath);
            billboard.compress(Bitmap.CompressFormat.PNG, 90, out);
            MetaioDebug.log("Texture file is saved to " + texturepath);
            return texturepath;
        } catch (Exception e) {
            MetaioDebug.log("Failed to save texture file");
            e.printStackTrace();
        }
    } catch (Exception e) {
        MetaioDebug.log("Error creating annotation texture: "
                + e.getMessage());
        MetaioDebug.printStackTrace(Log.DEBUG, e);
        return null;
    } finally {
        if (billboard != null) {
            billboard.recycle();
            billboard = null;
        }
    }

    return null;
}
    <?xml version="1.0"?>

    <TrackingData>
        <Sensors>
            <Sensor Type="FeatureBasedSensorSource" Subtype="Fast">

                <!--    Assign an ID to this sensor -->
                <SensorID>FeatureTracking1</SensorID>

                <Parameters>
                    <FeatureDescriptorAlignment>regular</FeatureDescriptorAlignment>
                    <MaxObjectsToDetectPerFrame>5</MaxObjectsToDetectPerFrame>
                    <MaxObjectsToTrackInParallel>10</MaxObjectsToTrackInParallel>
                    <SimilarityThreshold>0.6</SimilarityThreshold>
                </Parameters>
                <SensorCOS>
                    <SensorCosID>Patch1</SensorCosID>
                    <Parameters>
                        <ReferenceImage>myself.jpg</ReferenceImage>
                        <SimilarityThreshold>0.6</SimilarityThreshold>
                    </Parameters>
                </SensorCOS>
                <SensorCOS>
                    <SensorCosID>Patch2</SensorCosID>
                    <Parameters>
                        <ReferenceImage>tiger.jpg</ReferenceImage>
                        <SimilarityThreshold>0.6</SimilarityThreshold>
                    </Parameters>
                </SensorCOS>
            </Sensor>
        </Sensors>
        <Connections>
            <COS>
                <Name>MarkerlessCOS1</Name>
                <Fuser Type="SmoothingFuser">
                    <Parameters>
                        <KeepPoseForNumberOfFrames>2</KeepPoseForNumberOfFrames>
                        <GravityAssistance></GravityAssistance>
                        <AlphaTranslation>1.0</AlphaTranslation>
                        <GammaTranslation>1.0</GammaTranslation>
                        <AlphaRotation>0.8</AlphaRotation>
                        <GammaRotation>0.8</GammaRotation>
                        <ContinueLostTrackingWithOrientationSensor>false</ContinueLostTrackingWithOrientationSensor>
                    </Parameters>
                </Fuser>

                <SensorSource>
                    <SensorID>FeatureTracking1</SensorID>
                    <SensorCosID>Patch1</SensorCosID>
                    <HandEyeCalibration>

                        <TranslationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                        </TranslationOffset>
                        <RotationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                            <W>1</W>
                        </RotationOffset>
                    </HandEyeCalibration>
                    <COSOffset>
                        <TranslationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                        </TranslationOffset>
                        <RotationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                            <W>1</W>
                        </RotationOffset>
                    </COSOffset>
                </SensorSource>
            </COS>

            <COS>
                <Name>MarkerlessCOS2</Name>
                <Fuser Type="SmoothingFuser">
                    <Parameters>
                        <KeepPoseForNumberOfFrames>2</KeepPoseForNumberOfFrames>
                        <GravityAssistance></GravityAssistance>
                        <AlphaTranslation>0.8</AlphaTranslation>
                        <GammaTranslation>0.8</GammaTranslation>
                        <AlphaRotation>0.5</AlphaRotation>
                        <GammaRotation>0.5</GammaRotation>
                        <ContinueLostTrackingWithOrientationSensor>false</ContinueLostTrackingWithOrientationSensor>
                    </Parameters>
                </Fuser>

                <SensorSource>
                    <SensorID>FeatureTracking1</SensorID>
                    <SensorCosID>Patch2</SensorCosID>
                    <HandEyeCalibration>
                        <TranslationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                        </TranslationOffset>
                        <RotationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                            <W>1</W>
                        </RotationOffset>
                    </HandEyeCalibration>
                    <COSOffset>
                        <TranslationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                        </TranslationOffset>
                        <RotationOffset>
                            <X>0</X>
                            <Y>0</Y>
                            <Z>0</Z>
                            <W>1</W>
                        </RotationOffset>
                    </COSOffset>
                </SensorSource>
            </COS>

        </Connections>
    </TrackingData>