/**
         * この関数は、インスタンスを初期化します。
         * 継承先のクラスから呼び出してください。
         * @param i_param
         * カメラパラメータオブジェクト。このサイズは、{@link #detectMarker}に入力する画像と同じサイズである必要があります。
         * @param i_encoder
         * IDマーカの値エンコーダを指定します。
         * @param i_marker_width
         * マーカの物理縦横サイズをmm単位で指定します。
         * @
         */
        protected void initInstance(NyARParam i_param, INyIdMarkerDataEncoder i_encoder, double i_marker_width)
        {
            //初期化済?
            Debug.Assert(this._initialized == false);

            NyARIntSize scr_size = i_param.getScreenSize();

            // 解析オブジェクトを作る
            this._square_detect = new RleDetector(
                i_param,
                i_encoder,
                new NyIdMarkerPickup());
            this._transmat = new NyARTransMat(i_param);

            // 2値画像バッファを作る
            this._gs_raster = new NyARGrayscaleRaster(scr_size.w, scr_size.h);
            this._histmaker = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster));
            //ワーク用のデータオブジェクトを2個作る
            this._data_current     = i_encoder.createDataInstance();
            this._threshold_detect = new NyARHistogramAnalyzer_SlidePTile(15);
            this._initialized      = true;
            this._is_active        = false;
            this._offset           = new NyARRectOffset();
            this._offset.setSquare(i_marker_width);
            return;
        }
예제 #2
0
        /**
         *
         * @param i_ref_raster
         * 基本画像
         * @param i_ref_raster_distortion
         * 歪み解除オブジェクト(nullの場合歪み解除を省略)
         * @param i_ref_rob_raster
         * エッジ探索用のROB画像
         * @param
         */
        public NyARVectorReader_INT1D_GRAY_8(NyARGrayscaleRaster i_ref_raster, NyARCameraDistortionFactor i_ref_raster_distortion, NyARGrayscaleRaster i_ref_rob_raster)
            : base()

        {
            Debug.Assert(i_ref_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8);
            Debug.Assert(i_ref_rob_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8);
            this.initInstance(i_ref_raster, i_ref_raster_distortion, i_ref_rob_raster, new NyARContourPickup());
        }
예제 #3
0
 public NyARSensor(NyARIntSize i_size)
 {
     this._gs_raster  = NyARGrayscaleRaster.createInstance(i_size.w, i_size.h, NyARBufferType.INT1D_GRAY_8, true);
     this._gs_hist    = new NyARHistogram(256);
     this._src_ts     = 0;
     this._gs_id_ts   = 0;
     this._gs_hist_ts = 0;
     this._hist_drv   = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster));
 }
 /**
  * 継承クラスのコンストラクタから呼び出す。
  * @param i_ref_raster
  * 基本画像
  * @param i_ref_raster_distortion
  * 歪み解除オブジェクト(nullの場合歪み解除を省略)
  * @param i_ref_rob_raster
  * エッジ探索用のROB画像
  * @param i_contour_pickup
  * 輪郭線取得クラス
  * @param
  */
 public void initInstance(NyARGrayscaleRaster i_ref_raster, NyARCameraDistortionFactor i_ref_raster_distortion, NyARGrayscaleRaster i_ref_rob_raster, NyARContourPickup i_contour_pickup)
 {
     this._rob_resolution  = i_ref_raster.getWidth() / i_ref_rob_raster.getWidth();
     this._ref_rob_raster  = i_ref_rob_raster;
     this._ref_base_raster = i_ref_raster;
     this._coord_buf       = new NyARIntCoordinates((i_ref_raster.getWidth() + i_ref_raster.getHeight()) * 4);
     this._factor          = i_ref_raster_distortion;
     this._tmp_coord_pos   = VecLinearCoordinates.VecLinearCoordinatePoint.createArray(this._coord_buf.items.Length);
     this._cpickup         = i_contour_pickup;
     return;
 }
예제 #5
0
        /**
         * i_inのデータをサンプリングして、o_outにサンプル値を作成します。
         * この関数は、o_outにi_inのサンプリング結果を出力します。既にo_outにあるデータは初期化されます。
         * @param i_in
         * 入力元のデータです。
         * @param i_th
         * ラべリングの敷居値です。
         * @param o_out
         * 出力先のデータです。
         * @throws NyARException
         */
        public void Sampling(NyARGrayscaleRaster i_in, int i_th, LowResolutionLabelingSamplerOut o_out)
        {
            //クラスのパラメータ初期化
            Main_Labeling lb = this._main_labeling;

            lb.current_output = o_out;
            lb.current_th     = i_th;

            //パラメータの設定
            o_out.initializeParams();

            //ラべリング
            lb.setAreaRange(10000, 3);
            lb.labeling(i_in, i_th);
        }
예제 #6
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));
            }
        }
        /**
         * @param i_number_of_sample
         * サンプラが検出する最大数。
         * 通常100~200以上を指定します。(QVGA画像あたり、100個を基準にします。)
         * 数が少なすぎると、検出率が低下します。最低でも、NyARTrackerに設定するターゲット数の合計*2以上を指定してください。
         * @param i_ref_raster_distortion
         * 歪み矯正の為のオブジェクトを指定します。歪み矯正が必要ない時は、NULLを指定します。
         * @param i_width
         * ソース画像のサイズ
         * @param i_height
         * ソース画像のサイズ
         * @param i_depth
         * 解像度の深さ(1/(2^n))倍の画像として処理する。
         * @param i_is_alloc
         * ベースラスタのバッファを内部確保外部参照にするかのフラグです。
         * trueの場合、バッファは内部に確保され、{@link #wrapBuffer}関数が使用できなくなります。
         * @throws NyARException
         */
        public NyARTrackerSource_Reference(int i_number_of_sample, NyARCameraDistortionFactor i_ref_raster_distortion, int i_width, int i_height, int i_depth, bool i_is_alloc)
            : base((int)Math.Pow(2, i_depth))
        {
            Debug.Assert(i_depth > 0);
            int div = this._rob_resolution;

            //主GSラスタ
            this._base_raster = new NyARGrayscaleRaster(i_width, i_height, NyARBufferType.INT1D_GRAY_8, i_is_alloc);
            //Roberts変換ラスタ
            this._rb_source = new NyARGrayscaleRaster(i_width / div, i_height / div, NyARBufferType.INT1D_GRAY_8, true);
            //Robertsラスタは最も解像度の低いラスタと同じ
            this._rbraster   = new NyARGrayscaleRaster(i_width / div, i_height / div, NyARBufferType.INT1D_GRAY_8, true);
            this._vec_reader = new NyARVectorReader_INT1D_GRAY_8(this._base_raster, i_ref_raster_distortion, this._rbraster);
            //samplerとsampleout
            this._sampler    = new LowResolutionLabelingSampler(i_width, i_height, (int)Math.Pow(2, i_depth));
            this._sample_out = new LowResolutionLabelingSamplerOut(i_number_of_sample);
        }
예제 #8
0
        /**
         * この関数は、インスタンスを初期化します。
         * 継承先のクラスから呼び出してください。
         * @param i_param
         * カメラパラメータオブジェクト。このサイズは、{@link #detectMarker}に入力する画像と同じサイズである必要があります。
         * @
         */
        protected void initInstance(NyARParam i_param)
        {
            //初期化済?
            Debug.Assert(this._initialized == false);

            NyARIntSize scr_size = i_param.getScreenSize();

            // 解析オブジェクトを作る
            this._transmat = new NyARTransMat(i_param);
            this._thdetect = new NyARHistogramAnalyzer_SlidePTile(15);

            // 2値画像バッファを作る
            this._gs_raster   = new NyARGrayscaleRaster(scr_size.w, scr_size.h);
            this._initialized = true;
            //コールバックハンドラ
            this._detectmarker = new DetectSquare(i_param);
            this._offset       = new NyARRectOffset();
            return;
        }
        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);
        }
 /**
  * GS画像をセットします。
  * この関数を使ってセットした画像は、インスタンスから参照されます。
  * @param i_ref_source
  * @throws NyARException
  */
 public void wrapBuffer(NyARGrayscaleRaster i_ref_source)
 {
     //バッファのスイッチ
     this._base_raster.wrapBuffer(i_ref_source.getBuffer());
 }
예제 #11
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;
        }