Пример #1
0
        /**
         * ImputStreamからARToolKit形式のマーカデータを読み込んでo_codeに格納します。
         * @param i_stream
         * 読出し元のストリームです。
         * @param o_code
         * 出力先のNyARCodeオブジェクトです。
         * @throws NyARException
         */
        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;
        }
 /** <summary>
 * {@link #addARMarker(INyARRgbRaster, int, int, double)}It is a wrapper. I make a marker pattern from Bitmap.
 * The arguments are{@link #addARMarker(INyARRgbRaster, int, int, double)}Please refer to the.
 *
 * </summary>
 * <param name="i_img"></param>
 * <param name="i_patt_resolution">I specify the resolution of the marker to be generated.</param>
 * <param name="i_patt_edge_percentage">Specifies the percentage of the edge region of the image.</param>
 * <param name="i_marker_size">I specify the physical size of the marker.</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);
     //Marker pattern cut out from a raster
     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);
     //Set the pattern cut
     c.setRaster(tr);
     return base.addARMarker(c, i_patt_edge_percentage, i_marker_size);
 }
 //
 // This reogion may be moved to NyARJ2seMarkerSystem.
 //
 /// <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(Bitmap 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;
     using (NyARBitmapRaster bmr = new NyARBitmapRaster(i_img))
     {
         NyARCode c = new NyARCode(i_patt_resolution, i_patt_resolution);
         //ラスタからマーカパターンを切り出す。
         INyARPerspectiveCopy pc = (INyARPerspectiveCopy)bmr.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);
     }
 }
Пример #4
0
        public void Test()
        {
            //AR用カメラパラメタファイルをロード
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(camera_file));
            ap.changeScreenSize(320, 240);

            //AR用のパターンコードを読み出し	
            NyARCode code = NyARCode.createFromARPattFile(new StreamReader(code_file), 16, 16);

            //試験イメージの読み出し(320x240 BGRAのRAWデータ)
            StreamReader sr = new StreamReader(data_file);
            BinaryReader bs = new BinaryReader(sr.BaseStream);
            byte[] raw = bs.ReadBytes(320 * 240 * 4);
            
//            NyARBitmapRaster ra = new NyARBitmapRaster(320, 240);
//            Graphics g = Graphics.FromImage(ra.getBitmap());
//            g.DrawImage(new Bitmap("../../../../../data/320x240ABGR.png"), 0, 0);
            

            NyARRgbRaster ra = new NyARRgbRaster(320, 240,NyARBufferType.BYTE1D_B8G8R8X8_32,false);
            ra.wrapBuffer(raw);

            //1パターンのみを追跡するクラスを作成
            NyARSingleDetectMarker ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0,NyARSingleDetectMarker.PF_NYARTOOLKIT);
            NyARDoubleMatrix44 result_mat = new NyARDoubleMatrix44();
            ar.setContinueMode(false);
            ar.detectMarkerLite(ra, 100);
            ar.getTransmationMatrix(result_mat);

            //マーカーを検出
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 1000; i++)
            {
                //変換行列を取得
                ar.detectMarkerLite(ra, 100);
                ar.getTransmationMatrix(result_mat);
            }
            Console.WriteLine(result_mat.m00 + "," + result_mat.m01 + ","+result_mat.m02+","+result_mat.m03);
            Console.WriteLine(result_mat.m10 + "," + result_mat.m11 + ","+result_mat.m12+","+result_mat.m13);
            Console.WriteLine(result_mat.m20 + "," + result_mat.m21 + ","+result_mat.m22+","+result_mat.m23);
            Console.WriteLine(result_mat.m30 + "," + result_mat.m31 + ","+result_mat.m32+","+result_mat.m33);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds + "[ms]");
            return;
        }
Пример #5
0
        public void Test()
        {
            //AR用カメラパラメタファイルをロード
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(camera_file));
            ap.changeScreenSize(320, 240);

            //試験イメージの読み出し(320x240 RGBのRAWデータ)
            StreamReader sr = new StreamReader(data_file);
            BinaryReader bs = new BinaryReader(sr.BaseStream);
            byte[] raw = bs.ReadBytes(320 * 240 * 3);
            NyARRgbRaster ra = new NyARRgbRaster(320, 240,NyARBufferType.BYTE1D_R8G8B8_24,false);
            ra.wrapBuffer(raw);

            MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferType());
            pr.detectMarker(ra);
            Console.WriteLine(pr.transmat.m00 + "," + pr.transmat.m01 + "," + pr.transmat.m02 + "," + pr.transmat.m03);
            Console.WriteLine(pr.transmat.m10 + "," + pr.transmat.m11 + "," + pr.transmat.m12 + "," + pr.transmat.m13);
            Console.WriteLine(pr.transmat.m20 + "," + pr.transmat.m21 + "," + pr.transmat.m22 + "," + pr.transmat.m23);
            Console.WriteLine(pr.transmat.m30 + "," + pr.transmat.m31 + "," + pr.transmat.m32 + "," + pr.transmat.m33);
            Console.WriteLine(pr.current_id);
            return;
        }
        /**
         * このターゲットについて、非同期に認識依頼を出します。このプログラムはサンプルなので、別スレッドで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;
        }
 public AsyncThread(ASyncIdMarkerTable i_parent,long i_serial,NyARRgbRaster i_raster)
 {
     this._parent=i_parent;
     this._serial=i_serial;
     this._source=i_raster;
 }
	/**
	 * この関数は、画像から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);
	}
 /**
  * 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;
 }