Exemplo n.º 1
0
        /**
         * ImputStreamからARToolKit形式のマーカデータを読み込み、o_codeオブジェクトへ格納します。
         * @param i_stream
         * 読出し元のストリームです。
         * @param o_code
         * 出力先の{@link NyARCode}オブジェクトです。
         * @
         */
        public static void loadFromARToolKitFormFile(StreamReader i_stream, NyARCode o_code)
        {
            int           width      = o_code.getWidth();
            int           height     = o_code.getHeight();
            NyARRgbRaster tmp_raster = new NyARRgbRaster(width, height, NyARBufferType.INT1D_X8R8G8B8_32);

            //4個の要素をラスタにセットする。
            try
            {
                int[]    buf  = (int[])tmp_raster.getBuffer();
                string[] data = i_stream.ReadToEnd().Split(new Char[] { ' ', '\r', '\n' });
                //GBRAで一度読みだす。
                int idx = 0;
                for (int h = 0; h < 4; h++)
                {
                    idx = readBlock(data, idx, width, height, buf);
                    //ARCodeにセット(カラー)
                    o_code.getColorData(h).setRaster(tmp_raster);
                    o_code.getBlackWhiteData(h).setRaster(tmp_raster);
                }
            }
            catch (Exception e)
            {
                throw new NyARException(e);
            }
            tmp_raster = null;//ポイ
            return;
        }
Exemplo n.º 2
0
        /// <summary>
        /// {@link #addARMarker(INyARRgbRaster, int, int, double)}のラッパーです。Bitmapからマーカパターンを作ります。
        /// 引数については、{@link #addARMarker(INyARRgbRaster, int, int, double)}を参照してください。
        /// 
        /// </summary>
        /// <param name="i_img"></param>
        /// <param name="i_patt_resolution">生成するマーカの解像度を指定します。</param>
        /// <param name="i_patt_edge_percentage">画像のエッジ領域を%で指定します。</param>
        /// <param name="i_marker_size">マーカの物理サイズを指定します。</param>
        /// <returns></returns>
        public int addARMarker(Texture2D i_img, int i_patt_resolution, int i_patt_edge_percentage, double i_marker_size)
        {
            int w = i_img.width;
              int h = i_img.height;
              NyARUnityRaster ur = new NyARUnityRaster(i_img);
              NyARCode c = new NyARCode(i_patt_resolution, i_patt_resolution);

              //ラスタからマーカパターンを切り出す
              INyARPerspectiveCopy pc = (INyARPerspectiveCopy)ur.createInterface(typeof(INyARPerspectiveCopy));
              NyARRgbRaster tr = new NyARRgbRaster(i_patt_resolution, i_patt_resolution);
              pc.copyPatt(0, 0, w, 0, w, h, 0, h, i_patt_edge_percentage, i_patt_edge_percentage, 4, tr);

              //切り出したパターンをセット
              c.setRaster(tr);
              return base.addARMarker(c, i_patt_edge_percentage, i_marker_size);
        }
Exemplo n.º 3
0
 /**
  * ImputStreamからARToolKit形式のマーカデータを読み込み、o_codeオブジェクトへ格納します。
  * @param i_stream
  * 読出し元のストリームです。
  * @param o_code
  * 出力先の{@link NyARCode}オブジェクトです。
  * @
  */
 public static void loadFromARToolKitFormFile(StreamReader i_stream, NyARCode o_code)
 {
     int width = o_code.getWidth();
     int height = o_code.getHeight();
     NyARRgbRaster tmp_raster = new NyARRgbRaster(width, height, NyARBufferType.INT1D_X8R8G8B8_32);
     //4個の要素をラスタにセットする。
     try
     {
         int[] buf = (int[])tmp_raster.getBuffer();
         string[] data = i_stream.ReadToEnd().Split(new Char[] { ' ', '\r', '\n' });
         //GBRAで一度読みだす。
         int idx = 0;
         for (int h = 0; h < 4; h++)
         {
             idx = readBlock(data, idx, width, height, buf);
             //ARCodeにセット(カラー)
             o_code.getColorData(h).setRaster(tmp_raster);
             o_code.getBlackWhiteData(h).setRaster(tmp_raster);
         }
     }
     catch (Exception e)
     {
         throw new NyARException(e);
     }
     tmp_raster = null;//ポイ
     return;
 }
Exemplo n.º 4
0
        /**
         * このターゲットについて、非同期に認識依頼を出します。このプログラムはサンプルなので、別スレッドでIDマーカ判定をして、
         * 三秒後に適当なサイズとDirectionを返却するだけです。
         * @param i_target
         * @return
         * @throws NyARException
         */
        public void requestAsyncMarkerDetect(NyARReality i_reality, NyARRealitySource i_source, NyARRealityTarget i_target)
        {
            //ターゲットから画像データなどを取得するときは、スレッドからではなく、ここで同期して取得してコピーしてからスレッドに引き渡します。

              //100x100の領域を切りだして、Rasterを作る。
              NyARRgbRaster raster = new NyARRgbRaster(100, 100, NyARBufferType.INT1D_X8R8G8B8_32);
              i_reality.GetRgbPatt2d(i_source, i_target.refTargetVertex(), 1, raster);
              //コピーしたラスタとターゲットのIDをスレッドへ引き渡す。
              Thread t = new Thread(new AsyncThread(this, i_target.getSerialId(), raster).Run);
              t.Start();
              return;
        }
Exemplo n.º 5
0
 public AsyncThread(ASyncIdMarkerTable i_parent, long i_serial, NyARRgbRaster i_raster)
 {
     this._parent = i_parent;
     this._serial = i_serial;
     this._source = i_raster;
 }
Exemplo n.º 6
0
 /**
  * この関数は、画像からARマーカパターンを生成して、登録します。
  * ビットマップ等の画像から生成したパターンは、撮影画像から生成したパターンファイルと比較して、撮影画像の色調変化に弱くなります。
  * 注意してください。
  * @param i_raster
  * マーカ画像を格納したラスタオブジェクト
  * @param i_patt_resolution
  * マーカの解像度
  * @param i_patt_edge_percentage
  * マーカのエッジ領域のサイズ。マーカパターンは、i_rasterからエッジ領域を除いたパターンから生成します。
  * ARToolKitスタイルの画像を用いる場合は、25を指定します。
  * @param i_marker_size
  * マーカの平方サイズ[mm]
  * @return
  * マーカID(ハンドル)値。
  * @throws NyARException
  */
 public int addARMarker(INyARRgbRaster i_raster, int i_patt_resolution, int i_patt_edge_percentage, double i_marker_size)
 {
     NyARCode c = new NyARCode(i_patt_resolution, i_patt_resolution);
       NyARIntSize s = i_raster.getSize();
       //ラスタからマーカパターンを切り出す。
       INyARPerspectiveCopy pc = (INyARPerspectiveCopy)i_raster.createInterface(typeof(INyARPerspectiveCopy));
       NyARRgbRaster tr = new NyARRgbRaster(i_patt_resolution, i_patt_resolution);
       pc.copyPatt(0, 0, s.w, 0, s.w, s.h, 0, s.h, i_patt_edge_percentage, i_patt_edge_percentage, 4, tr);
       //切り出したパターンをセット
       c.setRaster(tr);
       return this.addARMarker(c, i_patt_edge_percentage, i_marker_size);
 }