public Form1() { InitializeComponent(); //ARの設定 //AR用カメラパラメタファイルをロード NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE)); ap.changeScreenSize(320, 240); //AR用のパターンコードを読み出し NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE),16, 16); NyARDoubleMatrix44 result_mat = new NyARDoubleMatrix44(); //計算モードの設定 //キャプチャを作る /************************************************** このコードは、0番目(一番初めに見つかったキャプチャデバイス) を使用するようにされています。 複数のキャプチャデバイスを持つシステムの場合、うまく動作しないかもしれません。 n番目のデバイスを使いたいときには、CaptureDevice cap=cl[0];←ここの0を変えてください。 手動で選択させる方法は、SimpleLiteDirect3Dを参考にしてください。 **************************************************/ CaptureDeviceList cl=new CaptureDeviceList(); CaptureDevice cap=cl[0]; cap.SetCaptureListener(this); cap.PrepareCapture(320, 240,30); this.m_cap = cap; //ラスタを作る。 this.m_raster = new DsRgbRaster(cap.video_width, cap.video_height,NyARBufferType.OBJECT_CS_Bitmap); //1パターンのみを追跡するクラスを作成 this.m_ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0); this.m_ar.setContinueMode(false); }
public SimpleLiteMain(Form i_form,CaptureDevice i_dev) { //setup camera i_dev.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30.0f); //setup form i_form.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT); //setup AR INyARMarkerSystemConfig cf = new NyARMarkerSystemConfig(SCREEN_WIDTH, SCREEN_HEIGHT); this._ms = new NyARD3dMarkerSystem(cf); this._ss = new NyARDirectShowCamera(i_dev); this.mid = this._ms.addARMarker(AR_CODE_FILE, 16, 25, 80); //setup directx //3dデバイスを準備する this._d3d = NyARD3dUtil.createD3dDevice(i_form); this._d3d.RenderState.ZBufferEnable = true; this._d3d.RenderState.Lighting = false; //ビューポートとビューの位置 this._d3d.Transform.View = NyARD3dUtil.getARView(); this._d3d.Viewport = NyARD3dUtil.getARViewPort(SCREEN_WIDTH,SCREEN_HEIGHT); //Projectionの設定 this._ms.setProjectionMatrixClipping(10, 10000); Matrix pm = new Matrix(); NyARD3dUtil.toCameraFrustumRH(this._ms.getARParam(),10,10000, ref pm); this._d3d.Transform.Projection = pm; //カラーキューブの描画インスタンス this._cube = new ColorCube(this._d3d, 40); //背景サーフェイスを作成 this._surface = new NyARD3dSurface(this._d3d,SCREEN_WIDTH,SCREEN_HEIGHT); }
/* 非同期イベントハンドラ * 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); NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat; //テクスチャにRGBを取り込み() lock (this) { //カメラ映像をARのバッファにコピー this._raster.setBuffer(i_buffer,i_buffer_len, i_sender.video_vertical_flip); //マーカーは見つかったかな? bool is_marker_enable = this._ar.detectMarkerLite(this._raster, 110); if (is_marker_enable) { //あればMatrixを計算 this._ar.getTransmationMatrix(nyar_transmat); NyARD3dUtil.toD3dCameraView(nyar_transmat, 1f, ref this._trans_mat); } this._is_marker_enable=is_marker_enable; //テクスチャ内容を更新 this._surface.setRaster(this._raster); } return; }
private void initInstance(CaptureDevice i_cdev, int i_raster_type) { this._raster = new DsRgbRaster(i_cdev.video_width, i_cdev.video_height, i_raster_type); //ラスタのセット this.update(this._raster); this._cdev = i_cdev; i_cdev.SetCaptureListener(this); }
private void initInstance(CaptureDevice i_cdev, int i_raster_type) { this._raster = new DsRgbRaster(i_cdev.video_width, i_cdev.video_height,i_raster_type); //ラスタのセット this.update(this._raster); this._cdev = i_cdev; i_cdev.SetCaptureListener(this); }
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); Bitmap b = new Bitmap(w, h, s, PixelFormat.Format32bppRgb, i_buffer); // If the image is upsidedown b.RotateFlip(RotateFlipType.RotateNoneFlipY); pictureBox1.Image = b; //ARの計算 this.m_raster.setBuffer(i_buffer,i_buffer_len,i_sender.video_vertical_flip); if (this.m_ar.detectMarkerLite(this.m_raster, 100)) { NyARDoubleMatrix44 result_mat = new NyARDoubleMatrix44(); this.m_ar.getTransmationMatrix(result_mat); this.Invoke( (MethodInvoker)delegate() { label1.Text = this.m_ar.getConfidence().ToString(); label3.Text = result_mat.m00.ToString(); label4.Text = result_mat.m01.ToString(); label5.Text = result_mat.m02.ToString(); label6.Text = result_mat.m03.ToString(); label7.Text = result_mat.m10.ToString(); label8.Text = result_mat.m11.ToString(); label9.Text = result_mat.m12.ToString(); label10.Text = result_mat.m13.ToString(); label11.Text = result_mat.m20.ToString(); label12.Text = result_mat.m21.ToString(); label13.Text = result_mat.m22.ToString(); label14.Text = result_mat.m23.ToString(); } ); }else{ this.Invoke( (MethodInvoker)delegate(){ label1.Text = "マーカー未検出"; label2.Text = "-"; label3.Text = "-"; label4.Text = "-"; label5.Text = "-"; label6.Text = "-"; label7.Text = "-"; label8.Text = "-"; label9.Text = "-"; label10.Text = "-"; label11.Text = "-"; label12.Text = "-"; label13.Text = "-"; label14.Text = "-"; } ); } }
public void OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len) { //ロックされていなければ、RGBラスタを更新する。 lock (this) { try { this._raster.setBuffer(i_buffer, i_buffer_len, i_sender.video_vertical_flip); this.updateTimeStamp(); } catch (Exception e) { System.Console.Error.WriteLine(e.Message); } } }
/* 非同期イベントハンドラ * 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); //テクスチャにRGBを取り込み() lock (this)//このロックは、OnEnterとOnUpdateの間でMainLoopがtransmatを参照することを防ぎます。 { //カメラ映像をARのバッファにコピー this._raster.setBuffer(i_buffer,i_buffer_len, i_sender.video_vertical_flip); //フレームワークに画像を転送 this._processor.detectMarker(this._raster); //テクスチャ内容を更新 this._surface.setRaster(this._raster); } 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); //テクスチャにRGBを取り込み() lock (this) { //カメラ映像をARのバッファにコピー this._raster.setBuffer(i_buffer,i_sender.video_vertical_flip); //テクスチャ内容を更新 this._surface.CopyFromXRGB32(this._raster); } 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); //テクスチャにRGBを取り込み() lock (this) { //カメラ映像をARのバッファにコピー this._raster.setBuffer(i_buffer,i_buffer_len,i_sender.video_vertical_flip); this.filter.convert(this.gs); this.tracksource.wrapBuffer(this.gs); this.tracker.progress(this.tracksource); } return; }
public override void setup(CaptureDevice i_cap) { Device d3d = this.size(SCREEN_WIDTH, SCREEN_HEIGHT); INyARMarkerSystemConfig cf = new NyARMarkerSystemConfig(SCREEN_WIDTH, SCREEN_HEIGHT); d3d.RenderState.ZBufferEnable = true; d3d.RenderState.Lighting = false; d3d.RenderState.CullMode = Cull.CounterClockwise; this._ms = new NyARD3dMarkerSystem(cf); this._ss = new NyARSensor(cf.getScreenSize()); this._rs = new NyARD3dRender(d3d, this._ms); this.mid = this._ms.addARMarker(AR_CODE_FILE, 16, 25, 80); //set View mmatrix this._rs.loadARViewMatrix(d3d); //set Viewport matrix this._rs.loadARViewPort(d3d); //setD3dProjectionMatrix this._rs.loadARProjectionMatrix(d3d); this._ss.update( new NyARBitmapRaster(new Bitmap(TEST_IMAGE))); }
/* 非同期イベントハンドラ * 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; }
public override void setup(CaptureDevice i_cap) { Device d3d = this.size(SCREEN_WIDTH, SCREEN_HEIGHT); i_cap.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30.0f); INyARMarkerSystemConfig cf = new NyARMarkerSystemConfig(SCREEN_WIDTH, SCREEN_HEIGHT); d3d.RenderState.ZBufferEnable = true; d3d.RenderState.Lighting = false; d3d.RenderState.CullMode = Cull.CounterClockwise; this._ms = new NyARD3dMarkerSystem(cf); this._ss = new NyARDirectShowCamera(i_cap); this._rs = new NyARD3dRender(d3d, this._ms); this.mid = this._ms.addARMarker(AR_CODE_FILE, 16, 25, 80); //set View mmatrix this._rs.loadARViewMatrix(d3d); //set Viewport matrix this._rs.loadARViewPort(d3d); //setD3dProjectionMatrix this._rs.loadARProjectionMatrix(d3d); this._ss.start(); }
/* 非同期イベントハンドラ * CaptureDeviceからのイベントをハンドリングして、バッファとテクスチャを更新する。 */ public void OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len) { try { lock (this) { 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; } //ターゲットに一致するデータを検索 RawbitSerialIdTable.IdentifyIdResult r=new RawbitSerialIdTable.IdentifyIdResult(); if (this._mklib.identifyId(t, this._reality_source, r)) { //テーブルにターゲットが見つかったので遷移する。 if(!this._reality.changeTargetToKnown(t,r.artk_direction,r.marker_width)){ //遷移の成功チェック return;//失敗 } //遷移に成功したので、tagにユーザ定義情報を書きこむ。 long l = new long(); l = r.id; t.tag = l; }else{ //一致しないので、このターゲットは捨てる。(15フレーム無視) this._reality.changeTargetToDead(t,15); } } } catch (Exception e) { System.Console.WriteLine(e.StackTrace); } return; }
public override void setup(CaptureDevice i_cap) { Device d3d=this.size(SCREEN_WIDTH, SCREEN_HEIGHT); i_cap.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30.0f); INyARMarkerSystemConfig cf = new NyARMarkerSystemConfig(SCREEN_WIDTH, SCREEN_HEIGHT); d3d.RenderState.ZBufferEnable = true; d3d.RenderState.Lighting = false; d3d.RenderState.CullMode = Cull.CounterClockwise; this._ms = new NyARD3dMarkerSystem(cf); this._ss = new NyARDirectShowCamera(i_cap); this._rs = new NyARD3dRender(d3d, this._ms); this.mid = this._ms.addARMarker(AR_CODE_FILE, 16, 25, 80); // this.mid = this._ms.addPsARPlayCard(1,80); // this.mid = this._ms.addARMarker(new Bitmap("../../../../../data/hiro.png"), 16, 25, 80); // you can use PNG style marker too. //this.mid = this._ms.addNyIdMarker(0, 80);// For Id marker #0 //set View mmatrix this._rs.loadARViewMatrix(d3d); //set Viewport matrix this._rs.loadARViewPort(d3d); //setD3dProjectionMatrix this._rs.loadARProjectionMatrix(d3d); this._ss.start(); }
public bool InitializeApplication(Form1 topLevelForm,CaptureDevice i_cap_device) { topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT); i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32); #region my code try { byte[] bimg = service.getb(); //if(bimg != null) { Image img = byteToImage(bimg); if (img != null) { //frm.textBox1.Text = img.ToString(); this._raster = new NyARBitmapRaster((Bitmap)img); } } //else } catch (Exception x) { //MessageBox.Show(x.ToString()); } #endregion NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE)); ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT); NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE),16, 16); this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT); this._ar.setContinueMode(true); this._device = PrepareD3dDevice(topLevelForm); this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(),ap.getScreenSize(),1, 10, 10000,ref tmp); this._device.Transform.Projection = tmp; this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; this._device.Viewport = vp; this._cube = new ColorCube(this._device, 40); this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); this._is_marker_enable = false; return true; }
public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device) { //キャプチャを作る(QVGAでフレームレートは30) i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //ARの設定 //ARラスタを作る(DirectShowキャプチャ仕様)。 this._raster = new DsBGRX32Raster(i_cap_device.video_width, i_cap_device.video_height, i_cap_device.video_width * i_cap_device.video_bit_count / 8); //3dデバイスを準備する this._device = PrepareD3dDevice(topLevelForm); // ライトを無効 this._device.RenderState.Lighting = false; //背景サーフェイスを作成 this._surface = new NyARSurface_XRGB32(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); return true; }
/// <summary> /// This function as is NyARDirectShowCamera(i_cdev,NyARBufferType.OBJECT_CS_Bitmap) /// </summary> /// <param name="i_cdev"></param> public NyARDirectShowCamera(CaptureDevice i_cdev) : base(new NyARIntSize(i_cdev.video_width, i_cdev.video_height)) { //RGBラスタの生成 this.initInstance(i_cdev, NyARBufferType.OBJECT_CS_Bitmap); }
/// <summary> /// </summary> /// <param name="i_cdev"></param> /// <param name="i_raster_type"> /// OBJECT_CS_Bitmap is slower than BYTE1D_B8G8R8X8_32(20%) but compatible with Bitmap. /// OBJECT_CS_Bitmap is fast but not compatible with Bitmap. /// </param> public NyARDirectShowCamera(CaptureDevice i_cdev,int i_raster_type) : base(new NyARIntSize(i_cdev.video_width, i_cdev.video_height)) { //RGBラスタの生成 this.initInstance(i_cdev, i_raster_type); }
public abstract void setup(CaptureDevice i_cap);
public bool InitializeApplication(Form1 topLevelForm,CaptureDevice i_cap_device) { topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT); //キャプチャを作る(QVGAでフレームレートは30) i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //AR用カメラパラメタファイルをロードして設定 NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE)); ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT); //マーカライブラリ(NyId)の構築 this._mklib = new RawbitSerialIdTable(10); //マーカサイズテーブルの作成(とりあえず全部8cm) this._mklib.addAnyItem("any id", 80); //Realityの準備 this._reality = new NyARRealityD3d(ap, 10, 10000, 2, 10); this._reality_source = new NyARRealitySource_DShow(SCREEN_WIDTH, SCREEN_HEIGHT, null, 2, 100); //3dデバイスを準備する this._device = PrepareD3dDevice(topLevelForm); this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; //カメラProjectionの設定 Matrix tmp = new Matrix(); this._reality.getD3dCameraFrustum(ref tmp); this._device.Transform.Projection = tmp; // ビュー変換の設定(左手座標系ビュー行列で設定する) // 0,0,0から、Z+方向を向いて、上方向がY軸 this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); Viewport vp = new Viewport(); vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; //ビューポート設定 this._device.Viewport = vp; //カラーキューブの描画インスタンス this._cube = new ColorCube(this._device, 40); //背景サーフェイスを作成 this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); return true; }
/// <summary> /// </summary> /// <param name="i_cdev"></param> /// <param name="i_raster_type"> /// OBJECT_CS_Bitmap is slower than BYTE1D_B8G8R8X8_32(20%) but compatible with Bitmap. /// OBJECT_CS_Bitmap is fast but not compatible with Bitmap. /// </param> public NyARDirectShowCamera(CaptureDevice i_cdev, int i_raster_type) : base(new NyARIntSize(i_cdev.video_width, i_cdev.video_height)) { //RGBラスタの生成 this.initInstance(i_cdev, i_raster_type); }
public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device) { topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT); //キャプチャを作る(QVGAでフレームレートは30) i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //ARラスタを作る(DirectShowキャプチャ仕様)。 this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32); //AR用カメラパラメタファイルをロードして設定 NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE)); ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT); //プロセッサの準備 this._processor = new MarkerProcessor(ap, this._raster.getBufferType()); this._processor.setMarkerWidth(100); //3dデバイスを準備する this._device = PrepareD3dDevice(topLevelForm); this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; this._device.RenderState.CullMode = Cull.CounterClockwise; Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; //ビューポート設定 this._device.Viewport = vp; this._text = new TextPanel(this._device, 1); //カメラProjectionの設定 Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp); this._device.Transform.Projection = tmp; // ビュー変換の設定(左手座標系ビュー行列で設定する) // 0,0,0から、Z+方向を向いて、上方向がY軸 this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); //背景サーフェイスを作成 this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); return true; }
public bool InitializeApplication(Form1 topLevelForm,CaptureDevice i_cap_device) { topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT); //キャプチャを作る(QVGAでフレームレートは30) i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //ARの設定 //ARラスタを作る(DirectShowキャプチャ仕様)。 this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32); //AR用カメラパラメタファイルをロードして設定 NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE)); ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT); //AR用のパターンコードを読み出し NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE),16, 16); //1パターンのみを追跡するクラスを作成 this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT); //計算モードの設定 this._ar.setContinueMode(true); //3dデバイスを準備する this._device = PrepareD3dDevice(topLevelForm); this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; //カメラProjectionの設定 Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(),ap.getScreenSize(),1, 10, 10000,ref tmp); this._device.Transform.Projection = tmp; // ビュー変換の設定(左手座標系ビュー行列で設定する) // 0,0,0から、Z+方向を向いて、上方向がY軸 this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; //ビューポート設定 this._device.Viewport = vp; //カラーキューブの描画インスタンス this._cube = new ColorCube(this._device, 40); //背景サーフェイスを作成 this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); this._is_marker_enable = false; return true; }
public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device) { this._top_form = topLevelForm; topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT); //キャプチャを作る(QVGAでフレームレートは30) i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //ARの設定 //ARラスタを作る(DirectShowキャプチャ仕様)。 this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.OBJECT_CS_Bitmap); this.gs = new NyARGrayscaleRaster(i_cap_device.video_width, i_cap_device.video_height); this.filter = NyARRgb2GsFilterFactory.createRgbAveDriver(this._raster); this.tracker = new NyARTracker(100, 1, 10); this.tracksource = new NyARTrackerSource_Reference(100, null, i_cap_device.video_width, i_cap_device.video_height,2, false); return true; }
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); NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat; lock (this) { //this._raster.setBuffer(i_buffer,i_buffer_len, i_sender.video_vertical_flip); #region My Code try { byte[] bimg = service.getb(); //if(bimg != null) { Image img = byteToImage(bimg); if (img != null) { //frm.textBox1.Text = img.ToString(); this._raster = new NyARBitmapRaster((Bitmap)img); } } //else } catch (Exception x) { //MessageBox.Show(x.ToString()); } #endregion bool is_marker_enable = this._ar.detectMarkerLite(this._raster, 110); if (is_marker_enable) { this._ar.getTransmationMatrix(nyar_transmat); NyARD3dUtil.toD3dCameraView(nyar_transmat, 1f, ref this._trans_mat); } this._is_marker_enable = is_marker_enable; this._surface.setRaster(this._raster); } return; }