示例#1
0
        /* DsXRGB32Rasterの内容を保持しているテクスチャにコピーします。
         * i_rasterのサイズは、このインスタンスに指定したテクスチャサイズ(コンストラクタ等に指定したサイズ)と同じである必要です。
         * ラスタデータはテクスチャの左上を基点にwidth x heightだけコピーされ、残りの部分は更新されません。
         */
        public void setRaster(INyARRgbRaster i_raster)
        {
            Debug.Assert(!this._is_dispose);
            int pitch;

            using (GraphicsStream texture_rect = this.m_texture.LockRectangle(0, LockFlags.None, out pitch))
            {
                try{
                    int dst = (int)texture_rect.InternalData;
                    switch (i_raster.getBufferType())
                    {
                    case NyARBufferType.BYTE1D_B8G8R8X8_32:
                    {
                        byte[] buf = (byte[])i_raster.getBuffer();
                        //テクスチャのピッチって何?
                        int src_w = this.m_width * 4;
                        int src   = 0;
                        for (int r = this.m_height - 1; r >= 0; r--)
                        {
                            Marshal.Copy(buf, src, (IntPtr)dst, pitch);
                            dst += pitch;
                            src += src_w;
                        }
                    }
                    break;

                    case NyARBufferType.OBJECT_CS_Bitmap:
                        NyARBitmapRaster ra = (NyARBitmapRaster)(i_raster);
                        BitmapData       bm = ra.lockBitmap();
                        try
                        {
                            int src = (int)bm.Scan0;
                            for (int r = this.m_height - 1; r >= 0; r--)
                            {
                                NyARD3dUtil.RtlCopyMemory((IntPtr)dst, (IntPtr)src, pitch);
                                dst += pitch;
                                src += bm.Stride;
                            }
                        }
                        finally
                        {
                            ra.unlockBitmap();
                        }
                        break;

                    default:
                        throw new NyARException();
                    }
                }
                finally
                {
                    //テクスチャをアンロックする
                    this.m_texture.UnlockRectangle(0);
                }
            }
            return;
        }
示例#2
0
        /* DsXRGB32Rasterの内容を保持しているサーフェイスにコピーします。
         */
        public void setRaster(INyARRgbRaster i_sample)
        {
            Debug.Assert(!this._is_dispose);
            int pitch;
            int s_stride = this.m_width * 4;

            using (GraphicsStream gs = this._surface.LockRectangle(LockFlags.None, out pitch))
            {
                try{
                    switch (i_sample.getBufferType())
                    {
                    case NyARBufferType.BYTE1D_B8G8R8X8_32:
                        if (pitch % s_stride == 0)
                        {
                            Marshal.Copy((byte[])i_sample.getBuffer(), 0, (IntPtr)((int)gs.InternalData), this.m_width * 4 * this.m_height);
                        }
                        else
                        {
                            int s_idx = 0;
                            int d_idx = (int)gs.InternalData;
                            for (int i = this.m_height - 1; i >= 0; i--)
                            {
                                //どう考えてもポインタです。
                                Marshal.Copy((byte[])i_sample.getBuffer(), s_idx, (IntPtr)(d_idx), s_stride);
                                s_idx += s_stride;
                                d_idx += pitch;
                            }
                        }
                        break;

                    case NyARBufferType.OBJECT_CS_Bitmap:
                        NyARBitmapRaster ra = (NyARBitmapRaster)(i_sample);
                        BitmapData       bm = ra.lockBitmap();
                        try{
                            //コピー
                            int src = (int)bm.Scan0;
                            int dst = (int)gs.InternalData;
                            for (int r = this.m_height - 1; r >= 0; r--)
                            {
                                NyARD3dUtil.RtlCopyMemory((IntPtr)dst, (IntPtr)src, s_stride);
                                dst += pitch;
                                src += bm.Stride;
                            }
                        }finally{
                            ra.unlockBitmap();
                        }
                        break;

                    default:
                        throw new NyARException();
                    }
                }finally{
                    this._surface.UnlockRectangle();
                }
                return;
            }
        }
 /**
  * この関数は、{@link #getMarkerPlaneImage(int, NyARSensor, int, int, int, int, INyARRgbRaster)}
  * のラッパーです。取得画像を{@link #BufferedImage}形式で返します。
  * @param i_id
  * マーカid
  * @param i_sensor
  * 画像を取得するセンサオブジェクト。通常は{@link #update(NyARSensor)}関数に入力したものと同じものを指定します。
  * @param i_l
  * @param i_t
  * @param i_w
  * @param i_h
  * @param i_raster
  * 出力先のオブジェクト
  * @return
  * 結果を格納したi_rasterオブジェクト
  * @throws NyARException
  */
 public void getPlaneImage(
     int i_id,
     NyARSensor i_sensor,
     int i_l, int i_t,
     int i_w, int i_h,
     Bitmap i_img)
 {
     using (NyARBitmapRaster bmr = new NyARBitmapRaster(i_img))
     {
         base.getPlaneImage(i_id, i_sensor, i_l, i_t, i_w, i_h, bmr);
         return;
     }
 }
示例#4
0
        public void getImageFromService()
        {
            try
            {
                byte[] bimg = Helper.service.getImage(this.login);
                Image  img  = null;
                if (!chkBx_LocalImage.Checked)
                {
                    img = byteToImage(bimg);
                }
                else
                {
                    //img = Image.FromFile(@"D:\Users\zetrix\Desktop\Marker.jpg");
                    img = lstMarkerImageList[CurrentImage];
                }

                Image resizedImg = resizeImage(img, new Size(SCREEN_WIDTH, SCREEN_HEIGHT));

                if (img != null)
                {
                    //lock (this)
                    //this._raster = new NyARBitmapRaster((Bitmap)img);
                    this._raster = new NyARBitmapRaster((Bitmap)resizedImg);
                }
            }
            catch (WebException)
            {
                MessageBox.Show("Problème de connection", "RenderForm.getImageFromService");
                KillRenderThread();
            }
            catch (Exception x)
            {
                //If the app is closed we dont show the message.
                if (x.GetType() == typeof(System.Threading.ThreadAbortException))
                {
                    return;
                }

                if (this.isRunning)
                {
                    MessageBox.Show("La video n'est pas disponible maintenant, essayer plus tard.", "RenderForm.getImageFromService");
                }
                //MessageBox.Show(x.ToString());
                KillRenderThread();
                try
                {
                    ChangeVideoStateLabel("Démarrer");
                }
                catch (Exception) { }
            }
        }
        /// <summary>
        /// この関数は、{@link #getMarkerPlaneImage(int, NyARSensor, int, int, int, int, int, int, int, int, INyARRgbRaster)}
        /// のラッパーです。取得画像を{@link #BufferedImage}形式で返します。
        /// </summary>
        /// <param name="i_id"></param>
        /// <param name="i_sensor"></param>
        /// <param name="i_x1"></param>
        /// <param name="i_y1"></param>
        /// <param name="i_x2"></param>
        /// <param name="i_y2"></param>
        /// <param name="i_x3"></param>
        /// <param name="i_y3"></param>
        /// <param name="i_x4"></param>
        /// <param name="i_y4"></param>
        /// <param name="i_img"></param>
        /// <returns></returns>

        public void getMarkerPlaneImage(
            int i_id,
            NyARSensor i_sensor,
            int i_x1, int i_y1,
            int i_x2, int i_y2,
            int i_x3, int i_y3,
            int i_x4, int i_y4,
            Bitmap i_img)
        {
            using (NyARBitmapRaster bmr = new NyARBitmapRaster(i_img))
            {
                base.getMarkerPlaneImage(i_id, i_sensor, i_x1, i_y1, i_x2, i_y2, i_x3, i_y3, i_x4, i_y4, bmr);
                return;
            }
        }
        //
        // 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);
            }
        }
示例#7
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;
        }
        //
        // 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));
            }
        }
 /**
  * この関数は、{@link #getMarkerPlaneImage(int, NyARSensor, int, int, int, int, INyARRgbRaster)}
  * のラッパーです。取得画像を{@link #BufferedImage}形式で返します。
  * @param i_id
  * マーカid
  * @param i_sensor
  * 画像を取得するセンサオブジェクト。通常は{@link #update(NyARSensor)}関数に入力したものと同じものを指定します。
  * @param i_l
  * @param i_t
  * @param i_w
  * @param i_h
  * @param i_raster
  * 出力先のオブジェクト
  * @return
  * 結果を格納したi_rasterオブジェクト
  * @throws NyARException
  */
 public void getMarkerPlaneImage(
     int i_id,
     NyARSensor i_sensor,
     int i_l, int i_t,
     int i_w, int i_h,
     Bitmap i_img)
 {
     using (NyARBitmapRaster bmr = new NyARBitmapRaster(i_img))
     {
         base.getMarkerPlaneImage(i_id, i_sensor, i_l, i_t, i_w, i_h, bmr);
         this.getMarkerPlaneImage(i_id, i_sensor, i_l + i_w - 1, i_t + i_h - 1, i_l, i_t + i_h - 1, i_l, i_t, i_l + i_w - 1, i_t, bmr);
         return;
     }
 }
        /// <summary>
        /// この関数は、{@link #getMarkerPlaneImage(int, NyARSensor, int, int, int, int, int, int, int, int, INyARRgbRaster)}
        /// のラッパーです。取得画像を{@link #BufferedImage}形式で返します。
        /// </summary>
        /// <param name="i_id"></param>
        /// <param name="i_sensor"></param>
        /// <param name="i_x1"></param>
        /// <param name="i_y1"></param>
        /// <param name="i_x2"></param>
        /// <param name="i_y2"></param>
        /// <param name="i_x3"></param>
        /// <param name="i_y3"></param>
        /// <param name="i_x4"></param>
        /// <param name="i_y4"></param>
        /// <param name="i_img"></param>
        /// <returns></returns>

        public void getMarkerPlaneImage(
            int i_id,
            NyARSensor i_sensor,
            int i_x1, int i_y1,
            int i_x2, int i_y2,
            int i_x3, int i_y3,
            int i_x4, int i_y4,
            Bitmap i_img)
        {
            using (NyARBitmapRaster bmr = new NyARBitmapRaster(i_img))
            {
                base.getMarkerPlaneImage(i_id, i_sensor, i_x1, i_y1, i_x2, i_y2, i_x3, i_y3, i_x4, i_y4, bmr);
                return;
            }
        }
示例#11
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);
        }
示例#12
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);
        }