/** * この関数は、インスタンスを初期化します。 * 継承先のクラスから呼び出してください。 * @param i_param * カメラパラメータオブジェクト。このサイズは、{@link #detectMarker}に入力する画像と同じサイズである必要があります。 * @param i_encoder * IDマーカの値エンコーダを指定します。 * @param i_marker_width * マーカの物理縦横サイズをmm単位で指定します。 * @ */ protected void initInstance(NyARParam i_param, INyIdMarkerDataEncoder i_encoder, double i_marker_width) { //初期化済? Debug.Assert(this._initialized == false); NyARIntSize scr_size = i_param.getScreenSize(); // 解析オブジェクトを作る this._square_detect = new RleDetector( i_param, i_encoder, new NyIdMarkerPickup()); this._transmat = new NyARTransMat(i_param); // 2値画像バッファを作る this._gs_raster = NyARGrayscaleRaster.createInstance(scr_size.w, scr_size.h); this._histmaker = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster)); //ワーク用のデータオブジェクトを2個作る this._data_current = i_encoder.createDataInstance(); this._threshold_detect = new NyARHistogramAnalyzer_SlidePTile(15); this._initialized = true; this._is_active = false; this._offset = new NyARRectOffset(); this._offset.setSquare(i_marker_width); return; }
public NyARSensor(NyARIntSize i_size) { this._gs_raster = NyARGrayscaleRaster.createInstance(i_size.w, i_size.h, NyARBufferType.INT1D_GRAY_8, true); this._gs_hist = new NyARHistogram(256); this._src_ts = 0; this._gs_id_ts = 0; this._gs_hist_ts = 0; this._hist_drv = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster)); }
static void Main(string[] args) { String img_file = "../../../../../data/testcase/test.raw"; String cparam_file = "../../../../../data/testcase/camera_para5.dat"; String fset3file = "../../../../../data/testcase/pinball.fset3"; //カメラパラメータ NyARParam param = NyARParam.loadFromARParamFile(File.OpenRead(cparam_file), 640, 480, NyARParam.DISTFACTOR_LT_ARTK5); INyARGrayscaleRaster gs = NyARGrayscaleRaster.createInstance(640, 480); //試験画像の準備 { INyARRgbRaster rgb = NyARRgbRaster.createInstance(640, 480, NyARBufferType.BYTE1D_B8G8R8X8_32); Stream fs = File.OpenRead(img_file); byte[] b = (byte[])rgb.getBuffer(); fs.Read(b, 0, b.Length); INyARRgb2GsFilterRgbAve filter = (INyARRgb2GsFilterRgbAve)rgb.createInterface(typeof(INyARRgb2GsFilterRgbAve)); filter.convert(gs); } NyARDoubleMatrix44 tmat = new NyARDoubleMatrix44(); NyARNftFreakFsetFile f = NyARNftFreakFsetFile.loadFromfset3File(File.OpenRead(fset3file)); // KpmHandle kpm=new KpmHandle(new ARParamLT(param)); Stopwatch sw = new Stopwatch(); FreakKeypointMatching kpm = new FreakKeypointMatching(param); KeyframeMap keymap = new KeyframeMap(f, 0); for (int j = 0; j < 4; j++) { sw.Reset(); sw.Start(); for (int i = 0; i < 20; i++) { kpm.updateInputImage(gs); kpm.updateFeatureSet(); kpm.kpmMatching(keymap, tmat); } //FreakKeypointMatching#kMaxNumFeaturesを300にしてテストして。 sw.Stop(); System.Console.WriteLine("Total=" + (sw.ElapsedMilliseconds)); NyARDoubleMatrix44 TEST_PATT = new NyARDoubleMatrix44(new double[] { 0.98436354107742652, 0.0066768917838370646, -0.17602226595996517, -191.17967199668533, 0.011597578022657571, -0.99956974712564306, 0.026940987645082352, 63.00280574839347, -0.17576664981496215, -0.028561157958401542, -0.98401745160789567, 611.75871553558636, 0, 0, 0, 1 }); System.Console.WriteLine(TEST_PATT.Equals(tmat)); } }
/** * この関数は、インスタンスを初期化します。 * 継承先のクラスから呼び出してください。 * @param i_param * カメラパラメータオブジェクト。このサイズは、{@link #detectMarker}に入力する画像と同じサイズである必要があります。 * @ */ protected void initInstance(NyARParam i_param) { //初期化済? Debug.Assert(this._initialized == false); NyARIntSize scr_size = i_param.getScreenSize(); // 解析オブジェクトを作る this._transmat = new NyARTransMat(i_param); this._thdetect = new NyARHistogramAnalyzer_SlidePTile(15); // 2値画像バッファを作る this._gs_raster = NyARGrayscaleRaster.createInstance(scr_size.w, scr_size.h); this._initialized = true; //コールバックハンドラ this._detectmarker = new DetectSquare(i_param); this._offset = new NyARRectOffset(); return; }
static void Main(string[] args) { NyARDoubleMatrix44 DEST_MAT = new NyARDoubleMatrix44( new double[] { 0.9832165682361184, 0.004789697223621061, -0.18237945710280384, -190.59060790299358, 0.012860184615056927, -0.9989882709616935, 0.04309419210331572, 64.04490277502563, -0.18198852802987958, -0.044716355753573425, -0.9822833548209547, 616.6427596804766, 0, 0, 0, 1 }); NyARDoubleMatrix44 SRC_MAT = new NyARDoubleMatrix44(new double[] { 0.984363556, 0.00667689135, -0.176022261, -191.179672, 0.0115975942, -0.999569774, 0.0269410834, 63.0028076, -0.175766647, -0.0285612550, -0.984017432, 611.758728, 0, 0, 0, 1 }); String img_file = "../../../../../data/testcase/test.raw"; String cparam = "../../../../../data/testcase/camera_para5.dat"; String fsetfile = "../../../../../data/testcase/pinball.fset"; String isetfile = "../../../../../data/testcase/pinball.iset5"; //カメラパラメータ NyARParam param = NyARParam.loadFromARParamFile(File.OpenRead(cparam), 640, 480, NyARParam.DISTFACTOR_LT_ARTK5); INyARGrayscaleRaster gs = NyARGrayscaleRaster.createInstance(640, 480); //試験画像の準備 { INyARRgbRaster rgb = NyARRgbRaster.createInstance(640, 480, NyARBufferType.BYTE1D_B8G8R8X8_32); Stream fs = File.OpenRead(img_file); byte[] b = (byte[])rgb.getBuffer(); fs.Read(b, 0, b.Length); INyARRgb2GsFilterRgbAve filter = (INyARRgb2GsFilterRgbAve)rgb.createInterface(typeof(INyARRgb2GsFilterRgbAve)); filter.convert(gs); } NyARNftFsetFile fset = NyARNftFsetFile.loadFromFsetFile(File.OpenRead(fsetfile)); NyARNftIsetFile iset = NyARNftIsetFile.loadFromIsetFile(File.OpenRead(isetfile)); NyARSurfaceTracker st = new NyARSurfaceTracker(param, 16, 0.5); NyARSurfaceDataSet sd = new NyARSurfaceDataSet(iset, fset); NyARDoubleMatrix44 sret = new NyARDoubleMatrix44(); NyARDoublePoint2d[] o_pos2d = NyARDoublePoint2d.createArray(16); NyARDoublePoint3d[] o_pos3d = NyARDoublePoint3d.createArray(16); NyARSurfaceTrackingTransmatUtils tmat = new NyARSurfaceTrackingTransmatUtils(param, 5.0); NyARDoubleMatrix44 tret = new NyARDoubleMatrix44(); for (int j = 0; j < 10; j++) { Stopwatch s = new Stopwatch(); s.Reset(); s.Start(); for (int i = 0; i < 3000; i++) { sret.setValue(SRC_MAT); int nop = st.tracking(gs, sd, sret, o_pos2d, o_pos3d, 16); //Transmatの試験 NyARDoublePoint3d off = NyARSurfaceTrackingTransmatUtils.centerOffset(o_pos3d, nop, new NyARDoublePoint3d()); NyARSurfaceTrackingTransmatUtils.modifyInputOffset(sret, o_pos3d, nop, off); tmat.surfaceTrackingTransmat(sret, o_pos2d, o_pos3d, nop, tret, new NyARTransMatResultParam()); NyARSurfaceTrackingTransmatUtils.restoreOutputOffset(tret, off); System.Console.WriteLine(tret.Equals(DEST_MAT)); } s.Stop(); System.Console.WriteLine(s.ElapsedMilliseconds); } return; }