Esempio n. 1
0
        /* 非同期イベントハンドラ
         * 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;
        }
Esempio n. 2
0
        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);

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), SCREEN_WIDTH, SCREEN_HEIGHT);

            //Direct3d用のユーティリティ準備

            //プロセッサの準備
            this._processor = new MarkerProcessor(ap, this._raster.getBufferType());
            NyARCode[] codes = new NyARCode[2];
            codes[0] = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE1), 16, 16);
            codes[1] = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE2), 16, 16);
            this._processor.setARCodeTable(codes, 16, 80.0);


            //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);
        }
Esempio n. 3
0
        public D3dManager createD3dManager(Form i_form)
        {
            D3dManager result;

            result = new D3dManager(i_form, this._ar_param, -1);
            Matrix tmp = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(this._ar_param, 10, 10000, ref tmp);
            result.d3d_device.Transform.Projection = tmp;
            return(result);
        }
Esempio n. 4
0
        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;
        }
Esempio 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;
 }
Esempio n. 6
0
        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);
        }
        void DrawWord(string word, NyARTransMatResult result)
        {
            NyARD3dUtil.toD3dCameraView(result, 1f, ref this._trans_mat);
            this._surface.CopyFromXRGB32(Core.raster);

            lock (pbxNyAR)
            {
                //Ajustando a escala para cada desenho
                switch (word)
                {
                case "bola":
                    scaling = scaleArray[0];
                    break;

                case "gato":
                    scaling = scaleArray[1];
                    break;

                case "peixe":
                    scaling = scaleArray[2];
                    break;

                case "garfo":
                    scaling = scaleArray[3];
                    break;

                case "leao":
                    scaling = scaleArray[4];
                    break;

                case "caneta":
                    scaling = scaleArray[5];
                    break;

                case "panela":
                    scaling = scaleArray[6];
                    break;

                case "radio":
                    scaling = scaleArray[7];
                    break;

                case "tesoura":
                    scaling = scaleArray[8];
                    break;

                case "faca":
                    scaling = scaleArray[9];
                    break;

                case "espada":
                    scaling = scaleArray[10];
                    break;

                case "mesa":
                    scaling = scaleArray[11];
                    break;
                }

                // Background directly to the surface drawing
                Surface   dest_surface  = this._device.GetBackBuffer(0, 0, BackBufferType.Mono);
                Rectangle src_dest_rect = new Rectangle(0, 0, 543, 348);
                this._device.StretchRectangle(this._surface.d3d_surface, src_dest_rect, dest_surface, src_dest_rect, TextureFilter.None);

                // Drawing 3D objects from here
                this._device.BeginScene();
                this._device.Clear(ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0);

                //MATRIZ QUE DEFINE O POSICIONAMENTO DO OBJETO 3D
                //On 20mm cube (top marker) to be shifted
                Matrix transform_mat2 = Matrix.Scaling(scaling, scaling, scaling);
                transform_mat2 *= Matrix.RotationX((float)Math.PI * 1 / 2);

                //Multiply the transformation matrix
                transform_mat2 *= this._trans_mat;
                // Coordinate transformation matrix was calculated
                this._device.SetTransform(TransformType.World, transform_mat2);

                // Rendering (drawing)
                //this._cube.draw(this._device);

                //switch (word)
                //{
                //    case "sapo":
                //        DrawMesh(listSpacemesh[0], listSpacemeshmaterials[0], listSpacemeshtextures[0]);
                //        break;
                //    case "bola":
                //        DrawMesh(listSpacemesh[1], listSpacemeshmaterials[1], listSpacemeshtextures[1]);
                //        break;
                //}

                //Plota a imagem
                switch (word)
                {
                case "bola":
                    DrawMesh(listSpacemesh[0], listSpacemeshmaterials[0], listSpacemeshtextures[0]);
                    break;

                case "gato":
                    DrawMesh(listSpacemesh[1], listSpacemeshmaterials[1], listSpacemeshtextures[1]);
                    break;

                case "peixe":
                    DrawMesh(listSpacemesh[2], listSpacemeshmaterials[2], listSpacemeshtextures[2]);
                    break;

                case "garfo":
                    DrawMesh(listSpacemesh[3], listSpacemeshmaterials[3], listSpacemeshtextures[3]);
                    break;

                case "leao":
                    DrawMesh(listSpacemesh[4], listSpacemeshmaterials[4], listSpacemeshtextures[4]);
                    break;

                case "caneta":
                    DrawMesh(listSpacemesh[5], listSpacemeshmaterials[5], listSpacemeshtextures[5]);
                    break;

                case "panela":
                    DrawMesh(listSpacemesh[6], listSpacemeshmaterials[6], listSpacemeshtextures[6]);
                    break;

                case "radio":
                    DrawMesh(listSpacemesh[7], listSpacemeshmaterials[7], listSpacemeshtextures[7]);
                    break;

                case "tesoura":
                    DrawMesh(listSpacemesh[8], listSpacemeshmaterials[8], listSpacemeshtextures[8]);
                    break;

                case "faca":
                    DrawMesh(listSpacemesh[9], listSpacemeshmaterials[9], listSpacemeshtextures[9]);
                    break;

                case "espada":
                    DrawMesh(listSpacemesh[10], listSpacemeshmaterials[10], listSpacemeshtextures[10]);
                    break;

                case "mesa":
                    DrawMesh(listSpacemesh[11], listSpacemeshmaterials[11], listSpacemeshtextures[11]);
                    break;
                }
                //DrawMesh(spacemesh, spacemeshmaterials, spacemeshtextures);
                //DrawMesh(listSpacemesh[2], listSpacemeshmaterials[2], listSpacemeshtextures[2]);

                // Drawing up here
                this._device.EndScene();

                // Drawing on the actual display
                this._device.Present();
            }
        }
        public NyARWordsBingoCore(Label lbl, Game currentGame, PictureBox pbx)
        {
            //Instanciando o PictureBox com o recebido do Form
            pbxNyAR = pbx;
            lbNyAR  = lbl;
            gmNyAR  = currentGame;


            //Parâmetros da RA
            NyARParam ap = new NyARParam();

            ap.loadARParamFromFile(AR_CAMERA_FILE);   //Lendo arquivo .dat
            ap.changeScreenSize(640, 480);            //Setando tamanho da câmera.

            //Lendo padrão do marcador
            NyARCode codeKanji = new NyARCode(16, 16);
            NyARCode codeA     = new NyARCode(16, 16);
            NyARCode codeB     = new NyARCode(16, 16);
            NyARCode codeC     = new NyARCode(16, 16);
            NyARCode codeD     = new NyARCode(16, 16);
            NyARCode codeE     = new NyARCode(16, 16);
            NyARCode codeF     = new NyARCode(16, 16);
            NyARCode codeG     = new NyARCode(16, 16);
            NyARCode codeH     = new NyARCode(16, 16);
            NyARCode codeI     = new NyARCode(16, 16);
            NyARCode codeJ     = new NyARCode(16, 16);
            NyARCode codeK     = new NyARCode(16, 16);
            NyARCode codeL     = new NyARCode(16, 16);
            NyARCode codeM     = new NyARCode(16, 16);
            NyARCode codeN     = new NyARCode(16, 16);
            NyARCode codeO     = new NyARCode(16, 16);
            NyARCode codeP     = new NyARCode(16, 16);
            NyARCode codeQ     = new NyARCode(16, 16);
            NyARCode codeR     = new NyARCode(16, 16);
            NyARCode codeS     = new NyARCode(16, 16);
            NyARCode codeT     = new NyARCode(16, 16);
            NyARCode codeU     = new NyARCode(16, 16);
            NyARCode codeV     = new NyARCode(16, 16);
            NyARCode codeW     = new NyARCode(16, 16);
            NyARCode codeX     = new NyARCode(16, 16);
            NyARCode codeY     = new NyARCode(16, 16);
            NyARCode codeZ     = new NyARCode(16, 16);

            NyARCode codeBall      = new NyARCode(16, 16);
            NyARCode codeSword     = new NyARCode(16, 16);
            NyARCode codeCar       = new NyARCode(16, 16);
            NyARCode codeBrigadier = new NyARCode(16, 16);
            NyARCode codeFork      = new NyARCode(16, 16);
            NyARCode codePen       = new NyARCode(16, 16);
            NyARCode codeFish      = new NyARCode(16, 16);


            //Carregando os arquivos dos marcadores no NyARCode
            codeKanji.loadARPattFromFile(AR_CODE_FILE_KANJI);
            codeA.loadARPattFromFile(AR_CODE_FILE_A);
            codeB.loadARPattFromFile(AR_CODE_FILE_B);
            codeC.loadARPattFromFile(AR_CODE_FILE_C);
            codeD.loadARPattFromFile(AR_CODE_FILE_D);
            codeE.loadARPattFromFile(AR_CODE_FILE_E);
            codeF.loadARPattFromFile(AR_CODE_FILE_F);
            codeG.loadARPattFromFile(AR_CODE_FILE_G);
            codeH.loadARPattFromFile(AR_CODE_FILE_H);
            codeI.loadARPattFromFile(AR_CODE_FILE_I);
            codeJ.loadARPattFromFile(AR_CODE_FILE_J);
            codeK.loadARPattFromFile(AR_CODE_FILE_K);
            codeL.loadARPattFromFile(AR_CODE_FILE_L);
            codeM.loadARPattFromFile(AR_CODE_FILE_M);
            codeN.loadARPattFromFile(AR_CODE_FILE_N);
            codeO.loadARPattFromFile(AR_CODE_FILE_O);
            codeP.loadARPattFromFile(AR_CODE_FILE_P);
            codeQ.loadARPattFromFile(AR_CODE_FILE_Q);
            codeR.loadARPattFromFile(AR_CODE_FILE_R);
            codeS.loadARPattFromFile(AR_CODE_FILE_S);
            codeT.loadARPattFromFile(AR_CODE_FILE_T);
            codeU.loadARPattFromFile(AR_CODE_FILE_U);
            codeV.loadARPattFromFile(AR_CODE_FILE_V);
            codeW.loadARPattFromFile(AR_CODE_FILE_W);
            codeX.loadARPattFromFile(AR_CODE_FILE_X);
            codeY.loadARPattFromFile(AR_CODE_FILE_Y);
            codeZ.loadARPattFromFile(AR_CODE_FILE_Z);

            codeBall.loadARPattFromFile(AR_CODE_FILE_BALL);
            codeSword.loadARPattFromFile(AR_CODE_FILE_SWORD);
            codeCar.loadARPattFromFile(AR_CODE_FILE_CAR);
            codeBrigadier.loadARPattFromFile(AR_CODE_FILE_BRIGADIER);
            codeFork.loadARPattFromFile(AR_CODE_FILE_FORK);
            codePen.loadARPattFromFile(AR_CODE_FILE_PEN);
            codeFish.loadARPattFromFile(AR_CODE_FILE_FISH);



            double[] WidthArray = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0,
                                    80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0,
                                    80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 };

            NyARCode[] arrayCodes = { codeKanji, codeA, codeB, codeC, codeD, codeE, codeF, codeG, codeH, codeI,
                                      codeJ,     codeK, codeL, codeM, codeN, codeO, codeP, codeQ, codeR, codeS,
                                      codeT,     codeU, codeV, codeW, codeX, codeY, codeZ };

            double[]   WidthArrayImages = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 };
            NyARCode[] arrayCodesImage  = { codeBall, codeSword, codeCar, codeBrigadier, codeFork, codePen, codeFish };


            //Seta propriedades da câmera
            try
            {
                Core.cap.SetCaptureListener(this);
            }
            catch (Exception e)
            {
                MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente. Favor, reinicie a aplicação.", "Erro!");
                Environment.Exit(0);
            }

            Core.cap.PrepareCapture(640, 480, 30);


            //Create a cluster - Instanciando o Raster, passando os parâmetros do vídeo encontrado no CaptureDevice
            Core.raster = Core.InstanceRaster(Core.cap.video_width, Core.cap.video_height);


            //Instanciando os detectores únicos
            this.ballMarkerDetector = new NyARSingleDetectMarker(ap, codeBall, 80.0, Core.raster.getBufferType());
            this.ballMarkerDetector.setContinueMode(true);

            this.brigadierlMarkerDetector = new NyARSingleDetectMarker(ap, codeBrigadier, 80.0, Core.raster.getBufferType());
            this.brigadierlMarkerDetector.setContinueMode(true);

            this.carMarkerDetector = new NyARSingleDetectMarker(ap, codeCar, 80.0, Core.raster.getBufferType());
            this.carMarkerDetector.setContinueMode(true);

            this.forkMarkerDetector = new NyARSingleDetectMarker(ap, codeFork, 80.0, Core.raster.getBufferType());
            this.forkMarkerDetector.setContinueMode(true);

            this.penMarkerDetector = new NyARSingleDetectMarker(ap, codePen, 80.0, Core.raster.getBufferType());
            this.penMarkerDetector.setContinueMode(true);

            this.swordMarkerDetector = new NyARSingleDetectMarker(ap, codeSword, 80.0, Core.raster.getBufferType());
            this.swordMarkerDetector.setContinueMode(true);

            this.fishMarkerDetector = new NyARSingleDetectMarker(ap, codeFish, 80.0, Core.raster.getBufferType());
            this.fishMarkerDetector.setContinueMode(true);



            //Instanciando o detector de todas as letras
            this.markerDetectorLetters = new NyARDetectMarker(ap, arrayCodes, WidthArray, 27, Core.raster.getBufferType());
            this.markerDetectorLetters.setContinueMode(true);

            //Instanciando o detector das imagens que representam a palavra na cartela
            this.markerDetectorImages = new NyARDetectMarker(ap, arrayCodesImage, WidthArrayImages, 7, Core.raster.getBufferType());
            this.markerDetectorImages.setContinueMode(true);


            //Inicia a captura
            //Inicia a captura
            try
            {
                Core.cap.StartCapture();
            }
            catch (Exception e)
            {
                MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente.");
                Environment.Exit(0);
            }


            //Abaixo, são as funções que preparam todo o dispositivo e cenário para renderização 3D
            //Necessário descobrir mais detalhes do funcionamento.

            //Preparing the 3D device
            this._device = Core.PrepareD3dDevice(pbx); //Prepara o dispositivo em cima do PictureBox
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting      = false;

            //Projection Camera Settings
            Matrix tmp = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp);
            this._device.Transform.Projection = tmp;

            // View conversion settings (set in the left-handed view matrix).
            //From 0,0,0, and facing Z +, Y-axis direction on
            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;
            //Set viewport
            this._device.Viewport = vp;

            //Draw a color cube instance - Instância de um cubo colorido, padrão da biblioteca NyAR
            this._cube = new ColorCube(this._device, 40);

            //Create a background surface
            this._surface = new NyARSurface_XRGB32(this._device, 640, 480);

            //Carregando os meshs (objetos 3D)
            LoadMeshes();
        }
Esempio n. 9
0
 /**
  * アプリケーションフレームワークのハンドラ(マーカ更新)
  */
 protected override void onUpdateHandler(NyARSquare i_square, NyARDoubleMatrix44 result)
 {
     NyARD3dUtil.toD3dCameraView(result, 1f, ref this.transmat);
 }
Esempio n. 10
0
 /**
  * DirectXスタイルのProjectionMatrixを返却します。
  */
 public void getD3dCameraFrustum(ref Matrix o_mat)
 {
     NyARD3dUtil.mat44ToD3dMatrixT(this._frustum.refMatrix(), ref o_mat);
 }
Esempio n. 11
0
 /**
  *
  * NyARToolKitの姿勢変換行列を返します。
  * @throws NyARException
  */
 public void getD3dModelViewMatrix(NyARDoubleMatrix44 i_nyar_mat, ref Matrix o_mat)
 {
     NyARD3dUtil.toD3dCameraView(i_nyar_mat, 1f, ref o_mat);
     return;
 }
Esempio n. 12
0
        public bool InitializeApplication(Form1 topLevelForm)
        {
            topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
            this._raster            = new NyARBitmapRaster(new Bitmap(TEST_IMAGE));


            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), SCREEN_WIDTH, SCREEN_HEIGHT);

            //AR用のパターンコードを読み出し
            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(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, 10, 1000, 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);

            NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat;
            //マーカの認識
            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(true);
        }
Esempio n. 13
0
        public void AR_Initialization(Control topLevelForm)
        {
            //Camera parameters
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));

            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //List of patterns
            ar_code = new NyARCode[Constante.PATT_MAX];

            //Pattern files
            AR_CODE_FILES = new String[Constante.PATT_MAX];

            //Pattern index list
            ar_code_index = new int[Constante.PATT_MAX];

            AR_CODE_FILES[0] = "data/patt_U.dat";
            AR_CODE_FILES[1] = "data/patt_S.dat";
            AR_CODE_FILES[2] = "data/patt_T.dat";
            AR_CODE_FILES[3] = "data/patt_H.dat";
            AR_CODE_FILES[4] = "data/patt_B.dat";


            for (int count = 0; count < Constante.PATT_MAX; count++)
            {
                ar_code[count] = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILES[count]), 16, 16);
            }

            marker_width = new double[Constante.PATT_MAX];
            for (int count = 0; count < Constante.PATT_MAX; count++)
            {
                marker_width[count] = 80.0f;
            }


            this._ar = new NyARDetectMarker(ap, ar_code, marker_width, Constante.PATT_MAX);

            this._ar.setContinueMode(true);

            Matrix tmp = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(ap, 1, 2000, ref tmp);
            m_Device.Transform.Projection = tmp;

            // View Matrix:
            Vector3 camera_position = new Vector3(0, 0, -500);

            camera_position.Normalize();
            //camera_position.Multiply(m_Range);

            m_Device.Transform.View = Matrix.LookAtLH(
                camera_position, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
            //m_Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 2000);
            Viewport vp = new Viewport();

            vp.X = 0;
            vp.Y = 0;
            //vp.Height = ap.getScreenSize().h;
            //vp.Width = ap.getScreenSize().w;
            vp.Height = SCREEN_HEIGHT;
            vp.Width  = SCREEN_WIDTH;
            vp.MaxZ   = 1.0f;

            m_Device.Viewport = vp;

            this._surface = new NyARD3dSurface(m_Device, SCREEN_WIDTH, SCREEN_HEIGHT);

            NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat;

            int nb_marker_detected = 0;

            nb_marker_detected = this._ar.detectMarkerLite(this._raster, Constante.binarisation);

            if (nb_marker_detected > 0)
            {
                bestConfidence = 0;
                bestMarker     = 0;

                //if the number of detected markers is bigger than the max number available we set it back to MAX number
                if (nb_marker_detected > Constante.MARK_MAX)
                {
                    nb_marker_detected = Constante.MARK_MAX;
                }

                //get the best confidence from the detected markers
                for (int count = 0; count < nb_marker_detected; count++)
                {
                    ar_code_index[count] = this._ar.getARCodeIndex(count);
                    if (this._ar.getConfidence(count) > bestConfidence)
                    {
                        bestConfidence = this._ar.getConfidence(count);
                        bestMarker     = count;
                    }
                    //textBox1.Text += "bestConfidence: " + bestConfidence + "  bestMarker: " + bestMarker+"\n";
                }

                //textBox1.Text += "finally:\nbestConfidence: " + bestConfidence + "  bestMarker: " + bestMarker+"\n\n";

                try
                {
                    //MessageBox.Show("bestMarker: " + bestMarker, "RenderForm.AR_Initialization");
                    this._ar.getTransmationMatrix(bestMarker, nyar_transmat);
                }
                catch (Exception x)
                { //MessageBox.Show(x.ToString(), "RenderForm.AR_Initialize");
                }
                NyARD3dUtil.toD3dCameraView(nyar_transmat, 1f, ref this._trans_mat);
            }

            this._nb_marker_detected = nb_marker_detected;

            {
                try
                {
                    this._surface.setRaster(this._raster);
                }
                catch (Exception x)
                {
                    //MessageBox.Show(x.ToString(), "RenderForm.AR_Initialization");
                }
            }
        }
Esempio n. 14
0
        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);

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), SCREEN_WIDTH, SCREEN_HEIGHT);

            //AR用のパターンコードを読み出し
            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(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);
        }
Esempio n. 15
0
        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);
        }