Most applications on Android are developed in Java, and Android provides a rich framework of classes to support this. It is, however, also possible to develop parts of an application in native C/C++ code using the Android NDK. This is intended for accessing existing C/C++ codebases or potentially optimizing performance critical functions.

The general approach is to build a native C/C++ shared library containing functions that are exposed using the JNI naming scheme. A Java application can then load the library and map the native functions to Java methods, which can then be called like any other method in Java. Using this approach it is now possible to create ARToolKit applications on Android.

Certain parts of these applications, must be implemented in Java, other parts can be written in C/C++. Therefore, applications will typically be a combination of C/C++, Java, and the “glue” in between.

This SDK includes components in both C/C++ and Java to permit the development of ARToolKit applications on Android. These components include:

  • ARToolKit core modules. These are native static libraries which can be used to build a shared library.
  • ARToolKitWrapper: a C++ wrapper around ARToolKit, providing high level access to ARToolKit functions and marker management, with C and JNI interfaces. This is a native shared library that can be included in an Android application.
  • ARBaseLib: a Java Android library that communicates with ARToolKitWrapper. By using the classes provided ARBaseLib, an Android application gains easy access to the native functionality of ARToolKit.

With these components, several development strategies are possible, ranging in complexity:

  • Native development by creating a new shared library that links to the ARToolKit static libraries.
  • Native development by creating a new shared library that utilizes ARToolKitWrapper.
  • Java development using the provided ARBaseLib (Java) and ARToolKitWrapper (native) libraries.

Video Capture on Android

The ARToolKit port includes almost all of the core modules; the notable exception being the video capture module, which in other ARToolKit versions provides a standard interface for accessing video capture on different platforms and hardware.

Android does not currently permit camera access from native code. Instead, only Java code can open the camera and capture frames. Additionally, a live camera preview must be included in the current Activity’s view for frames to be captured. This means that ARToolKit itself cannot initiate video capture, but must instead wait on the Java application to pass video information and frames using JNI.

Therefore, video capture requires coordination between corresponding libraries on either side of JNI. While this forces a slightly fragmented approach, ARToolKitWrapper and ARBaseLib libraries are provided to handle the issue. Alternatively, the ARNative example included in the SDK demonstrates how to pass video independently of these libraries.

至于校准,属于独立篇章,之后看。

Developing with ARToolKitWrapper and ARBaseLib


You can copy the entire libs directory from: android/libs

Please ensure that you run the build.sh and build native.sh prior to copying the directory.

Read the Android Native Development for more information. Note: There are subdirectories for each CPU architecture, including armeabi, armeabi-v7a, mips and x86. It is the same library built for different instruction sets. The appropriate version is automatically chosen at runtime.

##ARBaseLib ARBaseLib provides additional classes to simplify development.

ARBaseLib is an Android library, meaning that it isn't an Android application itself, but can make use of the Android framework. Android applications can reference the library, and AndroidStudio will take care of including the necessary files when the APK is built and deployed. This allows reusable components to be placed in the library and used in many different examples and applications.

To use ARBaseLib, import the ARBaseLib as new module to your AndroidStudio project:

. **File/Project Structure…**
. Add a new module with the **+** button at the top left of by pressing ⌘+N (OSX) Alt+Insert (Windows)
. Select **Import .JAR/.AAR Package** hit Next
. Select the file with the ... on the right of the first text field. The ARBaseLib.aar file is located in $ARTOOLKIT5ROOT/AndroidStuiodProjects/ARBaseLibProj/arBaseLib/build/outputs/aar/

Development

Referencing ARBaseLib gives the application access to several new classes. Some of the key ones are:

    • ARToolKit:  A singleton class that handles the native calls.
    • ARActivity: A base class for an AR based activity.
    • ARRenderer: A base class for rendering AR scenes.

ARActivity takes care of setting up the view hierarchy that will display the live augmented reality view. The AR view is created by layering an OpenGL surface over the live camera preview surface. By using a transparent background clear color in OpenGL, the live video shows through from below.

A FrameLayout is used to hold the views because children of a FrameLayout are stacked on top of each other – precisely the arrangement required. The following diagram illustrates how the user interface is composed to produce an AR view.

ARActivity must be subclassed to be used. Abstract methods need to be overridden in the subclass to provide ARActivity with the objects it needs to work with.

The first object is a FrameLayout, mentioned above, which will contain the camera and OpenGL views.

protected abstract FrameLayout supplyFrameLayout();

The second required object is a renderer for displaying the AR scene. The renderer must inherit from ARRenderer, another class in ARBaseLib.

protected abstract ARRenderer supplyRenderer();

获得生效的Marker:

int markerID = ARToolKit.getInstance().addMarker("single;/sdcard/AR/Data/patt.hiro;80");
For single markers: single;path_to_pattern_file;pattern_width
Example: single;/sdcard/AR/Data/patt.hiro;80 For multi markers: multi;path_to_multi_config_file
Example: multi;/sdcard/AR/Data/multi/marker.dat

  

Developing directly with ARToolKit

For developers who want more control and direct access to ARToolKit functions, the core ARToolKit modules are available as static libraries:

  • libar: core AR functions
  • libaricp: Iterative Closest Point functions (provided as a built binary only)
  • libarmulti: multimarker support
  • libeden: additional math and rendering functions
  • libgl: OpenGL functions, particularly for video texturing

Android Examples


The examples are divided into 3 sets.

  1. All Java-based: examples where all user-developed code is in Java, and is based on the provided ARBaseLib classes.
  2. Mixed Java and native C/C++ using Android NDK: examples where user-developed code is split between the Java environment and native C/C++ environment. Code can use the provided ARBaseLib java classes while also addressing ARToolKit in C/C++ via the libARWrapper C/C++ API.
  3. AR and rendering code in native C/C++ using Android NDK: examples where most of the user-developed code is native C/C++. These examples offer the greatest power to the AR developer and direct access to the full native ARToolKit API.

All Java-based

  • **ARSimple**: An example that extends the ARActivity class in ARBaseLib to create a simple augmented reality application.
  • **ARSimpleInteraction**: An example that adds simple interaction to ARSimple.
  • **ARMulti**: An example that shows how to configure and use multi marker tracking.
  • **ARDistanceOpenGLES20**: An example on how to measure the distance and draw a line between two markers. The line is drawn using OpenGL ES 2.0 library features.
  • **ARMarkerDistance**: An example on how to measure the distance and draw a line between two markers. The line is drawn using OpenGL ES 1.0 library features.
  • **ARSimpleOpenGLES20**: Pretty much the same as ARSimple with the extension of using OpenGL ES 2.0 features for drawing and coloring the cube.

Mixed Java and Native C/C++ Using Android NDK

  • **ARSimpleNative**: An example that uses an additional native library to perform rendering in C rather than Java.
  • **ARSimpleNativeCars**: An example that uses a native OBJ model loader.

AR and Rendering Code in Native C/C++ Using Android NDK

  • **ARNative**: An example that uses the ARToolKit libraries directly and renders with OpenGL ES 2.0.
  • **ARNativeES1**: An example that uses the ARToolKit libraries directly and renders with OpenGL ES 1.0.
  • **ARNativeOSG**: An example that uses the ARToolKit libraries directly and loads and renders 3D model content using the advanced OpenSceneGraph framework.
  • **nftSimple**: An example that performs NFT (texture tracking) and renders with OpenGL.
  • **nftBook**: An example that performs NFT (texture tracking) and loads and renders 3D model content using the advanced OpenSceneGraph framework.
  • **ARMovie**: An example that performs NFT (texture tracking) and loads and renders 2D video content on devices running Android 4.0.3 and later.

ARNative

Loads marker names from a configuration file. (Square markers only.) The tracking will automatically be set to match the types of square markers (template (pictorial) vs. matrix (barcode)) used in the configuration file. It is not recommended that template and matrix markers are mixed in the same application, as this lowers the tracking reliability of both types.

ARNativeOSG

Loads marker names from a configuration file. (Square markers only.) The tracking will automatically be set to match the types of square markers (template (pictorial) vs. matrix (barcode)) used in the configuration file. It is not recommended that template and matrix markers are mixed in the same application, as this lowers the tracking reliability of both types.

Management of OSG objects is encapsulated in a C-pseudoclass named VirtualEnvironment, which in turn acts through the API offered by the ARosg library. ARosg contains a reasonable amount of functionality for manipulating the scene graph. See the API documentation for libARosg.

nftSimple

Loads NFT dataset names from a configuration file.

The example uses the “Pinball.jpg” image supplied in the “Misc/patterns” folder. ARToolKit NFT requires a fast device, preferably dual-core for good operation, e.g. Samsung Galaxy SII or similar. Build/deployment for Android API 9 (Android OS v2.3) or later is recommended.

nftBook

Loads NFT dataset names from a configuration file.

The example uses the “Pinball.jpg” image supplied in the “Misc/patterns” folder. ARToolKit NFT requires a fast device, preferably dual-core for good operation, e.g. Samsung Galaxy SII or similar. Build/deployment for Android API 9 (Android OS v2.3) or later is recommended.

Management of OSG objects is encapsulated in a C-pseudoclass named VirtualEnvironment, which in turn acts through the API offered by the ARosg library. ARosg contains a reasonable amount of functionality for manipulating the scene graph. See the API documentation for libARosg.

ARMovie

Shows an example of playback of a video file on a marker surface. The example is NDK (native)-based. Movie playback is only supported by Android OS v4.0 (“Ice Cream Sandwich”) and later (Android API level 14), and support varies in quality and reliability from device to device. It is highly recommended that you provide alternate playback mechanisms for devices where playback in the AR environment cannot proceed, e.g. full screen playback.

Android Native Development

The ARToolKit SDK package and the git cloned GitHub local repository of “artoolkit5” includes prebuilt native libraries. It's advised that a local repository be used since the downloaded SDK package is rarely up-to-date with the repository. If you are not planning on altering any native code then you do not need to consult this section or install the Android NDK.

On the other hand, if you want to implement part of your AR application in native code, then you will need to build ARToolKit native C/C++ dependencies.

 貌似也没有什么太特别的东西。代码分析才有干货。

[Artoolkit] ARToolKit's SDK Structure on Android的更多相关文章

  1. 打开SDK Manager检查Android SDK下载和更新失败的解决方法

    [故障描述] 打开SDK Manager检查Android  SDK状况,出现以下情况: Failed to fetch URL https://dl-ssl.google.com/android/r ...

  2. eclipse安装ADT插件重启后不显示Android SDK Manager和Android Virtual Device Manager图标的一种解决办法

    通常安装,搭建安卓环境后,不显示Android SDK Manager和Android Virtual Device Manager ize解决方法:Eclipse ->window->c ...

  3. eclipse中调出android sdk manager和android virtual device manager图标

    有时候在安装ADT插件后,eclipse菜单栏上不会显示android sdk manager和android virtual device manager两个图标, 这个时候,如果安装ADT插件的步 ...

  4. ADT后windows菜单未找到Android SDK Manager和Android Virtual Device Manager该解决方案的选择

    打开今天凌晨ADT准备编译androidproject的时候,突然发现windows菜单下的Android SDK Manager和Android Virtual Device Manager选项不见 ...

  5. cordova 打包出错 Android SDK not found Android target: not installed

    原文:cordova 打包出错 Android SDK not found Android target: not installed 今天用cordova打包的时候报Android SDK not ...

  6. Android Wear - App Structure for Android Wear(应用结构)

    ---------------------------------------------------------------------------------------------------- ...

  7. 趣拍SDK接入问题Android

    Android接入趣拍问题. 大部分android开发者第一次下载SDK后,特别是导入到eclipse后,可以运行工程,但点击app中的record没反映,每次点击record按钮 会出现如下log. ...

  8. Android SDK Tools和Android SDK Platform-tools

    SDK Platform 可以理解为版本,因此有 SDK Platform 7,SDK Platform 8等等Android SDK Tools 是各个版本都可通用的工具文件夹,里面有draw9pa ...

  9. 百度定位SDK:弥补Android基站WIFI定位缺失

    http://tech.qq.com/a/20120524/000347.htm 如今,基于位置信息的移动应用越来越多,从餐饮.购物等本地生活服务,到定向广告的匹配.移动社交网络的构建,LBS类应用的 ...

随机推荐

  1. 喵哈哈村的魔法考试 Round #20 (Div.2) 题解

    题解: A 喵哈哈村的跳棋比赛 题解:其实我们要理解题意就好了,画画图看看这个题意.x<y,那么就交换:x>y,那么x=x%y. 如果我们经过很多次,或者y<=0了,那么就会无限循环 ...

  2. Linux中日期的加减运算

    Linux中日期的加减运算 目录 在显示方面 在设定时间方面 时间的加减 正文 date命令本身提供了日期的加减运算. date 可以用来显示或设定系统的日期与时间. 回到顶部 在显示方面 使用者可以 ...

  3. ES-常见搜索方式

    1.query string search 2.query DSL 3.query filter 4.full-text search 5.phrase search 6.highlight sear ...

  4. Matplotlib新手上路(上)

    matplotlib是python里用于绘图的专用包,功能十分强大.下面介绍一些最基本的用法: 一.最基本的划线 先来一个简单的示例,代码如下,已经加了注释: import matplotlib.py ...

  5. Objective-C学习笔记(三)——用Objective-C编写第一个程序:Hello,World!

    不管是哪一个程序猿,或者是学习哪一门计算机语言.写的第一个程序基本上就是Hello World. 今天我们用OC来实现第一个程序:Hello World. 在Xcode中选择新建一个项目,在对话框中选 ...

  6. Dll注入经典方法完整版

    总结一下基本的注入过程,分注入和卸载 注入Dll: 1,OpenProcess获得要注入进程的句柄 2,VirtualAllocEx在远程进程中开辟出一段内存,长度为strlen(dllname)+1 ...

  7. 在iOS端如何使用Charles用作http调试

    转:http://blog.csdn.net/messageloop3/article/details/9966727 在iOS端如何使用Charles用作http调试 After noticing ...

  8. LeetCode题库13. 罗马数字转整数(c++实现)

    问题描述: 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II  ...

  9. 3、Python的应用

    Python的应用 Google 实现Web爬虫和搜索引擎中的很多组件. Yahoo Yahoo使用它(包括其他技术)管理讨论组. NASA NASA在它的几个系统中既用了Python开发,又将其作为 ...

  10. linux远程开启不挂起的服务

    解决Linux关闭终端(关闭SSH等)后运行的程序自动停止 λ nohup --help Usage: nohup COMMAND [ARG]... or: nohup OPTION Run COMM ...