
I’ve been looking at options to do Augmented Reality (AR) marker detection with Appcelerator Titanium and found a great module created by Atsushi KATAOKA. The original tutorial being in Japanese, I’ve used Google Translate and some guessing to get the module working.
Atsushi has been kind enough to share his code on Github if you want to modify and compile it yourself (You’ll need to fork the experimental branch for it to work with the latest 1.8.x SDK). If you don’t want to play around in xCode to build the module, here is my compiled version compatible with 1.8.x.
The module is iOS only and is based on top of OpenCV for the marker detection.
To install the module, copy the zip file in your /Library/Application Support/Titanium/ folder then reference it in your tiapp.xml (Make sure to clean your build folder).
<modules>
<module platform="iphone" version="0.1">com.armarkerti</module>
</modules>
The AR marker used here is a 16-bit binary number represented by a 4×4 grid of black and white pixels. This means that there are 65,536 possibilities in total (2^16), which translates to 16,456 unique codes since the marker can appear in different angles. The orientation is defined by a 1×1 pixel outside the top left corner.
I’ve modified a script I found online to help generating your marker.

Here is a sample app.js implementation looking for all visible markers and searching for the marker code associated with the letter ‘a’.
var window = Ti.UI.createWindow();
//create the marker overlay
var overlay = Ti.UI.createView({
center: {
x:0,
y:0
},
width:100,
height:100,
backgroundColor:'#fff',
borderRadius:12,
borderColor:'#fff',
visible:false
});
var label = Ti.UI.createLabel({
text:'a',
font: {
fontSize:60
},
width:'auto',
height:'auto',
textAlign:'center'
});
overlay.add(label);
//load and init the module
var armarker = require('com.armarkerti');
var cameraView = armarker.createCameraView();
cameraView.add(overlay);
//everytime a marker is detected
cameraView.addEventListener('detected', function(e) {
var hasMarker = false;
//read through all markers
for(var i in e.markers) {
var marker = e.markers[i];
//look for the 'a' marker code
if(marker.code == 40863) {
//create a 3d Matrix and assign the position
var t = Ti.UI.iOS.create3DMatrix();
t.m11 = marker.transform.m11;
t.m12 = marker.transform.m12;
t.m13 = marker.transform.m13;
t.m14 = marker.transform.m14;
t.m21 = marker.transform.m21;
t.m22 = marker.transform.m22;
t.m23 = marker.transform.m23;
t.m24 = marker.transform.m24;
t.m31 = marker.transform.m31;
t.m32 = marker.transform.m32;
t.m33 = marker.transform.m33;
t.m34 = marker.transform.m34;
t.m41 = marker.transform.m41;
t.m42 = marker.transform.m42;
t.m43 = marker.transform.m43;
t.m44 = marker.transform.m44;
overlay.animate({
transform:t,
duration:0
});
hasMarker = true;
break;
}
}
overlay.visible = hasMarker;
});
window.add(cameraView);
window.open();
Again, most of the credit goes to Atsushi for creating this awesome module. You can now replace the overlay with rich media like images or videos to match your marker. Feel free to ping me on Twitter if you have any questions or comments.