Ejemplo n.º 1
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;
        }
 /**
  * この関数は、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);
 }
Ejemplo n.º 3
0
        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);
            }
        }
 /**
  * この関数は、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);
 }
Ejemplo n.º 5
0
        /// <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;
        }