Esempio n. 1
0
        /// <summary>
        /// Initializes the detector for single marker detection.
        /// </summary>
        /// <param name="width">The width of the buffer that will be used for detection.</param>
        /// <param name="height">The height of the buffer that will be used for detection.</param>
        /// <param name="nearPlane">The near view plane of the frustum.</param>
        /// <param name="farPlane">The far view plane of the frustum.</param>
        /// <param name="markers">A list of markers that should be detected.</param>
        /// <param name="bufferType">The type of the buffer.</param>
        /// <param name="adaptive">Performs an adaptive bitmap thresholding if set to true. Default = false.</param>
        protected void Initialize(int width, int height, double nearPlane, double farPlane, IList <Marker> markers, int bufferType, bool adaptive = false)
        {
            // Check arguments
            if (markers == null || !markers.Any())
            {
                throw new ArgumentNullException("markers");
            }

            // Member init
            this.bufferWidth  = width;
            this.bufferHeight = height;
            this.isAdaptive   = adaptive;

            // Init pattern matchers with markers and check segment size, whcih has to be equal for all markers
            int segmentX        = markers[0].SegmentsX;
            int segmentY        = markers[0].SegmentsY;
            var patternMatchers = new List <PatternMatcher>(markers.Count);

            foreach (var marker in markers)
            {
                if (marker.SegmentsX != segmentX || marker.SegmentsY != segmentY)
                {
                    throw new ArgumentException("The Segment size has to be equal for all markers. Don't mix 16x16 and 32x32 markers for example.", "markers");
                }
                patternMatchers.Add(new PatternMatcher(marker));
            }

            // Load deafult camera calibration data
            var asmName = new System.Reflection.AssemblyName(System.Reflection.Assembly.GetExecutingAssembly().FullName).Name;

            var streamResInfoCam = Application.GetResourceStream(new Uri(asmName + ";component/data/Camera_Calibration_Default.dat", UriKind.Relative));
            var cameraParameters = new NyARParam();

            using (var cameraCalibrationDataStream = streamResInfoCam.Stream)
            {
                cameraParameters.loadARParam(cameraCalibrationDataStream);
                cameraParameters.changeScreenSize(width, height);
            }

            // Get projection matrix from camera calibration data
            this.Projection = cameraParameters.GetCameraFrustumRH(nearPlane, farPlane);

            // Init detector and necessary data
            var colorPattern = new NyARColorPatt_Perspective_O2(segmentX, segmentY, 4, 25);
            var patternMatchDeviationData = new NyARMatchPattDeviationColorData(segmentX, segmentY);

            this.squareDetector          = new NyARSquareContourDetector_Rle(cameraParameters.getScreenSize());
            this.squareDetectionListener = new SquareDetectionListener(patternMatchers, cameraParameters, colorPattern, patternMatchDeviationData);

            // Init buffer members
            this.filteredBuffer = new NyARBinRaster(width, height);
            if (adaptive)
            {
                this.bufferFilter = new NyARRasterFilter_AdaptiveThreshold(bufferType);
            }
            else
            {
                this.bufferFilter = new NyARRasterFilter_ARToolkitThreshold(this.Threshold, bufferType);
            }
        }
        protected void initInstance(
            INyARColorPatt i_patt_inst,
            NyARSquareContourDetector i_sqdetect_inst,
            INyARTransMat i_transmat_inst,
            INyARRasterFilter_Rgb2Bin i_filter,
            NyARParam i_ref_param,
            NyARCode i_ref_code,
            double i_marker_width)
        {
            NyARIntSize scr_size = i_ref_param.getScreenSize();

            // 解析オブジェクトを作る
            this._square_detect = i_sqdetect_inst;
            this._transmat      = i_transmat_inst;
            this._tobin_filter  = i_filter;
            //2値画像バッファを作る
            this._bin_raster = new NyARBinRaster(scr_size.w, scr_size.h);
            //パターンの一致検索処理用
            this._inst_patt      = i_patt_inst;
            this._deviation_data = new NyARMatchPattDeviationColorData(i_ref_code.getWidth(), i_ref_code.getHeight());
            this._coordline      = new NyARCoord2Linear(i_ref_param.getScreenSize(), i_ref_param.getDistortionFactor());
            this._match_patt     = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code);
            //オフセットを作成
            this._offset = new NyARRectOffset();
            this._offset.setSquare(i_marker_width);
            return;
        }
 public DetectSquareCB(INyARColorPatt i_inst_patt, NyARCode i_ref_code, NyARParam i_param)
 {
     this._inst_patt      = i_inst_patt;
     this._deviation_data = new NyARMatchPattDeviationColorData(i_ref_code.getWidth(), i_ref_code.getHeight());
     this._coordline      = new Coord2Linear(i_param.getScreenSize(), i_param.getDistortionFactor());
     this._match_patt     = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code);
     return;
 }
Esempio n. 4
0
 public void setNyARCodeTable(NyARCode[] i_ref_code, int i_code_resolution)
 {
     /*unmanagedで実装するときは、ここでリソース解放をすること。*/
     this._deviation_data = new NyARMatchPattDeviationColorData(i_code_resolution, i_code_resolution);
     this._inst_patt      = new NyARColorPatt_Perspective(i_code_resolution, i_code_resolution, 4, 25);
     this._match_patt     = new NyARMatchPatt_Color_WITHOUT_PCA[i_ref_code.Length];
     for (int i = 0; i < i_ref_code.Length; i++)
     {
         this._match_patt[i] = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]);
     }
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
        protected NyARSingleDetectMarker(NyARParam i_ref_param, NyARCode i_ref_code, double i_marker_width)
        {
            this._deviation_data = new NyARMatchPattDeviationColorData(i_ref_code.getWidth(), i_ref_code.getHeight());
            this._match_patt     = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code);
            this._offset         = new NyARRectOffset();
            this._offset.setSquare(i_marker_width);
            this._coordline = new NyARCoord2Linear(i_ref_param.getScreenSize(), i_ref_param.getDistortionFactor());
            //2値画像バッファを作る
            NyARIntSize s = i_ref_param.getScreenSize();

            this._bin_raster = new NyARBinRaster(s.w, s.h);
        }
        /// <summary>
        /// Initialize a new SquareDetectionListener.
        /// </summary>
        /// <param name="patternMatchers">The pattern matchers with the marker data.</param>
        /// <param name="cameraParameters">The camera calibration data.</param>
        /// <param name="colorPattern">The used color pattern.</param>
        /// <param name="patternMatchDeviationData">The pattern match deviation data.</param>
        public SquareDetectionListener(List <PatternMatcher> patternMatchers, NyARParam cameraParameters, INyARColorPatt colorPattern, NyARMatchPattDeviationColorData patternMatchDeviationData)
        {
            this.patternMatchers           = patternMatchers;
            this.colorPattern              = colorPattern;
            this.patternMatchDeviationData = patternMatchDeviationData;
            this.coordinationMapper        = new Coord2Linear(cameraParameters.getScreenSize(), cameraParameters.getDistortionFactor());
            this.matrixCalculator          = new NyARTransMat(cameraParameters);
            this.points           = NyARIntPoint2d.createArray(4);
            this.evaluationResult = new NyARMatchPattResult();

            Reset();
        }
            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            = new NyARRgbRaster(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;
            }
Esempio n. 9
0
        /**
         * o_targetsに、敷居値を越えたターゲットリストを返却する。
         * @param i_pix_drv
         * @param i_vertex
         * @param o_targets
         * @return
         * @
         */
        public bool Update(INyARPerspectiveCopy i_pix_drv, SquareStack.Item i_sq)
        {
            //sq_tmpに値を生成したかのフラグ
            bool is_ganalated_sq = false;

            for (int i = this.Count - 1; i >= 0; i--)
            {
                ARMarkerList.Item target = this[i];
                //解像度に一致する画像を取得
                NyARMatchPattDeviationColorData diff = this._mpickup.getDeviationColorData(target, i_pix_drv, i_sq.ob_vertex);

                //マーカのパターン解像度に一致したサンプリング画像と比較する。
                if (!target.matchpatt.evaluate(diff, this._patt_result))
                {
                    continue;
                }

                //敷居値をチェック
                if (this._patt_result.confidence < this._configense_th)
                {
                    continue;
                }

                //マーカマップへの追加対象か調べる。
                ARMarkerSortList.Item ip = this._mkmap.getInsertPoint(this._patt_result.confidence);
                if (ip == null)
                {
                    continue;
                }

                //マーカマップアイテムの矩形に参照値を設定する。
                ip              = this._mkmap.insertFromTailBefore(ip);
                ip.cf           = this._patt_result.confidence;
                ip.dir          = this._patt_result.direction;
                ip.marker       = target;
                ip.ref_sq       = i_sq;
                is_ganalated_sq = true;
            }
            return(is_ganalated_sq);
        }
            public RleDetector(INyARColorPatt i_inst_patt, NyARCode[] i_ref_code, int i_num_of_code, NyARParam i_param) : base(i_param.getScreenSize())
            {
                int cw = i_ref_code[0].getWidth();
                int ch = i_ref_code[0].getHeight();

                //NyARMatchPatt_Color_WITHOUT_PCA[]の作成
                this._match_patt    = new NyARMatchPatt_Color_WITHOUT_PCA[i_num_of_code];
                this._match_patt[0] = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[0]);
                for (int i = 1; i < i_num_of_code; i++)
                {
                    //解像度チェック
                    if (cw != i_ref_code[i].getWidth() || ch != i_ref_code[i].getHeight())
                    {
                        throw new NyARException();
                    }
                    this._match_patt[i] = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]);
                }
                this._inst_patt      = i_inst_patt;
                this._coordline      = new NyARCoord2Linear(i_param.getScreenSize(), i_param.getDistortionFactor());
                this._deviation_data = new NyARMatchPattDeviationColorData(cw, ch);
                return;
            }