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.

 

 

 

NyARToolkit for UnityでUnityちゃんを動かす

[English]

動画で紹介したNyRToolkitでUnityちゃんを動かすデモの作り方です。


以下の順で説明します。

  • 開発環境の準備
  • 機材とデータの準備
  • プログラムの改造
  • テスト
  • NFTデータセットの作り方

開発環境の準備

NyARToolkitでUnityちゃんを表示するためのプロジェクトを準備します。

  1. 新しいプロジェクトを作る
  2. NyARToolkit for Unityをインポートする
  3. SDUnityChanをインポートする

新しいプロジェクトを作る

Unityを起動して、空のプロジェクトを作成してください。(Unityのバージョンは5.3.4以降を使います)

1

 

NyARToolkit for Unityをインポートする

NyARToolkit for Unityのパッケージをダウンロードして、Unityへドラック&ドロップしてインポートします。
https://github.com/nyatla/NyARToolkitUnity/releases

2

SDUnityChanをインポートする

SDUnityChanのパッケージをダウンロードしてインポートします。
http://unity-chan.com/download/releaseNote.php?id=SDUnityChan&lang=jp

3

 

2つのパッケージを導入すると、projectは以下のようになります。

6

 

機材とデータの準備

デモには、PC以外に以下の機材が必要になります。

  1. ウェブカメラ
  2. Unityライセンスロゴを印刷した紙
  3. UnityライセンスロゴのNFTデータセット

ウェブカメラ

1つ以上のカメラがPCに接続されている必要があります。USBカメラなどを接続しておいてください。カメラ内蔵のPCの場合は必要ありません。

Unityちゃんマークを印刷した紙とNFTデータセット

これらはUnityライセンスのロゴイメージから作ることもできますが、必要なデータをセットにしたzipファイルを用意したのでダウンロードしてください。

unitychan-demodata.zip

zipファイルの中にあるUCLlogo180mm.pdfをA4用紙に印刷してください。このpdfは、Unityライセンスロゴを幅18cmで印刷した用紙です。

NFTターゲットデータは、同じくzipファイルの中にある、unitychan.nftdatasetを使います。

元の画像UCLlogo.pngから自作する場合は、解説の最後にあるNFTデータセットの作り方を参照してください。

 

プログラムの改造

ここから本編です。先ほど準備した開発環境にあるsample/SimpleNftシーンを改造して、Unityちゃんを表示するようにします。

 

オブジェクトツリーの編集

SimpleNftシーンを開いてください。シーンのHierarchyタブにあるMarkerObjectを展開すると、Cubeオブジェクトがあるので削除します。

7

UnityChan/SD_unitychan/Prefabにある、SD_unitychan_humanoidのPrefabをMarkerObjectの子にドラック&ドロップします。MarkerObjectはNFT位置に合わせて姿勢変換行列が更新されるオブジェクトです。この下に配置したオブジェクトがマーカの上に表示されます。

9

NFTデータセットのコピー

unitychan-demodata.zipの中にあるunitychan.nftdatasetを使います。unitychan.nftdatasetは、幅180mmのUnityライセンスロゴ用のNFTデータセットファイルです。自作した場合は置き換えて進めてください。

まず初めに、ファイルの拡張子を.nftdatasetから.bytesに変更します。これはUnityでバイナリファイルを埋め込むために必要な手順です。

次に、unitychan.bytesをAssetのResourceディレクトリにドラッグ&ドロップしてコピーします。これでUnityからリソースファイルを読むことができるようになります。

17

Unityちゃんの設定

NyARToolkit for Unityでは、マーカのスケール値1が1mmとして扱われます。また、中心座標は画像の左下を起点にXY方向で表現されています。Unityちゃんの位置とサイズを調整して、ロゴマークの中央にUnityちゃんが立つように設定します。

また、SpringManagerが有効だとうまく動かないので、チェックを外します。

18

 

コードの編集

最後に、C#コードを2か所書き換えて完成です。SimpleNFTのディレクトリにある、NftCameraBehaviour.csをダブルクリックして、開きます。変更箇所は2か所です。

NFTデータセットの変更

NFTデータセットをinfinitycatから先ほど追加したunitychanに書き換えます。また、画像の横幅を160から180(単位はmm)に書き換えます。

10

Cubeを操作する行の削除

削除したCubeに関わる行を削除します。

11

 

テスト

完成したらUnityのプレイボタンを押してみてください。画面にカメラ映像がでたら、印刷しておいたUnityちゃんロゴを撮影してみましょう。ユニティライセンスのロゴはやや認識しにくいので、ロゴ全体が撮影されるようにカメラを構えてください。

19

 

NFTデータセットの作り方

認識対象にするNFTデータセットは、ツールを使って画像ファイルから作ることができます。

ツールはNyARToolkit for UnityのData/toolディレクトリにあるNftFileGenerator.jarです。エクスプローラなどでNyARToolkit for UnityのAssetsディレクトリを開くと以下のファイルが見つかります。12

Windowsでは.batファイルをダブルクリックして下さい。その他のシステムでは、以下のようにターミナルから実行してください。

java -jar NftFileGenerator.jar

ツールが起動したら、元となる画像を読み込みます。メニューからImportを選択して、LoadImageを選択します。ダイアログが開くので画像をロードして、MakeFeatureSetを押してください。

14

データセットの生成には数分間かかります。しばらくお待ちください。出来上がると特徴点が表示されます。

15

出来上がったら、メニューからExport→Save NyARTK NFT dataset fileを選択してデータセットファイルを保存してください。(Save Feature Set Fileで保存したファイルはUnityでは使用できません。)

 

データセットのパラメタについて

  • SourceDPI – 画像のDPI値を設定します。特に変更する必要はありません。
  • Iset DPIs – ピラミッド画像の解像度セットです。AUTOはSourceDPIから自動で計算します。Customの場合は下段のカンマ区切りの数値の解像度セットを使います。特に変更する必要はありません。
  • FSET parametor – トラッキング特徴点(赤□)を検出するパラメータです。Lvが大きいほど検出する特徴点が多くなります。特徴点が多すぎる/少なすぎる場合に調整してください。

入力できる画像サイズはVGAサイズ以下にしてください。大きな画像を使いたい場合は、事前に縮尺してから使用してください。

Unityロゴのようなコントラストの強い白黒画像は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.

NyARToolkitCS/Unity 5.0.8リリース

NyARToolkitCS/5.0.8、及び、NyARToolkit for Unity/5.0.8をリリースしました。

VisualStadio開発環境と、UnityでもNFTが使用できるようになります。

 

NyARToolkitCS

NyARToolkitCSは、VisualStadio2013で開発することができます。
releaseからzipファイルをダウンロードして、展開してください。
https://github.com/nyatla/NyARToolkitCS/releases

NyARToolkitCSのNFTサンプルは、SimpleNFTプロジェクトです。NFTターゲットは、Dataにあるinfinitycat.pdfを使います。マーカの代わりにNFTターゲットを登録すること以外は、マーカベースのプログラムとほぼ同じです。

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

 

NyARToolkit for Unity

NyARToolkitCSは、Unity 5.3以降で開発することができます。
releaseからpackageファイルをダウンロードして、Unityへインポートしてください。

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

NFTサンプルは、SimpleNFTディレクトリにあります。NFTターゲットは、Dataにあるinfinitycat.pdfを使います。マーカの代わりにNFTターゲットを登録すること以外は、マーカベースのプログラムとほぼ同じです。

 

NyARToolkit for Processing 3.0.2

[Japanese] [Spanish(Emiliusvgs)]

NyARToolkit for Processing 3.0.2 is released.

n5psg3

New library can handle Neture Feature Tracking easily.

https://github.com/nyatla/NyARToolkit-for-Processing

NFT Sample Sketch

NFT sketch is very simple.

// examples/Simplenft.pde
import processing.video.*;
import jp.nyatla.nyar4psg.*;

Capture cam;
MultiNft nya;

void setup() {
  size(640,480,P3D);
  colorMode(RGB, 100);
  println(MultiMarker.VERSION);
  cam=new Capture(this,640,480);
  nya=new MultiNft(this,width,height,"camera_para5.dat",NyAR4PsgConfig.CONFIG_PSG);
  nya.addNftTarget("infinitycat",160);//id=0
  cam.start();
}

void draw()
{
  if (cam.available() !=true) {
      return;
  }
  cam.read();
  nya.detect(cam);
  background(0);
  nya.drawBackground(cam);//frustumを考慮した背景描画
    if(!nya.isExist(0)){
      return;
    }
    nya.beginTransform(0);
    fill(255,0,0);
    translate(-80,55,20);
    box(40);
    nya.endTransform(); 
}

The program sequence are same as marker sketch.
The only difference is that are using the MultiNft instead of MultiMarker.

How to change NFT target

In order to make the NFT target fileset to use the nftFilesGen sketch.
Sketch will launch the file generator.