Example #1
0
        /**
         * この関数は、画像から登録済のマーカ検出を行います。
         * マーカの検出に成功すると、thisのプロパティにマーカの二次元位置を記録します。
         * 関数の成功後は、マーカの姿勢行列と、一致度を、それぞれ{@link #getTransmationMatrix}と{@link #getConfidence}から得ることができます。
         * @param i_raster
         * マーカーを検出する画像。画像のサイズは、コンストラクタに指定した{@link NyARParam}オブジェクトと一致していなければなりません。
         * @param i_th
         * 2値化敷居値。0から256までの値を指定します。
         * @return
         * マーカーが検出できたかを、真偽値で返します。
         * @
         */
        public bool detectMarkerLite(INyARRgbRaster i_raster, int i_th)
        {
            NyARIntSize size1, size2;

            size1 = _bin_raster.getSize();
            size2 = i_raster.getSize();
            //System.Windows.Forms.MessageBox.Show("   bin: w " + size1.w.ToString() + " h " + size1.h.ToString() +
            //                                   "\nraster: w " + size2.w.ToString() + " h " + size2.h.ToString());
            //サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize()))
            {
                throw new NyARException();
            }
            //最終入力ラスタを更新
            if (this._last_input_raster != i_raster)
            {
                this._bin_filter        = (INyARRgb2GsFilterArtkTh)i_raster.createInterface(typeof(INyARRgb2GsFilterArtkTh));
                this._last_input_raster = i_raster;
            }
            //ラスタを2値イメージに変換する.
            this._bin_filter.doFilter(i_th, this._bin_raster);

            //コールバックハンドラの準備
            this._confidence        = 0;
            this._last_input_raster = i_raster;
            //
            //マーカ検出器をコール
            this.execDetectMarker();
            if (this._confidence == 0)
            {
                return(false);
            }
            return(true);
        }
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h))
            {
                throw new NyARException();
            }
            // ラスタを2値イメージに変換する.
            this._tobin_filter.setThreshold(this._current_threshold);
            this._tobin_filter.doFilter(i_raster, this._bin_raster);

            // スクエアコードを探す(第二引数に指定したマーカ、もしくは新しいマーカを探す。)
            this._callback.init(i_raster, this._is_active ? this._data_current : null);
            this._square_detect.detectMarkerCB(this._bin_raster, this._callback);

            // 認識状態を更新(マーカを発見したなら、current_dataを渡すかんじ)
            bool is_id_found = updateStatus(this._callback.square, this._callback.marker_data);

            //閾値フィードバック(detectExistMarkerにもあるよ)
            if (is_id_found)
            {
                //マーカがあれば、マーカの周辺閾値を反映
                this._current_threshold = (this._current_threshold + this._callback.threshold) / 2;
            }
            else
            {
                //マーカがなければ、探索+DualPTailで基準輝度検索
                int th = this._threshold_detect.analyzeRaster(i_raster);
                this._current_threshold = (this._current_threshold + th) / 2;
            }
            return;
        }
        public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output)
        {
            Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
            NyARIntSize s = i_input.getSize();

            this._do_filter_impl.doFilter(i_input, (int[])i_output.getBuffer(), 0, 0, s.w, s.h);
            return;
        }
        public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output)
        {
            Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
            NyARIntSize s = i_input.getSize();

            this._do_threshold_impl.doThFilter(i_input, 0, 0, s.w, s.h, this._threshold, i_output);
            return;
        }
 /**
  * 入力ラスタをHSV形式に変換して、出力ラスタへ書込みます。
  * 画素形式は、コンストラクタに指定した形式に合せてください。
  */
 public void doFilter(INyARRgbRaster i_input, INyARRaster i_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
     if (!this._do_filter_impl.isSupport(i_input, i_output))
     {
         this._do_filter_impl = this.createFilter(i_input, i_output);
     }
     this._do_filter_impl.doFilter(i_input, i_output, i_input.getSize());
 }
Example #6
0
        /// <summary>
        /// バックグラウンドにラスタを描画します。
        /// </summary>
        /// <param name="i_gl"></param>
        /// <param name="i_bg_image"></param>
        public void drawBackground(Device i_dev, INyARRgbRaster i_bg_image)
	    {
            NyARIntSize s = i_bg_image.getSize();
            if(this._surface==null){
                this._surface = new NyARD3dSurface(i_dev,s.w,s.h);
            }else if(!this._surface.isEqualSize(i_bg_image.getSize())){
                //サーフェイスの再構築
                this._surface.Dispose();
                this._surface = new NyARD3dSurface(i_dev, this._screen_size.w, this._screen_size.h);
            }
            this._surface.setRaster(i_bg_image);
            Surface dest_surface = i_dev.GetBackBuffer(0, 0, BackBufferType.Mono);
            Rectangle rect = new Rectangle(0, 0, this._screen_size.w, this._screen_size.h);
            i_dev.StretchRectangle((Surface)this._surface, rect, dest_surface, rect, TextureFilter.None);
	    }
        public bool copyPatt(double i_x1, double i_y1, double i_x2, double i_y2, double i_x3, double i_y3, double i_x4, double i_y4, int i_edge_x, int i_edge_y, int i_resolution, INyARRgbRaster i_out)
        {
            NyARIntSize out_size = i_out.getSize();
            int         xe       = out_size.w * i_edge_x / 50;
            int         ye       = out_size.h * i_edge_y / 50;

            //サンプリング解像度で分岐
            if (i_resolution == 1)
            {
                if (!this._perspective_gen.getParam((xe * 2 + out_size.w), (ye * 2 + out_size.h), i_x1, i_y1, i_x2, i_y2, i_x3, i_y3, i_x4, i_y4, this.__pickFromRaster_cpara))
                {
                    return(false);
                }
                this.onePixel(xe + LOCAL_LT, ye + LOCAL_LT, this.__pickFromRaster_cpara, i_out);
            }
            else
            {
                if (!this._perspective_gen.getParam((xe * 2 + out_size.w) * i_resolution, (ye * 2 + out_size.h) * i_resolution, i_x1, i_y1, i_x2, i_y2, i_x3, i_y3, i_x4, i_y4, this.__pickFromRaster_cpara))
                {
                    return(false);
                }
                this.multiPixel(xe * i_resolution + LOCAL_LT, ye * i_resolution + LOCAL_LT, this.__pickFromRaster_cpara, i_resolution, i_out);
            }
            return(true);
        }
        /**
         * i_in_rasterから4頂点i_vertexsでかこまれた領域の画像を射影変換して、o_outへ格納します。
         * @param i_in_raster
         * このラスタの形式は、コンストラクタで制限したものと一致している必要があります。
         * @param i_vertex
         * 4頂点を格納した配列です。
         * @param i_edge_x
         * X方向のエッジ割合です。0-99の数値を指定します。
         * @param i_edge_y
         * Y方向のエッジ割合です。0-99の数値を指定します。
         * @param i_resolution
         * 出力の1ピクセルあたりのサンプリング数を指定します。例えば2を指定すると、出力1ピクセルあたり4ピクセルをサンプリングします。
         * @param o_out
         * 出力先のラスタです。
         * @return
         * @throws NyARException
         */
        public bool read4Point(INyARRgbRaster i_in_raster, NyARDoublePoint2d[] i_vertex, int i_edge_x, int i_edge_y, int i_resolution, INyARRgbRaster o_out)
        {
            NyARIntSize out_size = o_out.getSize();
            int         xe       = out_size.w * i_edge_x / 50;
            int         ye       = out_size.h * i_edge_y / 50;

            //サンプリング解像度で分岐
            if (i_resolution == 1)
            {
                if (!this._perspective_gen.getParam((xe * 2 + out_size.w), (ye * 2 + out_size.h), i_vertex, this.__pickFromRaster_cpara))
                {
                    return(false);
                }
                this._picker.onePixel(xe + LOCAL_LT, ye + LOCAL_LT, this.__pickFromRaster_cpara, i_in_raster, o_out);
            }
            else
            {
                if (!this._perspective_gen.getParam((xe * 2 + out_size.w) * i_resolution, (ye * 2 + out_size.h) * i_resolution, i_vertex, this.__pickFromRaster_cpara))
                {
                    return(false);
                }
                this._picker.multiPixel(xe * i_resolution + LOCAL_LT, ye * i_resolution + LOCAL_LT, this.__pickFromRaster_cpara, i_resolution, i_in_raster, o_out);
            }
            return(true);
        }
Example #9
0
        public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output)
        {
            //INyARBufferReader in_buffer_reader = i_input.getBufferReader();
            //INyARBufferReader out_buffer_reader = i_output.getBufferReader();
            int in_buf_type = i_input.getBufferType();

            NyARIntSize size = i_output.getSize();

            Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT2D_BIN_8));
            Debug.Assert(checkInputType(in_buf_type) == true);
            Debug.Assert(i_input.getSize().isEqualSize(size.w * 2, size.h * 2) == true);

            int[][] out_buf = (int[][])i_output.getBuffer();


            switch (i_input.getBufferType())
            {
            case NyARBufferType.BYTE1D_B8G8R8_24:
            case NyARBufferType.BYTE1D_R8G8B8_24:
                convert24BitRgb((byte[])i_input.getBuffer(), out_buf, size);
                break;

            case NyARBufferType.BYTE1D_B8G8R8X8_32:
                convert32BitRgbx((byte[])i_input.getBuffer(), out_buf, size);
                break;

            case NyARBufferType.WORD1D_R5G6B5_16LE:
                convert16BitRgb565word((short[])i_input.getBuffer(), out_buf, size);
                break;

            default:
                throw new NyARException();
            }
            return;
        }
Example #10
0
        /**
         * この関数は、画像から登録済のマーカ検出を行います。
         * マーカの検出に成功すると、thisのプロパティにマーカの二次元位置を記録します。
         * 関数の成功後は、マーカの姿勢行列と、一致度を、それぞれ{@link #getTransmationMatrix}と{@link #getConfidence}から得ることができます。
         * @param i_raster
         * マーカーを検出する画像。画像のサイズは、コンストラクタに指定した{@link NyARParam}オブジェクトと一致していなければなりません。
         * @param i_th
         * 2値化敷居値。0から256までの値を指定します。
         * @return
         * マーカーが検出できたかを、真偽値で返します。
         * @
         */
        public bool detectMarkerLite(INyARRgbRaster i_raster, int i_th)
        {
            //サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize()))
            {
                throw new NyARException();
            }

            //最終入力ラスタを更新
            if (this._last_input_raster != i_raster)
            {
                this._bin_filter        = (INyARRgb2GsFilterArtkTh)i_raster.createInterface(typeof(INyARRgb2GsFilterArtkTh));
                this._last_input_raster = i_raster;
            }

            //ラスタを2値イメージに変換する.
            this._bin_filter.doFilter(i_th, this._bin_raster);

            //コールバックハンドラの準備
            this._confidence        = 0;
            this._last_input_raster = i_raster;

            //
            //マーカ検出器をコール
            this.execDetectMarker();
            if (this._confidence == 0)
            {
                return(false);
            }
            return(true);
        }
        /**
         * i_imageから、idマーカを読みだします。
         * o_dataにはマーカデータ、o_paramにはまーかのパラメータを返却します。
         * @param image
         * @param i_square
         * @param o_data
         * @param o_param
         * @return
         * @throws NyARException
         */
        public bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertex, NyIdMarkerPattern o_data, NyIdMarkerParam o_param)
        {
            //遠近法のパラメータを計算
            if (!this._perspective_reader.setSourceSquare(i_vertex))
            {
                return(false);
            }
            ;

            INyARRgbPixelReader reader      = image.getRgbPixelReader();
            NyARIntSize         raster_size = image.getSize();


            PerspectivePixelReader.TThreshold th = this.__pickFromRaster_th;
            MarkerPattEncoder encoder            = this.__pickFromRaster_encoder;

            //マーカパラメータを取得
            this._perspective_reader.detectThresholdValue(reader, raster_size, th);

            if (!this._perspective_reader.readDataBits(reader, raster_size, th, encoder))
            {
                return(false);
            }
            int d = encoder.encode(o_data);

            if (d < 0)
            {
                return(false);
            }
            o_param.direction = d;
            o_param.threshold = th.th;

            return(true);
        }
        public bool copyPatt(double i_x1, double i_y1, double i_x2, double i_y2, double i_x3, double i_y3, double i_x4, double i_y4, int i_edge_x, int i_edge_y, int i_resolution, INyARRgbRaster i_out)
        {
            NyARIntSize out_size = i_out.getSize();
            int xe = out_size.w * i_edge_x / 50;
            int ye = out_size.h * i_edge_y / 50;

            //サンプリング解像度で分岐
            if (i_resolution == 1)
            {
                if (!this._perspective_gen.getParam((xe * 2 + out_size.w), (ye * 2 + out_size.h), i_x1, i_y1, i_x2, i_y2, i_x3, i_y3, i_x4, i_y4, this.__pickFromRaster_cpara))
                {
                    return false;
                }
                this.onePixel(xe + LOCAL_LT, ye + LOCAL_LT, this.__pickFromRaster_cpara, i_out);
            }
            else
            {
                if (!this._perspective_gen.getParam((xe * 2 + out_size.w) * i_resolution, (ye * 2 + out_size.h) * i_resolution, i_x1, i_y1, i_x2, i_y2, i_x3, i_y3, i_x4, i_y4, this.__pickFromRaster_cpara))
                {
                    return false;
                }
                this.multiPixel(xe * i_resolution + LOCAL_LT, ye * i_resolution + LOCAL_LT, this.__pickFromRaster_cpara, i_resolution, i_out);
            }
            return true;
        }
        public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output)
        {
            //INyARBufferReader in_buffer_reader = i_input.getBufferReader();
            //INyARBufferReader out_buffer_reader = i_output.getBufferReader();
            int in_buf_type = i_input.getBufferType();

            NyARIntSize size = i_output.getSize();
            Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT2D_BIN_8));
            Debug.Assert(checkInputType(in_buf_type) == true);
            Debug.Assert(i_input.getSize().isEqualSize(size.w * 2, size.h * 2) == true);

            int[][] out_buf = (int[][])i_output.getBuffer();


            switch (i_input.getBufferType())
            {
                case NyARBufferType.BYTE1D_B8G8R8_24:
                case NyARBufferType.BYTE1D_R8G8B8_24:
                    convert24BitRgb((byte[])i_input.getBuffer(), out_buf, size);
                    break;
                case NyARBufferType.BYTE1D_B8G8R8X8_32:
                    convert32BitRgbx((byte[])i_input.getBuffer(), out_buf, size);
                    break;
                case NyARBufferType.WORD1D_R5G6B5_16LE:
                    convert16BitRgb565word((short[])i_input.getBuffer(), out_buf, size);
                    break;
                default:
                    throw new NyARException();
            }
            return;
        }
Example #14
0
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            Debug.Assert(this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));

            //BINイメージへの変換
            this._tobin_filter.setThreshold(this._threshold);
            this._tobin_filter.doFilter(i_raster, this._bin_raster);

            // スクエアコードを探す
            this._detectmarker_cb.init(i_raster, this._current_arcode_index);
            this._square_detect.detectMarkerCB(this._bin_raster, this._detectmarker_cb);

            // 認識状態を更新
            bool is_id_found = this.updateStatus(this._detectmarker_cb.square, this._detectmarker_cb.code_index);

            //閾値フィードバック(detectExistMarkerにもあるよ)
            if (!is_id_found)
            {
                //マーカがなければ、探索+DualPTailで基準輝度検索
                int th = this._threshold_detect.analyzeRaster(i_raster);
                this._threshold = (this._threshold + th) / 2;
            }


            return;
        }
        public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output)
        {

            Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
            this._do_threshold_impl.doThFilter(i_input, i_output, i_output.getSize());
            return;
        }
 /**
  * 入力ラスタをHSV形式に変換して、出力ラスタへ書込みます。
  * 画素形式は、コンストラクタに指定した形式に合せてください。
  */
 public void doFilter(INyARRgbRaster i_input, INyARRaster i_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
     if (!this._do_filter_impl.isSupport(i_input, i_output))
     {
         this._do_filter_impl = this.createFilter(i_input, i_output);
     }
     this._do_filter_impl.doFilter(i_input, i_output, i_input.getSize());
 }
Example #17
0
        /// <summary>
        /// バックグラウンドにラスタを描画します。
        /// </summary>
        /// <param name="i_gl"></param>
        /// <param name="i_bg_image"></param>
        public void drawBackground(Device i_dev, INyARRgbRaster i_bg_image)
        {
            NyARIntSize s = i_bg_image.getSize();

            if (this._surface == null)
            {
                this._surface = new NyARD3dSurface(i_dev, s.w, s.h);
            }
            else if (!this._surface.isEqualSize(i_bg_image.getSize()))
            {
                //サーフェイスの再構築
                this._surface.Dispose();
                this._surface = new NyARD3dSurface(i_dev, this._screen_size.w, this._screen_size.h);
            }
            this._surface.setRaster(i_bg_image);
            Surface   dest_surface = i_dev.GetBackBuffer(0, 0, BackBufferType.Mono);
            Rectangle rect         = new Rectangle(0, 0, this._screen_size.w, this._screen_size.h);

            i_dev.StretchRectangle((Surface)this._surface, rect, dest_surface, rect, TextureFilter.None);
        }
Example #18
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));
        }
Example #19
0
        /**
         * この関数は、画像を処理して、適切なマーカ検出イベントハンドラを呼び出します。
         * イベントハンドラの呼び出しは、この関数を呼び出したスレッドが、この関数が終了するまでに行います。
         * @param i_raster
         * 検出処理をする画像を指定します。
         * @
         */
        public void DetectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            if (!this._gs_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h))
            {
                throw new NyARException();
            }

            // ラスタをGSへ変換する。
            if (this._last_input_raster != i_raster)
            {
                this._togs_filter       = (INyARRgb2GsFilter)i_raster.createInterface(typeof(INyARRgb2GsFilter));
                this._last_input_raster = i_raster;
            }
            this._togs_filter.convert(this._gs_raster);

            // スクエアコードを探す(第二引数に指定したマーカ、もしくは新しいマーカを探す。)
            this._square_detect.init(this._gs_raster, this._is_active ? this._data_current : null);
            this._square_detect.detectMarker(this._gs_raster, this._current_threshold, this._square_detect);

            // 認識状態を更新(マーカを発見したなら、current_dataを渡すかんじ)
            bool is_id_found = UpdateStatus(this._square_detect.square, this._square_detect.marker_data);

            //閾値フィードバック(detectExistMarkerにもあるよ)
            if (is_id_found)
            {
                //マーカがあれば、マーカの周辺閾値を反映
                this._current_threshold = (this._current_threshold + this._square_detect.threshold) / 2;
            }
            else
            {
                //マーカがなければ、探索+DualPTailで基準輝度検索
                this._histmaker.createHistogram(4, this._hist);
                int th = this._threshold_detect.getThreshold(this._hist);
                this._current_threshold = (this._current_threshold + th) / 2;
            }
            return;
        }
Example #20
0
        /**
         * この関数は、画像を処理して、適切なマーカ検出イベントハンドラを呼び出します。
         * イベントハンドラの呼び出しは、この関数を呼び出したスレッドが、この関数が終了するまでに行います。
         * @param i_raster
         * 検出処理をする画像を指定します。
         * @
         */
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            Debug.Assert(this._gs_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));
            if (this._last_input_raster != i_raster)
            {
                this._histmaker         = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster));
                this._togs_filter       = (INyARRgb2GsFilter)i_raster.createInterface(typeof(INyARRgb2GsFilter));
                this._last_input_raster = i_raster;
            }

            //GSイメージへの変換とヒストグラムの生成
            this._togs_filter.convert(this._gs_raster);
            this._histmaker.createHistogram(4, this._hist);

            // スクエアコードを探す
            this._detectmarker.init(i_raster, this._current_arcode_index);
            this._detectmarker.detectMarker(this._gs_raster, this._thdetect.getThreshold(this._hist), this._detectmarker);

            // 認識状態を更新
            this.updateStatus(this._detectmarker.square, this._detectmarker.code_index);
            return;
        }
        /**
         * NyARRasterからパターンデータをセットします。
         * この関数は、データを元に所有するデータ領域を更新します。
         * @param i_buffer
         * @throws NyARException
         */
        public void setRaster(INyARRgbRaster i_raster)
        {
            Debug.Assert(i_raster.getSize().isEqualSize(this._size));
            switch (i_raster.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                this._pow = setRaster_INT1D_X8R8G8B8_32((int[])i_raster.getBuffer(), this._size.w * this._size.h, this._optimize_for_mod, this._data);
                break;

            default:
                this._pow = setRaster_ANY(i_raster.getRgbPixelReader(), this._size, this._size.w * this._size.h, this._data);
                break;
            }
            return;
        }
 /**
  * ラスタのコピーを実行します。
  * この関数は暫定です。低速なので注意してください。
  * @param i_input
  * @param o_output
  * @
  */
 public static void copy(INyARRgbRaster i_input, INyARRgbRaster o_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(o_output.getSize()));
     int width = i_input.getWidth();
     int height = i_input.getHeight();
     int[] rgb = new int[3];
     INyARRgbPixelDriver inr = i_input.getRgbPixelDriver();
     INyARRgbPixelDriver outr = o_output.getRgbPixelDriver();
     for (int i = height - 1; i >= 0; i--)
     {
         for (int i2 = width - 1; i2 >= 0; i2--)
         {
             inr.getPixel(i2, i, rgb);
             outr.setPixel(i2, i, rgb);
         }
     }
 }
        /**
         * ラスタのコピーを実行します。
         * この関数は暫定です。低速なので注意してください。
         * @param i_input
         * @param o_output
         * @
         */
        public static void copy(INyARRgbRaster i_input, INyARRgbRaster o_output)
        {
            Debug.Assert(i_input.getSize().isEqualSize(o_output.getSize()));
            int width  = i_input.getWidth();
            int height = i_input.getHeight();

            int[] rgb = new int[3];
            INyARRgbPixelDriver inr  = i_input.getRgbPixelDriver();
            INyARRgbPixelDriver outr = o_output.getRgbPixelDriver();

            for (int i = height - 1; i >= 0; i--)
            {
                for (int i2 = width - 1; i2 >= 0; i2--)
                {
                    inr.getPixel(i2, i, rgb);
                    outr.setPixel(i2, i, rgb);
                }
            }
        }
Example #24
0
        /**
         * i_imageにマーカー検出処理を実行し、結果を記録します。
         *
         * @param i_raster
         * マーカーを検出するイメージを指定します。
         * @param i_thresh
         * 検出閾値を指定します。0~255の範囲で指定してください。 通常は100~130くらいを指定します。
         * @return 見つかったマーカーの数を返します。 マーカーが見つからない場合は0を返します。
         * @throws NyARException
         */
        public int detectMarkerLite(INyARRgbRaster i_raster, int i_threshold)
        {
            // サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize()))
            {
                throw new NyARException();
            }

            // ラスタを2値イメージに変換する.
            ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);
            this._tobin_filter.doFilter(i_raster, this._bin_raster);

            //detect
            this._square_detect.init(i_raster);
            this._square_detect.detectMarker(this._bin_raster);

            //見付かった数を返す。
            return(this._square_detect.result_stack.getLength());
        }
        /**
         * この関数は、画像からマーカを検出します。
         * 関数は、登録されているマーカパターンそれぞれに対し、検出したマーカから最も一致した物を探し、その一致率と位置を計算します。
         * @param i_raster
         * マーカーを検出するイメージを指定します。
         * @param i_threshold
         * 検出閾値を指定します。0~255の範囲で指定してください。 通常は100~130くらいを指定します。
         * @return
         * 検出したマーカーの数を返します。 マーカーが見つからない場合は0を返します。
         * @
         */
        public int detectMarkerLite(INyARRgbRaster i_raster, int i_threshold)
        {
            // サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize()))
            {
                throw new NyARException();
            }
            if (this._last_input_raster != i_raster)
            {
                this._tobin_filter      = (INyARRgb2GsFilterArtkTh)i_raster.createInterface(typeof(INyARRgb2GsFilterArtkTh));
                this._last_input_raster = i_raster;
            }
            this._tobin_filter.doFilter(i_threshold, this._bin_raster);
            //detect
            this._square_detect.init(i_raster);
            this._square_detect.detectMarker(this._bin_raster, 0, this._square_detect);

            //見付かった数を返す。
            return(this._square_detect.result_stack.getLength());
        }
Example #26
0
        public void drawImage2d(Device i_dev, int i_x, int i_y, INyARRgbRaster i_raster)
        {
            NyARIntSize s = i_raster.getSize();

            if (this._texture == null)
            {
                this._texture = new NyARD3dTexture(i_dev, s.w, s.h);
            }
            else if (!this._texture.isEqualSize(s))
            {
                this._texture.Dispose();
                this._texture = new NyARD3dTexture(i_dev, s.w, s.h);
            }
            this._texture.setRaster(i_raster);
            using (Sprite sp = new Sprite(i_dev))
            {
                sp.Begin(SpriteFlags.None);
                sp.Draw((Texture)this._texture, new Rectangle(i_x, i_y, s.w, s.h), Vector3.Empty, new Vector3(i_dev.Viewport.X, i_dev.Viewport.Y, 0), Color.White);
                sp.End();
            }
        }
        /**
         * i_imageにマーカー検出処理を実行し、結果を記録します。
         *
         * @param i_raster
         * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ
         * と一致していなければなりません。
         * @return マーカーが検出できたかを真偽値で返します。
         * @throws NyARException
         */
        public bool detectMarkerLite(INyARRgbRaster i_raster)
        {
            //サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize()))
            {
                throw new NyARException();
            }

            //ラスタを2値イメージに変換する.
            this._tobin_filter.doFilter(i_raster, this._bin_raster);

            //コールバックハンドラの準備
            this._detect_cb.init(i_raster);
            //矩形を探す(戻り値はコールバック関数で受け取る。)
            this._square_detect.detectMarkerCB(this._bin_raster, _detect_cb);
            if (this._detect_cb.confidence == 0)
            {
                return(false);
            }
            return(true);
        }
        /**
         * この関数は、画像を処理して、適切なマーカ検出イベントハンドラを呼び出します。
         * イベントハンドラの呼び出しは、この関数を呼び出したスレッドが、この関数が終了するまでに行います。
         * @param i_raster
         * 検出処理をする画像を指定します。
         * @
         */
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            if (!this._gs_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h))
            {
                throw new NyARException();
            }
            // ラスタをGSへ変換する。
            if (this._last_input_raster != i_raster)
            {
                this._togs_filter = (INyARRgb2GsFilter)i_raster.createInterface(typeof(INyARRgb2GsFilter));
                this._last_input_raster = i_raster;
            }
            this._togs_filter.convert(this._gs_raster);

            // スクエアコードを探す(第二引数に指定したマーカ、もしくは新しいマーカを探す。)
            this._square_detect.init(this._gs_raster, this._is_active ? this._data_current : null);
            this._square_detect.detectMarker(this._gs_raster, this._current_threshold, this._square_detect);

            // 認識状態を更新(マーカを発見したなら、current_dataを渡すかんじ)
            bool is_id_found = updateStatus(this._square_detect.square, this._square_detect.marker_data);

            //閾値フィードバック(detectExistMarkerにもあるよ)
            if (is_id_found)
            {
                //マーカがあれば、マーカの周辺閾値を反映
                this._current_threshold = (this._current_threshold + this._square_detect.threshold) / 2;
            }
            else
            {
                //マーカがなければ、探索+DualPTailで基準輝度検索
                this._histmaker.createHistogram(4, this._hist);
                int th = this._threshold_detect.getThreshold(this._hist);
                this._current_threshold = (this._current_threshold + th) / 2;
            }
            return;
        }
 /**
  * 同一サイズのラスタi_inputとi_outputの間で、一部の領域だけにラスタ処理を実行します。
  * @param i_input
  * @param i_rect
  * @param i_output
  * @throws NyARException
  */
 public void doFilter(INyARRgbRaster i_input, NyARIntRect i_rect, NyARGrayscaleRaster i_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
     this._do_filter_impl.doFilter(i_input, (int[])i_output.getBuffer(), i_rect.x, i_rect.y, i_rect.w, i_rect.h);
 }
Example #30
0
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_raster = (NyARBitmapRaster)i_raster;
     this._ref_size   = i_raster.getSize();
 }
Example #31
0
 public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output)
 {
     NyARIntSize s = i_input.getSize();
     this._do_threshold_impl.doThFilter(i_input, 0, 0, s.w, s.h, this._threshold, i_output);
     return;
 }
Example #32
0
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_buf  = (Color32[])(((NyARUnityRaster)i_raster).getBuffer());
     this._ref_size = i_raster.getSize();
 }
        /**
         * この関数は、画像から登録済のマーカ検出を行います。
         * マーカの検出に成功すると、thisのプロパティにマーカの二次元位置を記録します。
         * 関数の成功後は、マーカの姿勢行列と、一致度を、それぞれ{@link #getTransmationMatrix}と{@link #getConfidence}から得ることができます。
         * @param i_raster
         * マーカーを検出する画像。画像のサイズは、コンストラクタに指定した{@link NyARParam}オブジェクトと一致していなければなりません。
         * @param i_th
         * 2値化敷居値。0から256までの値を指定します。
         * @return
         * マーカーが検出できたかを、真偽値で返します。
         * @
         */
        public bool detectMarkerLite(INyARRgbRaster i_raster, int i_th)
        {
            NyARIntSize size1, size2;
            size1 = _bin_raster.getSize();
            size2 = i_raster.getSize();
            //System.Windows.Forms.MessageBox.Show("   bin: w " + size1.w.ToString() + " h " + size1.h.ToString() +
            //                                   "\nraster: w " + size2.w.ToString() + " h " + size2.h.ToString());
            //サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize()))
            {
                throw new NyARException();
            }
            //最終入力ラスタを更新
            if (this._last_input_raster != i_raster)
            {
                this._bin_filter = (INyARRgb2GsFilterArtkTh)i_raster.createInterface(typeof(INyARRgb2GsFilterArtkTh));
                this._last_input_raster = i_raster;
            }
            //ラスタを2値イメージに変換する.
            this._bin_filter.doFilter(i_th, this._bin_raster);

            //コールバックハンドラの準備
            this._confidence = 0;
            this._last_input_raster = i_raster;
            //
            //マーカ検出器をコール
            this.execDetectMarker();
            if (this._confidence == 0)
            {
                return false;
            }
            return true;
        }
Example #34
0
 public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
     this._do_filter_impl.doFilter(i_input, i_output, i_input.getSize());
     return;
 }
        /**
         * i_imageから、idマーカを読みだします。
         * o_dataにはマーカデータ、o_paramにはまーかのパラメータを返却します。
         * @param image
         * @param i_square
         * @param o_data
         * @param o_param
         * @return
         * @throws NyARException
         */
        public bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertex, NyIdMarkerPattern o_data, NyIdMarkerParam o_param)
        {
            //遠近法のパラメータを計算
            if (!this._perspective_reader.setSourceSquare(i_vertex))
            {
                return false;
            };

            INyARRgbPixelReader reader = image.getRgbPixelReader();
            NyARIntSize raster_size = image.getSize();


            PerspectivePixelReader.TThreshold th = this.__pickFromRaster_th;
            MarkerPattEncoder encoder = this.__pickFromRaster_encoder;
            //マーカパラメータを取得
            this._perspective_reader.detectThresholdValue(reader, raster_size, th);

            if (!this._perspective_reader.readDataBits(reader, raster_size,th, encoder))
            {
                return false;
            }
            int d = encoder.encode(o_data);
            if (d < 0)
            {
                return false;
            }
            o_param.direction = d;
            o_param.threshold = th.th;

            return true;
        }
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_buf = (short[])i_raster.getBuffer();
     this._ref_size = i_raster.getSize();
 }
        /**
         * この関数は、画像を処理して、適切なマーカ検出イベントハンドラを呼び出します。
         * イベントハンドラの呼び出しは、この関数を呼び出したスレッドが、この関数が終了するまでに行います。
         * @param i_raster
         * 検出処理をする画像を指定します。
         * @
         */
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            Debug.Assert(this._gs_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));
            if (this._last_input_raster != i_raster)
            {
                this._histmaker = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster));
                this._togs_filter = (INyARRgb2GsFilter)i_raster.createInterface(typeof(INyARRgb2GsFilter));
                this._last_input_raster = i_raster;
            }

            //GSイメージへの変換とヒストグラムの生成
            this._togs_filter.convert(this._gs_raster);
            this._histmaker.createHistogram(4, this._hist);

            // スクエアコードを探す
            this._detectmarker.init(i_raster, this._current_arcode_index);
            this._detectmarker.detectMarker(this._gs_raster, this._thdetect.getThreshold(this._hist),this._detectmarker);

            // 認識状態を更新
            this.updateStatus(this._detectmarker.square, this._detectmarker.code_index);
            return;
        }
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            Debug.Assert(this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));

            //BINイメージへの変換
            this._tobin_filter.setThreshold(this._threshold);
            this._tobin_filter.doFilter(i_raster, this._bin_raster);

            // スクエアコードを探す
            this._detectmarker_cb.init(i_raster, this._current_arcode_index);
            this._square_detect.detectMarkerCB(this._bin_raster, this._detectmarker_cb);

            // 認識状態を更新
            bool is_id_found = this.updateStatus(this._detectmarker_cb.square, this._detectmarker_cb.code_index);
            //閾値フィードバック(detectExistMarkerにもあるよ)
            if (!is_id_found)
            {
                //マーカがなければ、探索+DualPTailで基準輝度検索
                int th = this._threshold_detect.analyzeRaster(i_raster);
                this._threshold = (this._threshold + th) / 2;
            }


            return;
        }
        /**
         * この関数は、画像から登録済のマーカ検出を行います。
         * マーカの検出に成功すると、thisのプロパティにマーカの二次元位置を記録します。
         * 関数の成功後は、マーカの姿勢行列と、一致度を、それぞれ{@link #getTransmationMatrix}と{@link #getConfidence}から得ることができます。
         * @param i_raster
         * マーカーを検出する画像。画像のサイズは、コンストラクタに指定した{@link NyARParam}オブジェクトと一致していなければなりません。
         * @param i_th
         * 2値化敷居値。0から256までの値を指定します。
         * @return
         * マーカーが検出できたかを、真偽値で返します。
         * @
         */
        public bool detectMarkerLite(INyARRgbRaster i_raster, int i_th)
        {
            //サイズチェック
              if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize())) { throw new NyARException(); }

              //最終入力ラスタを更新
              if (this._last_input_raster != i_raster) {
            this._bin_filter = (INyARRgb2GsFilterArtkTh)i_raster.createInterface(typeof(INyARRgb2GsFilterArtkTh));
            this._last_input_raster = i_raster;
              }

              //ラスタを2値イメージに変換する.
              this._bin_filter.doFilter(i_th, this._bin_raster);

              //コールバックハンドラの準備
              this._confidence = 0;
              this._last_input_raster = i_raster;

              //
              //マーカ検出器をコール
              this.execDetectMarker();
              if (this._confidence == 0) { return false; }
              return true;
        }
	/**
	 * この関数は、画像からARマーカパターンを生成して、登録します。
	 * ビットマップ等の画像から生成したパターンは、撮影画像から生成したパターンファイルと比較して、撮影画像の色調変化に弱くなります。
	 * 注意してください。
	 * @param i_raster
	 * マーカ画像を格納したラスタオブジェクト
	 * @param i_patt_resolution
	 * マーカの解像度
	 * @param i_patt_edge_percentage
	 * マーカのエッジ領域のサイズ。マーカパターンは、i_rasterからエッジ領域を除いたパターンから生成します。
	 * ARToolKitスタイルの画像を用いる場合は、25を指定します。
	 * @param i_marker_size
	 * マーカの平方サイズ[mm]
	 * @return
	 * マーカID(ハンドル)値。
	 * @throws NyARException
	 */
	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));
		NyARRgbRaster tr=new NyARRgbRaster(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);
	}
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_buf =(Color32[])(((NyARUnityRaster)i_raster).getBuffer());
     this._ref_size = i_raster.getSize();
 }
Example #42
0
 public void drawImage2d(Device i_dev,int i_x,int i_y,INyARRgbRaster i_raster)
 {
     NyARIntSize s = i_raster.getSize();
     if (this._texture == null)
     {
         this._texture=new NyARD3dTexture(i_dev,s.w,s.h);
     }
     else if (!this._texture.isEqualSize(s))
     {
         this._texture.Dispose();
         this._texture = new NyARD3dTexture(i_dev, s.w, s.h);
     }
     this._texture.setRaster(i_raster);
     using (Sprite sp = new Sprite(i_dev))
     {
         sp.Begin(SpriteFlags.None);
         sp.Draw((Texture)this._texture, new Rectangle(i_x,i_y, s.w,s.h), Vector3.Empty,new Vector3(i_dev.Viewport.X, i_dev.Viewport.Y, 0),Color.White);
         sp.End();
     }
 }
 public void doFilter(INyARRgbRaster i_input, NyARIntRect i_area, NyARBinRaster i_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
     this._do_threshold_impl.doThFilter(i_input, i_area.x, i_area.y, i_area.w, i_area.h, this._threshold, i_output);
     return;
 }
        /**
         * i_imageにマーカー検出処理を実行し、結果を記録します。
         * 
         * @param i_raster
         * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ
         * と一致していなければなりません。
         * @return マーカーが検出できたかを真偽値で返します。
         * @throws NyARException
         */
        public bool detectMarkerLite(INyARRgbRaster i_raster)
        {
            //サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize()))
            {
                throw new NyARException();
            }

            //ラスタを2値イメージに変換する.
            this._tobin_filter.doFilter(i_raster, this._bin_raster);

            //コールバックハンドラの準備
            this._detect_cb.init(i_raster);
            //矩形を探す(戻り値はコールバック関数で受け取る。)
            this._square_detect.detectMarkerCB(this._bin_raster, _detect_cb);
            if (this._detect_cb.confidence == 0)
            {
                return false;
            }
            return true;
        }
	    public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output)
	    {
		    Debug.Assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
		    this._dofilterimpl.doFilter(i_input,i_output,i_input.getSize());
	    }
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h))
            {
                throw new NyARException();
            }
            // ラスタを2値イメージに変換する.
            this._tobin_filter.setThreshold(this._current_threshold);
            this._tobin_filter.doFilter(i_raster, this._bin_raster);

            // スクエアコードを探す(第二引数に指定したマーカ、もしくは新しいマーカを探す。)
            this._callback.init(i_raster, this._is_active ? this._data_current : null);
            this._square_detect.detectMarkerCB(this._bin_raster, this._callback);

            // 認識状態を更新(マーカを発見したなら、current_dataを渡すかんじ)
            bool is_id_found = updateStatus(this._callback.square, this._callback.marker_data);

            //閾値フィードバック(detectExistMarkerにもあるよ)
            if (is_id_found)
            {
                //マーカがあれば、マーカの周辺閾値を反映
                this._current_threshold = (this._current_threshold + this._callback.threshold) / 2;
            }
            else
            {
                //マーカがなければ、探索+DualPTailで基準輝度検索
                int th = this._threshold_detect.analyzeRaster(i_raster);
                this._current_threshold = (this._current_threshold + th) / 2;
            }
            return;
        }
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_raster = (NyARBitmapRaster)i_raster;
     this._ref_size = i_raster.getSize();
 }
Example #48
0
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_buf  = (short[])i_raster.getBuffer();
     this._ref_size = i_raster.getSize();
 }