Exemplo n.º 1
0
        public void Test_arDetectMarkerLite()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            
            //AR用カメラパラメタファイルをロード
            NyARParam ap = new NyARParam();
            ap.loadARParam(assembly.GetManifestResourceStream(RES_CAMERA));
            ap.changeScreenSize(320, 240);

            //AR用のパターンコードを読み出し	
            NyARCode code = new NyARCode(16, 16);
            Stream sr1=assembly.GetManifestResourceStream(RES_PATT);
            code.loadARPatt(new StreamReader(sr1));

            //試験イメージの読み出し(320x240 BGRAのRAWデータ)
            StreamReader sr = new StreamReader(assembly.GetManifestResourceStream(RES_DATA));
            BinaryReader bs = new BinaryReader(sr.BaseStream);
            byte[] raw = bs.ReadBytes(320 * 240 * 4);
            NyARRgbRaster_BGRA ra = new NyARRgbRaster_BGRA(320, 240,false);
            ra.wrapBuffer(raw);
            //		Blank_Raster ra=new Blank_Raster(320, 240);

            //1パターンのみを追跡するクラスを作成
//            NyARSingleDetectMarker_Quad ar = new NyARSingleDetectMarker_Quad(ap, code, 80.0);
            NyARSingleDetectMarker ar = new NyARSingleDetectMarker(ap, code, 80.0,ra.getBufferType());
            NyARTransMatResult result_mat = new NyARTransMatResult();
            ar.setContinueMode(false);
            ar.detectMarkerLite(ra, 100);
            ar.getTransmationMatrix(result_mat);

            //マーカーを検出
            for (int i3 = 0; i3 < 10; i3++)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                for (int i = 0; i < 10; i++)
                {
                    //変換行列を取得
                    ar.detectMarkerLite(ra, 100);
                    ar.getTransmationMatrix(result_mat);
                }
                sw.Stop();
                Debug.WriteLine(sw.ElapsedMilliseconds + "[ms]");
            }
            return;
        }
Exemplo n.º 2
0
        private void nyar()
        {
            // - load the image to a bitmap
            Bitmap _latestFrameBitmap = (Bitmap)_latestFrame;

            // - create a new bitmap with diff. file format. PixelFormat.Format32bppArbg
            Bitmap _latestFrameShift = new Bitmap(_latestFrameBitmap.Width, _latestFrameBitmap.Height, PixelFormat.Format32bppArgb);
            _latestFrameShift.SetResolution(_latestFrameBitmap.HorizontalResolution, _latestFrameBitmap.VerticalResolution);

            // - copy the data from first bitmap to second.
            Graphics g = Graphics.FromImage(_latestFrameShift);
            g.DrawImage(_latestFrameBitmap, 0, 0);
            g.Dispose();

            // - change the bitmap into an intptr
            Rectangle _latestFrameShiftRect = new Rectangle(0, 0, _latestFrameShift.Width, _latestFrameShift.Height);
            BitmapData _latestFrameShiftData = _latestFrameShift.LockBits(_latestFrameShiftRect, ImageLockMode.ReadWrite, _latestFrameShift.PixelFormat);
            IntPtr fakeBuffer = _latestFrameShiftData.Scan0;

            _latestFrameShift.UnlockBits(_latestFrameShiftData);

            // - use the fake buffer
            _raster.setBuffer(fakeBuffer);

            //Begin to DETECT.

            //Try all three.
            _ar1.detectMarkerLite(_raster, 110);
            _ar2.detectMarkerLite(_raster, 110);
            _ar3.detectMarkerLite(_raster, 110);
            _ar4.detectMarkerLite(_raster, 110);

            NyARSingleDetectMarker[] _arArray = new NyARSingleDetectMarker[4] { _ar1, _ar2, _ar3, _ar4 };
            _arFinal = largestNyar(_arArray);

            is_marker_enable = _arFinal.detectMarkerLite(_raster, 110);

            if (is_marker_enable && _arFinal.getConfidence() > 0.3)
            {
                labelDemoName.Text = "Pattern #" + largestNyarIndex(_arArray) + "[" + _arFinal.getConfidence().ToString() + "]";
            }
            else
            {
                labelDemoName.Text = "No Pattern";
            }

            //display some feedback.
            pictureBoxAlbum.Image = _latestFrameShift;
        }