This article describes how to enable OpenNI on Android. Currently, the source code of NITE is not avaiable but binaries, and only support Ubuntu, MacOS and Windows. So you may see lots of demo on those OS but leak of Android. OpenNI is going to support Andorid but on ARM from the discussion group and trying to make it stronger, you can also search some demo on ARM-based Android. Hence, I try to enable it on IA architecture. But because leak of NITE source code or binary for Android, so lots of key function could not work like Gesture detection, Skeleton, User Tracking and etc. In current stage, it is just a "garbage" demo and we hope the NITE for Android could be released soon and support Android-IA. At this moment, just can get the depth information from the sensor.
Download OpenNI, Xiton sensor module & Android NDK
OpenNI:
Xiton sensor module
NDK
Step 1: Add supporting for Android x86:
Create a folder name called “Android-x86” under $(OpenNI_PATH)/Include
Shell > cd Android-x86
Shell > cp ../Android-Arm/* ./
Shell > mv XnPlatformAndroid-Arm.h XnPlatformAndroid-x86.h
Open the file and replace Arm to x86 as following file.
========================================================================================================
#ifndef _XN_PLATFORM_ANDROID_X86_H_
#define _XN_PLATFORM_ANDROID_X86_H_
// Start with Linux-x86, and override what's different
#include "../Linux-x86/XnPlatformLinux-x86.h"
//---------------------------------------------------------------------------
// Platform Basic Definition
//---------------------------------------------------------------------------
#undef XN_PLATFORM
#undef XN_PLATFORM_STRING
#define XN_PLATFORM XN_PLATFORM_ANDROID_X86
#define XN_PLATFORM_STRING "Android-x86"
#define XN_PLATFORM_HAS_NO_TIMED_OPS
#define XN_PLATFORM_HAS_NO_CLOCK_GETTIME
#define XN_PLATFORM_HAS_NO_SCHED_PARAM
#define XN_PLATFORM_HAS_BUILTIN_SEMUN
#define XN_PLATFORM_LINUX_NO_GLIBC
#define XN_PLATFORM_LINUX_NO_SYSV
#define XN_PLATFORM_LINUX_NO_GLOB
#define XN_PLATFORM_LINUX_NO_POSIX_MEMALIGN
#define XN_PLATFORM_LINUX_NO_SHM
#define XN_PLATFORM_LINUX_NO_PTHREAD_CANCEL
#endif //_XN_PLATFORM_LINUX_X86_H_
========================================================================================================
Step 2: Modify files to support Android on x86
2-1. Open XnPlatform.h and add the text in red as following
Add
#define XN_PLATFORM_ANDROID_X86 10
and insert the following codes in red.
#elif defined(ANDROID) && defined(_arm_)
#include "Android-Arm/XnPlatformAndroid-Arm.h"
#elif defined(ANDROID) && defined(i386)
#include "Android-x86/XnPlatformAndroid-x86.h"
2-2. Open Source/XnDeviceSensorV2/XnDeviceSensorInit.h and add the text in red as following
#elif (XN_PLATFORM == XN_PLATFORM_LINUX_X86 || XN_PLATFORM == XN_PLATFORM_LINUX_ARM || XN_PLATFORM == XN_PLATFORM_MACOSX || XN_PLATFORM ==
XN_PLATFORM_ANDROID_ARM || XN_PLATFORM == XN_PLATFORM_ANDROID_X86)
#define XN_SENSOR_USB_IMAGE_BUFFER_SIZE_MULTIPLIER_ISO 32
#define XN_SENSOR_USB_IMAGE_BUFFER_SIZE_MULTIPLIER_BULK 40
2-3. Open ./OpenNI/Source/XnDeviceSensorV2/XnDeviceSensorInit.cpp and add the text in red as following
#if (XN_PLATFORM == XN_PLATFORM_ANDROID_ARM || XN_PLATFORM == XN_PLATFORM_ANDROID_X86)
nRetVal = xnOSCreateMutex(&pDevicePrivateData->hExecuteMutex);
XN_IS_STATUS_OK(nRetVal);
#else
2-4. Open ./OpenNI/Source/OpenNI/XnOpenNI.cpp and add the text in red as following
#elif (XN_PLATFORM == XN_PLATFORM_ANDROID_ARM || XN_PLATFORM == XN_PLATFORM_ANDROID_X86)
#define XN_OPEN_NI_FILES_LOCATION "/data/ni/"
#else
#error "Unsupported platform!"
#endif
2-5.Open ./OpenNI/Source/OpenNI/Linux/LinuxProcesses.cpp and add the text in red as following
#if (XN_PLATFORM == XN_PLATFORM_MACOSX || XN_PLATFORM == XN_PLATFORM_ANDROID_ARM || XN_PLATFORM == XN_PLATFORM_ANDROID_X86)
#include
#else
#include
#endif
2-6. Open ./OpenNI/Source/OpenNI/Linux/XnUSBLinux.cpp and add the text in red as following
#if (XN_PLATFORM == XN_PLATFORM_ANDROID_ARM || XN_PLATFORM == XN_PLATFORM_ANDROID_X86)
#include
#else
#include
#endif
2-7.Open ./OpenNI/Include/XnOS.h and add the text in red as following
#if (XN_PLATFORM == XN_PLATFORM_WIN32)
#include "Win32/XnOSWin32.h"
#elif (XN_PLATFORM == XN_PLATFORM_LINUX_X86 || XN_PLATFORM == XN_PLATFORM_LINUX_ARM || XN_PLATFORM == XN_PLATFORM_MACOSX || XN_PLATFORM ==
XN_PLATFORM_ANDROID_ARM ||XN_PLATFORM == XN_PLATFORM_ANDROID_X86)
#include "Linux-x86/XnOSLinux-x86.h"
#elif defined(_ARC)
#include "ARC/XnOSARC.h"
#else
#error OpenNI OS Abstraction Layer - Unsupported Platform!
#endif
Step 3: Merge OpenNI & Senor folder for easier compiling... :p
shell > cp -arf $(PATH_TO_SENSOR)/Platform/Android/* $(PATH_TO_OPENNI)/Platform/Android/
shell > cp -arf $(PATH_TO_SENSOR)/Include/* $(PATH_TO_OPENNI)/Include/
Step 4: Moidfy ABI from armeabi-v7a to x86
shell > cd $(PATH_TO_OPENNI)/Platform/Android/jni
4.1 Modify Application.mk
Open Application.mk and change the APP_ABI setting from armeabi-v7a to x86 and also remark the APP_CFLAGS
APP_ABI := x86
#APP_CFLAGS := -O3 -ftree-vectorize -ffast-math -funroll-loops
4.2 Modify Android.mk
Open Android.mk and remove $(call import-module,OpenNI)
#$(call import-module,OpenNI)
Step 5: Remove --dynamic-linker compiler option
Search for *.mk under jni folder and remove --dynamic-linker compiler option
Step 6: Build
then run ndk-build under $(SOURCE_ROOT)/Platform/Android/jni/
Step 7: Copy shared libaries
7.1 Remount system as read/write (Optional)
7.2 Copy Platform/Android/libs/x86/*.so to the Android rootfs under system/lib
7.3 Copy all executable files under Platofrm/Android/obj/local/x86/ to Android rootfs under system/xbin
These execuatable files are for debug purpose, they are niReg, niLicense, Sample-SimpleRead & Sample-SimpleSkeleton
Step 8: mount usbfs
/system/xbin/busybox/mount -o devmode=0666 -t usbfs none /proc/bus/usb
Step 8: Copy config files to Android rootfs as following (find the files in Attached files section)
- copy SampleConfig.xml to /data/ni & /data/
- copy modules.xml to /data/ni
- copy licenses.xml to /data/ni
- copy GlobalDefaults.ini to /usr/etc/primesense
Please reference to the 4th link listed in Reference for SDK and NDK installation. This application is called SimpleViewer.
Result:
Attached Files
I don't know how to attach files in webpages :p
Reference:
- http://www.hirotakaster.com/archives/2012/03/openni-for-android-apk-and-shared-binaries.php
- http://www.cnblogs.com/xiaowenji/archive/2011/03/12/1982309.html
- http://www.hirotakaster.com/archives/2012/05/openni-and-sensorkinect-for-android.php
- http://www.hirotakaster.com/archives/2012/01/how-to-build-openni-android-application.php