/**
         * 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);
        }
示例#2
0
        /**
         * i_imageから、idマーカを読みだします。
         * o_dataにはマーカデータ、o_paramにはマーカのパラメータを返却します。
         * @param image
         * @param i_vertex
         * @param o_data
         * @param o_param
         * @return
         * @
         */
        private bool _pickFromRaster(INyARGsPixelDriver i_pix_drv, NyIdMarkerPattern o_data, NyIdMarkerParam o_param)
        {
            PerspectivePixelReader.TThreshold th = this.__pickFromRaster_th;
            MarkerPattEncoder encoder            = this.__pickFromRaster_encoder;

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

            if (!this._perspective_reader.readDataBits(i_pix_drv, i_pix_drv.getSize(), 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 readDataBits(INyARRgbPixelReader i_reader, NyARIntSize i_raster_size, PerspectivePixelReader.TThreshold i_th, MarkerPattEncoder o_bitbuffer)
        {
            double[] index_x = this.__readDataBits_index_bit_x;
            double[] index_y = this.__readDataBits_index_bit_y;
            //読み出し位置を取得
            int size       = detectDataBitsIndex(i_reader, i_raster_size, i_th, index_x, index_y);
            int resolution = size + size - 1;

            if (size < 0)
            {
                return(false);
            }
            if (!o_bitbuffer.initEncoder(size - 1))
            {
                return(false);
            }

            double[] cpara       = this._cparam;
            int[]    ref_x       = this._ref_x;
            int[]    ref_y       = this._ref_y;
            int[]    pixcel_temp = this._pixcel_temp;

            double cpara_0 = cpara[0];
            double cpara_1 = cpara[1];
            double cpara_3 = cpara[3];
            double cpara_6 = cpara[6];


            int th = i_th.th;
            int p  = 0;

            for (int i = 0; i < resolution; i++)
            {
                //1列分のピクセルのインデックス値を計算する。
                double cy0     = 1 + index_y[i * 2 + 0];
                double cy1     = 1 + index_y[i * 2 + 1];
                double cpy0_12 = cpara_1 * cy0 + cpara[2];
                double cpy0_45 = cpara[4] * cy0 + cpara[5];
                double cpy0_7  = cpara[7] * cy0 + 1.0;
                double cpy1_12 = cpara_1 * cy1 + cpara[2];
                double cpy1_45 = cpara[4] * cy1 + cpara[5];
                double cpy1_7  = cpara[7] * cy1 + 1.0;

                int pt = 0;
                for (int i2 = 0; i2 < resolution; i2++)
                {
                    double d;
                    double cx0 = 1 + index_x[i2 * 2 + 0];
                    double cx1 = 1 + index_x[i2 * 2 + 1];

                    double cp6_0  = cpara_6 * cx0;
                    double cpx0_0 = cpara_0 * cx0;
                    double cpx3_0 = cpara_3 * cx0;

                    double cp6_1  = cpara_6 * cx1;
                    double cpx0_1 = cpara_0 * cx1;
                    double cpx3_1 = cpara_3 * cx1;

                    d         = cp6_0 + cpy0_7;
                    ref_x[pt] = (int)((cpx0_0 + cpy0_12) / d);
                    ref_y[pt] = (int)((cpx3_0 + cpy0_45) / d);
                    pt++;

                    d         = cp6_0 + cpy1_7;
                    ref_x[pt] = (int)((cpx0_0 + cpy1_12) / d);
                    ref_y[pt] = (int)((cpx3_0 + cpy1_45) / d);
                    pt++;

                    d         = cp6_1 + cpy0_7;
                    ref_x[pt] = (int)((cpx0_1 + cpy0_12) / d);
                    ref_y[pt] = (int)((cpx3_1 + cpy0_45) / d);
                    pt++;

                    d         = cp6_1 + cpy1_7;
                    ref_x[pt] = (int)((cpx0_1 + cpy1_12) / d);
                    ref_y[pt] = (int)((cpx3_1 + cpy1_45) / d);
                    pt++;
                }
                //1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
                i_reader.getPixelSet(ref_x, ref_y, resolution * 4, pixcel_temp);
                //グレースケールにしながら、line→mapへの転写
                for (int i2 = 0; i2 < resolution; i2++)
                {
                    int index = i2 * 3 * 4;
                    int pixel = (pixcel_temp[index + 0] + pixcel_temp[index + 1] + pixcel_temp[index + 2] +
                                 pixcel_temp[index + 3] + pixcel_temp[index + 4] + pixcel_temp[index + 5] +
                                 pixcel_temp[index + 6] + pixcel_temp[index + 7] + pixcel_temp[index + 8] +
                                 pixcel_temp[index + 9] + pixcel_temp[index + 10] + pixcel_temp[index + 11]) / (4 * 3);
                    //暗点を1、明点を0で表現します。
                    o_bitbuffer.setBitByBitIndex(p, pixel > th ? 0 : 1);
                    p++;
                }
            }

            /*
             *      for(int i=0;i<225*4;i++){
             *          this.vertex_x[i]=0;
             *          this.vertex_y[i]=0;
             *      }
             *      for(int i=0;i<(resolution)*2;i++){
             *          for(int i2=0;i2<(resolution)*2;i2++){
             *              this.vertex_x[i*(resolution)*2+i2]=(int)index_x[i2];
             *              this.vertex_y[i*(resolution)*2+i2]=(int)index_y[i];
             *
             *          }
             *      }
             */
            return(true);
        }
        public bool readDataBits(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,PerspectivePixelReader.TThreshold i_th, MarkerPattEncoder o_bitbuffer)
        {
            double[] index_x = this.__readDataBits_index_bit_x;
            double[] index_y = this.__readDataBits_index_bit_y;
            //読み出し位置を取得
            int size = detectDataBitsIndex(i_reader, i_raster_size,i_th, index_x, index_y);
            int resolution = size + size - 1;
            if (size < 0)
            {
                return false;
            }
            if (!o_bitbuffer.initEncoder(size - 1))
            {
                return false;
            }

            double[] cpara = this._cparam;
            int[] ref_x = this._ref_x;
            int[] ref_y = this._ref_y;
            int[] pixcel_temp = this._pixcel_temp;

            double cpara_0 = cpara[0];
            double cpara_1 = cpara[1];
            double cpara_3 = cpara[3];
            double cpara_6 = cpara[6];


            int th = i_th.th;
            int p = 0;
            for (int i = 0; i < resolution; i++)
            {
                //1列分のピクセルのインデックス値を計算する。
                double cy0 = 1 + index_y[i * 2 + 0];
                double cy1 = 1 + index_y[i * 2 + 1];
                double cpy0_12 = cpara_1 * cy0 + cpara[2];
                double cpy0_45 = cpara[4] * cy0 + cpara[5];
                double cpy0_7 = cpara[7] * cy0 + 1.0;
                double cpy1_12 = cpara_1 * cy1 + cpara[2];
                double cpy1_45 = cpara[4] * cy1 + cpara[5];
                double cpy1_7 = cpara[7] * cy1 + 1.0;

                int pt = 0;
                for (int i2 = 0; i2 < resolution; i2++)
                {

                    double d;
                    double cx0 = 1 + index_x[i2 * 2 + 0];
                    double cx1 = 1 + index_x[i2 * 2 + 1];

                    double cp6_0 = cpara_6 * cx0;
                    double cpx0_0 = cpara_0 * cx0;
                    double cpx3_0 = cpara_3 * cx0;

                    double cp6_1 = cpara_6 * cx1;
                    double cpx0_1 = cpara_0 * cx1;
                    double cpx3_1 = cpara_3 * cx1;

                    d = cp6_0 + cpy0_7;
                    ref_x[pt] = (int)((cpx0_0 + cpy0_12) / d);
                    ref_y[pt] = (int)((cpx3_0 + cpy0_45) / d);
                    pt++;

                    d = cp6_0 + cpy1_7;
                    ref_x[pt] = (int)((cpx0_0 + cpy1_12) / d);
                    ref_y[pt] = (int)((cpx3_0 + cpy1_45) / d);
                    pt++;

                    d = cp6_1 + cpy0_7;
                    ref_x[pt] = (int)((cpx0_1 + cpy0_12) / d);
                    ref_y[pt] = (int)((cpx3_1 + cpy0_45) / d);
                    pt++;

                    d = cp6_1 + cpy1_7;
                    ref_x[pt] = (int)((cpx0_1 + cpy1_12) / d);
                    ref_y[pt] = (int)((cpx3_1 + cpy1_45) / d);
                    pt++;
                }
                //1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
                i_reader.getPixelSet(ref_x, ref_y, resolution * 4, pixcel_temp);
                //グレースケールにしながら、line→mapへの転写
                for (int i2 = 0; i2 < resolution; i2++)
                {
                    int index = i2 * 3 * 4;
                    int pixel = (pixcel_temp[index + 0] + pixcel_temp[index + 1] + pixcel_temp[index + 2] +
                                pixcel_temp[index + 3] + pixcel_temp[index + 4] + pixcel_temp[index + 5] +
                                pixcel_temp[index + 6] + pixcel_temp[index + 7] + pixcel_temp[index + 8] +
                                pixcel_temp[index + 9] + pixcel_temp[index + 10] + pixcel_temp[index + 11]) / (4 * 3);
                    //暗点を1、明点を0で表現します。
                    o_bitbuffer.setBitByBitIndex(p, pixel > th ? 0 : 1);
                    p++;
                }
            }
            /*		
                    for(int i=0;i<225*4;i++){
                        this.vertex_x[i]=0;
                        this.vertex_y[i]=0;
                    }
                    for(int i=0;i<(resolution)*2;i++){
                        for(int i2=0;i2<(resolution)*2;i2++){
                            this.vertex_x[i*(resolution)*2+i2]=(int)index_x[i2];
                            this.vertex_y[i*(resolution)*2+i2]=(int)index_y[i];
				
                        }
                    }
            */
            return true;
        }
        /**
         * この関数は、マーカパターンからデータを読み取ります。
         * @param i_reader
         * ラスタリーダ
         * @param i_raster_size
         * ラスタのサイズ
         * @param i_th
         * 敷居値情報
         * @param o_bitbuffer
         * データビットの出力先
         * @return
         * 成功するとtrue
         * @
         */
        public bool readDataBits(INyARGrayscaleRaster i_raster, PerspectivePixelReader.TThreshold i_th, MarkerPattEncoder o_bitbuffer)
        {
            int raster_width  = i_raster.getWidth();
            int raster_height = i_raster.getHeight();

            double[] index_x = this.__readDataBits_index_bit_x;
            double[] index_y = this.__readDataBits_index_bit_y;


            //読み出し位置を取得
            int size       = detectDataBitsIndex(i_raster, i_th, index_x, index_y);
            int resolution = size + size - 1;

            if (size < 0)
            {
                return(false);
            }
            if (!o_bitbuffer.initEncoder(size - 1))
            {
                return(false);
            }

            double[] cpara       = this._cparam;
            int[]    ref_x       = this._ref_x;
            int[]    ref_y       = this._ref_y;
            int[]    pixcel_temp = this._pixcel_temp;

            double cpara_0 = cpara[0];
            double cpara_1 = cpara[1];
            double cpara_3 = cpara[3];
            double cpara_6 = cpara[6];


            int th = i_th.th;
            int p  = 0;

            for (int i = 0; i < resolution; i++)
            {
                //1列分のピクセルのインデックス値を計算する。
                double cy0     = 1 + index_y[i * 2 + 0];
                double cy1     = 1 + index_y[i * 2 + 1];
                double cpy0_12 = cpara_1 * cy0 + cpara[2];
                double cpy0_45 = cpara[4] * cy0 + cpara[5];
                double cpy0_7  = cpara[7] * cy0 + 1.0;
                double cpy1_12 = cpara_1 * cy1 + cpara[2];
                double cpy1_45 = cpara[4] * cy1 + cpara[5];
                double cpy1_7  = cpara[7] * cy1 + 1.0;

                int pt = 0;
                for (int i2 = 0; i2 < resolution; i2++)
                {
                    int    xx, yy;
                    double d;
                    double cx0 = 1 + index_x[i2 * 2 + 0];
                    double cx1 = 1 + index_x[i2 * 2 + 1];

                    double cp6_0  = cpara_6 * cx0;
                    double cpx0_0 = cpara_0 * cx0;
                    double cpx3_0 = cpara_3 * cx0;

                    double cp6_1  = cpara_6 * cx1;
                    double cpx0_1 = cpara_0 * cx1;
                    double cpx3_1 = cpara_3 * cx1;

                    d         = cp6_0 + cpy0_7;
                    ref_x[pt] = xx = (int)((cpx0_0 + cpy0_12) / d);
                    ref_y[pt] = yy = (int)((cpx3_0 + cpy0_45) / d);
                    if (xx < 0 || xx >= raster_width || yy < 0 || yy >= raster_height)
                    {
                        ref_x[pt] = xx < 0 ? 0 : (xx >= raster_width ? raster_width - 1 : xx);
                        ref_y[pt] = yy < 0 ? 0 : (yy >= raster_height ? raster_height - 1 : yy);
                    }
                    pt++;

                    d         = cp6_0 + cpy1_7;
                    ref_x[pt] = xx = (int)((cpx0_0 + cpy1_12) / d);
                    ref_y[pt] = yy = (int)((cpx3_0 + cpy1_45) / d);
                    if (xx < 0 || xx >= raster_width || yy < 0 || yy >= raster_height)
                    {
                        ref_x[pt] = xx < 0 ? 0 : (xx >= raster_width ? raster_width - 1 : xx);
                        ref_y[pt] = yy < 0 ? 0 : (yy >= raster_height ? raster_height - 1 : yy);
                    }
                    pt++;

                    d         = cp6_1 + cpy0_7;
                    ref_x[pt] = xx = (int)((cpx0_1 + cpy0_12) / d);
                    ref_y[pt] = yy = (int)((cpx3_1 + cpy0_45) / d);
                    if (xx < 0 || xx >= raster_width || yy < 0 || yy >= raster_height)
                    {
                        ref_x[pt] = xx < 0 ? 0 : (xx >= raster_width ? raster_width - 1 : xx);
                        ref_y[pt] = yy < 0 ? 0 : (yy >= raster_height ? raster_height - 1 : yy);
                    }
                    pt++;

                    d         = cp6_1 + cpy1_7;
                    ref_x[pt] = xx = (int)((cpx0_1 + cpy1_12) / d);
                    ref_y[pt] = yy = (int)((cpx3_1 + cpy1_45) / d);
                    if (xx < 0 || xx >= raster_width || yy < 0 || yy >= raster_height)
                    {
                        ref_x[pt] = xx < 0 ? 0 : (xx >= raster_width ? raster_width - 1 : xx);
                        ref_y[pt] = yy < 0 ? 0 : (yy >= raster_height ? raster_height - 1 : yy);
                    }
                    pt++;
                }
                //1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
                i_raster.getPixelSet(ref_x, ref_y, resolution * 4, pixcel_temp, 0);
                //グレースケールにしながら、line→mapへの転写
                for (int i2 = 0; i2 < resolution; i2++)
                {
                    int index = i2 * 4;
                    int pixel = (pixcel_temp[index + 0] + pixcel_temp[index + 1] + pixcel_temp[index + 2] + pixcel_temp[index + 3]) / 4;
                    //				+pixcel_temp[index+4]+pixcel_temp[index+5]+
                    //							pixcel_temp[index+6]+pixcel_temp[index+7]+pixcel_temp[index+8]+
                    //							pixcel_temp[index+9]+pixcel_temp[index+10]+pixcel_temp[index+11])/(4*3);
                    //暗点を1、明点を0で表現します。
                    o_bitbuffer.setBitByBitIndex(p, pixel > th ? 0 : 1);
                    p++;
                }
            }
            return(true);
        }