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 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_O2(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]); } }
/** * 現在セットされているARコードとi_pattを比較します。 */ public bool evaluate(NyARMatchPattDeviationColorData i_patt, NyARMatchPattResult o_result) { Debug.Assert(this._code_patt != null); // int[] linput = i_patt.refData(); int sum; double max = Double.MinValue; int res = NyARMatchPattResult.DIRECTION_UNKNOWN; int for_mod = this._optimize_for_mod; for (int j = 0; j < 4; j++) { //合計値初期化 sum = 0; NyARMatchPattDeviationColorData code_patt = this._code_patt.getColorData(j); int[] pat_j = code_patt.refData(); //<全画素について、比較(FORの1/16展開)> int i; for (i = this._rgbpixels - 1; i >= for_mod; i--) { sum += linput[i] * pat_j[i]; } for (; i >= 0;) { sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; } //<全画素について、比較(FORの1/16展開)/> double sum2 = sum / code_patt.getPow(); // sum2 = sum / patpow[k][j]/ datapow; if (sum2 > max) { max = sum2; res = j; } } o_result.direction = res; o_result.confidence = max / i_patt.getPow(); return(true); }
/// <summary> /// Initialize a new SquareDetectionListener. /// </summary> /// <param name="patternMatchers">The pattern matchers with the marker data.</param> /// <param name="cameraParameters">The camera calibration data.</param> /// <param name="colorPattern">The used color pattern.</param> /// <param name="patternMatchDeviationData">The pattern match deviation data.</param> public SquareDetectionListener(List<PatternMatcher> patternMatchers, NyARParam cameraParameters, INyARColorPatt colorPattern, NyARMatchPattDeviationColorData patternMatchDeviationData) { this.patternMatchers = patternMatchers; this.colorPattern = colorPattern; this.patternMatchDeviationData = patternMatchDeviationData; this.coordinationMapper = new Coord2Linear(cameraParameters.getScreenSize(), cameraParameters.getDistortionFactor()); this.matrixCalculator = new NyARTransMat(cameraParameters); this.points = NyARIntPoint2d.createArray(4); this.evaluationResult = new NyARMatchPattResult(); Reset(); }
/** * 現在セットされているARコードとi_pattを比較します。 */ public bool evaluate(NyARMatchPattDeviationColorData i_patt, NyARMatchPattResult o_result) { Debug.Assert(this._code_patt != null); // int[] linput = i_patt.refData(); int sum; double max = Double.MinValue; int res = NyARMatchPattResult.DIRECTION_UNKNOWN; int for_mod = this._optimize_for_mod; for (int j = 0; j < 4; j++) { //合計値初期化 sum = 0; NyARMatchPattDeviationColorData code_patt = this._code_patt.getColorData(j); int[] pat_j = code_patt.refData(); //<全画素について、比較(FORの1/16展開)> int i; for (i = this._rgbpixels - 1; i >= for_mod; i--) { sum += linput[i] * pat_j[i]; } for (; i >= 0; ) { sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; sum += linput[i] * pat_j[i]; i--; } //<全画素について、比較(FORの1/16展開)/> double sum2 = sum / code_patt.getPow();// sum2 = sum / patpow[k][j]/ datapow; if (sum2 > max) { max = sum2; res = j; } } o_result.direction = res; o_result.confidence = max / i_patt.getPow(); return true; }
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; }
/// <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 string location = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); StreamReader reader = new StreamReader(location + "/Content/Data/Camera_Calibration_1280x720.dat"); var cameraParameters = new NyARParam(); using (var cameraCalibrationDataStream = reader.BaseStream) { cameraParameters.loadARParam(cameraCalibrationDataStream); cameraParameters.changeScreenSize(width, height); } //var asmName = new System.Reflection.AssemblyName(System.Reflection.Assembly.GetExecutingAssembly().FullName).Name; //var uri = new Uri(asmName + ";component/Assets/data/Camera_Calibration_1280x720.dat", UriKind.Relative); //var streamResInfoCam = Application.GetResourceStream(uri); //if (null == streamResInfoCam) // throw new FileNotFoundException("Application.GetResourceStream returned null", uri.OriginalString); //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); } }
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); }