2014-11-28 2 views
0

Моя идея - отображать имена изображений, распознаваемых трекере Metaio. Я успешно смог отобразить изображение, созданное «на лету» для первого COS, но оно не отображает изображение, созданное «на лету» для второго COS. Он обнаруживает второе изображение (он находится внутри этого блока, записал этот код -> Java), но я не понимаю, почему он не отображает изображение для второго. Он определенно определяет второе изображение, потому что, когда я рисую камеру назад к первому изображению только за первые несколько секунд, имя второго изображения отражает и снова меняется на имя первого изображения.Показать изображение на мониторе изображения Metaio для нескольких изображений

Я использовал рекламный щит для создания изображения на лету. Спасибо разработчикам metaio за это!

Ждут ответа. Спасибо заранее, ребята!

screenshot of metaio tracker

Java Code

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); 

// metaioSDK.set }

@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 File

<?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> 

ответ

1

решаемые выделения ИД системы координат соответствующей текстуры, который создается на лету. :)

Смежные вопросы