Tutorial of NyARToolkit for Unity With Unity-chan

This tutorial describes the basic process of dealing with the 3D model with the NyARToolkit for Unity.

There are 4 steps.

  • Preparlation of the environment
  • Require hardware and data
  • Modify SimpleNFT code.
  • Test program
  • How to make NFT dataset

Preparlation of the environment

There are preparation before development.

  1. Create a new Unity project
  2. Import NyARToolkit for Unity package
  3. Import SDUnityChan package

Create a new Unity project

Create an empty new Unity project. (Require Unity 5.3.4 or later.)

1

 

Import NyARToolkit for Unity package

Download NyARToolkit for Unity, and drag and drop it to Unity IDE.
https://github.com/nyatla/NyARToolkitUnity/releases

2

Import SDUnityChan package

Download SDUnityChan, and drag and drop it to Unity IDE.
http://unity-chan.com/download/releaseNote.php?id=SDUnityChan&lang=jp

3
The project will be following image after 2 packages were imported.

6

 

Require hardware and data

A list of required things other than computer.

  1. Webcamera
  2. A paper that is printed Unity licence logo.
  3. Nft dataset that made from Unity licence ligo.

Webcamera

Must be connected a webcam to the computer. It is not nesseccary if your computer has internal camera device.

A paper that is printed Unity licence logo, and the NftDatset

These can also be made from the Unity logo image. Howeber for simplity, please download zip file that containe set the necessary data on this tutorial.
unitychan-demodata.zip

Print UCLlogo180mm.pdf to A4 paper. It is Unity licence logo in 180mm width.

The NftDataset is unitychan.nftdataset. It is contained with same zipfile.

Check “Neft dataset that made from Unity licence logo” paragraph if you want to make a dataset.

 

Test program

From here is the main.
Modify sample/SimpleNft scine to display Unity-chan on the captured image.

 

Edit Object tree

Open SimpleNft scene. Next, expand MarkerObject node and delete cube object.

7

In UnityChan/SD_unitychan/Prefab, drag SD_unitychan_humanoid prefab and drop in MarkerObject. MarkerObject is updated automaticary by marker transform matrix. The objects placed under MarkerObject is displayed on Nft target.

9

Copy NFT dataset file

NFT data is unitychan.nftdataset that is in the unitychan-demodata.zip.
unitychan.nftdataset is NFT data set file made from 180mm width Unity license logo.
Replaced it if you have your own data.

First, change file extention to .bytes from .nftdataset. It is necessary in order to read binary file by Unity.

Next, drag unitychan.bytes and drop to Asser/Resource directory. It is able to read file from Unity.

17

Setting for Unity

In NyARToolkit for Unity, the scale unit of Markerobject is treated as 1mm.
In addition, the coordinates is expressed in the XY direction. And the origin is the lower left corner of the image.

Adjust the position and size of the Unity-chan to center of logo.

Remove the SpringManager check because it does not work correctly.

18

 

Edit source code

Finally, change two point on sourcecode.
In SimpleNFT directory, open NftCameraBehaviour.cs file.

Change NFT dataset

Change nftdataset name to infinitycat from unitychan. And change the image width to 180[mm] from 160.

10

Remove Cube related line

Remove a cuble related line.

11

 

Test

After complete, press the play button of Unity. Capture Unity logo image into the camera. Since the unity license logo is a little difficult to recognize. Hold the camera so that the entire logo captured.

19

 

How to make NFT dataset

You can NFT dataset from general image by tool program.

The tool is NftFileGenerator.jar. It is placed in Data/tool directory.
Open Assert directory by Explorer etc.

wp-image-1764″ src=”http://nyatla.jp/nyartoolkit/wp/wp-content/uploads/12.png” alt=”12″ width=”635″ height=”165″ />

In windows, click .bat file. other environment, open the terminal and type a command below.

java -jar NftFileGenerator.jar

After run the tool, Open a source image. Select Import from menu, and select LoadImage.
Next, push MakeFeatureSet button.

14

Dataset generation takes a few minutes.
When complete, feature points are displayedu

15

Finally, save dataset file. Select Export -> NyARTK NFT dataset file from menu. (NyARToolkit for Unity can not handle files that wrote by “Save Feature Set File”.)

 

Dataset parameters

  • SourceDPI – This is main image DPI. Normally, do not need to change.
  • Iset DPIs – Set of pyramid image resolutions. AUTO means auto caluclation from SourceDPI. Custom means manual setting which wrote in lower CSV. Normally, do not need to change.
  • FSET parametor – Parametor of tracking feature points detection.(red square)In proportion to the size of lv, feature points detected is incremented. Adjust when the feature points is too much / too little.

Should be restrict a size of image under VGA size. Large image will take a long time.
If you want to use a large image, use from shrinking.

High contrast image such as Unity licence logo is poor for detection.
Neture image are more good for NFT.

 

 

 

NyARToolkitCS/Unity 5.0.8

NyARToolkitCS/5.0.8 and  NyARToolkit for Unity/5.0.8 were been released.

 

NyARToolkitCS

NyARToolkiyCS can be developed VisualStadio2013  environment.

Download zip file from release page. It contains Solution and projects.

https://github.com/nyatla/NyARToolkitCS/releases

The sample project of NFT is a SimpleNFT. NFT target image is infinitycat.pdf.  it located in Data directory.

The program structure is similar with marker based program.
In case of NFT, use the NFT target data instead of MarkerData.

https://github.com/nyatla/NyARToolkitCS/tree/master/forFW2.0/sample/SimpleNFT

NyARToolkit for Unity

NyARToolkiy for Unity can be developed Unity 5.3   environment.UnityPackage can be download from release.

https://github.com/nyatla/NyARToolkitUnity/releases

NFT sample is located in SimpleNFT directory. The target image(infinitycat.pdf) is located in Data directory.

NyARToolkit for Java 5.0.0

NyARToolkit for Java 5.0.0 has been released.
https://github.com/nyatla/NyARToolkit

NyARToolkit 5.0.0 supports the natural features tracking which is same as implemented on ARToolKit5 (NFT) .

The development of NyARToolKit5 has received the funding and technical assistance by DAQRI LLC.
I’m grateful to DAQRI LLC and ARToolKit team.

How to running NFT sample

  1. Checkout NyARToolKit from Github.
  2. Import NyARToolkit projects to Eclipse. Make sure that there are no errors in the project shown in .
    p1
  3. Print NFT image  to paper. If you do not have a printer, display the pdf file into the screen.
    infinitycat.pdf
  4. Connect your webcam to computer.
  5. Run NftSimpleLite.java in NyARToolkit.sample.jogl package.
    p2
  6. It takes a few seconds to startup. When you take a picture with the camera, The color cube will display on image.
    Ce7VUtqUIAAvu0o

NFT Programming

NFT programming with NyARToolkit is simply.
It requires only a few dozen lines of code.

NftSimpleLite.java is a template of NFT application. You can create the unique application by modify the template.

public class NftSimpleLite extends GlSketch
{
  String nftdataset="d:\\infinitycat";
  String cparam="../../Data/testcase/camera_para5.dat";
  private Webcam camera;
  private NyARGlNftSystem nyar;
  private NyARGlRender render;
  private NyARSensor sensor;
  public void setup(GL gl)throws Exception
  {
    this.size(640,480);
    NyARNftSystemConfig config = new NyARNftSystemConfig(new FileInputStream(cparam),640,480);
    this.camera=Webcam.getDefault();
    this.camera.setViewSize(new Dimension(640,480));
    this.nyar=new NyARGlNftSystem(config);   //create MarkerSystem
    this.render=new NyARGlRender(this.nyar);
    this.sensor=new NyARSensor(config.getScreenSize());
    //
    this.id=this.nyar.addNftTarget(nftdataset,160);
    gl.glEnable(GL.GL_DEPTH_TEST);
    this.camera.open();
  }
  private int id;
  public void draw(GL gl)throws Exception
  {
    synchronized(this.camera){
      try {
        this.sensor.update(new NyARBufferedImageRaster(this.camera.getImage()));        
        this.render.drawBackground(gl,this.sensor.getSourceImage());
        this.render.loadARProjectionMatrix(gl);
        this.nyar.update(this.sensor);
        if(this.nyar.isExistTarget(this.id)){
          this.nyar.loadTransformMatrix(gl,this.id);
          this.render.colorCube(gl,40,80,60,20);
        }
        Thread.sleep(1);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }  
  public static void main(String[] args)
  {
    new NftSimpleLite().run();
    return;
  }
}
  • How to change the tracking image file?
    →Change nftdataset value. In NFT, it need to place 3 files(.iset, .fset, .fset3) onto same path.
    For example: If you specify “d \\ example”, “c:\\ example.iset”, “c:\\ example.fset”, “c:\\example.fset3” will be used as a tracking image.
  • How to change the tracking image size?
    →Set the paper image width in mm to the second parameter of addNftTarget function.
  • How to make the tracking image set file?
    →NftFileGenerator.jar is a fileset generator.
    Download NyARToolkit.utility.zip from the following URL.
    https://github.com/nyatla/NyARToolkit/releases

For compatibility with ARToolKit5

Calculation algorithm of NyARToolKit is identical to the ARToolKit5 but there is a slight difference.
The cause of the difference are the accuracy of floating-point calculations, and the simplification of  the math functions.

The NyARToolKit and ARToolKit data files(iset fset fset3) are compatible.
These files can be used with each other.

 

NyIdマーカの利用権について

NyIdマーカの利用権についてご質問がありましたので、説明を書きました。

NyIdマーカの利用権について

NyIdマーカには、無償で誰でも使用できる利用権の不要なプライベートIDマーカと、利用権を登録して独占的に利用できるグローバルIDマーカがあります。

NyIdの利用権は、グローバルIDマーカを独占する為の有償の権利です。

プライベートIDマーカとグローバルIDマーカの違い

利用権不要なプライベートIDマーカとグローバルIDマーカの違いを説明します。

表示については、どちらのIDマーカも、四角い枠の中にドットを打った同一な形式のマーカです。

  1. プライベートIDマーカ(一意にIDを識別できないマーカ)
    どなたでも利用できるID番号を持つマーカです。利用権無しで無償で使用できますが、同じIDを他の方が違う目的で使用することがあります。また、IDから登録者を逆引きすることが出来ません。
    商用利用は可能ですが、独占利用の宣言と名称の変更は禁止しています。この番号は、NyIDのドメイン0に割り当てられています。
  2. グローバルIDマーカ(一意にIDを識別できるマーカ)
    利用権の所有者のみが使用できるID番号を持つマーカです。有料ですが、所有者以外が同じIDを使用することを制限します。(他の事業者が無断で使用した場合の補償はありません。管理上の公式な逆引き結果は補償します。)
    割当は特定のID空間(例えば1000番~2000番)までをの独占的な割当を行い、
    割当範囲についてNyARToolKitProjectのホームページで公開します。
    所有者は割り当てられたID番号に対して、第三者への利用許可・再販・独占利用の宣言と名称の変更ができます。この番号は、NyIDマーカのドメイン0以外に割り当てられています。

利用権が必要な場合

現在一般的に使われているNyIdマーカは、全てプライベートIDマーカです。

グローバルIDが必要なのは、他の利用者にそのIDマーカを利用させたくない場合と、NyIdマーカの名称を使いたくない場合だけです。

他の利用者が同じIDマーカを使用しても差し支えないアプリケーションかつNyIdマーカの名称を変更する必要が無ければ、無償で利用できるプライベートIDマーカを利用することをお勧めします。