My idea is to display the names of the image recognized by the Metaio image tracker. I was successfully able to display the image created on the fly for the first COS but it doesn't display the image created on the fly for the second COS. It does detect the second image ( it goes inside that if block , have logged that --> Java code ) but i don't get the point why doesn't it shows up the image for the second one. It definitely detects the second image because when i draw the camera back to the first image just for first few miliseconds the name of the second image reflects and it changes to the name of the first image again.
I have used the billboard method of creating the image on the fly. Thanks to the metaio developers for that !
Waiting for a response.. Thanks in advance guys!
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>
Solved by allotting the coordinate system id to the respective texture which was being created on the fly. :)