/// <summary> /// Initializes the detector for single marker detection. /// </summary> /// <param name="width">The width of the buffer that will be used for detection.</param> /// <param name="height">The height of the buffer that will be used for detection.</param> /// <param name="nearPlane">The near view plane of the frustum.</param> /// <param name="farPlane">The far view plane of the frustum.</param> /// <param name="markers">A list of markers that should be detected.</param> /// <param name="bufferType">The type of the buffer.</param> /// <param name="adaptive">Performs an adaptive bitmap thresholding if set to true. Default = false.</param> protected void Initialize(int width, int height, double nearPlane, double farPlane, IList <Marker> markers, int bufferType, bool adaptive = false) { // Check arguments if (markers == null || !markers.Any()) { throw new ArgumentNullException("markers"); } // Member init this.bufferWidth = width; this.bufferHeight = height; this.isAdaptive = adaptive; // Init pattern matchers with markers and check segment size, whcih has to be equal for all markers int segmentX = markers[0].SegmentsX; int segmentY = markers[0].SegmentsY; var patternMatchers = new List <PatternMatcher>(markers.Count); foreach (var marker in markers) { if (marker.SegmentsX != segmentX || marker.SegmentsY != segmentY) { throw new ArgumentException("The Segment size has to be equal for all markers. Don't mix 16x16 and 32x32 markers for example.", "markers"); } patternMatchers.Add(new PatternMatcher(marker)); } // Load deafult camera calibration data var asmName = new System.Reflection.AssemblyName(System.Reflection.Assembly.GetExecutingAssembly().FullName).Name; var streamResInfoCam = Application.GetResourceStream(new Uri(asmName + ";component/data/Camera_Calibration_Default.dat", UriKind.Relative)); var cameraParameters = new NyARParam(); using (var cameraCalibrationDataStream = streamResInfoCam.Stream) { cameraParameters.loadARParam(cameraCalibrationDataStream); cameraParameters.changeScreenSize(width, height); } // Get projection matrix from camera calibration data this.Projection = cameraParameters.GetCameraFrustumRH(nearPlane, farPlane); // Init detector and necessary data var colorPattern = new NyARColorPatt_Perspective_O2(segmentX, segmentY, 4, 25); var patternMatchDeviationData = new NyARMatchPattDeviationColorData(segmentX, segmentY); this.squareDetector = new NyARSquareContourDetector_Rle(cameraParameters.getScreenSize()); this.squareDetectionListener = new SquareDetectionListener(patternMatchers, cameraParameters, colorPattern, patternMatchDeviationData); // Init buffer members this.filteredBuffer = new NyARBinRaster(width, height); if (adaptive) { this.bufferFilter = new NyARRasterFilter_AdaptiveThreshold(bufferType); } else { this.bufferFilter = new NyARRasterFilter_ARToolkitThreshold(this.Threshold, bufferType); } }
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 void InitTracker(params object[] configs) { if (!(configs.Length == 3 || configs.Length == 5)) { throw new MarkerException("Problem in InitTracker in NewNyAR"); } int imgWidth = 0; int imgHeight = 0; try { imgWidth = (int)configs[0]; imgHeight = (int)configs[1]; configFilename = (String)configs[2]; if (configs.Length == 5) { threshold = (int)configs[3]; continuousMode = (bool)configs[4]; } else { threshold = 100; continuousMode = false; } } catch (Exception) { throw new MarkerException("Problem in InitTracker in NewNyAR"); } nyARIntSize = new NyARIntSize(imgWidth, imgHeight); param = new NyARParam(); param.loadARParam(TitleContainer.OpenStream(configFilename)); param.changeScreenSize(nyARIntSize.w, nyARIntSize.h); camProjMat = GetProjectionMatrix(param, zNearPlane, zFarPlane); INyARMarkerSystemConfig arMarkerSystemConfig = new NyARMarkerSystemConfig(param); markerSystem = new NyARMarkerSystem(arMarkerSystemConfig); initialized = true; }