public NyARCameraDistortionFactorLT(int i_screen_width, int i_screen_height, int i_offset, INyARCameraDistortionFactor i_base_factor) { this._xsize = i_screen_width + i_offset * 2; this._ysize = i_screen_height + i_offset * 2; this._xOff = i_offset; this._yOff = i_offset; this._i2o = new double[this._xsize * this._ysize * 2]; this._o2i = new double[this._xsize * this._ysize * 2]; this._base_factor = i_base_factor; NyARDoublePoint2d tmp = new NyARDoublePoint2d();// for (int j = 0; j < this._ysize; j++) { for (int i = 0; i < this._xsize; i++) { int ptr = (j * this._xsize + i) * 2; i_base_factor.ideal2Observ(i - i_offset, j - i_offset, tmp); this._i2o[ptr + 0] = (double)tmp.x; this._i2o[ptr + 1] = (double)tmp.y; i_base_factor.observ2Ideal(i - i_offset, j - i_offset, tmp); this._o2i[ptr + 0] = (double)tmp.x; this._o2i[ptr + 1] = (double)tmp.y; } } return; }
/** * * @param i_ref_raster * 基本画像 * @param i_ref_raster_distortion * 歪み解除オブジェクト(nullの場合歪み解除を省略) * @param i_ref_rob_raster * エッジ探索用のROB画像 * @param */ public NyARVectorReader_INT1D_GRAY_8(NyARGrayscaleRaster i_ref_raster, INyARCameraDistortionFactor i_ref_raster_distortion, NyARGrayscaleRaster i_ref_rob_raster) : base() { Debug.Assert(i_ref_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8); Debug.Assert(i_ref_rob_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8); this.initInstance(i_ref_raster, i_ref_raster_distortion, i_ref_rob_raster, new NyARContourPickup()); }
/** * * @param i_ref_raster * 基本画像 * @param i_ref_raster_distortion * 歪み解除オブジェクト(nullの場合歪み解除を省略) * @param i_ref_rob_raster * エッジ探索用のROB画像 * @param */ public NyARVectorReader_INT1D_GRAY_8(NyARGrayscaleRaster i_ref_raster,INyARCameraDistortionFactor i_ref_raster_distortion,NyARGrayscaleRaster i_ref_rob_raster) :base() { Debug.Assert (i_ref_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8); Debug.Assert (i_ref_rob_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8); this.initInstance(i_ref_raster, i_ref_raster_distortion, i_ref_rob_raster,new NyARContourPickup()); }
/** * * @param i_width * ラスタのサイズを指定します。 * @param i_height * ラスタのサイズを指定します。 * @param i_ref_raster_distortion * 歪み矯正の為のオブジェクトを指定します。歪み矯正が必要ない時は、NULLを指定します。 * @param i_depth * エッジ画像のサイズを1/(2^n)で指定します。(例:QVGA画像で1を指定すると、エッジ検出画像は160x120になります。) * 数値が大きいほど高速になり、検出精度は低下します。実用的なのは、1<=n<=3の範囲です。標準値は2です。 * @param i_number_of_sample * サンプリングするターゲット数を指定します。大体100以上をしておけばOKです。具体的な計算式は、{@link NyARTrackerSource_Reference#NyARTrackerSource_Reference}を参考にして下さい。 * @param i_raster_type * ラスタタイプ * @throws NyARException */ public NyARRealitySource_Reference(int i_width,int i_height,INyARCameraDistortionFactor i_ref_raster_distortion,int i_depth,int i_number_of_sample,int i_raster_type) { this._rgb_source=new NyARRgbRaster(i_width,i_height,i_raster_type); this._filter=(INyARRgb2GsFilter) this._rgb_source.createInterface(typeof(INyARRgb2GsFilter)); this._source_perspective_reader=(INyARPerspectiveCopy)this._rgb_source.createInterface(typeof(INyARPerspectiveCopy)); this._tracksource=new NyARTrackerSource_Reference(i_number_of_sample,i_ref_raster_distortion,i_width,i_height,i_depth,true); return; }
/** * * @param i_width * ラスタのサイズを指定します。 * @param i_height * ラスタのサイズを指定します。 * @param i_ref_raster_distortion * 歪み矯正の為のオブジェクトを指定します。歪み矯正が必要ない時は、NULLを指定します。 * @param i_depth * エッジ画像のサイズを1/(2^n)で指定します。(例:QVGA画像で1を指定すると、エッジ検出画像は160x120になります。) * 数値が大きいほど高速になり、検出精度は低下します。実用的なのは、1<=n<=3の範囲です。標準値は2です。 * @param i_number_of_sample * サンプリングするターゲット数を指定します。大体100以上をしておけばOKです。具体的な計算式は、{@link NyARTrackerSource_Reference#NyARTrackerSource_Reference}を参考にして下さい。 * @param i_raster_type * ラスタタイプ * @throws NyARException */ public NyARRealitySource_Reference(int i_width, int i_height, INyARCameraDistortionFactor i_ref_raster_distortion, int i_depth, int i_number_of_sample, int i_raster_type) { this._rgb_source = new NyARRgbRaster(i_width, i_height, i_raster_type); this._filter = (INyARRgb2GsFilter)this._rgb_source.createInterface(typeof(INyARRgb2GsFilter)); this._source_perspective_reader = (INyARPerspectiveCopy)this._rgb_source.createInterface(typeof(INyARPerspectiveCopy)); this._tracksource = new NyARTrackerSource_Reference(i_number_of_sample, i_ref_raster_distortion, i_width, i_height, i_depth, true); return; }
private double _f3;//s /** * コピー元のオブジェクト。{@link NyARCameraDistortionFactorV2}クラスである必要があります。 */ public void copyFrom(INyARCameraDistortionFactor i_ref) { NyARCameraDistortionFactorV2 inst = (NyARCameraDistortionFactorV2)i_ref; this._f0 = inst._f0; this._f1 = inst._f1; this._f2 = inst._f2; this._f3 = inst._f3; return; }
private double _f3; //s /** * コピー元のオブジェクト。{@link NyARCameraDistortionFactorV2}クラスである必要があります。 */ public void copyFrom(INyARCameraDistortionFactor i_ref) { NyARCameraDistortionFactorV2 inst = (NyARCameraDistortionFactorV2)i_ref; this._f0 = inst._f0; this._f1 = inst._f1; this._f2 = inst._f2; this._f3 = inst._f3; return; }
/** * この関数は、コンストラクタから呼び出してください。 * @param i_distfactor * 歪みの逆矯正に使うオブジェクト。 * @param i_projmat * @ */ private void initInstance(INyARCameraDistortionFactor i_distfactor, NyARPerspectiveProjectionMatrix i_projmat) { this._transsolver = new NyARTransportVectorSolver(i_projmat, 4); //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。 //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。 this._rotmatrix = new NyARRotMatrix(i_projmat); this._mat_optimize = new NyARPartialDifferentiationOptimize(i_projmat); this._ref_dist_factor = i_distfactor; this._ref_projection_mat = i_projmat; return; }
/** * この関数は、コンストラクタから呼び出してください。 * @param i_distfactor * 歪みの逆矯正に使うオブジェクト。 * @param i_projmat * @ */ private void initInstance(INyARCameraDistortionFactor i_distfactor, NyARPerspectiveProjectionMatrix i_projmat) { this._transsolver = new NyARTransportVectorSolver(i_projmat, 4); //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。 //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。 this._rotmatrix = new NyARRotMatrix(i_projmat); this._mat_optimize = new NyARPartialDifferentiationOptimize(i_projmat); this._ref_dist_factor = i_distfactor; this._ref_projection_mat = i_projmat; return; }
/** * 継承クラスのコンストラクタから呼び出す。 * @param i_ref_raster * 基本画像 * @param i_ref_raster_distortion * 歪み解除オブジェクト(nullの場合歪み解除を省略) * @param i_ref_rob_raster * エッジ探索用のROB画像 * @param i_contour_pickup * 輪郭線取得クラス * @param */ public void initInstance(NyARGrayscaleRaster i_ref_raster, INyARCameraDistortionFactor i_ref_raster_distortion, NyARGrayscaleRaster i_ref_rob_raster, NyARContourPickup i_contour_pickup) { this._rob_resolution = i_ref_raster.getWidth() / i_ref_rob_raster.getWidth(); this._ref_rob_raster = i_ref_rob_raster; this._ref_base_raster = i_ref_raster; this._coord_buf = new NyARIntCoordinates((i_ref_raster.getWidth() + i_ref_raster.getHeight()) * 4); this._factor = i_ref_raster_distortion; this._tmp_coord_pos = VecLinearCoordinates.VecLinearCoordinatePoint.createArray(this._coord_buf.items.Length); this._cpickup = i_contour_pickup; return; }
/** * 継承クラスのコンストラクタから呼び出す。 * @param i_ref_raster * 基本画像 * @param i_ref_raster_distortion * 歪み解除オブジェクト(nullの場合歪み解除を省略) * @param i_ref_rob_raster * エッジ探索用のROB画像 * @param i_contour_pickup * 輪郭線取得クラス * @param */ public void initInstance(NyARGrayscaleRaster i_ref_raster,INyARCameraDistortionFactor i_ref_raster_distortion,NyARGrayscaleRaster i_ref_rob_raster,NyARContourPickup i_contour_pickup) { this._rob_resolution=i_ref_raster.getWidth()/i_ref_rob_raster.getWidth(); this._ref_rob_raster=i_ref_rob_raster; this._ref_base_raster=i_ref_raster; this._coord_buf = new NyARIntCoordinates((i_ref_raster.getWidth() + i_ref_raster.getHeight()) * 4); this._factor=i_ref_raster_distortion; this._tmp_coord_pos = VecLinearCoordinates.VecLinearCoordinatePoint.createArray(this._coord_buf.items.Length); this._cpickup = i_contour_pickup; return; }
/** * コンストラクタです。 * 座標計算に必要なオブジェクトの参照値を元に、インスタンスを生成します。 * @param i_ref_distfactor * 樽型歪み矯正オブジェクトの参照値です。歪み矯正が不要な時は、nullを指定します。 * @param i_ref_projmat * 射影変換オブジェクトの参照値です。 * @ */ public NyARTransMat_ARToolKit(INyARCameraDistortionFactor i_ref_distfactor, NyARPerspectiveProjectionMatrix i_ref_projmat) { INyARCameraDistortionFactor dist = i_ref_distfactor; NyARPerspectiveProjectionMatrix pmat = i_ref_projmat; this._transsolver = new NyARTransportVectorSolver_ARToolKit(pmat); //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。 //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。 this._rotmatrix = new NyARRotMatrix_ARToolKit_O2(pmat); this._mat_optimize = new NyARRotMatrixOptimize_O2(pmat); this._ref_dist_factor = dist; return; }
private void initInstance(INyARCameraDistortionFactor i_ref_distfactor, NyARPerspectiveProjectionMatrix i_ref_projmat) { INyARCameraDistortionFactor dist = i_ref_distfactor; NyARPerspectiveProjectionMatrix pmat = i_ref_projmat; this._transsolver = new NyARTransportVectorSolver_ARToolKit(pmat); //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。 //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。 this._rotmatrix = new NyARRotMatrix_ARToolKit_O2(pmat); this._mat_optimize = new NyARRotMatrixOptimize_O2(pmat); this._ref_dist_factor = dist; }
/** * ストリームから読み出したデータでインスタンスを初期化します。 * @param i_stream * @throws NyARRuntimeException */ public ParamLoader(Stream i_stream, int i_screen_width, int i_screen_height) { //読み出し byte[] data = jp.nyatla.nyartoolkit.cs.cs4.BinaryReader.toArray(i_stream); jp.nyatla.nyartoolkit.cs.cs4.BinaryReader bis = new jp.nyatla.nyartoolkit.cs.cs4.BinaryReader(data, jp.nyatla.nyartoolkit.cs.cs4.BinaryReader.ENDIAN_BIG); //読み出したサイズでバージョンを決定 int[] version_table = { 136, 144, 152, 176 }; int version = -1; for (int i = 0; i < version_table.Length; i++) { if (data.Length % version_table[i] == 0) { version = i + 1; break; } } //一致しなければ無し if (version == -1) { throw new NyARRuntimeException(); } int camera_width = bis.getInt(); int camera_height = bis.getInt(); //size this.size = new NyARIntSize(i_screen_width, i_screen_height); double x_scale = (double)i_screen_width / (double)(camera_width); // scale = (double)xsize / (double)(source->xsize); double y_scale = (double)i_screen_height / (double)(camera_height); // scale = (double)ysize / (double)(source->ysize); //projection matrix this.pmat = new NyARPerspectiveProjectionMatrix(); double[] pjv = bis.getDoubleArray(new double[16], 12); pjv[12] = pjv[13] = pjv[14] = 0; pjv[15] = 1; this.pmat.setValue(pjv); this.pmat.changeScale(x_scale, y_scale); //dist factor switch (version) { case 1: //Version1 this.dist_factor = new NyARCameraDistortionFactorV2(bis.getDoubleArray(new double[NyARCameraDistortionFactorV2.NUM_OF_FACTOR]), x_scale, y_scale); break; case 4: //Version4 this.dist_factor = new NyARCameraDistortionFactorV4(bis.getDoubleArray(new double[NyARCameraDistortionFactorV4.NUM_OF_FACTOR]), x_scale, y_scale); break; default: throw new NyARRuntimeException(); } }
/** * 標準パラメータでインスタンスを初期化します。 * @throws NyARException */ public ParamLoader() { double[] df = { 318.5, 263.5, 26.2, 1.0127565206658486 }; double[] pj = { 700.9514702992245, 0, 316.5, 0, 0, 726.0941816535367, 241.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; this.size = new NyARIntSize(640, 480); this.pmat = new NyARPerspectiveProjectionMatrix(); this.pmat.setValue(pj); this.dist_factor = new NyARCameraDistortionFactorV2(); this.dist_factor.setValue(df); }
} /** * この関数は、参照元から歪みパラメータ値をコピーします。 * @param i_ref * コピー元のオブジェクト。 */ public void copyFrom(INyARCameraDistortionFactor i_ref) { NyARCameraDistortionFactorV4 src = (NyARCameraDistortionFactorV4)i_ref; this._k1 = src._k1; this._k2 = src._k2; this._p1 = src._p1; this._p2 = src._p2; this._fx = src._fx; this._fy = src._fy; this._x0 = src._x0; this._y0 = src._y0; this._s = src._s; }
/** * コンストラクタです。 * 輪郭取得元画像の歪み矯正オブジェクトとサイズを指定して、インスタンスを生成します。 * @param i_size * 入力画像のサイズ * @param i_distfactor * 樽型歪みを補正する場合に、オブジェクトを指定します。 * nullの場合、補正を行いません。 */ public NyARCoord2Linear(NyARIntSize i_size, INyARCameraDistortionFactor i_distfactor) { if (i_distfactor != null) { this._dist_factor = new NyARObserv2IdealMap(i_distfactor, i_size); } else { this._dist_factor = null; } // 輪郭バッファ this._pca = new NyARPca2d_MatrixPCA_O2(); this._xpos = new double[i_size.w + i_size.h]; //最大辺長はthis._width+this._height this._ypos = new double[i_size.w + i_size.h]; //最大辺長はthis._width+this._height return; }
/** * 標準パラメータでインスタンスを初期化します。 * @throws NyARRuntimeException */ public ParamLoader(int i_screen_width, int i_screen_height) { double[] df = { 318.5, 263.5, 26.2, 1.0127565206658486 }; double[] pj = { 700.9514702992245, 0, 316.5, 0, 0, 726.0941816535367, 241.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; double x_scale = (double)i_screen_width / (double)(640); // scale = (double)xsize / (double)(source->xsize); double y_scale = (double)i_screen_height / (double)(480); // scale = (double)ysize / (double)(source->ysize); this.size = new NyARIntSize(i_screen_width, i_screen_height); this.pmat = new NyARPerspectiveProjectionMatrix(); this.pmat.setValue(pj); this.pmat.changeScale(x_scale, y_scale); this.dist_factor = new NyARCameraDistortionFactorV2(df, x_scale, y_scale); }
/** * コンストラクタです。 * 輪郭取得元画像の歪み矯正オブジェクトとサイズを指定して、インスタンスを生成します。 * @param i_size * 入力画像のサイズ * @param i_distfactor * 樽型歪みを補正する場合に、オブジェクトを指定します。 * nullの場合、補正を行いません。 */ public NyARCoord2Linear(NyARIntSize i_size, INyARCameraDistortionFactor i_distfactor) { if (i_distfactor != null) { this._dist_factor = new NyARObserv2IdealMap(i_distfactor, i_size); } else { this._dist_factor = null; } // 輪郭バッファ this._pca = new NyARPca2d_MatrixPCA_O2(); this._xpos = new double[i_size.w + i_size.h];//最大辺長はthis._width+this._height this._ypos = new double[i_size.w + i_size.h];//最大辺長はthis._width+this._height return; }
/** * @param i_number_of_sample * サンプラが検出する最大数。 * 通常100~200以上を指定します。(QVGA画像あたり、100個を基準にします。) * 数が少なすぎると、検出率が低下します。最低でも、NyARTrackerに設定するターゲット数の合計*2以上を指定してください。 * @param i_ref_raster_distortion * 歪み矯正の為のオブジェクトを指定します。歪み矯正が必要ない時は、NULLを指定します。 * @param i_width * ソース画像のサイズ * @param i_height * ソース画像のサイズ * @param i_depth * 解像度の深さ(1/(2^n))倍の画像として処理する。 * @param i_is_alloc * ベースラスタのバッファを内部確保外部参照にするかのフラグです。 * trueの場合、バッファは内部に確保され、{@link #wrapBuffer}関数が使用できなくなります。 * @throws NyARException */ public NyARTrackerSource_Reference(int i_number_of_sample, INyARCameraDistortionFactor i_ref_raster_distortion, int i_width, int i_height, int i_depth, bool i_is_alloc) : base((int)Math.Pow(2, i_depth)) { Debug.Assert(i_depth>0); int div=this._rob_resolution; //主GSラスタ this._base_raster=new NyARGrayscaleRaster(i_width,i_height,NyARBufferType.INT1D_GRAY_8,i_is_alloc); this._gs_graphics = NyARGsRasterGraphicsFactory.createDriver(this._base_raster); //Roberts変換ラスタ this._rb_source=new NyARGrayscaleRaster(i_width/div,i_height/div,NyARBufferType.INT1D_GRAY_8, true); //Robertsラスタは最も解像度の低いラスタと同じ this._rbraster=new NyARGrayscaleRaster(i_width/div,i_height/div,NyARBufferType.INT1D_GRAY_8, true); this._vec_reader=new NyARVectorReader_INT1D_GRAY_8(this._base_raster,i_ref_raster_distortion,this._rbraster); //samplerとsampleout this._sampler=new LowResolutionLabelingSampler(i_width, i_height,(int)Math.Pow(2,i_depth)); this._sample_out=new LowResolutionLabelingSamplerOut(i_number_of_sample); }
/** * @param i_number_of_sample * サンプラが検出する最大数。 * 通常100~200以上を指定します。(QVGA画像あたり、100個を基準にします。) * 数が少なすぎると、検出率が低下します。最低でも、NyARTrackerに設定するターゲット数の合計*2以上を指定してください。 * @param i_ref_raster_distortion * 歪み矯正の為のオブジェクトを指定します。歪み矯正が必要ない時は、NULLを指定します。 * @param i_width * ソース画像のサイズ * @param i_height * ソース画像のサイズ * @param i_depth * 解像度の深さ(1/(2^n))倍の画像として処理する。 * @param i_is_alloc * ベースラスタのバッファを内部確保外部参照にするかのフラグです。 * trueの場合、バッファは内部に確保され、{@link #wrapBuffer}関数が使用できなくなります。 * @throws NyARException */ public NyARTrackerSource_Reference(int i_number_of_sample, INyARCameraDistortionFactor i_ref_raster_distortion, int i_width, int i_height, int i_depth, bool i_is_alloc) : base((int)Math.Pow(2, i_depth)) { Debug.Assert(i_depth > 0); int div = this._rob_resolution; //主GSラスタ this._base_raster = new NyARGrayscaleRaster(i_width, i_height, NyARBufferType.INT1D_GRAY_8, i_is_alloc); this._gs_graphics = NyARGsRasterGraphicsFactory.createDriver(this._base_raster); //Roberts変換ラスタ this._rb_source = new NyARGrayscaleRaster(i_width / div, i_height / div, NyARBufferType.INT1D_GRAY_8, true); //Robertsラスタは最も解像度の低いラスタと同じ this._rbraster = new NyARGrayscaleRaster(i_width / div, i_height / div, NyARBufferType.INT1D_GRAY_8, true); this._vec_reader = new NyARVectorReader_INT1D_GRAY_8(this._base_raster, i_ref_raster_distortion, this._rbraster); //samplerとsampleout this._sampler = new LowResolutionLabelingSampler(i_width, i_height, (int)Math.Pow(2, i_depth)); this._sample_out = new LowResolutionLabelingSamplerOut(i_number_of_sample); }
/** * コンストラクタです。 * 入力した{@link NyARCameraDistortionFactor}とそのサイズから、テーブルを作成します。 * 2つのパラメータは整合性が取れていなければなりません。 * (通常は、{@link NyARParam}の{@link NyARParam#getDistortionFactor()},{@link NyARParam#getScreenSize()}から得られた * パラメータを入力します。) * @param i_distfactor * 樽型歪みパラメータのオブジェクト。 * @param i_screen_size * スクリーンサイズ */ public NyARObserv2IdealMap(INyARCameraDistortionFactor i_distfactor, NyARIntSize i_screen_size) { NyARDoublePoint2d opoint = new NyARDoublePoint2d(); this._mapx = new double[i_screen_size.w * i_screen_size.h]; this._mapy = new double[i_screen_size.w * i_screen_size.h]; this._stride = i_screen_size.w; int ptr = i_screen_size.h * i_screen_size.w - 1; //歪みマップを構築 for (int i = i_screen_size.h - 1; i >= 0; i--) { for (int i2 = i_screen_size.w - 1; i2 >= 0; i2--) { i_distfactor.observ2Ideal(i2, i, opoint); this._mapx[ptr] = opoint.x; this._mapy[ptr] = opoint.y; ptr--; } } return; }
/** * intrinsic_matrixとdistortion_coeffsからインスタンスを初期化する。 * @param i_w * カメラパラメータ生成時の画面サイズ * @param i_h * カメラパラメータ生成時の画面サイズ * @param i_intrinsic_matrix 3x3 matrix このパラメータは、OpenCVのcvCalibrateCamera2関数が出力するintrinsic_matrixの値と合致します。 * @param i_distortion_coeffs 4x1 vector このパラメータは、OpenCVのcvCalibrateCamera2関数が出力するdistortion_coeffsの値と合致します。 */ public ParamLoader(int i_w, int i_h, double[] i_intrinsic_matrix, double[] i_distortion_coeffs) { this.size = new NyARIntSize(i_w, i_h); //dist factor NyARCameraDistortionFactorV4 v4dist = new NyARCameraDistortionFactorV4(); v4dist.setValue(this.size, i_intrinsic_matrix, i_distortion_coeffs); double s = v4dist.getS(); this.dist_factor = v4dist; //projection matrix this.pmat = new NyARPerspectiveProjectionMatrix(); NyARDoubleMatrix33 r = new NyARDoubleMatrix33(); r.setValue(i_intrinsic_matrix); r.m00 /= s; r.m01 /= s; r.m10 /= s; r.m11 /= s; this.pmat.setValue(r, new NyARDoublePoint3d()); }
/** * コンストラクタです。 * 入力した{@link INyARCameraDistortionFactor}とそのサイズから、テーブルを作成します。 * 2つのパラメータは整合性が取れていなければなりません。 * (通常は、{@link NyARParam}の{@link NyARParam#getDistortionFactor()},{@link NyARParam#getScreenSize()}から得られた * パラメータを入力します。) * @param i_distfactor * 樽型歪みパラメータのオブジェクト。 * @param i_screen_size * スクリーンサイズ */ public NyARObserv2IdealMap(INyARCameraDistortionFactor i_distfactor, NyARIntSize i_screen_size) { NyARDoublePoint2d opoint = new NyARDoublePoint2d(); this._mapx = new double[i_screen_size.w * i_screen_size.h]; this._mapy = new double[i_screen_size.w * i_screen_size.h]; this._stride = i_screen_size.w; int ptr = i_screen_size.h * i_screen_size.w - 1; //歪みマップを構築 for (int i = i_screen_size.h - 1; i >= 0; i--) { for (int i2 = i_screen_size.w - 1; i2 >= 0; i2--) { i_distfactor.observ2Ideal(i2, i, opoint); this._mapx[ptr] = opoint.x; this._mapy[ptr] = opoint.y; ptr--; } } return; }
public NyARCameraDistortionFactorMap(int i_screen_width, int i_screen_height, INyARCameraDistortionFactor i_base_factor) { this._base_factor = i_base_factor; NyARDoublePoint2d opoint = new NyARDoublePoint2d(); this._mapx = new double[i_screen_width * i_screen_height]; this._mapy = new double[i_screen_width * i_screen_height]; this._stride = i_screen_width; int ptr = i_screen_height * i_screen_width - 1; //歪みマップを構築 for (int i = i_screen_height - 1; i >= 0; i--) { for (int i2 = i_screen_width - 1; i2 >= 0; i2--) { i_base_factor.observ2Ideal(i2, i, opoint); this._mapx[ptr] = opoint.x; this._mapy[ptr] = opoint.y; ptr--; } } return; }
/** * intrinsic_matrixとdistortion_coeffsからインスタンスを初期化する。 * @param i_camera_width * カメラパラメータ生成時の画面サイズ * @param i_camera_height * カメラパラメータ生成時の画面サイズ * @param i_intrinsic_matrix 3x3 matrix このパラメータは、OpenCVのcvCalibrateCamera2関数が出力するintrinsic_matrixの値と合致します。 * @param i_distortion_coeffs 4x1 vector このパラメータは、OpenCVのcvCalibrateCamera2関数が出力するdistortion_coeffsの値と合致します。 */ public ParamLoader(int i_camera_width, int i_camera_height, double[] i_intrinsic_matrix, double[] i_distortion_coeffs, int i_screen_width, int i_screen_height) { double x_scale = (double)i_screen_width / (double)(i_camera_width); // scale = (double)xsize / (double)(source->xsize); double y_scale = (double)i_screen_height / (double)(i_camera_height); // scale = (double)ysize / (double)(source->ysize); this.size = new NyARIntSize(i_camera_width, i_camera_height); //dist factor(倍率1倍の基準点) NyARCameraDistortionFactorV4 v4dist = new NyARCameraDistortionFactorV4(i_camera_width, i_camera_height, i_intrinsic_matrix, i_distortion_coeffs, x_scale, y_scale); double s = v4dist.getS(); //projection matrix NyARDoubleMatrix33 r = new NyARDoubleMatrix33(); r.setValue(i_intrinsic_matrix); r.m00 /= s; r.m01 /= s; r.m10 /= s; r.m11 /= s; NyARPerspectiveProjectionMatrix pm = new NyARPerspectiveProjectionMatrix(); pm.setValue(r, new NyARDoublePoint3d()); pm.changeScale(x_scale, y_scale); this.dist_factor = v4dist; this.pmat = pm; }
/** * コンストラクタから呼び出す共通な初期化部分です。 * @param i_dist_factor * @param i_prjmat * @throws NyARException */ protected void initInstance(NyARIntSize i_screen,double i_near,double i_far,NyARPerspectiveProjectionMatrix i_prjmat,INyARCameraDistortionFactor i_dist_factor) { int number_of_reality_target=this.MAX_LIMIT_KNOWN+this.MAX_LIMIT_UNKNOWN; //演算インスタンス this._transmat=new NyARTransMat(i_dist_factor,i_prjmat); //データインスタンス this._pool=new NyARRealityTargetPool(number_of_reality_target,i_prjmat); this.target=new NyARRealityTargetList(number_of_reality_target); //Trackerの特性値 this._tracker=new NyARTracker((this.MAX_LIMIT_KNOWN+this.MAX_LIMIT_UNKNOWN)*2,1,this.MAX_LIMIT_KNOWN*2); //フラスタムの計算とスクリーンサイズの保存 this._ref_prjmat=i_prjmat; this._frustum=new NyARFrustum(i_prjmat,i_screen.w,i_screen.h, i_near, i_far); //初期化 this._number_of_dead=this._number_of_unknown=this._number_of_known=0; return; }
public NyARParam(NyARIntSize i_screen_size,NyARPerspectiveProjectionMatrix i_projection_mat,INyARCameraDistortionFactor i_dist_factor) { this._screen_size=new NyARIntSize(i_screen_size); this._dist=i_dist_factor; this._projection_matrix=i_projection_mat; }
/** * ストリームから読み出したデータでインスタンスを初期化します。 * @param i_stream * @throws NyARException */ public ParamLoader(StreamReader i_stream) { try { //読み出し ByteBufferedInputStream bis=new ByteBufferedInputStream(i_stream,512); int s=bis.readToBuffer(512); bis.order(ByteBufferedInputStream.ENDIAN_BIG); //読み出したサイズでバージョンを決定 int[] version_table={136,144,152,176}; int version=-1; for(int i=0;i<version_table.Length;i++){ if(s%version_table[i]==0){ version=i+1; break; } } //一致しなければ無し if(version==-1){ throw new NyARException(); } //size this.size=new NyARIntSize(); this.size.setValue(bis.getInt(),bis.getInt()); //projection matrix this.pmat=new NyARPerspectiveProjectionMatrix(); double[] pjv=new double[16]; for(int i=0;i<12;i++){ pjv[i]=bis.getDouble(); } pjv[12]=pjv[13]=pjv[14]=0; pjv[15]=1; this.pmat.setValue(pjv); //dist factor double[] df; switch(version) { case 1://Version1 df=new double[NyARCameraDistortionFactorV2.NUM_OF_FACTOR]; this.dist_factor=new NyARCameraDistortionFactorV2(); break; case 4://Version4 df=new double[NyARCameraDistortionFactorV4.NUM_OF_FACTOR]; this.dist_factor=new NyARCameraDistortionFactorV4(); break; default: throw new NyARException(); } for(int i=0;i<df.Length;i++){ df[i]=bis.getDouble(); } this.dist_factor.setValue(df); } catch (Exception e) { throw new NyARException(e); } }
/** * 標準パラメータでインスタンスを初期化します。 * @throws NyARException */ public ParamLoader() { double[] df={318.5,263.5,26.2,1.0127565206658486}; double[] pj={ 700.9514702992245,0,316.5,0, 0,726.0941816535367,241.5,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0}; this.size=new NyARIntSize(640,480); this.pmat=new NyARPerspectiveProjectionMatrix(); this.pmat.setValue(pj); this.dist_factor=new NyARCameraDistortionFactorV2(); this.dist_factor.setValue(df); }
/** * intrinsic_matrixとdistortion_coeffsからインスタンスを初期化する。 * @param i_w * カメラパラメータ生成時の画面サイズ * @param i_h * カメラパラメータ生成時の画面サイズ * @param i_intrinsic_matrix 3x3 matrix このパラメータは、OpenCVのcvCalibrateCamera2関数が出力するintrinsic_matrixの値と合致します。 * @param i_distortion_coeffs 4x1 vector このパラメータは、OpenCVのcvCalibrateCamera2関数が出力するdistortion_coeffsの値と合致します。 */ public ParamLoader(int i_w, int i_h, double[] i_intrinsic_matrix, double[] i_distortion_coeffs) { this.size = new NyARIntSize(i_w, i_h); //dist factor NyARCameraDistortionFactorV4 v4dist = new NyARCameraDistortionFactorV4(); v4dist.setValue(this.size, i_intrinsic_matrix, i_distortion_coeffs); double s = v4dist.getS(); this.dist_factor = v4dist; //projection matrix this.pmat = new NyARPerspectiveProjectionMatrix(); NyARDoubleMatrix33 r = new NyARDoubleMatrix33(); r.setValue(i_intrinsic_matrix); r.m00 /= s; r.m01 /= s; r.m10 /= s; r.m11 /= s; this.pmat.setValue(r, new NyARDoublePoint3d()); }
/** * ストリームから読み出したデータでインスタンスを初期化します。 * @param i_stream * @throws NyARException */ public ParamLoader(StreamReader i_stream) { try { //読み出し ByteBufferedInputStream bis = new ByteBufferedInputStream(i_stream, 512); int s = bis.readToBuffer(512); bis.order(ByteBufferedInputStream.ENDIAN_BIG); //読み出したサイズでバージョンを決定 int[] version_table = { 136, 144, 152, 176 }; int version = -1; for (int i = 0; i < version_table.Length; i++) { if (s % version_table[i] == 0) { version = i + 1; break; } } //一致しなければ無し if (version == -1) { throw new NyARException(); } //size this.size = new NyARIntSize(); this.size.setValue(bis.getInt(), bis.getInt()); //projection matrix this.pmat = new NyARPerspectiveProjectionMatrix(); double[] pjv = new double[16]; for (int i = 0; i < 12; i++) { pjv[i] = bis.getDouble(); } pjv[12] = pjv[13] = pjv[14] = 0; pjv[15] = 1; this.pmat.setValue(pjv); //dist factor double[] df; switch (version) { case 1: //Version1 df = new double[NyARCameraDistortionFactorV2.NUM_OF_FACTOR]; this.dist_factor = new NyARCameraDistortionFactorV2(); break; case 4: //Version4 df = new double[NyARCameraDistortionFactorV4.NUM_OF_FACTOR]; this.dist_factor = new NyARCameraDistortionFactorV4(); break; default: throw new NyARException(); } for (int i = 0; i < df.Length; i++) { df[i] = bis.getDouble(); } this.dist_factor.setValue(df); } catch (Exception e) { throw new NyARException(e); } }
/** * コンストラクタから呼び出す共通な初期化部分です。 * @param i_dist_factor * @param i_prjmat * @throws NyARException */ protected void InitInstance(NyARIntSize i_screen, double i_near, double i_far, NyARPerspectiveProjectionMatrix i_prjmat, INyARCameraDistortionFactor i_dist_factor) { int number_of_reality_target = this.MAX_LIMIT_KNOWN + this.MAX_LIMIT_UNKNOWN; //演算インスタンス this._transmat = new NyARTransMat(i_dist_factor, i_prjmat); //データインスタンス this._pool = new NyARRealityTargetPool(number_of_reality_target, i_prjmat); this.target = new NyARRealityTargetList(number_of_reality_target); //Trackerの特性値 this._tracker = new NyARTracker((this.MAX_LIMIT_KNOWN + this.MAX_LIMIT_UNKNOWN) * 2, 1, this.MAX_LIMIT_KNOWN * 2); //フラスタムの計算とスクリーンサイズの保存 this._ref_prjmat = i_prjmat; this._frustum = new NyARFrustum(i_prjmat, i_screen.w, i_screen.h, i_near, i_far); //初期化 this._number_of_dead = this._number_of_unknown = this._number_of_known = 0; return; }
/** * コンストラクタ。 * @param i_screen * スクリーン(入力画像)のサイズを指定します。 * @param i_near * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @param i_far * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @param i_prjmat * ARToolKit形式の射影変換パラメータを指定します。 * @param i_dist_factor * カメラ歪み矯正オブジェクトを指定します。歪み矯正が不要な時は、nullを指定します。 * @param i_max_known_target * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @param i_max_unknown_target * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @throws NyARException */ public NyARReality(NyARIntSize i_screen, double i_near, double i_far, NyARPerspectiveProjectionMatrix i_prjmat, INyARCameraDistortionFactor i_dist_factor, int i_max_known_target, int i_max_unknown_target) { this.MAX_LIMIT_KNOWN = i_max_known_target; this.MAX_LIMIT_UNKNOWN = i_max_unknown_target; this.InitInstance(i_screen, i_near, i_far, i_prjmat, i_dist_factor); }
/** * 元ar2GenTemplate関数。 * 与えられた座標を中心に、テンプレート画像を生成する。 * 座標は観察座標点。 * @param i_x * @param i_y * @param i_scale * @param o_template * @return * @throws NyARException */ public void makeFromReferenceImage(double i_x, double i_y, NyARDoubleMatrix44 i_ref_ctrans, INyARCameraDistortionFactor i_ref_dist_factor, NyARNftIsetFile.ReferenceImage i_source) { int[] img = this.img; int img1_ptr = 0; int k = 0; int sum2 = 0; int sum = 0; NyARDoublePoint2d ideal = this.__in; for (int j = -(this.yts); j <= this.yts; j++) { for (int i = -(this.xts); i <= this.xts; i++) { i_ref_dist_factor.observ2Ideal(i_x + i * AR2_TEMP_SCALE, i_y + j * AR2_TEMP_SCALE, ideal); double ideal_x = ideal.x; double ideal_y = ideal.y; //ar2ScreenCoord2MarkerCoord(in.x,in.y,i_ref_ctrans,in);の展開 double c11 = i_ref_ctrans.m20 * ideal_x - i_ref_ctrans.m00; double c12 = i_ref_ctrans.m21 * ideal_x - i_ref_ctrans.m01; double c21 = i_ref_ctrans.m20 * ideal_y - i_ref_ctrans.m10; double c22 = i_ref_ctrans.m21 * ideal_y - i_ref_ctrans.m11; double b1 = i_ref_ctrans.m03 - i_ref_ctrans.m23 * ideal_x; double b2 = i_ref_ctrans.m13 - i_ref_ctrans.m23 * ideal_y; double m = c11 * c22 - c12 * c21; //public int ar2GetImageValue(double sx, double sy) throws NyARExceptionの展開 { int ix = (int)((((c22 * b1 - c12 * b2) / m) * i_source.dpi / 25.4f) + 0.5); int iy = (int)((i_source.height - (((c11 * b2 - c21 * b1) / m) * i_source.dpi) / 25.4f) + 0.5); //座標計算と値取得は分けよう。 if (ix < 0 || ix >= i_source.width || iy < 0 || iy >= i_source.height) { img[img1_ptr] = AR2_TEMPLATE_NULL_PIXEL; } else { int ret = img[img1_ptr] = i_source.img[iy * i_source.width + ix]; sum2 += ret * ret; sum += ret; k++; } //byte値はint化 } img1_ptr++; } } int vlen = sum2 - sum * sum / k; this.vlen = (int)Math.Sqrt((double)(vlen)); this.sum_of_img = sum; this.valid_pixels = k; return; }
/** * コンストラクタ。 * @param i_screen * スクリーン(入力画像)のサイズを指定します。 * @param i_near * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @param i_far * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @param i_prjmat * ARToolKit形式の射影変換パラメータを指定します。 * @param i_dist_factor * カメラ歪み矯正オブジェクトを指定します。歪み矯正が不要な時は、nullを指定します。 * @param i_max_known_target * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @param i_max_unknown_target * {@link #NyARReality(NyARParam i_param,double i_near,double i_far,int i_max_known_target,int i_max_unknown_target)}を参照 * @throws NyARException */ public NyARReality(NyARIntSize i_screen,double i_near,double i_far,NyARPerspectiveProjectionMatrix i_prjmat,INyARCameraDistortionFactor i_dist_factor,int i_max_known_target,int i_max_unknown_target) { this.MAX_LIMIT_KNOWN=i_max_known_target; this.MAX_LIMIT_UNKNOWN=i_max_unknown_target; this.initInstance(i_screen,i_near,i_far,i_prjmat,i_dist_factor); }
/** * タイプに応じた歪み矯正クラスを生成して返します。 * @param i_screen_size * @param i_base_factor * @param i_type * @return */ private static INyARCameraDistortionFactor makeDistFactor(NyARIntSize i_screen_size, INyARCameraDistortionFactor i_base_factor, int i_type) { switch (i_type) { case DISTFACTOR_RAW: return(i_base_factor); case DISTFACTOR_LT_ARTK2: return(new NyARCameraDistortionFactorMap(i_screen_size.w, i_screen_size.h, i_base_factor)); case DISTFACTOR_LT_ARTK5: return(new NyARCameraDistortionFactorLT(i_screen_size.w, i_screen_size.h, NyARCameraDistortionFactorLT.AR_PARAM_LT_DEFAULT_OFFSET, i_base_factor)); default: throw new NyARRuntimeException(); } }
public void extractVisibleFeatures( NyARNftFsetFile i_fset, NyARSurfaceTransMatrixSet i_ctrans, NyARSurfaceFeatures candidate, NyARSurfaceFeatures candidate2) { //get work objects NyARDoublePoint2d ide2d = this.__ide2d; NyARDoublePoint2d obs2d = this.__obs2d; NyARDoublePoint2d rideal2d = this.__rideal2d; // trans1.setCoefficient(i_cparam.getPerspectiveProjectionMatrix(), trans1); candidate.clear(); candidate2.clear(); int xsize = this._ref_size.w; int ysize = this._ref_size.h; INyARCameraDistortionFactor df = this._ref_dist_factor; for (int j = 0; j < i_fset.list.Length; j++) { NyARNftFsetFile.NyAR2FeaturePoints fpoint_ptr = i_fset.list[j]; for (int k = 0; k < fpoint_ptr.coord.Length; k++) { NyARNftFsetFile.NyAR2FeatureCoord coord_ptr = fpoint_ptr.coord[k]; //理想画面点を計算 i_ctrans.calculate2dPos(coord_ptr.mx, coord_ptr.my, ide2d); df.ideal2Observ(ide2d.x, ide2d.y, obs2d); //観察座標に変換後、画面内にあるか確認 if (obs2d.x < 0 || obs2d.x >= xsize) { continue; } if (obs2d.y < 0 || obs2d.y >= ysize) { continue; } //逆変換可能か確認 df.observ2Ideal(obs2d, rideal2d); if (ide2d.sqDist(rideal2d) > 1.0) { continue; } //原点からのベクトルを計算 //Z軸が+だとつかえないので判定? if (i_ctrans.calculateVd(coord_ptr.mx, coord_ptr.my) > -0.1) { continue; } // double vd0 = trans1.m00 * coord_ptr.mx+ trans1.m01 * coord_ptr.my+ trans1.m03; // double vd1 = trans1.m10 * coord_ptr.mx+ trans1.m11 * coord_ptr.my+ trans1.m13; // double vd2 = trans1.m20 * coord_ptr.mx+ trans1.m21 * coord_ptr.my+ trans1.m23; // if( (vd0*trans1.m02 + vd1*trans1.m12 + vd2*trans1.m22)/Math.sqrt( vd0*vd0 + vd1*vd1 + vd2*vd2 ) > -0.1 ){ // continue; // } //撮影箇所のdpiを計算(x,y方向で計算して、大・小の順番で格納?) double dpi = i_ctrans.ar2GetMinResolution(coord_ptr); //dpiによってコレクトする候補を分離 if (dpi <= fpoint_ptr.maxdpi && dpi >= fpoint_ptr.mindpi) { NyARSurfaceFeatureItem item = candidate.prePush(); if (item == null) { return; } item.ref_feature = coord_ptr; item.scale = fpoint_ptr.scale; item.x = obs2d.x; item.y = obs2d.y; } else if (dpi <= fpoint_ptr.maxdpi * 2 && dpi >= fpoint_ptr.mindpi / 2) { NyARSurfaceFeatureItem item = candidate2.prePush(); if (item == null) { return; } item.ref_feature = coord_ptr; item.scale = fpoint_ptr.scale; item.x = obs2d.x; item.y = obs2d.y; } } } return; }
public PatchImagePositions(INyARCameraDistortionFactor i_ref_distortionFactor) { this._ref_df = i_ref_distortionFactor; }
} /** * この関数は、参照元から歪みパラメータ値をコピーします。 * @param i_ref * コピー元のオブジェクト。 */ public void copyFrom(INyARCameraDistortionFactor i_ref) { NyARCameraDistortionFactorV4 src = (NyARCameraDistortionFactorV4)i_ref; this._k1 = src._k1; this._k2 = src._k2; this._p1 = src._p1; this._p2 = src._p2; this._fx = src._fx; this._fy = src._fy; this._x0 = src._x0; this._y0 = src._y0; this._s = src._s; }
/** * コンストラクタです。 * 座標計算に必要なオブジェクトの参照値を元に、インスタンスを生成します。 * @param i_ref_distfactor * 樽型歪み矯正オブジェクトの参照値です。歪み矯正が不要な時は、nullを指定します。 * @param i_ref_projmat * 射影変換オブジェクトの参照値です。 * @ */ public NyARTransMat_ARToolKit(INyARCameraDistortionFactor i_ref_distfactor, NyARPerspectiveProjectionMatrix i_ref_projmat) { initInstance(i_ref_distfactor, i_ref_projmat); return; }
public NyARParam(NyARIntSize i_screen_size, NyARPerspectiveProjectionMatrix i_projection_mat, INyARCameraDistortionFactor i_dist_factor) { this._screen_size = new NyARIntSize(i_screen_size); this._dist = i_dist_factor; this._projection_matrix = i_projection_mat; }
/** * コンストラクタです。 * 座標計算に必要なオブジェクトの参照値を元に、インスタンスを生成します。 * @param i_ref_distfactor * 樽型歪み矯正オブジェクトの参照値です。歪み矯正が不要な時は、nullを指定します。 * @param i_ref_projmat * 射影変換オブジェクトの参照値です。 * @ */ public NyARTransMat(INyARCameraDistortionFactor i_ref_distfactor, NyARPerspectiveProjectionMatrix i_ref_projmat) { initInstance(i_ref_distfactor, i_ref_projmat); return; }
public NyARVisibleFeatureExtractor(NyARIntSize i_ref_screen_size, INyARCameraDistortionFactor i_ref_dist_factor) { this._ref_size = i_ref_screen_size; this._ref_dist_factor = i_ref_dist_factor; }