/* 非同期イベントハンドラ * 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; }
/* 非同期イベントハンドラ * CaptureDeviceからのイベントをハンドリングして、バッファとテクスチャを更新する。 */ public void OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len) { int w = i_sender.video_width; int h = i_sender.video_height; int s = w * (i_sender.video_bit_count / 8); lock (this) { //カメラ映像をARのバッファにコピー this._reality_source.setDShowImage(i_buffer, i_buffer_len, i_sender.video_vertical_flip); this._reality.progress(this._reality_source); //テクスチャ内容を更新 this._surface.setRaster(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.6) { //一致率が低すぎる。 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, 15); } } return; }
/* 非同期イベントハンドラ * CaptureDeviceからのイベントをハンドリングして、バッファとテクスチャを更新する。 */ public void OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len) { int w = i_sender.video_width; int h = i_sender.video_height; int s = w * (i_sender.video_bit_count / 8); lock (this) { //カメラ映像をARのバッファにコピー this._reality_source.setDShowImage(i_buffer,i_buffer_len,i_sender.video_vertical_flip); this._reality.progress(this._reality_source); //テクスチャ内容を更新 this._surface.setRaster(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.6) { //一致率が低すぎる。 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,15); } } return; }