Exemplo n.º 1
0
        public SimpleLiteD3d(NyARToolkitCS topLevelForm, ResourceBuilder i_resource)
        {
            NyMath.initialize();
            this._capture = i_resource.createWmCapture();
            this._capture.setOnSample(this);

            this._d3dmgr = i_resource.createD3dManager(topLevelForm);
            this._back_ground = i_resource.createBackGround(this._d3dmgr);
            this._d3dcube = new ColorCube(this._d3dmgr.d3d_device,40);


            //AR用のパターンコードを読み出
            NyARCode code = i_resource.createNyARCode();
            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this.m_raster = i_resource.createARRaster();

            //1パターンのみを追跡するクラスを作成
            this.m_ar = new NyARSingleDetectMarker(i_resource.ar_param, code, 80.0, this.m_raster.getBufferType());
            //計算モードの設定
            this.m_ar.setContinueMode(false);

            ////立方体(頂点数8)の準備


            return;
        }
        /* 非同期イベントハンドラ
          * CaptureDeviceからのイベントをハンドリングして、バッファとテクスチャを更新する。
          */
        public void onSample(WmCapture i_sender, INySample i_sample)
        {
            int w = SCREEN_WIDTH;
            int h = SCREEN_HEIGHT;
            int s = w * h;

            Thread.Sleep(0); 
            lock (this)
            {
                //カメラ映像をARのバッファにコピー
                this._reality_source.setWMCaptureSample(i_sample.GetData(), i_sender.vertical_flip);
                this._reality.progress(this._reality_source);

                //テクスチャ内容を更新
                this._back_ground.CopyFromRaster((DsRGB565Raster)this._reality_source.refRgbSource());

                //UnknownTargetを1個取得して、遷移を試す。
                NyARRealityTarget t = this._reality.selectSingleUnknownTarget();
                if (t == null)
                {
                    return;
                }
                //ターゲットに一致するデータを検索
                ARTKMarkerTable.GetBestMatchTargetResult r = new ARTKMarkerTable.GetBestMatchTargetResult();
                if (this._mklib.getBestMatchTarget(t, this._reality_source, r))
                {
                    if (r.confidence < 0.5)
                    {	//一致率が低すぎる。
                        return;
                    }
                    //既に認識しているターゲットの内側のものでないか確認する?(この処理をすれば、二重認識は無くなる。)

                    //一致度を確認して、80%以上ならKnownターゲットへ遷移
                    if (!this._reality.changeTargetToKnown(t, r.artk_direction, r.marker_width))
                    {
                        //遷移の成功チェック
                        return;//失敗
                    }
                    //遷移に成功したので、tagにResult情報をコピーしておく。(後で表示に使う)
                    t.tag = r;
                }
                else
                {
                    //一致しないので、このターゲットは捨てる。
                    this._reality.changeTargetToDead(t, 10);
                }
            }

            return;
        }
Exemplo n.º 3
0
 public WmCapture createWmCapture()
 {
     WmCapture result = new WmCapture(this._cap_size,this._cvertical);
     return result;
 }
        public Test_NyARRealityD3d_ARMarker(Form1 topLevelForm, ResourceBuilder i_resource)
        {
            this._capture = i_resource.createWmCapture();
            this._capture.setOnSample(this);

            this._d3dmgr = i_resource.createD3dManager(topLevelForm);
            this._back_ground = i_resource.createBackGround(this._d3dmgr);
            this._d3dcube = new ColorCube(this._d3dmgr.d3d_device,40);


            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this.m_raster = i_resource.createARRaster();
            //AR用のパターンコードを読み出


            //マーカライブラリ(ARTKId)の構築
            this._mklib = new ARTKMarkerTable(10, 16, 16, 25, 25, 4);
            //マーカテーブルの作成(1種類)
            this._mklib.addMarker(i_resource.createNyARCode(), 0, "HIRO", 80, 80);

            //Realityの準備
            this._reality = new NyARRealityD3d(i_resource.ar_param, 10, 10000, 1, 5);
            this._reality_source = new NyARRealitySource_WMCapture(SCREEN_WIDTH, SCREEN_HEIGHT, null, 2, 100);


        }
Exemplo n.º 5
0
 /* 非同期イベントハンドラ
  * CaptureDeviceからのイベントをハンドリングして、バッファとテクスチャを更新する。
  */
 public void onSample(WmCapture i_sender, INySample i_sample)
 {
     lock (this)
     {
         IntPtr data=i_sample.GetData();
         this.m_raster.setBuffer(data, i_sender.vertical_flip);
         //テクスチャ内容を更新
         this._back_ground.CopyFromRaster(this.m_raster);
         //マーカーは見つかったかな?
         is_marker_enable = this.m_ar.detectMarkerLite(this.m_raster, 110);
         if (is_marker_enable)
         {
             //あればMatrixを計算
             this.m_ar.getTransmationMatrix(trans_result);
             NyARD3dUtil.toD3dCameraView(trans_result,1, ref trans_matrix);
         }
     }
     Thread.Sleep(0);
     return;
 }