Sunday, February 10, 2013

Living and dying in the Sunderbans

This is a well established wikipedia fact the the Sunderbans are the world's largest single block of Mangrove forests. It is difficult to grasp the scale and density of it unless you are drifting around in the countless rivers cris-crossing it for an entire day. A couple of days ago, I did just that. Nothing as dangerous as what the locals do - strolling into the deep forest with a pass bought for AUD50 or so and spending days at end collecting fish and honey. Occasionally falling prey to tigers or crocodiles. At least they get to see the elusive tiger briefly. They keep doing it since profit margins are huge, some AUD4000 per month, better than sitting exams and waiting for a government job.

Public river transport
On the same day we saw human footprints heading into the jungle and after drifting around a bit more tiger footprints crossing the river. Crocodiles were everywhere, sunning themselves. We even saw a juvenile croc, looked rather harmless. One of the anecdotes we picked up was about a tiger losing his back legs to a croc while crossing the rivers.
The khal and kumir 
Those who don't earn their living from the forest have taken to clearing it and planting rice. The conservation efforts are ongoing to protect the forest and reduce land clearing. The big cyclone in 2009 - Aila, caused stormsurges and deposited salt on most of the rice fields. This has sent people back to the forests, until the salt tolerant rice comes along. The other noticeable thing was the profusion of solar panels, since most of this area is off the grid. Often there were separate panels supplying separate rooms and one clearly identified for the TV, attached to a satellite dish.
The musicians
The television is a rarity only afforded by the rich. The local live music and theatre scene seems to be pretty active. You can often spot musicians on the ferry heading to a gig on a pushbike with a dhol strapped to their back. Tourism is catching up to provide some more support and even more exposure for the area. It provides an alternative to "jungling", our cook lost her husband to a tiger. However local tourism can be quite destructive, since the locals tend to dump rubbish everywhere and get drunk and drown themselves in the river. Not much different from stories I read about Australians in Laos.

Sunset boat ride
It is a beautiful place, but in the danger of disappearing under the pressure of people. The great economic importance the forests have in their non-destructive use is keeping them from destruction. Things may go slightly awry if urbanisation finally catches up, being off the grid is actually good for this place.

Two weddings and Tiger Footprints

It is that time of the year when I visit my family in India and throw in a drive by tour of another place in Asia. This trip is almost round the world in its scope - Adelaide, Singapore, HongKong, Kunming, Kolkata, Dubai .... back. There are always memorable things at each spot. Singapore airport is just too familiar, but on 2 flights I sat next to Capgemini employees flying in and out of China (from Australia and to India). Something huge is brewing.

Hong Kong skyline
The highlight of HongKong was the busy life-style, crazy shopping and the hybrid cultural wedding. The lights make for great photography and testing out of my new 4/3 camera. Some serious lens shopping coming up. The wedding was a fun, great venue, good scale and +Rowan Fry looked understandly over the moon. The best part was the entrance in traditional chinese gear, he would have made a rather respectable official in imperial china. I wish them a happy life together.

Last week I attended another wedding in Bengal. The contrast was stark, the rush, the colours, the food. The only thing that was constant was the hot wire cut foam decorations, the flowers and the suit I wore to the other wedding. The wedding invitations extend to whoever bothers to come, I hardly knew anybody, not even bride and the groom. Felt a bit like a wedding crasher, till we went to see the bride's dad, he was laid up with all the stress from getting the feast organised for some 600 people.
Devil is in the detail
The last few days we toured the Sunderbans with a Backpackers group aimed at foreigners, much more relaxed than trying to do it packed like sardines in local style. There seems to be zero-respect locally for the Sunderbans, since the majority have not been lucky enough to see the tigers, all believe no tigers exist. They should perform 3D photogrammetry on tiger footprints, lay out some tiger sized dolls and change the holiday season to coincide with tiger mating season. Only then will people believe tigers do exist. Saw plenty of crocs though and some crazy tourists to keep us company. I was both local and foreign, had fun teaching Bengali - managed to teach a Canadian to count to ten. Should start some word association based Bengali learning kit.

Tiger paw prints

Tuesday, December 18, 2012

On map Augmented Reality with Vuforia + Unity

I have been doing some more development with Android, using a different (and easier) renderer this time than the still nascent OpenSceneGraph port, with a bit of Augmented Reality thrown in via Vuforia.Which basically functions as an OpenCV port with image orientation recognition thrown in optimized for Qualcomm's Snapdragon SoC. The feature detection and texture packing is annoyingly performed at the Qualcomm site, I guess they want to keep track of images over which features are detected and prevent inappropriate use by script kiddies. From the looks of FastCV, the features are either MSER or Harris corners.
I already have Android dev kits going so the fun bit was in importing our nice models into Unity and sending the package over to the device. Textured models seem to import best into Unity via Blender, after a bit of copying around of textures and forcing association with the right materials.
Setting up the scene in Unity is fairly straight forward, the Vuforia SDK delegated to Unity for rendering and simply attaches a handler to the Camera. The visible object is automatically centred in the scene so the camera to target geometry is irrelevant in this case. However lighting is not, so a bit of tweaking in lights is necessary for a nice model render. Switch all the materials to diffuse/mobile to load the appropriate shaders in GLES2. Add an LODGroup node if the model is getting too big, though I was able to render some 100,000 triangle models.
When all is set the tracking can begin. I lined up the model to our orthoimagery, the screenshot does not do it justice. It is really cool watching a 3D object stick out of your screen. Everybody at work is very used to viewing things in stereo, but multi-perspective 3D still has a wow-factor.

Tuesday, December 4, 2012

Building OpenSceneGraph with Android NDK

I have been rapidly picking up Android development for the last 2 days with Native coding in C++ thrown in. Cross compiling for embedded systems is nothing new for me having played with Beagleboards in various incarnations, the Hawkboard and Pandaboard. Neither is JNI, I did a fair bit of JNI work while at CSIRO trying to make NetCDF faster.

So to build OpenSceneGraph for Android (I am using my Nexus S running 4.2), do the obvious:
  • Get OSG source
  • Get ADK
  • Get NDK
  • Get ADT if you are Eclipse fan like me
  • Get Sequoyah, CDT and whatever else Eclipse wants to build native code.
Build OSG for Android with whatever hack you can imagine. I ended up getting CMake to generate with NMake build files, but built directly using ndk_build afterwards since the MSYS shell could not access DOS commands ndk-build seems to call. Install automation did not work either so I copied OSG headers over by hand into the build directory. It took a while to build, the NDK compilers are rather slow, in the future I will run with -j 12 to take advantage of all my cores.

The next bit was rather easy since the OSG Android sample is already configured for Eclipse. I had to fix up settings with MSYS for bash. Most tutorials refer to cygwin for Linuxy utilities, but I loathe cygwin and I already a have a bunch of MSYS installs floating around through OSGeo4W and Git-bash. The include files and compiler checks are rather strict in Eclipse and any errors in the IDE will prevent uploading the build, be naughty and just delete the errors due to ADT bugs. This is just a proof of concept after all. I had to change a few little things like false to JNI_FALSE to keep the compiler happy. After some toing and froing with gnustl_static, the whole thing built and ran fine.



I wanted to have jpeg textures embedded in the .ive and .osgb files displayed as well as load models with PagedLOD's over http. So I needed to link the little trivial application to curl and jpeg in their Android native incarnations. The hard work has been done already and you can get thirdparty bundles. The first attempt with 8192x8192 textures expectly blew up on the little platform, but atleast libjpeg seemed to be working, I squished textures down to something sane. Libcurl works to download a file hosted on our webserver just fine, but you can't wait for an eternity on this plaform, unless the basefile is a few kb and links to the rest via LOD's the GL context will be lost before the download finishes. Overall it was a fun experiment and I am glad i managed to load a Jesus statue to celebrate this festive season - though it represents death rather than birth.

Thursday, November 8, 2012

Blender as a Python module, happy coding from Eclipse

This post is going to be a reminder to self in-case I ever need to do this again, or I am cloned and the clone is wondering how the original spent his time.

Get Blender source
Set options as pointed by IdeasMan to build as Python module
Compile with Visual Studio
Set BLENDER_SYSTEM_SCRIPTS as an environment variable, small undocumented caveat where reading the source actually helps.


Import Bpy and Python 3.2 in Eclipse and use Blender algorithms in headless mode.

Tuesday, October 30, 2012

Trivial CMAKE for OpenSceneGraph

It is often fun to get open source projects working with Visual Studio since a lot of build systems leave out a few Microsoft specific vagaries. With CMAKE life in the last few years has become much easier, though sometimes it requires a bit of digging to locate the right incantations to pull in the right dependencies for a trivial project.

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(AeroViewer)

SET(TARGET_SRC aeroviewer.cpp )

find_package(OpenSceneGraph REQUIRED osgDB osgUtil osgGA osgViewer osgText)

ADD_EXECUTABLE(aeroviewer ${TARGET_SRC})

INCLUDE_DIRECTORIES(${OPENSCENEGRAPH_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(aeroviewer ${OPENSCENEGRAPH_LIBRARIES})  


The aim of this quick dash is to add a screen overlay with the company logo to the default osgViewer. This requires adding a geometry node to the scene with some static geometry in camera space. Which ends up being equivalent to a HUD in osg parlance. After a bit of tweaking and rotations in texture space I got this, not too bad for a cold-start in OSG land. This bit of sample code is better for HUD's than the tutorial, the required projection and modelview matrices are encapsulated by the CameraNode.

Saturday, October 20, 2012

Why is gold valuable anyway ? - Midas and Supernovas

Growing up as a child in India in a family of goldsmiths it is hard to ignore the role gold plays in perception of wealth and daily conversation. My uncle would often refer to "stuff" or "maal", meaning gold. On my last visit the regular obsession was checking the current gold price from the wholesalers via SMS. According to a recent article - Man's addiction to gold - India holds pretty large stockpiles of the metal in the proverbial family jewels. It changes hand at marriages as gifts and dowry.

Midas as an allegory of a supernova Gold has no intrinsic bio-chemical value which supports life as the cautionary tale of King Midas points our. Its inherent inertness however gives it great value in the burgeoning electronics industry and it is very rare to start with anyway due to the cosmic element forming processes making it harder and harder to produce heavier elements. The vagaries of nucleosynthesis are so universal that they have even made it to being a Hollywood plot device in "Cowboys and Aliens" where aliens set up a gold mine.

The ultimate statement on how we value things comes down to supply and demand - gold is in short supply due to its nuclear weight and on high demand due to its permanence once acquired. We now just need to find suitable biochemistries or bioelectronics to make it part of a living body. Gold abundance is a measure of the midas touch of supernovas.