示例#1
0
        public MainWindow()
        {
            InitializeComponent();

            this.GdMainZm.Height             = 600;
            this.CameraZm.Height             = 600;
            this.CameraZm.DesiredPixelHeight = 600;

            this.GdMainZm.Width             = 800;
            this.CameraZm.Width             = 800;
            this.CameraZm.DesiredPixelWidth = 800;

            this.CameraZm.EnableSampleGrabbing = true;
            this.CameraZm.NewVideoSample      += CameraZm_NewVideoSample;

            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), 800, 600);

            this.ARRgbRaster = new NyARRgbRaster_BYTE1D_B8G8R8_24(800, 600, false);

            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE), 16, 16);

            this.ARDetectMarker = new NyARDetectMarker(ap, new NyARCode[] { code }, new double[] { 80.0 }, 1);
            this.ARDetectMarker.setContinueMode(false);

            this.Loaded += MainWindow_Loaded;
        }
        public MainWindow()
        {
            InitializeComponent();

            CaptureDeviceList cl = new CaptureDeviceList();

            m_cap = cl[0];
            m_cap.SetCaptureListener(this);
            m_cap.PrepareCapture(cameraResX, cameraResY, 30); // 800x600 resolution, 30 fps

            NyARParam ap = new NyARParam();

            ap.loadARParamFromFile(AR_CAMERA_FILE);
            ap.changeScreenSize(cameraResX, cameraResY);

            this.m_raster = new NyARRgbRaster(m_cap.video_width, m_cap.video_height, NyARBufferType.BYTE1D_R8G8B8_24,
                                              false);

            NyARCode code = new NyARCode(16, 16); // 16 pixels to detect within black box

            code.loadARPattFromFile(AR_CODE_FILE);
            this.m_ar = new NyARDetectMarker(ap, new NyARCode[] { code }, new double[] { 80.0 }, 1,
                                             NyARBufferType.BYTE1D_B8G8R8_24);
            this.m_ar.setContinueMode(false);

            this.Loaded += MainWindow_Loaded;
        }
示例#3
0
        public void Test()
        {
            //AR用カメラパラメタファイルをロード
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(camera_file));

            ap.changeScreenSize(320, 240);

            //試験イメージの読み出し(320x240 RGBのRAWデータ)
            StreamReader sr = new StreamReader(data_file);
            BinaryReader bs = new BinaryReader(sr.BaseStream);

            byte[]        raw = bs.ReadBytes(320 * 240 * 3);
            NyARRgbRaster ra  = new NyARRgbRaster(320, 240, NyARBufferType.BYTE1D_R8G8B8_24, false);

            ra.wrapBuffer(raw);

            MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferType());

            pr.detectMarker(ra);
            Console.WriteLine(pr.transmat.m00 + "," + pr.transmat.m01 + "," + pr.transmat.m02 + "," + pr.transmat.m03);
            Console.WriteLine(pr.transmat.m10 + "," + pr.transmat.m11 + "," + pr.transmat.m12 + "," + pr.transmat.m13);
            Console.WriteLine(pr.transmat.m20 + "," + pr.transmat.m21 + "," + pr.transmat.m22 + "," + pr.transmat.m23);
            Console.WriteLine(pr.transmat.m30 + "," + pr.transmat.m31 + "," + pr.transmat.m32 + "," + pr.transmat.m33);
            Console.WriteLine(pr.current_id);
            return;
        }
示例#4
0
 /**
  * コンストラクタです。
  * @param i_max
  * 登録するアイテムの最大数です。
  * @param i_resolution_x
  * 登録するパターンの解像度です。
  * ARToolKit互換の標準値は16です。
  * @param i_resolution_y
  * 登録するパターンの解像度です。
  * ARToolKit互換の標準値は16です。
  * @param i_edge_x
  * エッジ部分の割合です。ARToolKit互換の標準値は25です。
  * @param i_edge_y
  * エッジ部分の割合です。ARToolKit互換の標準値は25です。
  * @param i_sample_per_pix
  * パターン取得の1ピクセルあたりのサンプリング数です。1なら1Pixel=1,2なら1Pixel=4のサンプリングをします。
  * ARToolKit互換の標準値は4です。
  * 高解像度(64以上)のパターンを用いるときは、サンプリング数を低く設定してください。
  * @throws NyARException
  */
 public ARTKMarkerTable(int i_max, int i_resolution_x, int i_resolution_y, int i_edge_x, int i_edge_y, int i_sample_per_pix)
 {
     this._resolution_width  = i_resolution_x;
     this._resolution_height = i_resolution_y;
     this._edge_x            = i_edge_x;
     this._edge_y            = i_edge_y;
     this._sample_per_pix    = i_sample_per_pix;
     this._tmp_raster        = new NyARRgbRaster(i_resolution_x, i_resolution_y, NyARBufferType.INT1D_X8R8G8B8_32);
     this._table             = new MarkerTable(i_max);
     this._deviation_data    = new NyARMatchPattDeviationColorData(i_resolution_x, i_resolution_y);
     this._match_patt        = new NyARMatchPatt_Color_WITHOUT_PCA(i_resolution_x, i_resolution_y);
 }
示例#5
0
        public int addARMarker(INyARRgbRaster i_raster, int i_patt_resolution, int i_patt_edge_percentage,
                               double i_marker_size)
        {
            NyARCode             c  = new NyARCode(i_patt_resolution, i_patt_resolution);
            NyARIntSize          s  = i_raster.getSize();
            INyARPerspectiveCopy pc = (INyARPerspectiveCopy)i_raster.createInterface(typeof(INyARPerspectiveCopy));
            INyARRgbRaster       tr = NyARRgbRaster.createInstance(i_patt_resolution, i_patt_resolution);

            pc.copyPatt(0, 0, s.w, 0, s.w, s.h, 0, s.h, i_patt_edge_percentage, i_patt_edge_percentage, 4, tr);
            c.setRaster(tr);
            return(this.addARMarker(c, i_patt_edge_percentage, i_marker_size));
        }
示例#6
0
        /**
         * i_rasterからパターンコードを生成して、テーブルへ追加します。
         * @param i_raster
         * @param i_id
         * このマーカを識別するユーザ定義のID値です。任意の値を指定できます。不要な場合は0を指定してください。
         * @param i_name
         * ユーザ定義の名前です。任意の値を指定できます。不要な場合はnullを指定して下さい。
         * @param i_width
         * マーカの高さ[通常mm単位]
         * @param i_height
         * マーカの幅[通常mm単位]
         * @return
         * @throws NyARException
         */
        public bool addMarker(NyARRgbRaster i_raster, int i_id, String i_name, double i_width, double i_height)
        {
            MarkerTable.SerialTableRow d = this._table.prePush();
            if (d == null)
            {
                return(false);
            }
            NyARCode c = new NyARCode(this._resolution_width, this._resolution_height);

            c.setRaster(i_raster);
            d.setValue(c, i_id, i_name, i_width, i_height);
            return(true);
        }
示例#7
0
        public void Test()
        {
            //AR用カメラパラメタファイルをロード
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(camera_file));

            ap.changeScreenSize(320, 240);

            //AR用のパターンコードを読み出し
            NyARCode code = NyARCode.createFromARPattFile(new StreamReader(code_file), 16, 16);

            //試験イメージの読み出し(320x240 BGRAのRAWデータ)
            StreamReader sr = new StreamReader(data_file);
            BinaryReader bs = new BinaryReader(sr.BaseStream);

            byte[] raw = bs.ReadBytes(320 * 240 * 4);

//            NyARBitmapRaster ra = new NyARBitmapRaster(320, 240);
//            Graphics g = Graphics.FromImage(ra.getBitmap());
//            g.DrawImage(new Bitmap("../../../../../data/320x240ABGR.png"), 0, 0);


            NyARRgbRaster ra = new NyARRgbRaster(320, 240, NyARBufferType.BYTE1D_B8G8R8X8_32, false);

            ra.wrapBuffer(raw);

            //1パターンのみを追跡するクラスを作成
            NyARSingleDetectMarker ar         = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT);
            NyARDoubleMatrix44     result_mat = new NyARDoubleMatrix44();

            ar.setContinueMode(false);
            ar.detectMarkerLite(ra, 100);
            ar.getTransmationMatrix(result_mat);

            //マーカーを検出
            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 1000; i++)
            {
                //変換行列を取得
                ar.detectMarkerLite(ra, 100);
                ar.getTransmationMatrix(result_mat);
            }
            Console.WriteLine(result_mat.m00 + "," + result_mat.m01 + "," + result_mat.m02 + "," + result_mat.m03);
            Console.WriteLine(result_mat.m10 + "," + result_mat.m11 + "," + result_mat.m12 + "," + result_mat.m13);
            Console.WriteLine(result_mat.m20 + "," + result_mat.m21 + "," + result_mat.m22 + "," + result_mat.m23);
            Console.WriteLine(result_mat.m30 + "," + result_mat.m31 + "," + result_mat.m32 + "," + result_mat.m33);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds + "[ms]");
            return;
        }
示例#8
0
        /**
         * このターゲットについて、非同期に認識依頼を出します。このプログラムはサンプルなので、別スレッドでIDマーカ判定をして、
         * 三秒後に適当なサイズとDirectionを返却するだけです。
         * @param i_target
         * @return
         * @throws NyARException
         */
        public void requestAsyncMarkerDetect(NyARReality i_reality, NyARRealitySource i_source, NyARRealityTarget i_target)
        {
            //ターゲットから画像データなどを取得するときは、スレッドからではなく、ここで同期して取得してコピーしてからスレッドに引き渡します。

            //100x100の領域を切りだして、Rasterを作る。
            NyARRgbRaster raster = new NyARRgbRaster(100, 100, NyARBufferType.INT1D_X8R8G8B8_32);

            i_reality.getRgbPatt2d(i_source, i_target.refTargetVertex(), 1, raster);
            //コピーしたラスタとターゲットのIDをスレッドへ引き渡す。
            Thread t = new Thread(new AsyncThread(this, i_target.getSerialId(), raster).run);

            t.Start();
            return;
        }
            public Item(int i_patt_w, int i_patt_h, int i_edge_percentage)
            {
                int r = 1;

                //解像度は幅を基準にする。
                while (i_patt_w * r < 64)
                {
                    r *= 2;
                }
                this._patt            = NyARRgbRaster.createInstance(i_patt_w, i_patt_h, NyARBufferType.INT1D_X8R8G8B8_32, true);
                this._patt_d          = new NyARMatchPattDeviationColorData(i_patt_w, i_patt_h);
                this._patt_edge       = i_edge_percentage;
                this._patt_resolution = r;
            }
        /// <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(Texture2D 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;
            NyARUnityRaster ur = new NyARUnityRaster(i_img);
            NyARCode        c  = new NyARCode(i_patt_resolution, i_patt_resolution);
            //ラスタからマーカパターンを切り出す
            INyARPerspectiveCopy pc = (INyARPerspectiveCopy)ur.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));
        }
示例#11
0
        static void Main(string[] args)
        {
            String img_file    = "../../../../../data/testcase/test.raw";
            String cparam_file = "../../../../../data/testcase/camera_para5.dat";
            String fset3file   = "../../../../../data/testcase/pinball.fset3";
            //カメラパラメータ
            NyARParam param = NyARParam.loadFromARParamFile(File.OpenRead(cparam_file), 640, 480, NyARParam.DISTFACTOR_LT_ARTK5);

            INyARGrayscaleRaster gs = NyARGrayscaleRaster.createInstance(640, 480);
            //試験画像の準備
            {
                INyARRgbRaster rgb = NyARRgbRaster.createInstance(640, 480, NyARBufferType.BYTE1D_B8G8R8X8_32);
                Stream         fs  = File.OpenRead(img_file);
                byte[]         b   = (byte[])rgb.getBuffer();
                fs.Read(b, 0, b.Length);
                INyARRgb2GsFilterRgbAve filter = (INyARRgb2GsFilterRgbAve)rgb.createInterface(typeof(INyARRgb2GsFilterRgbAve));
                filter.convert(gs);
            }
            NyARDoubleMatrix44   tmat = new NyARDoubleMatrix44();
            NyARNftFreakFsetFile f    = NyARNftFreakFsetFile.loadFromfset3File(File.OpenRead(fset3file));
//			KpmHandle kpm=new KpmHandle(new ARParamLT(param));
            Stopwatch             sw     = new Stopwatch();
            FreakKeypointMatching kpm    = new FreakKeypointMatching(param);
            KeyframeMap           keymap = new KeyframeMap(f, 0);

            for (int j = 0; j < 4; j++)
            {
                sw.Reset();
                sw.Start();
                for (int i = 0; i < 20; i++)
                {
                    kpm.updateInputImage(gs);
                    kpm.updateFeatureSet();
                    kpm.kpmMatching(keymap, tmat);
                }
                //FreakKeypointMatching#kMaxNumFeaturesを300にしてテストして。
                sw.Stop();
                System.Console.WriteLine("Total=" + (sw.ElapsedMilliseconds));
                NyARDoubleMatrix44 TEST_PATT = new NyARDoubleMatrix44(new double[] {
                    0.98436354107742652, 0.0066768917838370646, -0.17602226595996517, -191.17967199668533,
                    0.011597578022657571, -0.99956974712564306, 0.026940987645082352, 63.00280574839347,
                    -0.17576664981496215, -0.028561157958401542, -0.98401745160789567, 611.75871553558636,
                    0, 0, 0, 1
                });
                System.Console.WriteLine(TEST_PATT.Equals(tmat));
            }
        }
示例#12
0
        //
        // 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));
            }
        }
示例#13
0
        public MainWindow()
        {
            InitializeComponent();

            CaptureDeviceList cl = new CaptureDeviceList();

            m_cap = cl[0];
            m_cap.SetCaptureListener(this);
            m_cap.PrepareCapture(800, 600, 30);

            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), 800, 600);

            this.m_raster = new NyARRgbRaster_BYTE1D_B8G8R8_24(m_cap.video_width, m_cap.video_height, false);

            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE), 16, 16);

            this.m_ar = new NyARDetectMarker(ap, new NyARCode[] { code }, new double[] { 80.0 }, 1);
            this.m_ar.setContinueMode(false);

            this.Loaded  += MainWindow_Loaded;
            this.Closing += MainWindow_Closing;
        }
示例#14
0
 public AsyncThread(ASyncIdMarkerTable i_parent, long i_serial, NyARRgbRaster i_raster)
 {
     this._parent = i_parent;
     this._serial = i_serial;
     this._source = i_raster;
 }
示例#15
0
        static void Main(string[] args)
        {
            NyARDoubleMatrix44 DEST_MAT = new NyARDoubleMatrix44(
                new double[] {
                0.9832165682361184, 0.004789697223621061, -0.18237945710280384, -190.59060790299358,
                0.012860184615056927, -0.9989882709616935, 0.04309419210331572, 64.04490277502563,
                -0.18198852802987958, -0.044716355753573425, -0.9822833548209547, 616.6427596804766,
                0, 0, 0, 1
            });
            NyARDoubleMatrix44 SRC_MAT = new NyARDoubleMatrix44(new double[] {
                0.984363556, 0.00667689135, -0.176022261, -191.179672,
                0.0115975942, -0.999569774, 0.0269410834, 63.0028076,
                -0.175766647, -0.0285612550, -0.984017432, 611.758728,
                0, 0, 0, 1
            });

            String img_file = "../../../../../data/testcase/test.raw";
            String cparam   = "../../../../../data/testcase/camera_para5.dat";
            String fsetfile = "../../../../../data/testcase/pinball.fset";
            String isetfile = "../../../../../data/testcase/pinball.iset5";
            //カメラパラメータ
            NyARParam param = NyARParam.loadFromARParamFile(File.OpenRead(cparam), 640, 480, NyARParam.DISTFACTOR_LT_ARTK5);


            INyARGrayscaleRaster gs = NyARGrayscaleRaster.createInstance(640, 480);
            //試験画像の準備
            {
                INyARRgbRaster rgb = NyARRgbRaster.createInstance(640, 480, NyARBufferType.BYTE1D_B8G8R8X8_32);
                Stream         fs  = File.OpenRead(img_file);
                byte[]         b   = (byte[])rgb.getBuffer();
                fs.Read(b, 0, b.Length);
                INyARRgb2GsFilterRgbAve filter = (INyARRgb2GsFilterRgbAve)rgb.createInterface(typeof(INyARRgb2GsFilterRgbAve));
                filter.convert(gs);
            }

            NyARNftFsetFile    fset = NyARNftFsetFile.loadFromFsetFile(File.OpenRead(fsetfile));
            NyARNftIsetFile    iset = NyARNftIsetFile.loadFromIsetFile(File.OpenRead(isetfile));
            NyARSurfaceTracker st   = new NyARSurfaceTracker(param, 16, 0.5);
            NyARSurfaceDataSet sd   = new NyARSurfaceDataSet(iset, fset);
            NyARDoubleMatrix44 sret = new NyARDoubleMatrix44();

            NyARDoublePoint2d[] o_pos2d           = NyARDoublePoint2d.createArray(16);
            NyARDoublePoint3d[] o_pos3d           = NyARDoublePoint3d.createArray(16);
            NyARSurfaceTrackingTransmatUtils tmat = new NyARSurfaceTrackingTransmatUtils(param, 5.0);
            NyARDoubleMatrix44 tret = new NyARDoubleMatrix44();

            for (int j = 0; j < 10; j++)
            {
                Stopwatch s = new Stopwatch();
                s.Reset();
                s.Start();
                for (int i = 0; i < 3000; i++)
                {
                    sret.setValue(SRC_MAT);
                    int nop = st.tracking(gs, sd, sret, o_pos2d, o_pos3d, 16);
                    //Transmatの試験
                    NyARDoublePoint3d off = NyARSurfaceTrackingTransmatUtils.centerOffset(o_pos3d, nop, new NyARDoublePoint3d());
                    NyARSurfaceTrackingTransmatUtils.modifyInputOffset(sret, o_pos3d, nop, off);
                    tmat.surfaceTrackingTransmat(sret, o_pos2d, o_pos3d, nop, tret, new NyARTransMatResultParam());
                    NyARSurfaceTrackingTransmatUtils.restoreOutputOffset(tret, off);
                    System.Console.WriteLine(tret.Equals(DEST_MAT));
                }
                s.Stop();
                System.Console.WriteLine(s.ElapsedMilliseconds);
            }
            return;
        }