2012年9月30日 星期日

OpenNI on Android-x86

OpenNI on Android-x86


  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:
            https://github.com/OpenNI/OpenNI.git
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)
  1. copy SampleConfig.xml to /data/ni & /data/
  2. copy modules.xml to /data/ni
  3. copy licenses.xml to /data/ni
  4. copy GlobalDefaults.ini to /usr/etc/primesense
Step 9: Build Android application with Eclipse
    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:





2011年12月6日 星期二

Qemu-1.0 rc

Qemu-1.0 release了, 但是目前還是在RC stage,http://wiki.qemu.org/Download
從source code可以看出,以前比較屬於H/W engeineer的coding style有一些改變囉~~越來越有 fu 了~~新的version也有支援一些ARM A15的指令,和 ARM 相關的 change log 如下:

1. QEMU now supports the new Cortex-A15 instructions in linux-user mode (via "-cpu any"): VFPv4 fused multiply-accumulate (VFMA, VFMS, VFNMA, VFNMS) and also integer division (UDIV, SDIV).
2. The vexpress-a9, versatileab, versatilepb and realview-* boards now have audio support.
3. QEMU is known not to work on ARM hosts in this release. (ARM target emulation is fine.)

一些額外自已可以設定的參數,也使用了script 去parsing qemu-options.hx以產生qemu-options.def讓c file去include,增加了一些小彈性。