MarkerSystemで敷居値探索アルゴリズムを変える方法

映像にマーカは映っているのに、何故か認識しないことがありますね。
そんなときに、敷居値探索アルゴリズムを変えると、うまく認識する場合があります。

MarkerSystemを使う場合には、敷居値探索アルゴリズムを簡単に切り替えることができます。

変更方法

アルゴリズムの変更には2つの実装が必要です。

  1. 敷居値決定アルゴリズムを導入したMarkerSystemConfigを定義する。
  2. 新しく定義したMarkerSystemConfigをMarkerSystemへセットする。

次の例では、敷居値探索アルゴリズムを判別法に切り替えています。

MyMarkerSystemConfigの定義

  class MyNyARMarkerSystemConfig extends NyARMarkerSystemConfig
  {
    public MyNyARMarkerSystemConfig(InputStream i_ar_param_stream,int i_width,int i_height) throws NyARException
    {
      super(i_ar_param_stream,i_width,i_height);
    }
    public MyNyARMarkerSystemConfig(int i_width,int i_height) throws NyARException
    {
      super(i_width,i_height);
    }
    public INyARHistogramAnalyzer_Threshold createAutoThresholdArgorism()
    {
      return new NyARHistogramAnalyzer_DiscriminantThreshold();
    }

  }

MarkerSystemへセット

  NyARMarkerSystemConfig config = new MyNyARMarkerSystemConfig(320,240);
  NyARMarkerSystem s=new NyARMarkerSystem(config);

実装済のアルゴリズム

NyARToolKitには3種類の敷居値探索アルゴリズムが実装済みです。これらは、ヒストグラムから敷居値を探索します。

  1. 判別法 NyARHistogramAnalyzer_DiscriminantThreshold
  2. Kittler法 NyARHistogramAnalyzer_KittlerThreshold
  3. Spタイル法 NyARHistogramAnalyzer_SlidePTile

判別法、Kitter法は、良く知られたものです。Spタイル法は、NyARToolKit固有のものです。
NyARToolkitは、標準ではSpタイル法を使っています。

Spタイル法

Spタイル法は、白黒マーカの検出の為に考案した敷居値検出方式です。明点、暗点の両側から、一定割合の画素を除外して、その中心点を敷居値とします。


この方式は、入力画像の暗/明点付近にマーカの構成要素(白/黒)が集中している場合に、良好な結果が得られます。そうでない場合、あまり良い結果が得られません。
例えば、自然画の中にある浅い色のマーカが認識できないようなことが起こります。

独自の敷居値探索アルゴリズムの実装方法

INyARHistogramAnalyzer_Thresholdインタフェイスを実装したクラスを定義し、MarkerSystemConfigにセットすることで、ヒストグラムベースの敷居値探索アルゴリズムを使うことが出来ます。
例えば、次のコードは固定敷居値を返します。

public class MyHistogramAnalyzer implements INyARHistogramAnalyzer_Threshold
{
  public int getThreshold(NyARHistogram i_histogram)
  {
     return 128;
  }
}

敷居値探索オブジェクトは、MarkerSystem起動時に1度だけ作られます。検出してその値を返す以外に、フレーム間で敷居値の平均を取る処理等を追加することも出来ると思います。

NyARToolkit version 4.0.1 Java/C#/Unity Released

NyARToolkit/4.0.1をリリースしました。Java/C#/Unityの同時リリースです。

NyARToolkit for Java

  • MarkerSystemのバグ修正(IdマーカのトラッキングがOFFになっていた問題)
  • 画像タイプにBYTE1D_X8B8G8R8_32を追加
  • NyARGlRender#drawImageをdrawImage2dに変更
  • NyARGlmarkerSystem#getGlMarkerMatrixをgetMarkerMatrixへ変更
  • NyARGlmarkerSystem#getGlMarkerMatrix(int i_id,double[] i_buf)のパラメタを変更
  • NyARGlmarkerSystem#getMarkerPlaneImageの戻り値を変更
  • NyARBufferedImageRasterがB8G8R8X8フォーマットの画像を正しく処理しない不具合を修正。

http://sourceforge.jp/projects/nyartoolkit/releases/?package_id=7512

NyARToolkit for C#

  • Javaに適応した問題の修正

http://sourceforge.jp/projects/nyartoolkit/releases/?package_id=7672

NyARToolkit for Unity

  • NyARToolkit/4.0.1のAPIに対応。
  • サンプルシーン4種を追加。
  • Texture2Dとの画像の相互変換に対応。
  • UnityMarkerSystemクラスを強化。
  • 座標系をX軸で180度回転しました。

http://sourceforge.jp/projects/nyartoolkit/releases/?package_id=12917

English

NyARToolkit/4.0.1 for Java/C#/Unity were released.

NyARToolkit for Java

Fixed some bugs.

  • Updated tracking parametor
  • Fixed a bug of MarkerSystemClass (NyIdMarker did not effect tracking.)
  • Added a new image format BYTE1D_X8B8G8R8_32.
  • Rename NyARGlRender#drawImage to drawImage2d.
  • Rename NyARGlmarkerSystem#getGlMarkerMatrix to getMarkerMatrix
  • Changed parametor of NyARGlmarkerSystem#getGlMarkerMatrix(int i_id,double[] i_buf).
  • Changed the return type of NyARGlmarkerSystem#getMarkerPlaneImage.
  • Fixed a bug of NyARBufferedImageRaster on B8G8R8X8 format.

http://sourceforge.jp/projects/nyartoolkit/releases/?package_id=7512

NyARToolkit for C#

  • Update for NyARToolkit/4.0.1 APIs.

http://sourceforge.jp/projects/nyartoolkit/releases/?package_id=7672

NyARToolkit for Unity

  • Update NyARToolkit/4.0.1 API
  • Added 4 sample seane.
  • Increased Texture2D compatibility.
  • Updated UnityMarkerSystm class.
  • Rotated Z axis around X axis 180 degrees.

http://sourceforge.jp/projects/nyartoolkit/releases/?package_id=12917

NyARToolkit/4.0.0 release

NyARToolkit version 4.0.0をリリースします。

今回の更新では、パフォーマンスを若干犠牲にして、APIの使い勝手とコードの移植性を向上させました。以前のバージョンと比較して、より簡単に、複雑な機能(複数マーカの制御等)が利用できます。

追加機能

主な機能追加は、以前こちらのトピックで紹介した通りですが、もう一つだけ、画像ファイルをそのままマーカパターンに使うための機能を、MarkerSystemに追加しました。

  • MarkerSystemモジュールを追加しました。このモジュールは、NyAR4psgのMultimarkerの上位互換の機能を提供します。自動敷居値設定、複数マーカの管理、トラッキング、座標変換、画像取得機能を提供します。
  • OpenGL環境下で動作する、簡易なスケッチシステムを追加しました。アプリケーションの実装が容易になります。
  • NyARToolkitPro(仮)とのインタフェイスを追加しました。ARToolKitv4のアルゴリズムを、少量の修正のみで、NyARToolkitから使用できるようになります。
  • JavaのBufferedImageとの相互運用インタフェイスを強化しました。PNG画像をマーカパターンに使用したり、画像をBufferedImageで取得することが容易になります。

修正・変更

  • 多くの変更が有ります。一部のAPIは、3.0系のNyARToolkitと互換性がありません。(代替機能は用意してあります。)
  • ラスタ処理系を大幅に変更しました。INyARRaster、INyARRgbRastetrに関連するクラスは、ほぼ全て更新されています。
  • 画像を処理系をグレースケールで処理するようになりました。

ダウンロード

Sorceforcgeからダウンロードして下さい。
http://sourceforge.jp/projects/nyartoolkit/releases/?package_id=7512

English

NyARToolkit version 4.0.0 is released.

In this update, The API access rule and the code portability are more good than old version.  For example, multiple marker handling is more easy. But performance is a little down(3-10%).

New functions

  • MarkerSystem module – The MarkerSystem module provide NyAR4psg like APIs. For example, the module provides, auto threshold detection, multimarker management, tracking , coordinate system converter, image pattern accessor.
  • Sketch system – Sketch system – The sketch system is look like the processing. The sketch system enables application development by shorter code.
  • NyARToolkitV4Pro interface. – NyARToolkitV4 has the NyARToolkitV4Pro addon interface. (It has ARToolKitV4 functions).
  • The interface with BufferedImage of Java is strengthened. For example, a PNG image can be used for a marker pattern as it is.

Update and bugfix

  • A lot of update. Part of APIs are not compatible old NyARToolkit.
  • The raster processor classes was changed a lot. The class revant to INyARRaster and INyARRgbRaster is updated mostly altogether.

NyARToolkitV4 alpha

NyARToolkitV4のAPIの実装が終わりました。パッケージを作るのはまだ先になりそうなので、Subversionリポジトリにソースコードをコミットしました。もしよろしければ、バグ探しにお付き合いください。

リビジョン番号は、906になります。

NyARToolkitV4 alpha version is committed  on SVN repository at rev 906. The package release will be released at a few weeks after.  Please try, if you like it!

http://sourceforge.jp/projects/nyartoolkit/svn/view/NyARToolkit/trunk/?root=nyartoolkit

追加機能

  • MarkerSystemの追加
  • JavaGraphicsとの相互運用性の向上
  • スケッチシステムの追加
  • 画像処理機構の再構築
  • ARToolkitV4 proとのインタフェイスの追加
  • その他、APIの変更など沢山

MarkerSystemの追加

MarkerSystemは、ARマーカとNyIdと同時に複数使用できる、新しいマーカ管理モジュールです。NyARToolkit.sample.joglにサンプルコードがあります。

このモジュールは、コンフィギュレーション、画像取得(センサ)、マーカ管理、画像出力(レンダラ)の4モジュールで構成されています。例えば、画像取得モジュールにはQuickTime、JMF、NyARSensorの3種類があり、これらを切り替えて使うことが出来ます。
今回のMarkerSystemは頂点トラッキング機能があり、従来よりも低速時の追従性が向上しています。

JavaGraphicsとの相互運用性の向上

NyARRasterを介して、BufferedImage、OpenGLテクスチャの間で、画像データの相互運用が出来るようになりました。BufferedImageをOpenGLテクスチャに書き込んだり、元画像をbufferedImageで処理したりすることが容易にできます。

スケッチシステムの追加

processingライクな簡易スケッチシステムを追加しました。プロトタイピングが簡単になります。例えば、SimpleLiteをスケッチシステムとMarkerSystemを使って実装すると、60行ほどでプログラムが完成します。

package jp.nyatla.nyartoolkit.jogl.sample.sketch;

import javax.media.opengl.*;
import jp.nyatla.nyartoolkit.*;
import jp.nyatla.nyartoolkit.jmf.utils.*;
import jp.nyatla.nyartoolkit.jogl.sketch.GlSketch;
import jp.nyatla.nyartoolkit.jogl.utils.*;
import jp.nyatla.nyartoolkit.markersystem.NyARMarkerSystemConfig;
/**
 * JMFからの映像入力からマーカ1種を検出し、そこに立方体を重ねます。
 * ARマーカには、patt.hiroを使用して下さい。
 */
public class SimpleLite extends GlSketch
{
  private NyARJmfCamera camera;
  private NyARGlMarkerSystem nyar;
  private NyARGlRender render;
  public void setup(GL gl)throws NyARException
  {
    this.size(640,480);
    NyARMarkerSystemConfig config = new NyARMarkerSystemConfig(640,480);
    this.camera=new NyARJmfCamera(config,30.0f);//create sensor system
    this.nyar=new NyARGlMarkerSystem(config);   //create MarkerSystem
    this.render=new NyARGlRender(this.nyar);

    this.id=this.nyar.addARMarker(ARCODE_FILE,16,25,80);
    gl.glEnable(GL.GL_DEPTH_TEST);
    this.camera.start();
  }
  private final static String ARCODE_FILE = "../../Data/patt.hiro";
  private int id;

  public void draw(GL gl)
  {
    synchronized(this.camera){
      try {
        this.render.drawBackground(gl, this.camera.getSourceImage());
        this.render.loadARProjectionMatrix(gl);
        this.nyar.update(this.camera);
        if(this.nyar.isExistMarker(this.id)){
          this.render.loadMarkerMatrix(gl,this.id);
          this.render.colorCube(gl,40,0,0,20);
        }
        Thread.sleep(1);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  public static void main(String[] args)
  {
    try {
      new SimpleLite();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return;
  }
}

画像処理機構の再構築

COMインタフェイスを参考にした画像処理機構を導入しました。従来は画像処理機構と画像オブジェクトが分離したモデルでしたが、今回のモデルでは画像オブジェクトが処理インタフェイスを提供し、アプリケーションはインタフェイスを介して画像オブジェクトを操作する形になりました。低速な汎用の処理系と組み合わせることで、高速性と汎用性を両立し、新しい画像形式や画像処理のオフロード対応を容易にします。

ARToolkitV4 proとのインタフェイスの追加

ARToolKit Professionalある位置合わせ技術を使用するためのインタフェイスを追加しました。Pro版については、近いうちにARToolworksから使えるようにしてもらいます。(多分有料)

なお、ARToolKit Professional版の機能を利用する為の変更は、以下のようにコンフィギュレーションの切替(1行)のみで行えます。

:
this.size(640,480);
//This line activates NyARToolkit professional!
NyARProMarkerSystemConfig config = new NyARProMarkerSystemConfig(640,480);
//NyARMarkerSystemConfig(640,480);
this.camera=new NyARJmfCamera(config,30.0f);//create sensor system
this.nyar=new NyARGlMarkerSystem(config);   //create MarkerSystem
this.render=new NyARGlRender(this.nyar);

その他、APIの変更など沢山

リファクタリング、頻度の低い関数の変更、画像処理系の変更に伴う多量の更新が有ります。

不具合報告/ご要望は、twitter、又はフォーラムまでお寄せください。
please your message to Twitter @nyatla or Forum.