Exemple #1
0
 public NyARMatchPatt_BlackWhite(NyARCode i_code_ref)
 {
     //最適化定数の計算
     this._pixels    = i_code_ref.getWidth() * i_code_ref.getHeight();
     this._code_patt = i_code_ref;
     return;
 }
Exemple #2
0
        /**
         * ImputStreamからARToolKit形式のマーカデータを読み込んでo_codeに格納します。
         * @param i_stream
         * 読出し元のストリームです。
         * @param o_code
         * 出力先のNyARCodeオブジェクトです。
         * @throws NyARException
         */
        public static void loadFromARToolKitFormFile(StreamReader i_stream, NyARCode o_code)
        {
            int           width      = o_code.getWidth();
            int           height     = o_code.getHeight();
            NyARRgbRaster tmp_raster = new NyARRgbRaster(width, height, NyARBufferType.INT1D_X8R8G8B8_32);

            //4個の要素をラスタにセットする。
            try
            {
                int[]    buf  = (int[])tmp_raster.getBuffer();
                string[] data = i_stream.ReadToEnd().Split(new Char[] { ' ', '\r', '\n' });
                //GBRAで一度読みだす。
                int idx = 0;
                for (int h = 0; h < 4; h++)
                {
                    idx = readBlock(data, idx, width, height, buf);
                    //ARCodeにセット(カラー)
                    o_code.getColorData(h).setRaster(tmp_raster);
                    o_code.getBlackWhiteData(h).setRaster(tmp_raster);
                }
            }
            catch (Exception e)
            {
                throw new NyARException(e);
            }
            tmp_raster = null;//ポイ
            return;
        }
 /**
  * ARコードファイルからデータを読み込んでo_codeに格納します。
  * @param i_stream
  * @param o_code
  * @throws NyARException
  */
 public static void loadFromARToolKitFormFile(StreamReader i_stream, NyARCode o_code)
 {
     int width = o_code.getWidth();
     int height = o_code.getHeight();
     NyARRaster tmp_raster = new NyARRaster(width, height, NyARBufferType.INT1D_X8R8G8B8_32);
     //4個の要素をラスタにセットする。
     try
     {
         int[] buf = (int[])tmp_raster.getBuffer();
         string[] data = i_stream.ReadToEnd().Split(new Char[] { ' ', '\r', '\n' });
         //GBRAで一度読みだす。
         int idx=0;
         for (int h = 0; h < 4; h++)
         {
             idx=readBlock(data,idx, width, height, buf);
             //ARCodeにセット(カラー)
             o_code.getColorData(h).setRaster(tmp_raster);
             o_code.getBlackWhiteData(h).setRaster(tmp_raster);
         }
     }
     catch (Exception e)
     {
         throw new NyARException(e);
     }
     tmp_raster = null;//ポイ
     return;
 }
        /**
         * コンストラクタから呼び出す関数です。
         * @param i_ref_param
         * @param i_ref_code
         * @param i_marker_width
         * @param i_input_raster_type
         * @param i_profile_id
         * @throws NyARException
         */
        protected void initialize(
            NyARParam i_ref_param,
            NyARCode i_ref_code,
            double i_marker_width,
            int i_input_raster_type,
            int i_profile_id)
        {
            NyARRasterFilter_ARToolkitThreshold th = new NyARRasterFilter_ARToolkitThreshold(100, i_input_raster_type);
            INyARColorPatt patt_inst;
            NyARSquareContourDetector sqdetect_inst;
            INyARTransMat transmat_inst;

            switch (i_profile_id)
            {
                case PF_ARTOOLKIT_COMPATIBLE:
                    patt_inst = new NyARColorPatt_O3(i_ref_code.getWidth(), i_ref_code.getHeight());
                    sqdetect_inst = new NyARSquareContourDetector_ARToolKit(i_ref_param.getScreenSize());
                    transmat_inst = new NyARTransMat_ARToolKit(i_ref_param);
                    break;
                case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:
                    patt_inst = new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(), 4, 25);
                    sqdetect_inst = new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());
                    transmat_inst = new NyARTransMat_ARToolKit(i_ref_param);
                    break;
                case PF_NYARTOOLKIT://default
                    patt_inst = new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(), 4, 25);
                    sqdetect_inst = new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());
                    transmat_inst = new NyARTransMat(i_ref_param);
                    break;
                default:
                    throw new NyARException();
            }
            base.initInstance(patt_inst, sqdetect_inst, transmat_inst,th, i_ref_param, i_ref_code, i_marker_width);
            return;
        }
 public NyARMatchPatt_BlackWhite(NyARCode i_code_ref)
 {
     //最適化定数の計算
     this._pixels = i_code_ref.getWidth() * i_code_ref.getHeight();
     this._code_patt = i_code_ref;
     return;
 }
        /**
         * inputStreamからARToolKit形式のパターンデータを指定サイズで読み出して、格納したインスタンスを生成します。
         * ロードするパターンデータの縦横解像度は、このインスタンスの値と同じである必要があります。
         * @param i_stream
         * 読出し元のStreamオブジェクト
         * @param i_width
         * パターンの幅pixel数。データの内容と一致している必要があります。
         * @param i_height
         * パターンの幅pixel数。データの内容と一致している必要があります。
         * @throws NyARException
         */
        public static NyARCode createFromARPattFile(StreamReader i_stream, int i_width, int i_height)
        {
            //ラスタにパターンをロードする。
            NyARCode ret = new NyARCode(i_width, i_height);

            NyARCodeFileReader.loadFromARToolKitFormFile(i_stream, ret);
            return(ret);
        }
 public DetectSquareCB(INyARColorPatt i_inst_patt, NyARCode i_ref_code, NyARParam i_param)
 {
     this._inst_patt = i_inst_patt;
     this._deviation_data = new NyARMatchPattDeviationColorData(i_ref_code.getWidth(), i_ref_code.getHeight());
     this._coordline = new Coord2Linear(i_param.getScreenSize(), i_param.getDistortionFactor());
     this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code);
     return;
 }
 /** */
 public MarkerInfoARMarker(NyARCode i_patt, int i_patt_edge_percentage, double i_patt_size)
     : base()
 {
     this.matchpatt = new NyARMatchPatt_Color_WITHOUT_PCA(i_patt);
     this.patt_edge_percentage = i_patt_edge_percentage;
     this.marker_offset.setSquare(i_patt_size);
     this.patt_w = i_patt.getWidth();
     this.patt_h = i_patt.getHeight();
     return;
 }
 /**
  * コンストラクタ。
  * 基準パターンを元に、インスタンスを生成します。
  * @param i_code_ref
  * セットする基準パターンの参照値
  */
 public NyARMatchPatt_Color_WITHOUT_PCA(NyARCode i_code_ref)
 {
     int w = i_code_ref.getWidth();
     int h = i_code_ref.getHeight();
     //最適化定数の計算
     this._rgbpixels = w * h * 3;
     this._optimize_for_mod = this._rgbpixels - (this._rgbpixels % 16);
     this.setARCode(i_code_ref);
     return;
 }
Exemple #10
0
        public NyARMatchPatt_Color_WITHOUT_PCA(NyARCode i_code_ref)
        {
            int w = i_code_ref.getWidth();
            int h = i_code_ref.getHeight();

            //最適化定数の計算
            this._rgbpixels        = w * h * 3;
            this._optimize_for_mod = this._rgbpixels - (this._rgbpixels % 16);
            this.setARCode(i_code_ref);
            return;
        }
 public void setNyARCodeTable(NyARCode[] i_ref_code, int i_code_resolution)
 {
     /*unmanagedで実装するときは、ここでリソース解放をすること。*/
     this._deviation_data = new NyARMatchPattDeviationColorData(i_code_resolution, i_code_resolution);
     this._inst_patt = new NyARColorPatt_Perspective(i_code_resolution, i_code_resolution, 4, 25);
     this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA[i_ref_code.Length];
     for (int i = 0; i < i_ref_code.Length; i++)
     {
         this._match_patt[i] = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]);
     }
 }
 /** <summary>
 * {@link #addARMarker(INyARRgbRaster, int, int, double)}It is a wrapper. I make a marker pattern from Bitmap.
 * The arguments are{@link #addARMarker(INyARRgbRaster, int, int, double)}Please refer to the.
 *
 * </summary>
 * <param name="i_img"></param>
 * <param name="i_patt_resolution">I specify the resolution of the marker to be generated.</param>
 * <param name="i_patt_edge_percentage">Specifies the percentage of the edge region of the image.</param>
 * <param name="i_marker_size">I specify the physical size of the marker.</param>
 * <returns></returns>
 **/
 public int addARMarker(Texture2D i_img, int i_patt_resolution, int i_patt_edge_percentage, double i_marker_size)
 {
     int w = i_img.width;
     int h = i_img.height;
     NyARUnityRaster ur = new NyARUnityRaster(i_img);
     NyARCode c = new NyARCode(i_patt_resolution, i_patt_resolution);
     //Marker pattern cut out from a raster
     INyARPerspectiveCopy pc = (INyARPerspectiveCopy)ur.createInterface(typeof(INyARPerspectiveCopy));
     NyARRgbRaster tr = new NyARRgbRaster(i_patt_resolution, i_patt_resolution);
     pc.copyPatt(0, 0, w, 0, w, h, 0, h, i_patt_edge_percentage, i_patt_edge_percentage, 4, tr);
     //Set the pattern cut
     c.setRaster(tr);
     return base.addARMarker(c, i_patt_edge_percentage, i_marker_size);
 }
        //
        // This reogion may be moved to NyARJ2seMarkerSystem.
        //


        /// <summary>
        /// {@link #addARMarker(INyARRgbRaster, int, int, double)}のラッパーです。Bitmapからマーカパターンを作ります。
        /// 引数については、{@link #addARMarker(INyARRgbRaster, int, int, double)}を参照してください。
        /// 
        /// </summary>
        /// <param name="i_img"></param>
        /// <param name="i_patt_resolution">生成するマーカの解像度を指定します。</param>
        /// <param name="i_patt_edge_percentage">画像のエッジ領域を%で指定します。</param>
        /// <param name="i_marker_size">マーカの物理サイズを指定します。</param>
        /// <returns></returns>
        public int addARMarker(Bitmap i_img, int i_patt_resolution, int i_patt_edge_percentage, double i_marker_size)
        {
            int w = i_img.Width;
            int h = i_img.Height;
            using (NyARBitmapRaster bmr = new NyARBitmapRaster(i_img))
            {
                NyARCode c = new NyARCode(i_patt_resolution, i_patt_resolution);
                //ラスタからマーカパターンを切り出す。
                INyARPerspectiveCopy pc = (INyARPerspectiveCopy)bmr.createInterface(typeof(INyARPerspectiveCopy));
                NyARRgbRaster tr = new NyARRgbRaster(i_patt_resolution, i_patt_resolution);
                pc.copyPatt(0, 0, w, 0, w, h, 0, h, i_patt_edge_percentage, i_patt_edge_percentage, 4, tr);
                //切り出したパターンをセット
                c.setRaster(tr);
                return base.addARMarker(c, i_patt_edge_percentage, i_marker_size);
            }
        }
Exemple #14
0
        public void Test_arDetectMarkerLite()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            
            //AR用カメラパラメタファイルをロード
            NyARParam ap = new NyARParam();
            ap.loadARParam(assembly.GetManifestResourceStream(RES_CAMERA));
            ap.changeScreenSize(320, 240);

            //AR用のパターンコードを読み出し	
            NyARCode code = new NyARCode(16, 16);
            Stream sr1=assembly.GetManifestResourceStream(RES_PATT);
            code.loadARPatt(new StreamReader(sr1));

            //試験イメージの読み出し(320x240 BGRAのRAWデータ)
            StreamReader sr = new StreamReader(assembly.GetManifestResourceStream(RES_DATA));
            BinaryReader bs = new BinaryReader(sr.BaseStream);
            byte[] raw = bs.ReadBytes(320 * 240 * 4);
            NyARRgbRaster_BGRA ra = new NyARRgbRaster_BGRA(320, 240,false);
            ra.wrapBuffer(raw);
            //		Blank_Raster ra=new Blank_Raster(320, 240);

            //1パターンのみを追跡するクラスを作成
//            NyARSingleDetectMarker_Quad ar = new NyARSingleDetectMarker_Quad(ap, code, 80.0);
            NyARSingleDetectMarker ar = new NyARSingleDetectMarker(ap, code, 80.0,ra.getBufferType());
            NyARTransMatResult result_mat = new NyARTransMatResult();
            ar.setContinueMode(false);
            ar.detectMarkerLite(ra, 100);
            ar.getTransmationMatrix(result_mat);

            //マーカーを検出
            for (int i3 = 0; i3 < 10; i3++)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                for (int i = 0; i < 10; i++)
                {
                    //変換行列を取得
                    ar.detectMarkerLite(ra, 100);
                    ar.getTransmationMatrix(result_mat);
                }
                sw.Stop();
                Debug.WriteLine(sw.ElapsedMilliseconds + "[ms]");
            }
            return;
        }
 public NyARCode createNyARCode()
 {
     NyARCode result = new NyARCode(this._code_size, this._code_size);
     result.loadARPattFromFile(this._root_path + "\\" + this._code_file);
     return result;
 }
        private void ParseArray(string arrayName, ref MarkerInfo markerInfo)
        {
            XElement markerArray = XElement.Load(@"" + arrayName);

            int pattWidth = 0, pattHeight = 0;
            float pattSize = 0, conf = 0;
            String pattName = "";
            Vector3 upperLeftCorner = Vector3.Zero;
            string[] tmp = null;

            foreach (XElement markerElement in markerArray.Elements("marker"))
            {
                try
                {
                    pattName = markerElement.Attribute("patternName").Value;
                    pattWidth = int.Parse(markerElement.Attribute("patternWidth").Value);
                    pattHeight = int.Parse(markerElement.Attribute("patternHeight").Value);
                    pattSize = float.Parse(markerElement.Attribute("patternSize").Value);
                    conf = float.Parse(markerElement.Attribute("confidence").Value);
                    tmp = markerElement.Attribute("upperLeftCorner").Value.Split(',');
                    upperLeftCorner.X = -float.Parse(tmp[0]);
                    upperLeftCorner.Y = float.Parse(tmp[1]);
                }
                catch (Exception exp)
                {
                    throw new MarkerException("Wrong marker array format: " + exp.Message);
                }

                NyARCode code = new NyARCode(pattWidth, pattHeight);
                code.loadARPatt(new System.IO.StreamReader(TitleContainer.OpenStream(pattName)));
                codes.Add(code);
                pattSizes.Add(pattSize);

                PatternInfo info = new PatternInfo();
                info.ConfidenceThreshold = conf;

                int id = codes.Count - 1;
                markerInfo.PatternInfos.Add(id, info);
                markerInfo.RelativeTransforms.Add(id, Matrix.CreateTranslation(upperLeftCorner));

                markerInfoMap.Add(id, markerInfo);
            }
        }
        public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
            //キャプチャを作る(QVGAでフレームレートは30)
            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;

            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32);

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //Direct3d用のユーティリティ準備

            //プロセッサの準備
            this._processor = new MarkerProcessor(ap, this._raster.getBufferType());
            NyARCode[] codes = new NyARCode[2];
            codes[0] = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE1),16, 16);
            codes[1] = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE2),16, 16);
            this._processor.setARCodeTable(codes,16,80.0);


            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting = false;
            this._device.RenderState.CullMode = Cull.CounterClockwise;

            Viewport vp = new Viewport();
            vp.X = 0;
            vp.Y = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width = ap.getScreenSize().w;
            vp.MaxZ = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            this._text = new TextPanel(this._device, 1);
            //カメラProjectionの設定
            Matrix tmp = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp);
            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));

            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            return true;
        }
 protected NyARSingleDetectMarker(NyARParam i_ref_param, NyARCode i_ref_code, double i_marker_width)
 {
     this._deviation_data = new NyARMatchPattDeviationColorData(i_ref_code.getWidth(), i_ref_code.getHeight());
     this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code);
     this._offset = new NyARRectOffset();
     this._offset.setSquare(i_marker_width);
     this._coordline = new NyARCoord2Linear(i_ref_param.getScreenSize(), i_ref_param.getDistortionFactor());
     //2値画像バッファを作る
     NyARIntSize s = i_ref_param.getScreenSize();
     this._bin_raster = new NyARBinRaster(s.w, s.h);
 }
 public NyARSingleDetectMarker_NyARTK_FITTING_ARTKv2(NyARParam i_ref_param, NyARCode i_ref_code, double i_marker_width)
     : base(i_ref_param, i_ref_code, i_marker_width)
 {
     this._inst_patt = new NyARColorPatt_Perspective(i_ref_code.getWidth(), i_ref_code.getHeight(), 4, 25);
     this._transmat = new NyARTransMat_ARToolKit(i_ref_param);
     this._square_detect = new NyARSingleDetectMarker_ARTKv2.ARTKDetector(this, i_ref_param.getScreenSize());
 }
 /**
  * この関数は、ARToolKitスタイルのマーカーをストリームから読みだして、登録します。
  * @param i_stream
  * マーカデータを読み出すストリーム
  * @param i_patt_edge_percentage
  * エッジ割合。ARToolkitと同じ場合は25を指定します。
  * @param i_marker_size
  * マーカの平方サイズ[mm]
  * @return
  * マーカID(ハンドル)値。
  * @throws NyARException
  */
 public int addARMarker(StreamReader i_stream,int i_patt_resolution,int i_patt_edge_percentage,double i_marker_size)
 {
     NyARCode c=new NyARCode(i_patt_resolution,i_patt_resolution);
     c.loadARPatt(i_stream);
     return this.addARMarker(c, i_patt_edge_percentage, i_marker_size);
 }
        /// <summary>
        /// Associates a marker with an identifier so that the identifier can be used to find this
        /// marker after processing the image. 
        /// </summary>
        /// <param name="markerConfigs">A set of parameters that identifies a maker. (e.g., for
        /// ARTag, this parameter would be the marker array name or marker ID)</param>
        /// <returns>An identifier for this marker object</returns>
        public Object AssociateMarker(params Object[] markerConfigs)
        {
            // make sure we are initialized
            if (!initialized)
                throw new MarkerException("ARToolkitTracker is not initialized. Call InitTracker(...)");

            if (!(markerConfigs.Length == 2 || markerConfigs.Length == 5))
                throw new MarkerException(GetAssocMarkerUsage());

            MarkerInfo markerInfo = new MarkerInfo();

            if (markerConfigs.Length == 2)
            {
                string arrayName = "";
                ComputationMethod method = ComputationMethod.Average;

                try
                {
                    arrayName = (String)markerConfigs[0];
                    method = (ComputationMethod)markerConfigs[1];
                }
                catch (Exception)
                {
                    throw new MarkerException(GetAssocMarkerUsage());
                }

                ParseArray(arrayName, ref markerInfo);

                markerInfo.Method = method;
            }
            else
            {
                int pattWidth = 0, pattHeight = 0;
                float pattSize = 0, conf = 0;
                String pattName = "";

                try
                {
                    pattName = (String)markerConfigs[0];
                    pattWidth = (int)markerConfigs[1];
                    pattHeight = (int)markerConfigs[2];
                    pattSize = (float)markerConfigs[3];
                    conf = (float)markerConfigs[4];
                }
                catch (Exception)
                {
                    throw new MarkerException(GetAssocMarkerUsage());
                }

                NyARCode code = new NyARCode(pattWidth, pattHeight);
                code.loadARPatt(new System.IO.StreamReader(TitleContainer.OpenStream(pattName)));
                codes.Add(code);
                pattSizes.Add(pattSize);

                PatternInfo info = new PatternInfo();
                info.ConfidenceThreshold = conf;

                int id = codes.Count - 1;
                markerInfo.PatternInfos.Add(id, info);
                markerInfo.RelativeTransforms.Add(id, Matrix.Identity);
                markerInfo.Method = ComputationMethod.Average;

                markerInfoMap.Add(id, markerInfo);
            }

            markerInfoList.Add(markerInfo);

            // reinitialize the multi marker detector if the programmer adds new marker node
            // after the initialization phase
            if (started)
            {
                multiDetector = new MarkerDetector(param, codes.ToArray(), pattSizes.ToArray(),
                    codes.Count, raster.getBufferType());
                multiDetector.setContinueMode(continuousMode);
            }

            return markerInfo;
        }
 public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width, int i_input_raster_type)
 {
     initialize(i_param, i_code, i_marker_width, i_input_raster_type, PF_NYARTOOLKIT);
     return;
 }
 /**
  * この関数は、ARToolKitスタイルのマーカーを登録します。
  * @param i_code
  * 登録するマーカパターンオブジェクト
  * @param i_patt_edge_percentage
  * エッジ割合。ARToolkitと同じ場合は25を指定します。
  * @param i_marker_size
  * マーカの平方サイズ[mm]
  * @return
  * マーカID(ハンドル)値。
  * @throws NyARException
  */
 public int addARMarker(NyARCode i_code,int i_patt_edge_percentage,double i_marker_size)
 {
     MarkerInfoARMarker target=new MarkerInfoARMarker(i_code,i_patt_edge_percentage,i_marker_size);
     this._armk_list.add(target);
     this._tracking_list.add(target);
     return (this._armk_list.Count-1)| IDTYPE_ARTK;
 }
 /**
  * この関数は、検出するマーカパターンテーブルの配列を指定します。 
  * マーカパターンには、配列の先頭から、0から始まるID番号を割り当てられます。
  * このIDは、{@link #onEnterHandler}イベントハンドラに通知されるID番号に対応し、マーカパターンの識別に使います。
  * @param i_ref_code_table
  * マーカパターンテーブルにセットする配列です。配列にあるマーカパターンの解像度は、i_code_resolutionに一致している必要があります。
  * @param i_code_resolution
  * マーカパターン縦横解像度です。
  * @param i_marker_width
  * <p>メモ:
  * マーカを検出している状態で関数を実行すると、イベント通知なしに、認識中のマーカを見失います。
  * </p>
  * @ 
  */
 public void setARCodeTable(NyARCode[] i_ref_code_table, int i_code_resolution, double i_marker_width)
 {
     if (this._current_arcode_index != -1)
     {
         // 強制リセット
         reset(true);
     }
     //検出するマーカセット、情報、検出器を作り直す。(1ピクセル4ポイントサンプリング,マーカのパターン領域は50%)
     this._detectmarker.setNyARCodeTable(i_ref_code_table, i_code_resolution);
     this._offset.setSquare(i_marker_width);
     return;
 }
 /**
  * この関数は、ARToolKitスタイルのマーカーをファイルから読みだして、登録します。
  * @param i_stream
  * マーカデータを読み出すストリーム
  * @param i_patt_edge_percentage
  * エッジ割合。ARToolkitと同じ場合は25を指定します。
  * @param i_marker_size
  * マーカの平方サイズ[mm]
  * @return
  * マーカID(ハンドル)値。
  * @throws NyARException
  */
 public int addARMarker(String i_file_name,int i_patt_resolution,int i_patt_edge_percentage,double i_marker_size)
 {
     NyARCode c=new NyARCode(i_patt_resolution,i_patt_resolution);
     try{
     c.loadARPatt(new StreamReader(i_file_name));
     }catch(Exception e){
     throw new NyARException(e);
     }
     return this.addARMarker(c,i_patt_edge_percentage, i_marker_size);
 }
	    /**
	     * inputStreamからARToolKit形式のパターンデータを指定サイズで読み出して、格納したインスタンスを生成します。
	     * ロードするパターンデータの縦横解像度は、このインスタンスの値と同じである必要があります。
	     * @param i_stream
	     * 読出し元のStreamオブジェクト
	     * @param i_width
	     * パターンの幅pixel数。データの内容と一致している必要があります。
	     * @param i_height
	     * パターンの幅pixel数。データの内容と一致している必要があります。
	     * @throws NyARException
	     */	
	    public static NyARCode createFromARPattFile(StreamReader i_stream,int i_width,int i_height)
	    {
		    //ラスタにパターンをロードする。
		    NyARCode ret=new NyARCode(i_width,i_height);
		    NyARCodeFileReader.loadFromARToolKitFormFile(i_stream,ret);
		    return ret;
    		
	    }
Exemple #27
0
        private void buttonBookDemo_Click(object sender, EventArgs e)
        {
            if (bookDemo == false)
            {
                StopOtherApps(this, e);
                bookDemo = true;
                labelDemoName.Text = "Book";
                buttonBookDemo.Text = "Stop Book";
                labelDemoInstructions.Enabled = true;
                labelDemoInstructions.Text = "Book Demo Instructions:\n\n"
                    + "Book \n";

                //pictureBoxAlbum.Show();
                lblResult.Hide();

                //NYAR
                //initialize nyar components.
                NyARParam ap = new NyARParam();
                ap.loadARParamFromFile(AR_CAMERA_FILE);
                ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);
                _raster = new DsBGRX32Raster(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH * 32 / 8);
                _utils = new NyARD3dUtil();

                // For each pattern
                NyARCode code1 = new NyARCode(16, 16);
                code1.loadARPattFromFile(AR_CODE_FILE1);
                _ar1 = new NyARSingleDetectMarker(ap, code1, 80.0);
                _ar1.setContinueMode(false);

                NyARCode code2 = new NyARCode(16, 16);
                code2.loadARPattFromFile(AR_CODE_FILE2);
                _ar2 = new NyARSingleDetectMarker(ap, code2, 80.0);
                _ar2.setContinueMode(false);

                NyARCode code3 = new NyARCode(16, 16);
                code3.loadARPattFromFile(AR_CODE_FILE3);
                _ar3 = new NyARSingleDetectMarker(ap, code3, 80.0);
                _ar3.setContinueMode(false);

                NyARCode code4 = new NyARCode(16, 16);
                code4.loadARPattFromFile(AR_CODE_FILE4);
                _ar4 = new NyARSingleDetectMarker(ap, code4, 80.0);
                _ar4.setContinueMode(false);
            }
            else
            {
                bookDemo = false;
                labelDemoName.Text = "WUW";
                buttonBookDemo.Text = "Book";
                Cursor = Cursors.Arrow;
                labelDemoInstructions.Enabled = false;
                labelDemoInstructions.Text = "";
                ResetEnvironment();

                //pictureBoxAlbum.Hide();
                lblResult.Show();
            }
        }
 /**
  * 処理プロファイルを指定して、{@link NyARSingleDetectoMarker}オブジェクトを生成します。
  * @param i_param
  * カメラパラメータを指定します。このサイズは、{@link #detectMarkerLite}に入力する画像と同じである必要があります。
  * @param i_code
  * 検出するマーカパターンを指定します。
  * @param i_marker_width
  * 正方形マーカの物理サイズをmm単位で指定します。
  * @param i_input_raster_type
  * {@link #detectMarkerLite}に入力するラスタの画素形式を指定します。
  * この値は、{@link INyARRgbRaster#getBufferType}関数の戻り値を利用します。
  * @param i_profile_id
  * 計算アルゴリズムの選択値です。以下の定数のいずれかを指定します。
  * <ul>
  * <li>{@link #PF_ARTOOLKIT_COMPATIBLE}
  * <li>{@link #PF_NYARTOOLKIT}
  * <li>{@link #PF_NYARTOOLKIT_ARTOOLKIT_FITTING}
  * </ul>
  * @
  * @
  */
 public static NyARSingleDetectMarker createInstance(NyARParam i_param, NyARCode i_code, double i_marker_width, int i_profile_id)
 {
     switch (i_profile_id)
     {
         case PF_ARTOOLKIT_COMPATIBLE:
             return new NyARSingleDetectMarker_ARTKv2(i_param, i_code, i_marker_width);
         case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:
             return new NyARSingleDetectMarker_NyARTK_FITTING_ARTKv2(i_param, i_code, i_marker_width);
         case PF_NYARTOOLKIT://default
             return new NyARSingleDetectMarker_NyARTK(i_param, i_code, i_marker_width);
         default:
             throw new NyARException();
     }
 }
 public static NyARSingleDetectMarker createInstance(NyARParam i_param, NyARCode i_code, double i_marker_width)
 {
     return createInstance(i_param, i_code, i_marker_width, PF_NYARTOOLKIT);
 }
 /**
  * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
  * 
  * @param i_param
  * カメラパラメータを指定します。
  * @param i_code
  * 検出するARCodeを指定します。
  * @param i_marker_width
  * ARコードの物理サイズを、ミリメートルで指定します。
  * @param i_input_raster_type
  * 入力ラスタのピクセルタイプを指定します。この値は、INyARBufferReaderインタフェイスのgetBufferTypeの戻り値を指定します。
  * @throws NyARException
  */
 public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width, int i_input_raster_type, int i_profile_id)
 {
     initialize(i_param, i_code, i_marker_width, i_input_raster_type, i_profile_id);
     return;
 }
        protected void initInstance(
            INyARColorPatt i_patt_inst,
            NyARSquareContourDetector i_sqdetect_inst,
            INyARTransMat i_transmat_inst,
            INyARRasterFilter_Rgb2Bin i_filter,
            NyARParam i_ref_param,
            NyARCode i_ref_code,
            double i_marker_width)
        {
            NyARIntSize scr_size = i_ref_param.getScreenSize();
            // 解析オブジェクトを作る
            this._square_detect = i_sqdetect_inst;
            this._transmat = i_transmat_inst;
            this._tobin_filter = i_filter;
            //2値画像バッファを作る
            this._bin_raster = new NyARBinRaster(scr_size.w, scr_size.h);
            //_detect_cb
            this._detect_cb = new DetectSquareCB(i_patt_inst, i_ref_code, i_ref_param);
            //オフセットを作成
            this._offset = new NyARRectOffset();
            this._offset.setSquare(i_marker_width);
            return;

        }
Exemple #32
0
 /**
  * 比較対象のARCodeをセットします。
  * @throws NyARException
  */
 public void setARCode(NyARCode i_code_ref)
 {
     this._code_patt = i_code_ref;
     return;
 }
	/**
	 * この関数は、ARToolKitスタイルのマーカーを登録します。
	 * @param i_code
	 * 登録するマーカパターンオブジェクト
	 * @param i_patt_edge_percentage
	 * エッジ割合。ARToolkitと同じ場合は25を指定します。
	 * @param i_marker_size
	 * マーカの平方サイズ[mm]
	 * @return
	 * マーカID(ハンドル)値。
	 * @throws NyARException
	 */
	public int addARMarker(NyARCode i_code,int i_patt_edge_percentage,double i_marker_size)
	{
		ARMarkerList.Item target=new ARMarkerList.Item(i_code,i_patt_edge_percentage,i_marker_size);
		this._armk_list.add(target);
		this._tracking_list.add(target);
        this._on_sq_handler.setMaxDetectMarkerCapacity(this._tracking_list.Count);
        return (this._armk_list.Count - 1) | IDTYPE_ARTK;
	}
 /**
  * 基準パターンをセットします。セットできる基準パターンは、コンストラクタに設定したサイズと同じものである必要があります。
  * @param i_code_ref
  * セットする基準パターンを格納したオブジェクト
  * @
  */
 public void setARCode(NyARCode i_code_ref)
 {
     this._ref_code_patt = i_code_ref;
     return;
 }
	/**
	 * この関数は、画像から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);
	}