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;
        }
 public NyARRgb2GsFilterArtkTh_BYTE1D_C8C8C8_24(INyARRgbRaster i_raster)
 {
     Debug.Assert(
             i_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) ||
             i_raster.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
     this._raster = i_raster;
 }
        /**
         * この関数は、ラスタのi_vertexsで定義される四角形からパターンを取得して、インスタンスに格納します。
         */
        public override bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
        {
            NyARMat cpara = this.wk_pickFromRaster_cpara;
            // xdiv2,ydiv2の計算
            int xdiv2, ydiv2;
            int l1, l2;
            int w1, w2;
            // x計算
            w1 = i_vertexs[0].x - i_vertexs[1].x;
            w2 = i_vertexs[0].y - i_vertexs[1].y;
            l1 = (w1 * w1 + w2 * w2);
            w1 = i_vertexs[2].x - i_vertexs[3].x;
            w2 = i_vertexs[2].y - i_vertexs[3].y;
            l2 = (w1 * w1 + w2 * w2);
            if (l2 > l1)
            {
                l1 = l2;
            }
            l1 = l1 / 4;
            xdiv2 = this._size.w;
            while (xdiv2 * xdiv2 < l1)
            {
                xdiv2 *= 2;
            }
            if (xdiv2 > AR_PATT_SAMPLE_NUM)
            {
                xdiv2 = AR_PATT_SAMPLE_NUM;
            }

            // y計算
            w1 = i_vertexs[1].x - i_vertexs[2].x;
            w2 = i_vertexs[1].y - i_vertexs[2].y;
            l1 = (w1 * w1 + w2 * w2);
            w1 = i_vertexs[3].x - i_vertexs[0].x;
            w2 = i_vertexs[3].y - i_vertexs[0].y;
            l2 = (w1 * w1 + w2 * w2);
            if (l2 > l1)
            {
                l1 = l2;
            }
            ydiv2 = this._size.h;
            l1 = l1 / 4;
            while (ydiv2 * ydiv2 < l1)
            {
                ydiv2 *= 2;
            }
            if (ydiv2 > AR_PATT_SAMPLE_NUM)
            {
                ydiv2 = AR_PATT_SAMPLE_NUM;
            }

            // cparaの計算
            if (!get_cpara(i_vertexs, cpara))
            {
                return false;
            }
            updateExtpat(image, cpara, xdiv2, ydiv2);

            return true;
        }
 /**
  * この関数は、i_rasterを操作するピクセルドライバインスタンスを生成します。
  * @param i_raster
  * @return
  * @
  */
 public static INyARRgbPixelDriver createDriver(INyARRgbRaster i_raster)
 {
     INyARRgbPixelDriver ret;
     switch (i_raster.getBufferType())
     {
         case NyARBufferType.BYTE1D_B8G8R8_24:
             ret = new NyARRgbPixelDriver_BYTE1D_B8G8R8_24();
             break;
         case NyARBufferType.BYTE1D_B8G8R8X8_32:
             ret = new NyARRgbPixelDriver_BYTE1D_B8G8R8X8_32();
             break;
         case NyARBufferType.BYTE1D_R8G8B8_24:
             ret = new NyARRgbPixelDriver_BYTE1D_R8G8B8_24();
             break;
         case NyARBufferType.BYTE1D_X8R8G8B8_32:
             ret = new NyARRgbPixelDriver_BYTE1D_X8R8G8B8_32();
             break;
         case NyARBufferType.INT1D_GRAY_8:
             ret = new NyARRgbPixelDriver_INT1D_GRAY_8();
             break;
         case NyARBufferType.INT1D_X8R8G8B8_32:
             ret = new NyARRgbPixelDriver_INT1D_X8R8G8B8_32();
             break;
         case NyARBufferType.BYTE1D_R5G6B5_16BE:
             ret = new NyARRgbPixelDriver_WORD1D_R5G6B5_16LE();
             break;
         default:
             throw new NyARException();
     }
     ret.switchRaster(i_raster);
     return ret;
 }
        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;
        }
        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;
        }
 /**
  * この関数は(Yrcb)でグレースケール化するフィルタを生成します。
  * 最適化されていません。
  * @param i_raster
  * @return
  * @
  */
 public static INyARRgb2GsFilterYCbCr createYCbCrDriver(INyARRgbRaster i_raster)
 {
     switch (i_raster.getBufferType())
     {
         default:
             return new NyARRgb2GsFilterYCbCr_Any(i_raster);
     }
 }
 /**
  * この関数は、(R*G*B>>16) でグレースケール化するフィルタを生成します。
  * 最適化されていません。
  * @param i_raster
  * @return
  * @
  */
 public static INyARRgb2GsFilterRgbAve createRgbCubeDriver(INyARRgbRaster i_raster)
 {
     switch (i_raster.getBufferType())
     {
         default:
             return new NyARRgb2GsFilterRgbCube_Any(i_raster);
     }
 }
		/// <summary>
		/// This function is dissabled.
		/// See "void update(Texture2D i_input)"
		/// </summary>
		/// <param name='i_input'>
		/// undefined.
		/// </param>
		public override void update(INyARRgbRaster i_input)
		{
			//Must be same instance as internal raster.
			if(i_input!=this._raster){
				throw new NyARException();
			}
			base.update(i_input);
		}
        public static INyARHistogramFromRaster createInstance(INyARRgbRaster i_raster) 
	{
        if (i_raster is INyARRgbRaster)
        {
			return new NyARHistogramFromRaster_AnyRgb((INyARRgbRaster)i_raster);
		}
		throw new NyARException();
	}
        /**
         * This function retrieves bitmap from the area defined by RECT(i_l,i_t,i_r,i_b) above transform matrix i_base_mat. 
         * ----
         * この関数は、basementで示される平面のAで定義される領域から、ビットマップを読み出します。
         * 例えば、8cmマーカでRECT(i_l,i_t,i_r,i_b)に-40,0,0,-40.0を指定すると、マーカの左下部分の画像を抽出します。
         * 
         * マーカから離れた場所になるほど、また、マーカの鉛直方向から外れるほど誤差が大きくなります。
         * @param i_src_imege
         * 詠み出し元の画像を指定します。
         * @param i_l
         * 基準点からの左上の相対座標(x)を指定します。
         * @param i_t
         * 基準点からの左上の相対座標(y)を指定します。
         * @param i_r
         * 基準点からの右下の相対座標(x)を指定します。
         * @param i_b
         * 基準点からの右下の相対座標(y)を指定します。
         * @param i_base_mat
         * @return 画像の取得の成否を返す。
         */
        public bool pickupImage2d(INyARRgbRaster i_src_imege, double i_l, double i_t, double i_r, double i_b, NyARTransMatResult i_base_mat)
        {
            double cp00, cp01, cp02, cp11, cp12;
            cp00 = this._ref_perspective.m00;
            cp01 = this._ref_perspective.m01;
            cp02 = this._ref_perspective.m02;
            cp11 = this._ref_perspective.m11;
            cp12 = this._ref_perspective.m12;
            //マーカと同一平面上にある矩形の4個の頂点を座標変換して、射影変換して画面上の
            //頂点を計算する。
            //[hX,hY,h]=[P][RT][x,y,z]

            //出力先
            NyARIntPoint2d[] poinsts = this._work_points;

            double yt0, yt1, yt2;
            double x3, y3, z3;

            double m00 = i_base_mat.m00;
            double m10 = i_base_mat.m10;
            double m20 = i_base_mat.m20;

            //yとtの要素を先に計算
            yt0 = i_base_mat.m01 * i_t + i_base_mat.m03;
            yt1 = i_base_mat.m11 * i_t + i_base_mat.m13;
            yt2 = i_base_mat.m21 * i_t + i_base_mat.m23;
            // l,t
            x3 = m00 * i_l + yt0;
            y3 = m10 * i_l + yt1;
            z3 = m20 * i_l + yt2;
            poinsts[0].x = (int)((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
            poinsts[0].y = (int)((y3 * cp11 + z3 * cp12) / z3);
            // r,t
            x3 = m00 * i_r + yt0;
            y3 = m10 * i_r + yt1;
            z3 = m20 * i_r + yt2;
            poinsts[1].x = (int)((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
            poinsts[1].y = (int)((y3 * cp11 + z3 * cp12) / z3);

            //yとtの要素を先に計算
            yt0 = i_base_mat.m01 * i_b + i_base_mat.m03;
            yt1 = i_base_mat.m11 * i_b + i_base_mat.m13;
            yt2 = i_base_mat.m21 * i_b + i_base_mat.m23;

            // r,b
            x3 = m00 * i_r + yt0;
            y3 = m10 * i_r + yt1;
            z3 = m20 * i_r + yt2;
            poinsts[2].x = (int)((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
            poinsts[2].y = (int)((y3 * cp11 + z3 * cp12) / z3);
            // l,b
            x3 = m00 * i_l + yt0;
            y3 = m10 * i_l + yt1;
            z3 = m20 * i_l + yt2;
            poinsts[3].x = (int)((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
            poinsts[3].y = (int)((y3 * cp11 + z3 * cp12) / z3);
            return this.pickFromRaster(i_src_imege, poinsts);
        }
 /**
  * 入力ラスタを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());
 }
 public static IRasterDriver createDriver(INyARRgbRaster i_raster)
 {
     switch (i_raster.getBufferType())
     {
         case NyARBufferType.INT1D_X8R8G8B8_32:
             return new NyARMatchPattDeviationDataDriver_INT1D_X8R8G8B8_32(i_raster);
         default:
             break;
     }
     return new NyARMatchPattDeviationDataDriver_RGBAny(i_raster);
 }
示例#14
0
 /* DsXRGB32Rasterの内容を保持しているサーフェイスにコピーします。
  */
 public void setRaster(INyARRgbRaster i_sample)
 {
     Debug.Assert(!this._is_dispose);
     int pitch;
     int s_stride = this.m_width * 4;
     using (GraphicsStream gs = this._surface.LockRectangle(LockFlags.None, out pitch))
     {
         try{                    
             switch (i_sample.getBufferType())
             {
                 case NyARBufferType.BYTE1D_B8G8R8X8_32:
                     if (pitch % s_stride == 0)
                     {
                         Marshal.Copy((byte[])i_sample.getBuffer(), 0, (IntPtr)((int)gs.InternalData), this.m_width * 4 * this.m_height);
                     }
                     else
                     {
                         int s_idx = 0;
                         int d_idx = (int)gs.InternalData;
                         for (int i = this.m_height - 1; i >= 0; i--)
                         {
                             //どう考えてもポインタです。
                             Marshal.Copy((byte[])i_sample.getBuffer(), s_idx, (IntPtr)(d_idx), s_stride);
                             s_idx += s_stride;
                             d_idx += pitch;
                         }
                     }
                     break;
                 case NyARBufferType.OBJECT_CS_Bitmap:
                     NyARBitmapRaster ra = (NyARBitmapRaster)(i_sample);
                     BitmapData bm = ra.lockBitmap();
                     try{
                         //コピー
                         int src = (int)bm.Scan0;
                         int dst = (int)gs.InternalData;
                         for (int r = this.m_height - 1; r >= 0; r--)
                         {
                             NyARD3dUtil.RtlCopyMemory((IntPtr)dst, (IntPtr)src, s_stride);
                             dst += pitch;
                             src += bm.Stride;
                         }
                     }finally{
                         ra.unlockBitmap();
                     }
                     break;
                 default:
                     throw new NyARException();
             }
         }finally{
             this._surface.UnlockRectangle();
         }
         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 = 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;
 }
 /**
  * この関数は、(R*G*B)/3 でグレースケール化するフィルタを生成します。
  * 最適化されている形式は以下の通りです。
  * <ul>
  * <li>{@link NyARBufferType#BYTE1D_B8G8R8X8_32}</li>
  * </ul>
  * @param i_raster
  * @return
  * @
  */
 public static INyARRgb2GsFilterRgbAve createRgbAveDriver(INyARRgbRaster i_raster)
 {
     switch (i_raster.getBufferType())
     {
         case NyARBufferType.BYTE1D_B8G8R8X8_32:
             return new NyARRgb2GsFilterRgbAve_BYTE1D_B8G8R8X8_32(i_raster);
         case NyARBufferType.BYTE1D_B8G8R8_24:
             return new NyARRgb2GsFilterRgbAve_BYTE1D_C8C8C8_24(i_raster);
         case NyARBufferType.BYTE1D_X8R8G8B8_32:
             return new NyARRgb2GsFilterRgbAve_INT1D_X8R8G8B8_32(i_raster);
         default:
             return new NyARRgb2GsFilterRgbAve_Any(i_raster);
     }
 }
示例#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);
	    }
 /**
  * 指定したIN/OUTに最適な{@link INyARPerspectiveReaader}を生成します。
  * <p>入力ラスタについて
  * 基本的には全ての{@link INyARRgbRaster}を実装したクラスを処理できますが、次の3種類のバッファを持つものを推奨します。
  * <ul>
  * <li>{@link NyARBufferType#BYTE1D_B8G8R8X8_32}
  * <li>{@link NyARBufferType#BYTE1D_B8G8R8_24}
  * <li>{@link NyARBufferType#BYTE1D_R8G8B8_24}
  * </ul>
  * </p>
  * <p>出力ラスタについて
  * 基本的には全ての{@link NyARBufferType#INT1D_X8R8G8B8_32}形式のバッファを持つラスタを使用してください。
  * 他の形式でも動作しますが、低速な場合があります。
  * </p>
  * <p>高速化について -
  * 入力ラスタ形式が、{@link NyARBufferType#BYTE1D_B8G8R8X8_32},{@link NyARBufferType#BYTE1D_B8G8R8_24}
  * ,{@link NyARBufferType#BYTE1D_R8G8B8_24}のものについては、他の形式よりも高速に動作します。
  * また、出力ラスタ形式が、{@link NyARBufferType#INT1D_X8R8G8B8_32}の物については、単体サンプリングモードの時のみ、さらに高速に動作します。
  * 他の形式のラスタでは、以上のものよりも低速転送で対応します。
  * @param i_in_raster_type
  * 入力ラスタの形式です。
  * @param i_out_raster_type
  * 出力ラスタの形式です。
  * @return
  */
 public static INyARPerspectiveCopy createDriver(INyARRgbRaster i_raster)
 {
     //新しいモードに対応したら書いてね。
     switch (i_raster.getBufferType())
     {
         case NyARBufferType.BYTE1D_B8G8R8X8_32:
             return new PerspectiveCopy_BYTE1D_B8G8R8X8_32(i_raster);
         case NyARBufferType.BYTE1D_B8G8R8_24:
             return new PerspectiveCopy_BYTE1D_B8G8R8_24(i_raster);
         case NyARBufferType.BYTE1D_R8G8B8_24:
             return new PerspectiveCopy_BYTE1D_R8G8B8_24(i_raster);
         default:
             return new PerspectiveCopy_ANYRgb(i_raster);
     }
 }
 /**
  * ラスタのコピーを実行します。
  * この関数は暫定です。低速なので注意してください。
  * @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);
         }
     }
 }
 public static INyARRgb2GsFilterArtkTh createDriver(INyARRgbRaster i_raster)
 {
     switch (i_raster.getBufferType())
     {
         case NyARBufferType.BYTE1D_B8G8R8_24:
         case NyARBufferType.BYTE1D_R8G8B8_24:
             return new NyARRgb2GsFilterArtkTh_BYTE1D_C8C8C8_24(i_raster);
         case NyARBufferType.BYTE1D_B8G8R8X8_32:
             return new NyARRgb2GsFilterArtkTh_BYTE1D_B8G8R8X8_32(i_raster);
         case NyARBufferType.BYTE1D_X8R8G8B8_32:
             return new NyARRgb2GsFilterArtkTh_BYTE1D_X8R8G8B8_32(i_raster);
         case NyARBufferType.INT1D_X8R8G8B8_32:
             return new NyARRgb2GsFilterArtkTh_INT1D_X8R8G8B8_32(i_raster);
         case NyARBufferType.WORD1D_R5G6B5_16LE:
             return new NyARRgb2GsFilterArtkTh_WORD1D_R5G6B5_16LE(i_raster);
         default:
             return new NyARRgb2GsFilterArtkTh_Any(i_raster);
     }
 }
        /**
         * この関数は、i_rasterを操作するピクセルドライバインスタンスを生成します。
         * @param i_raster
         * @return
         * @
         */
        public static INyARRgbPixelDriver createDriver(INyARRgbRaster i_raster)
        {
            INyARRgbPixelDriver ret;

            switch (i_raster.getBufferType())
            {
            case NyARBufferType.BYTE1D_B8G8R8_24:
                ret = new NyARRgbPixelDriver_BYTE1D_B8G8R8_24();
                break;

            case NyARBufferType.BYTE1D_B8G8R8X8_32:
                ret = new NyARRgbPixelDriver_BYTE1D_B8G8R8X8_32();
                break;

            case NyARBufferType.BYTE1D_R8G8B8_24:
                ret = new NyARRgbPixelDriver_BYTE1D_R8G8B8_24();
                break;

            case NyARBufferType.BYTE1D_X8R8G8B8_32:
                ret = new NyARRgbPixelDriver_BYTE1D_X8R8G8B8_32();
                break;

            case NyARBufferType.INT1D_GRAY_8:
                ret = new NyARRgbPixelDriver_INT1D_GRAY_8();
                break;

            case NyARBufferType.INT1D_X8R8G8B8_32:
                ret = new NyARRgbPixelDriver_INT1D_X8R8G8B8_32();
                break;

            case NyARBufferType.BYTE1D_R5G6B5_16BE:
                ret = new NyARRgbPixelDriver_WORD1D_R5G6B5_16LE();
                break;

            default:
                throw new NyARException();
            }
            ret.switchRaster(i_raster);
            return(ret);
        }
示例#22
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;
        }
        /**
         * この関数は、マーカ平面上の任意の4点で囲まれる領域から、画像を射影変換して返します。
         * {@link #isExistMarker(int)}がtrueの時にだけ使用できます。
         * @param i_id
         * マーカID(ハンドル)値。
         * @param i_sensor
         * 画像を取得するセンサオブジェクト。通常は{@link #update(NyARSensor)}関数に入力したものと同じものを指定します。
         * @param i_x1
         * 頂点1[mm]
         * @param i_y1
         * 頂点1[mm]
         * @param i_x2
         * 頂点2[mm]
         * @param i_y2
         * 頂点2[mm]
         * @param i_x3
         * 頂点3[mm]
         * @param i_y3
         * 頂点3[mm]
         * @param i_x4
         * 頂点4[mm]
         * @param i_y4
         * 頂点4[mm]
         * @param i_raster
         * 取得した画像を格納するオブジェクト
         * @return
         * 結果を格納したi_rasterオブジェクト
         * @throws NyARException
         */
        public INyARRgbRaster getMarkerPlaneImage(
            int i_id,
            NyARSensor i_sensor,
            double i_x1, double i_y1,
            double i_x2, double i_y2,
            double i_x3, double i_y3,
            double i_x4, double i_y4,
            INyARRgbRaster i_raster)
        {
            NyARDoublePoint3d[] pos  = this.__pos3d;
            NyARDoublePoint2d[] pos2 = this.__pos2d;
            NyARDoubleMatrix44  tmat = this.getMarkerMatrix(i_id);

            tmat.transform3d(i_x1, i_y1, 0, pos[1]);
            tmat.transform3d(i_x2, i_y2, 0, pos[0]);
            tmat.transform3d(i_x3, i_y3, 0, pos[3]);
            tmat.transform3d(i_x4, i_y4, 0, pos[2]);
            for (int i = 3; i >= 0; i--)
            {
                this._frustum.project(pos[i], pos2[i]);
            }
            return(i_sensor.getPerspectiveImage(pos2[0].x, pos2[0].y, pos2[1].x, pos2[1].y, pos2[2].x, pos2[2].y, pos2[3].x, pos2[3].y, i_raster));
        }
示例#24
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;
        }
        /**
         * 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._confidence = 0;
            this._ref_raster = i_raster;

            //矩形を探す(戻り値はコールバック関数で受け取る。)
            this._square_detect.detectMarker(this._bin_raster);
            if (this._confidence == 0)
            {
                return(false);
            }
            return(true);
        }
示例#26
0
        public override void setup(CaptureDevice i_cap)
        {
            Device d3d = this.size(SCREEN_WIDTH, SCREEN_HEIGHT);
            i_cap.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30.0f);
            INyARMarkerSystemConfig cf = new NyARMarkerSystemConfig(SCREEN_WIDTH, SCREEN_HEIGHT);
            d3d.RenderState.ZBufferEnable = true;
            d3d.RenderState.Lighting = false;
            d3d.RenderState.CullMode = Cull.CounterClockwise;
            this._ms = new NyARD3dMarkerSystem(cf);
            //recommended be NyARBufferType.BYTE1D_B8G8R8X8_32 or NyARBufferType.CS_BITMAP
            this._ss = new NyARDirectShowCamera(i_cap, NyARBufferType.OBJECT_CS_Bitmap);
            this._rs = new NyARD3dRender(d3d, this._ms);
            this.mid = this._ms.addARMarker(AR_CODE_FILE, 16, 25, 80);

            //set View mmatrix
            this._rs.loadARViewMatrix(d3d);
            //set Viewport matrix
            this._rs.loadARViewPort(d3d);
            //setD3dProjectionMatrix
            this._rs.loadARProjectionMatrix(d3d);
            this._ss.start();
            //should be NyARBufferType.BYTE1D_B8G8R8X8_32 or NyARBufferType.CS_BITMAP
            this._raster = new NyARBitmapRaster(64, 64, NyARBufferType.OBJECT_CS_Bitmap);
        }
        public static INyARRgb2GsFilterArtkTh createDriver(INyARRgbRaster i_raster)
        {
            switch (i_raster.getBufferType())
            {
            case NyARBufferType.BYTE1D_B8G8R8_24:
            case NyARBufferType.BYTE1D_R8G8B8_24:
                return(new NyARRgb2GsFilterArtkTh_BYTE1D_C8C8C8_24(i_raster));

            case NyARBufferType.BYTE1D_B8G8R8X8_32:
                return(new NyARRgb2GsFilterArtkTh_BYTE1D_B8G8R8X8_32(i_raster));

            case NyARBufferType.BYTE1D_X8R8G8B8_32:
                return(new NyARRgb2GsFilterArtkTh_BYTE1D_X8R8G8B8_32(i_raster));

            case NyARBufferType.INT1D_X8R8G8B8_32:
                return(new NyARRgb2GsFilterArtkTh_INT1D_X8R8G8B8_32(i_raster));

            case NyARBufferType.WORD1D_R5G6B5_16LE:
                return(new NyARRgb2GsFilterArtkTh_WORD1D_R5G6B5_16LE(i_raster));

            default:
                return(new NyARRgb2GsFilterArtkTh_Any(i_raster));
            }
        }
示例#28
0
        public void Test()
        {
            //AR用カメラパラメタファイルをロード
            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(camera_file), 320, 240);

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

            byte[]         raw = bs.ReadBytes(320 * 240 * 3);
            INyARRgbRaster ra  = NyARRgbRaster.createInstance(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;
        }
        /**
         * @see INyARColorPatt#pickFromRaster
         */
        public bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
        {
            //遠近法のパラメータを計算
            double[] cpara = this.__pickFromRaster_cpara;
            if (!this._perspective_gen.getParam(this._pickup_wh, i_vertexs, cpara))
            {
                return(false);
            }

            int resolution = this._resolution;
            int img_x      = image.getWidth();
            int img_y      = image.getHeight();
            int res_pix    = resolution * resolution;

            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;

            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;

            for (int iy = 0; iy < this._size.h * resolution; iy += resolution)
            {
                //解像度分の点を取る。
                for (int ix = 0; ix < this._size.w * resolution; ix += resolution)
                {
                    int r, g, b;
                    r = g = b = 0;
                    for (int i2y = iy; i2y < iy + resolution; i2y++)
                    {
                        int cy = this._pickup_lt.y + i2y;
                        for (int i2x = ix; i2x < ix + resolution; i2x++)
                        {
                            //1ピクセルを作成
                            int    cx = this._pickup_lt.x + i2x;
                            double d  = cpara[6] * cx + cpara[7] * cy + 1.0;
                            int    x  = (int)((cpara[0] * cx + cpara[1] * cy + cpara[2]) / d);
                            int    y  = (int)((cpara[3] * cx + cpara[4] * cy + cpara[5]) / d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            if (x >= img_x)
                            {
                                x = img_x - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            if (y >= img_y)
                            {
                                y = img_y - 1;
                            }

                            reader.getPixel(x, y, rgb_tmp);
                            r += rgb_tmp[0];
                            g += rgb_tmp[1];
                            b += rgb_tmp[2];
                        }
                    }
                    r /= res_pix;
                    g /= res_pix;
                    b /= res_pix;
                    this._patdata[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                    p++;
                }
            }
            //ピクセル問い合わせ
            //ピクセルセット
            return(true);
        }
        /**
         * この関数は、画像を処理して、適切なマーカ検出イベントハンドラを呼び出します。
         * イベントハンドラの呼び出しは、この関数を呼び出したスレッドが、この関数が終了するまでに行います。
         * @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;
        }
 /**
  * Initialize call back handler.
  */
 public void init(INyARRgbRaster i_raster, int i_target_id)
 {
     this._ref_raster = i_raster;
     this._target_id = i_target_id;
     this.code_index = -1;
     this.confidence = double.MinValue;
 }
 /**
  * Initialize call back handler.
  */
 public void init(INyARRgbRaster i_raster, INyIdMarkerData i_prev_data)
 {
     this.marker_data = null;
     this._prev_data  = i_prev_data;
     this._ref_raster = i_raster;
 }
        //分割数16未満になると少し遅くなるかも。
        private void updateExtpat(INyARRgbRaster image, NyARMat i_cpara, int i_xdiv2, int i_ydiv2)
        {
            int i, j;
            int r, g, b;
            //ピクセルリーダーを取得
            int    pat_size_w  = this._size.w;
            int    xdiv        = i_xdiv2 / pat_size_w;   // xdiv = xdiv2/Config.AR_PATT_SIZE_X;
            int    ydiv        = i_ydiv2 / this._size.h; // ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
            int    xdiv_x_ydiv = xdiv * ydiv;
            double reciprocal;

            double[][] para   = i_cpara.getArray();
            double     para00 = para[0 * 3 + 0][0];
            double     para01 = para[0 * 3 + 1][0];
            double     para02 = para[0 * 3 + 2][0];
            double     para10 = para[1 * 3 + 0][0];
            double     para11 = para[1 * 3 + 1][0];
            double     para12 = para[1 * 3 + 2][0];
            double     para20 = para[2 * 3 + 0][0];
            double     para21 = para[2 * 3 + 1][0];

            INyARRgbPixelDriver reader = image.getRgbPixelDriver();
            int img_width  = image.getWidth();
            int img_height = image.getHeight();

            //ワークバッファの準備
            reservWorkBuffers(xdiv, ydiv);
            double[] xw      = this.__updateExtpat_xw;
            double[] yw      = this.__updateExtpat_yw;
            int[]    xc      = this.__updateExtpat_xc;
            int[]    yc      = this.__updateExtpat_yc;
            int[]    rgb_set = this.__updateExtpat_rgbset;


            for (int iy = this._size.h - 1; iy >= 0; iy--)
            {
                for (int ix = pat_size_w - 1; ix >= 0; ix--)
                {
                    //xw,ywマップを作成
                    reciprocal = 1.0 / i_xdiv2;
                    for (i = xdiv - 1; i >= 0; i--)
                    {
                        xw[i] = LT_POS + SQ_SIZE * (ix * xdiv + i + 0.5) * reciprocal;
                    }
                    reciprocal = 1.0 / i_ydiv2;
                    for (i = ydiv - 1; i >= 0; i--)
                    {
                        yw[i] = LT_POS + SQ_SIZE * (iy * ydiv + i + 0.5) * reciprocal;
                    }
                    //1ピクセルを構成するピクセル座標の集合をxc,yc配列に取得
                    int number_of_pix = 0;
                    for (i = ydiv - 1; i >= 0; i--)
                    {
                        double para01_x_yw_para02 = para01 * yw[i] + para02;
                        double para11_x_yw_para12 = para11 * yw[i] + para12;
                        double para12_x_yw_para22 = para21 * yw[i] + 1.0;
                        for (j = xdiv - 1; j >= 0; j--)
                        {
                            double d = para20 * xw[j] + para12_x_yw_para22;
                            if (d == 0)
                            {
                                throw new NyARException();
                            }
                            int xcw = (int)((para00 * xw[j] + para01_x_yw_para02) / d);
                            int ycw = (int)((para10 * xw[j] + para11_x_yw_para12) / d);
                            if (xcw < 0 || xcw >= img_width || ycw < 0 || ycw >= img_height)
                            {
                                continue;
                            }
                            xc[number_of_pix] = xcw;
                            yc[number_of_pix] = ycw;
                            number_of_pix++;
                        }
                    }
                    //1ピクセル分の配列を取得
                    reader.getPixelSet(xc, yc, number_of_pix, rgb_set);
                    r = g = b = 0;
                    for (i = number_of_pix * 3 - 1; i >= 0; i -= 3)
                    {
                        r += rgb_set[i - 2]; // R
                        g += rgb_set[i - 1]; // G
                        b += rgb_set[i];     // B
                    }
                    //1ピクセル確定
                    this._patdata[iy * pat_size_w + ix] = (((r / xdiv_x_ydiv) & 0xff) << 16) | (((g / xdiv_x_ydiv) & 0xff) << 8) | (((b / xdiv_x_ydiv) & 0xff));
                }
            }
            return;
        }
示例#34
0
 public NyARMatchPattDeviationDataDriver_INT1D_X8R8G8B8_32(INyARRgbRaster i_raster)
 {
     this._ref_raster = i_raster;
 }
 public NyARRgb2GsFilterArtkTh_INT1D_X8R8G8B8_32(INyARRgbRaster i_raster)
 {
     Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
     this._raster = i_raster;
 }
 public NyARRgb2GsFilterArtkTh_Any(INyARRgbRaster i_raster)
 {
     this._raster = i_raster;
 }
示例#37
0
 /**
  * カメラ座標系の4頂点でかこまれる領域から、RGB画像をo_rasterに取得します。
  * @param i_vertex
  * @param i_matrix
  * i_vertexに適応する変換行列。
  * ターゲットの姿勢行列を指定すると、ターゲット座標系になります。不要ならばnullを設定してください。
  * @param i_resolution
  * @param o_raster
  * @return
  * @throws NyARException
  */
 public bool GetRgbPatt3d(NyARRealitySource i_src, NyARDoublePoint3d[] i_vertex, NyARDoubleMatrix44 i_matrix, int i_resolution, INyARRgbRaster o_raster)
 {
     NyARDoublePoint2d[] vx = NyARDoublePoint2d.createArray(4);
     if (i_matrix != null)
     {
         //姿勢変換してから射影変換
         NyARDoublePoint3d v3d = new NyARDoublePoint3d();
         for (int i = 3; i >= 0; i--)
         {
             i_matrix.transform3d(i_vertex[i], v3d);
             this._ref_prjmat.project(v3d, vx[i]);
         }
     }
     else
     {
         //射影変換のみ
         for (int i = 3; i >= 0; i--)
         {
             this._ref_prjmat.project(i_vertex[i], vx[i]);
         }
     }
     //パターンの取得
     return(i_src.refPerspectiveRasterReader().copyPatt(vx, 0, 0, i_resolution, o_raster));
 }
示例#38
0
 /**
  * 画面座標系の4頂点でかこまれる領域から、RGB画像をo_rasterに取得します。
  * @param i_vertex
  * @param i_resolution
  * 1ピクセルあたりのサンプル数です。二乗した値が実際のサンプル数になります。
  * @param o_raster
  * @return
  * @throws NyARException
  */
 public bool GetRgbPatt2d(NyARRealitySource i_src, NyARDoublePoint2d[] i_vertex, int i_resolution, INyARRgbRaster o_raster)
 {
     return(i_src.refPerspectiveRasterReader().copyPatt(i_vertex, 0, 0, i_resolution, o_raster));
 }
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            BitmapData in_bmp  = this._ref_raster.lockBitmap();
            int        in_w    = this._ref_raster.getWidth();
            int        in_h    = this._ref_raster.getHeight();
            int        res_pix = i_resolution * i_resolution;

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];
            double cp2 = cpara[2];
            double cp5 = cpara[5];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

            if (o_out is NyARBitmapRaster)
            {
                NyARBitmapRaster bmr = ((NyARBitmapRaster)o_out);
                BitmapData       bm  = bmr.lockBitmap();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff; // R
                                g += (px >> 8) & 0xff;  // G
                                b += (px) & 0xff;       // B
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride,
                                           (0x00ff0000 & ((r / res_pix) << 16)) | (0x0000ff00 & ((g / res_pix) << 8)) | (0x0000ff & (b / res_pix)));
                    }
                }
                bmr.unlockBitmap();
                this._ref_raster.unlockBitmap();
                return(true);
            }
            else if (o_out is INyARRgbRaster)
            {
                INyARRgbRaster out_raster = ((INyARRgbRaster)o_out);
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff; // R
                                g += (px >> 8) & 0xff;  // G
                                b += (px) & 0xff;       // B
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_raster.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                this._ref_raster.unlockBitmap();
                return(true);
            }
            else
            {
                throw new NyARRuntimeException();
            }
        }
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_raster = (NyARBitmapRaster)i_raster;
     this._ref_size = i_raster.getSize();
 }
示例#41
0
 public override void update(INyARRgbRaster i_input)
 {
     throw new NyARException();
 }
 public NyARRgb2GsFilterArtkTh_INT1D_X8R8G8B8_32(INyARRgbRaster i_raster)
 {
     Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
     this._raster = i_raster;
 }
 public NyARRgb2GsFilterArtkTh_BYTE1D_B8G8R8X8_32(INyARRgbRaster i_raster)
 {
     Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
     this._raster = i_raster;
 }
 public NyARRgb2GsFilterArtkTh_Any(INyARRgbRaster i_raster)
 {
     this._raster = i_raster;
 }
 public NyARRgb2GsFilterArtkTh_WORD1D_R5G6B5_16LE(INyARRgbRaster i_raster)
 {
     Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
     this._raster = i_raster;
 }
 public NyARHistogramFromRaster_AnyRgb(INyARRgbRaster i_raster)
 {
     this._gsr = i_raster;
 }
 public NyARRgb2GsFilterArtkTh_BYTE1D_B8G8R8X8_32(INyARRgbRaster i_raster)
 {
     Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
     this._raster = i_raster;
 }
示例#48
0
 public void switchRaster(INyARRgbRaster i_raster)
 {
     this._ref_buf =(Color32[])(((NyARUnityRaster)i_raster).getBuffer());
     this._ref_size = i_raster.getSize();
 }
 public NyARRgb2GsFilterArtkTh_WORD1D_R5G6B5_16LE(INyARRgbRaster i_raster)
 {
     Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
     this._raster = i_raster;
 }
示例#50
0
 public INyARRgbRaster getMarkerPlaneImage(int i_id, NyARSensor i_sensor, double i_x1, double i_y1, double i_x2,
                                           double i_y2, double i_x3, double i_y3, double i_x4, double i_y4, INyARRgbRaster i_raster)
 {
     return(this.getPlaneImage(i_id, i_sensor, i_x1, i_y1, i_x2, i_y2, i_x3, i_y3, i_x4, i_y4, i_raster));
 }
        /**
         * この関数は、ラスタのi_vertexsで定義される四角形からパターンを取得して、インスタンスに格納します。
         */
        public override bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
        {
            NyARMat cpara = this.wk_pickFromRaster_cpara;
            // xdiv2,ydiv2の計算
            int xdiv2, ydiv2;
            int l1, l2;
            int w1, w2;

            // x計算
            w1 = i_vertexs[0].x - i_vertexs[1].x;
            w2 = i_vertexs[0].y - i_vertexs[1].y;
            l1 = (w1 * w1 + w2 * w2);
            w1 = i_vertexs[2].x - i_vertexs[3].x;
            w2 = i_vertexs[2].y - i_vertexs[3].y;
            l2 = (w1 * w1 + w2 * w2);
            if (l2 > l1)
            {
                l1 = l2;
            }
            l1    = l1 / 4;
            xdiv2 = this._size.w;
            while (xdiv2 * xdiv2 < l1)
            {
                xdiv2 *= 2;
            }
            if (xdiv2 > AR_PATT_SAMPLE_NUM)
            {
                xdiv2 = AR_PATT_SAMPLE_NUM;
            }

            // y計算
            w1 = i_vertexs[1].x - i_vertexs[2].x;
            w2 = i_vertexs[1].y - i_vertexs[2].y;
            l1 = (w1 * w1 + w2 * w2);
            w1 = i_vertexs[3].x - i_vertexs[0].x;
            w2 = i_vertexs[3].y - i_vertexs[0].y;
            l2 = (w1 * w1 + w2 * w2);
            if (l2 > l1)
            {
                l1 = l2;
            }
            ydiv2 = this._size.h;
            l1    = l1 / 4;
            while (ydiv2 * ydiv2 < l1)
            {
                ydiv2 *= 2;
            }
            if (ydiv2 > AR_PATT_SAMPLE_NUM)
            {
                ydiv2 = AR_PATT_SAMPLE_NUM;
            }

            // cparaの計算
            if (!get_cpara(i_vertexs, cpara))
            {
                return(false);
            }
            updateExtpat(image, cpara, xdiv2, ydiv2);

            return(true);
        }
示例#52
0
 public INyARRgbRaster getMarkerPlaneImage(int i_id, NyARSensor i_sensor, double i_l, double i_t, double i_w,
                                           double i_h, INyARRgbRaster i_raster)
 {
     return(this.getPlaneImage(i_id, i_sensor, i_l, i_t, i_w, i_h, i_raster));
 }
 public override void update(INyARRgbRaster i_input)
 {
     throw new NyARException();
 }
 public void init(INyARRgbRaster i_raster)
 {
     this._ref_raster = i_raster;
     this.result_stack.clear();
 }
示例#55
0
        /**
         * この関数は、元画像を回転してから、差分画像を生成して、格納します。
         * 制限として、この関数はあまり高速ではありません。連続使用するときは、最適化を検討してください。
         * @param i_raster
         * 差分画像の元画像。サイズは、このインスタンスと同じである必要があります。
         * @param i_direction
         * 右上の位置です。0=1象限、1=2象限、、2=3象限、、3=4象限の位置に対応します。
         * @
         */
        public void setRaster(INyARRgbRaster i_raster, int i_direction)
        {
            int width           = this._size.w;
            int height          = this._size.h;
            int i_number_of_pix = width * height;

            int[] rgb  = new int[3];
            int[] dout = this._data;
            int   ave;//<PV/>

            //<平均値計算>
            ave = 0;
            for (int y = height - 1; y >= 0; y--)
            {
                for (int x = width - 1; x >= 0; x--)
                {
                    i_raster.getPixel(x, y, rgb);
                    ave += rgb[0] + rgb[1] + rgb[2];
                }
            }
            //<平均値計算>
            ave = i_number_of_pix * 255 * 3 - ave;
            ave = 255 - (ave / (i_number_of_pix * 3));//(255-R)-ave を分解するための事前計算

            int sum = 0, w_sum;
            int input_ptr = i_number_of_pix * 3 - 1;

            switch (i_direction)
            {
            case 0:
                for (int y = height - 1; y >= 0; y--)
                {
                    for (int x = width - 1; x >= 0; x--)
                    {
                        i_raster.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;

            case 1:
                for (int x = 0; x < width; x++)
                {
                    for (int y = height - 1; y >= 0; y--)
                    {
                        i_raster.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;

            case 2:
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        i_raster.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;

            case 3:
                for (int x = width - 1; x >= 0; x--)
                {
                    for (int y = 0; y < height; y++)
                    {
                        i_raster.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;
            }
            //<差分値計算>
            //<差分値計算(FORの1/8展開)/>
            double p = Math.Sqrt((double)sum);

            this._pow = (p != 0.0 ? p : 0.0000001);
        }
        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);
        }
示例#57
0
 public NyARMatchPattDeviationDataDriver_RGBAny(INyARRgbRaster i_raster)
 {
     this._ref_raster = i_raster;
 }
 public bool copyPatt(NyARIntPoint2d[] i_vertex, int i_edge_x, int i_edge_y, int i_resolution, INyARRgbRaster i_out)
 {
     return(this.copyPatt(i_vertex[0].x, i_vertex[0].y, i_vertex[1].x, i_vertex[1].y, i_vertex[2].x, i_vertex[2].y, i_vertex[3].x, i_vertex[3].y, i_edge_x, i_edge_y, i_resolution, i_out));
 }
 /**
  * @see INyARColorPatt#pickFromRaster
  */
 public bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
 {
     //遠近法のパラメータを計算
     return(this._perspective_reader.read4Point(image, i_vertexs, this._edge.x, this._edge.y, this._resolution, this));
 }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            BitmapData in_bmp = this._ref_raster.lockBitmap();
            int        in_w   = this._ref_raster.getWidth();
            int        in_h   = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int    out_w = o_out.getWidth();
            int    out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int    r, g, b, p;

            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                int[] pat_data = (int[])o_out.getBuffer();
                p = 0;
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx   = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else if (x >= in_w)
                        {
                            x = in_w - 1;
                        }
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else if (y >= in_h)
                        {
                            y = in_h - 1;
                        }

                        //
                        pat_data[p] = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                        //r = (px >> 16) & 0xff;// R
                        //g = (px >> 8) & 0xff; // G
                        //b = (px) & 0xff;    // B
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        //pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff));
                        //pat_data[p] = px;

                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                this._ref_raster.unlockBitmap();
                return(true);

            default:
                if (o_out is NyARBitmapRaster)
                {
                    NyARBitmapRaster bmr = (NyARBitmapRaster)o_out;
                    BitmapData       bm  = bmr.lockBitmap();
                    p = 0;
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }
                            int pix = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, pix);
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            p++;
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    bmr.unlockBitmap();
                    this._ref_raster.unlockBitmap();
                    return(true);
                }
                else if (o_out is INyARRgbRaster)
                {
                    //ANY to RGBx
                    INyARRgbRaster out_raster = ((INyARRgbRaster)o_out);
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }

                            int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            r = (px >> 16) & 0xff;  // R
                            g = (px >> 8) & 0xff;   // G
                            b = (px) & 0xff;        // B
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_raster.setPixel(ix, iy, r, g, b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    this._ref_raster.unlockBitmap();
                    return(true);
                }
                break;
            }
            this._ref_raster.unlockBitmap();
            return(false);
        }