public NyARSurfaceTrackingTransmatUtils(NyARParam i_ref_param, double i_tracking_threshold) { this._surface_threshold = i_tracking_threshold; this._icp = new NyARIcpPoint(i_ref_param.getPerspectiveProjectionMatrix()); this._icp_r = new NyARIcpPointRobust(i_ref_param.getPerspectiveProjectionMatrix()); this._last_inliner_probability = 0; }
/** * コンストラクタ。 * 樽型歪みが少ない、または補正済みの画像を入力するときには、{@link #NyARReality(NyARIntSize, double, double, NyARPerspectiveProjectionMatrix, NyARCameraDistortionFactor, int, int)} * のi_dist_factorにnullを指定すると、より高速な動作が期待できます。 * @param i_param * カメラパラメータを指定します。 * @param i_near * 視錐体のnear-pointをmm単位で指定します。 * default値は{@link #FRASTRAM_ARTK_NEAR}です。 * @param i_far * 視錐体のfar-pointをmm単位で指定します。 * default値は{@link #FRASTRAM_ARTK_FAR}です。 * @param i_max_known_target * Knownターゲットの最大数を指定します。 * @param i_max_unknown_target * UnKnownターゲットの最大数を指定します。 * @throws NyARException */ public NyARReality(NyARParam i_param, double i_near, double i_far, 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_param.getScreenSize(), i_near, i_far, i_param.getPerspectiveProjectionMatrix(), i_param.getDistortionFactor()); return; }
/** * The constructor. * @param i_param * ARToolkit parameter object that finished setup. * @param i_al_mode * fitting algorism type. * @throws NyARException */ public NyARIcpTransMat(NyARParam i_param, int i_al_mode) { this._icpc = new NyARIcpPlane(i_param.getPerspectiveProjectionMatrix()); switch (i_al_mode) { case AL_POINT: this._icpp = new NyARIcpPoint(i_param.getPerspectiveProjectionMatrix()); break; case AL_POINT_ROBUST: this._icpp = new NyARIcpPointRobust(i_param.getPerspectiveProjectionMatrix()); break; default: throw new System.ArgumentException(); } return; }
public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device) { topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT); //キャプチャを作る(QVGAでフレームレートは30) i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //ARラスタを作る(DirectShowキャプチャ仕様)。 this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height); //AR用カメラパラメタファイルをロードして設定 NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), SCREEN_WIDTH, SCREEN_HEIGHT); //Direct3d用のユーティリティ準備 //プロセッサの準備 this._processor = new MarkerProcessor(ap, this._raster.getBufferType()); NyARCode[] codes = new NyARCode[2]; codes[0] = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE1), 16, 16); codes[1] = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE2), 16, 16); this._processor.setARCodeTable(codes, 16, 80.0); //3dデバイスを準備する this._device = PrepareD3dDevice(topLevelForm); this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; this._device.RenderState.CullMode = Cull.CounterClockwise; Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; //ビューポート設定 this._device.Viewport = vp; this._text = new TextPanel(this._device, 1); //カメラProjectionの設定 Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp); this._device.Transform.Projection = tmp; // ビュー変換の設定(左手座標系ビュー行列で設定する) // 0,0,0から、Z+方向を向いて、上方向がY軸 this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); //背景サーフェイスを作成 this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); return(true); }
public NyARIcp(NyARParam i_param) { this._ref_matXc2U = i_param.getPerspectiveProjectionMatrix(); this._maxLoop = ICP_MAX_LOOP; this.breakLoopErrorThresh = ICP_BREAK_LOOP_ERROR_THRESH; this.breakLoopErrorRatioThresh = ICP_BREAK_LOOP_ERROR_RATIO_THRESH; this.breakLoopErrorThresh2 = ICP_BREAK_LOOP_ERROR_THRESH2; this.inlierProb = ICP_INLIER_PROBABILITY; }
public NyARTransMat_ARToolKit(NyARParam i_param) { NyARCameraDistortionFactor dist = i_param.getDistortionFactor(); NyARPerspectiveProjectionMatrix pmat = i_param.getPerspectiveProjectionMatrix(); 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; }
public NyARIcpStereo(NyARParam i_param_l, NyARParam i_param_r, NyARDoubleMatrix44 i_matC2_l, NyARDoubleMatrix44 i_matC2_r) { this.maxLoop = ICP_MAX_LOOP; this.breakLoopErrorThresh = ICP_BREAK_LOOP_ERROR_THRESH; this.breakLoopErrorRatioThresh = ICP_BREAK_LOOP_ERROR_RATIO_THRESH; this.breakLoopErrorThresh2 = ICP_BREAK_LOOP_ERROR_THRESH2; this.inlierProb = ICP_INLIER_PROBABILITY; this._ref_matXcl2Ul = i_param_l.getPerspectiveProjectionMatrix(); this._ref_matXcr2Ur = i_param_r.getPerspectiveProjectionMatrix(); this._matC2L = i_matC2_l; this._matC2R = i_matC2_r; return; }
/** * コンストラクタです。 * 座標計算に必要なカメラパラメータの参照値を元に、インスタンスを生成します。 * @param i_param * ARToolKit形式のカメラパラメータです。 * インスタンスは、この中から樽型歪み矯正オブジェクト、射影変換オブジェクトを参照します。 * @ */ public NyARTransMat_ARToolKit(NyARParam i_param) { initInstance(i_param.getDistortionFactor(), i_param.getPerspectiveProjectionMatrix()); }
private Matrix GetProjectionMatrix(NyARParam i_arparam, float near, float far) { NyARMat trans_mat = new NyARMat(3, 4); NyARMat icpara_mat = new NyARMat(3, 4); double[,] p = new double[3, 3], q = new double[4, 4]; int width, height; int i, j; NyARIntSize size = i_arparam.getScreenSize(); width = size.w; height = size.h; i_arparam.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat); double[][] icpara = icpara_mat.getArray(); double[][] trans = trans_mat.getArray(); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { p[i, j] = icpara[i][j] / icpara[2][2]; } } q[0, 0] = (2.0 * p[0, 0] / (width)); q[0, 1] = (2.0 * p[0, 1] / (width)); q[0, 2] = ((2.0 * p[0, 2] / (width)) - 1.0); q[0, 3] = 0.0; q[1, 0] = 0.0; q[1, 1] = (2.0 * p[1, 1] / (height)); q[1, 2] = ((2.0 * p[1, 2] / (height)) - 1.0); q[1, 3] = 0.0; q[2, 0] = 0.0; q[2, 1] = 0.0; q[2, 2] = (far + near) / (far - near); q[2, 3] = -2.0 * far * near / (far - near); q[3, 0] = 0.0; q[3, 1] = 0.0; q[3, 2] = 1.0; q[3, 3] = 0.0; Matrix mat = Matrix.Identity; mat.M11 = (float)(q[0, 0] * trans[0][0] + q[0, 1] * trans[1][0] + q[0, 2] * trans[2][0]); mat.M12 = (float)(q[1, 0] * trans[0][0] + q[1, 1] * trans[1][0] + q[1, 2] * trans[2][0]); mat.M13 = (float)(q[2, 0] * trans[0][0] + q[2, 1] * trans[1][0] + q[2, 2] * trans[2][0]); mat.M14 = (float)(q[3, 0] * trans[0][0] + q[3, 1] * trans[1][0] + q[3, 2] * trans[2][0]); mat.M21 = (float)(q[0, 1] * trans[0][1] + q[0, 1] * trans[1][1] + q[0, 2] * trans[2][1]); mat.M22 = (float)(q[1, 1] * trans[0][1] + q[1, 1] * trans[1][1] + q[1, 2] * trans[2][1]); mat.M23 = (float)(q[2, 1] * trans[0][1] + q[2, 1] * trans[1][1] + q[2, 2] * trans[2][1]); mat.M24 = (float)(q[3, 1] * trans[0][1] + q[3, 1] * trans[1][1] + q[3, 2] * trans[2][1]); mat.M31 = (float)(q[0, 2] * trans[0][2] + q[0, 1] * trans[1][2] + q[0, 2] * trans[2][2]); mat.M32 = (float)(q[1, 2] * trans[0][2] + q[1, 1] * trans[1][2] + q[1, 2] * trans[2][2]); mat.M33 = -(float)(q[2, 2] * trans[0][2] + q[2, 1] * trans[1][2] + q[2, 2] * trans[2][2]); mat.M34 = -(float)(q[3, 2] * trans[0][2] + q[3, 1] * trans[1][2] + q[3, 2] * trans[2][2]); mat.M41 = (float)(q[0, 3] * trans[0][3] + q[0, 1] * trans[1][3] + q[0, 2] * trans[2][3] + q[0, 3]); mat.M42 = (float)(q[1, 3] * trans[0][3] + q[1, 1] * trans[1][3] + q[1, 2] * trans[2][3] + q[1, 3]); mat.M43 = (float)(q[2, 3] * trans[0][3] + q[2, 1] * trans[1][3] + q[2, 2] * trans[2][3] + q[2, 3]); mat.M44 = (float)(q[3, 3] * trans[0][3] + q[3, 1] * trans[1][3] + q[3, 2] * trans[2][3] + q[3, 3]); return mat; }
public static void toCameraFrustumRH(NyARParam i_arparam, double i_near, double i_far, ref Matrix o_d3d_projection) { NyARMat trans_mat = new NyARMat(3, 4); NyARMat icpara_mat = new NyARMat(3, 4); double[,] p = new double[3, 3], q = new double[4, 4]; int width, height; int i, j; NyARIntSize size = i_arparam.getScreenSize(); width = size.w; height = size.h; i_arparam.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat); double[][] icpara = icpara_mat.getArray(); double[][] trans = trans_mat.getArray(); for (i = 0; i < 4; i++) { icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i]; } for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { p[i, j] = icpara[i][j] / icpara[2][2]; } } q[0, 0] = (2.0 * p[0, 0] / (width - 1)); q[0, 1] = (2.0 * p[0, 1] / (width - 1)); q[0, 2] = ((2.0 * p[0, 2] / (width - 1)) - 1.0); q[0, 3] = 0.0; q[1, 0] = 0.0; q[1, 1] = -(2.0 * p[1, 1] / (height - 1)); q[1, 2] = -((2.0 * p[1, 2] / (height - 1)) - 1.0); q[1, 3] = 0.0; q[2, 0] = 0.0; q[2, 1] = 0.0; q[2, 2] = (i_far + i_near) / (i_near - i_far); q[2, 3] = 2.0 * i_far * i_near / (i_near - i_far); q[3, 0] = 0.0; q[3, 1] = 0.0; q[3, 2] = -1.0; q[3, 3] = 0.0; o_d3d_projection.M11 = (float)(q[0, 0] * trans[0][0] + q[0, 1] * trans[1][0] + q[0, 2] * trans[2][0]); o_d3d_projection.M12 = (float)(q[1, 0] * trans[0][0] + q[1, 1] * trans[1][0] + q[1, 2] * trans[2][0]); o_d3d_projection.M13 = (float)(q[2, 0] * trans[0][0] + q[2, 1] * trans[1][0] + q[2, 2] * trans[2][0]); o_d3d_projection.M14 = (float)(q[3, 0] * trans[0][0] + q[3, 1] * trans[1][0] + q[3, 2] * trans[2][0]); o_d3d_projection.M21 = (float)(q[0, 0] * trans[0][1] + q[0, 1] * trans[1][1] + q[0, 2] * trans[2][1]); o_d3d_projection.M22 = (float)(q[1, 0] * trans[0][1] + q[1, 1] * trans[1][1] + q[1, 2] * trans[2][1]); o_d3d_projection.M23 = (float)(q[2, 0] * trans[0][1] + q[2, 1] * trans[1][1] + q[2, 2] * trans[2][1]); o_d3d_projection.M24 = (float)(q[3, 0] * trans[0][1] + q[3, 1] * trans[1][1] + q[3, 2] * trans[2][1]); o_d3d_projection.M31 = (float)(q[0, 0] * trans[0][2] + q[0, 1] * trans[1][2] + q[0, 2] * trans[2][2]); o_d3d_projection.M32 = (float)(q[1, 0] * trans[0][2] + q[1, 1] * trans[1][2] + q[1, 2] * trans[2][2]); o_d3d_projection.M33 = (float)(q[2, 0] * trans[0][2] + q[2, 1] * trans[1][2] + q[2, 2] * trans[2][2]); o_d3d_projection.M34 = (float)(q[3, 0] * trans[0][2] + q[3, 1] * trans[1][2] + q[3, 2] * trans[2][2]); o_d3d_projection.M41 = (float)(q[0, 0] * trans[0][3] + q[0, 1] * trans[1][3] + q[0, 2] * trans[2][3] + q[0, 3]); o_d3d_projection.M42 = (float)(q[1, 0] * trans[0][3] + q[1, 1] * trans[1][3] + q[1, 2] * trans[2][3] + q[1, 3]); o_d3d_projection.M43 = (float)(q[2, 0] * trans[0][3] + q[2, 1] * trans[1][3] + q[2, 2] * trans[2][3] + q[2, 3]); o_d3d_projection.M44 = (float)(q[3, 0] * trans[0][3] + q[3, 1] * trans[1][3] + q[3, 2] * trans[2][3] + q[3, 3]); return; }
public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device) { topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT); //キャプチャを作る(QVGAでフレームレートは30) i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //ARの設定 //ARラスタを作る(DirectShowキャプチャ仕様)。 this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height); //AR用カメラパラメタファイルをロードして設定 NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), SCREEN_WIDTH, SCREEN_HEIGHT); //AR用のパターンコードを読み出し NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE), 16, 16); //1パターンのみを追跡するクラスを作成 this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT); //計算モードの設定 this._ar.setContinueMode(true); //3dデバイスを準備する this._device = PrepareD3dDevice(topLevelForm); this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; //カメラProjectionの設定 Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp); this._device.Transform.Projection = tmp; // ビュー変換の設定(左手座標系ビュー行列で設定する) // 0,0,0から、Z+方向を向いて、上方向がY軸 this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; //ビューポート設定 this._device.Viewport = vp; //カラーキューブの描画インスタンス this._cube = new ColorCube(this._device, 40); //背景サーフェイスを作成 this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); this._is_marker_enable = false; return(true); }
/** * コンストラクタです。 * 座標計算に必要なカメラパラメータの参照値を元に、インスタンスを生成します。 * @param i_param * ARToolKit形式のカメラパラメータです。 * インスタンスは、この中から樽型歪み矯正オブジェクト、射影変換オブジェクトを参照します。 * @ */ public NyARTransMat_ARToolKit(NyARParam i_param) : this(i_param.getDistortionFactor(), i_param.getPerspectiveProjectionMatrix()) { }
public NyARTransMat_ARToolKit(NyARParam i_param) { initInstance(i_param.getDistortionFactor(), i_param.getPerspectiveProjectionMatrix()); }
public static void toCameraFrustumRH(NyARParam i_arparam, double i_near, double i_far, ref Matrix o_d3d_projection) { toCameraFrustumRH(i_arparam.getPerspectiveProjectionMatrix(), i_arparam.getScreenSize(), 1.0, i_near, i_far, ref o_d3d_projection); }
/// <summary> /// Returns a right-handed perspective transformation matrix built from the camera calibration data. /// </summary> /// <param name="arParameters">The camera calibration data.</param> /// <param name="nearPlane">The near view plane of the frustum.</param> /// <param name="farPlane">The far view plane of the frustum.</param> /// <returns>The projection matrix.</returns> internal static Matrix3D GetCameraFrustumRH(this NyARParam arParameters, double nearPlane, double farPlane) { NyARMat transformation = new NyARMat(3, 4); NyARMat icParameters = new NyARMat(3, 4); double[,] p = new double[3, 3]; double[,] q = new double[4, 4]; NyARIntSize size = arParameters.getScreenSize(); int width = size.w; int height = size.h; arParameters.getPerspectiveProjectionMatrix().decompMat(icParameters, transformation); double[][] icpara = icParameters.getArray(); double[][] trans = transformation.getArray(); for (int i = 0; i < 4; i++) { icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { p[i, j] = icpara[i][j] / icpara[2][2]; } } q[0, 0] = (2.0 * p[0, 0] / (width - 1)); q[0, 1] = (2.0 * p[0, 1] / (width - 1)); q[0, 2] = ((2.0 * p[0, 2] / (width - 1)) - 1.0); q[0, 3] = 0.0; q[1, 0] = 0.0; q[1, 1] = -(2.0 * p[1, 1] / (height - 1)); q[1, 2] = -((2.0 * p[1, 2] / (height - 1)) - 1.0); q[1, 3] = 0.0; q[2, 0] = 0.0; q[2, 1] = 0.0; q[2, 2] = (farPlane + nearPlane) / (nearPlane - farPlane); q[2, 3] = 2.0 * farPlane * nearPlane / (nearPlane - farPlane); q[3, 0] = 0.0; q[3, 1] = 0.0; q[3, 2] = -1.0; q[3, 3] = 0.0; return(new Matrix3D(q[0, 0] * trans[0][0] + q[0, 1] * trans[1][0] + q[0, 2] * trans[2][0], q[1, 0] * trans[0][0] + q[1, 1] * trans[1][0] + q[1, 2] * trans[2][0], q[2, 0] * trans[0][0] + q[2, 1] * trans[1][0] + q[2, 2] * trans[2][0], q[3, 0] * trans[0][0] + q[3, 1] * trans[1][0] + q[3, 2] * trans[2][0], q[0, 0] * trans[0][1] + q[0, 1] * trans[1][1] + q[0, 2] * trans[2][1], q[1, 0] * trans[0][1] + q[1, 1] * trans[1][1] + q[1, 2] * trans[2][1], q[2, 0] * trans[0][1] + q[2, 1] * trans[1][1] + q[2, 2] * trans[2][1], q[3, 0] * trans[0][1] + q[3, 1] * trans[1][1] + q[3, 2] * trans[2][1], q[0, 0] * trans[0][2] + q[0, 1] * trans[1][2] + q[0, 2] * trans[2][2], q[1, 0] * trans[0][2] + q[1, 1] * trans[1][2] + q[1, 2] * trans[2][2], q[2, 0] * trans[0][2] + q[2, 1] * trans[1][2] + q[2, 2] * trans[2][2], q[3, 0] * trans[0][2] + q[3, 1] * trans[1][2] + q[3, 2] * trans[2][2], q[0, 0] * trans[0][3] + q[0, 1] * trans[1][3] + q[0, 2] * trans[2][3] + q[0, 3], q[1, 0] * trans[0][3] + q[1, 1] * trans[1][3] + q[1, 2] * trans[2][3] + q[1, 3], q[2, 0] * trans[0][3] + q[2, 1] * trans[1][3] + q[2, 2] * trans[2][3] + q[2, 3], q[3, 0] * trans[0][3] + q[3, 1] * trans[1][3] + q[3, 2] * trans[2][3] + q[3, 3])); }
public NyARWordsBingoCore(Label lbl, Game currentGame, PictureBox pbx) { //Instanciando o PictureBox com o recebido do Form pbxNyAR = pbx; lbNyAR = lbl; gmNyAR = currentGame; //Parâmetros da RA NyARParam ap = new NyARParam(); ap.loadARParamFromFile(AR_CAMERA_FILE); //Lendo arquivo .dat ap.changeScreenSize(640, 480); //Setando tamanho da câmera. //Lendo padrão do marcador NyARCode codeKanji = new NyARCode(16, 16); NyARCode codeA = new NyARCode(16, 16); NyARCode codeB = new NyARCode(16, 16); NyARCode codeC = new NyARCode(16, 16); NyARCode codeD = new NyARCode(16, 16); NyARCode codeE = new NyARCode(16, 16); NyARCode codeF = new NyARCode(16, 16); NyARCode codeG = new NyARCode(16, 16); NyARCode codeH = new NyARCode(16, 16); NyARCode codeI = new NyARCode(16, 16); NyARCode codeJ = new NyARCode(16, 16); NyARCode codeK = new NyARCode(16, 16); NyARCode codeL = new NyARCode(16, 16); NyARCode codeM = new NyARCode(16, 16); NyARCode codeN = new NyARCode(16, 16); NyARCode codeO = new NyARCode(16, 16); NyARCode codeP = new NyARCode(16, 16); NyARCode codeQ = new NyARCode(16, 16); NyARCode codeR = new NyARCode(16, 16); NyARCode codeS = new NyARCode(16, 16); NyARCode codeT = new NyARCode(16, 16); NyARCode codeU = new NyARCode(16, 16); NyARCode codeV = new NyARCode(16, 16); NyARCode codeW = new NyARCode(16, 16); NyARCode codeX = new NyARCode(16, 16); NyARCode codeY = new NyARCode(16, 16); NyARCode codeZ = new NyARCode(16, 16); NyARCode codeBall = new NyARCode(16, 16); NyARCode codeSword = new NyARCode(16, 16); NyARCode codeCar = new NyARCode(16, 16); NyARCode codeBrigadier = new NyARCode(16, 16); NyARCode codeFork = new NyARCode(16, 16); NyARCode codePen = new NyARCode(16, 16); NyARCode codeFish = new NyARCode(16, 16); //Carregando os arquivos dos marcadores no NyARCode codeKanji.loadARPattFromFile(AR_CODE_FILE_KANJI); codeA.loadARPattFromFile(AR_CODE_FILE_A); codeB.loadARPattFromFile(AR_CODE_FILE_B); codeC.loadARPattFromFile(AR_CODE_FILE_C); codeD.loadARPattFromFile(AR_CODE_FILE_D); codeE.loadARPattFromFile(AR_CODE_FILE_E); codeF.loadARPattFromFile(AR_CODE_FILE_F); codeG.loadARPattFromFile(AR_CODE_FILE_G); codeH.loadARPattFromFile(AR_CODE_FILE_H); codeI.loadARPattFromFile(AR_CODE_FILE_I); codeJ.loadARPattFromFile(AR_CODE_FILE_J); codeK.loadARPattFromFile(AR_CODE_FILE_K); codeL.loadARPattFromFile(AR_CODE_FILE_L); codeM.loadARPattFromFile(AR_CODE_FILE_M); codeN.loadARPattFromFile(AR_CODE_FILE_N); codeO.loadARPattFromFile(AR_CODE_FILE_O); codeP.loadARPattFromFile(AR_CODE_FILE_P); codeQ.loadARPattFromFile(AR_CODE_FILE_Q); codeR.loadARPattFromFile(AR_CODE_FILE_R); codeS.loadARPattFromFile(AR_CODE_FILE_S); codeT.loadARPattFromFile(AR_CODE_FILE_T); codeU.loadARPattFromFile(AR_CODE_FILE_U); codeV.loadARPattFromFile(AR_CODE_FILE_V); codeW.loadARPattFromFile(AR_CODE_FILE_W); codeX.loadARPattFromFile(AR_CODE_FILE_X); codeY.loadARPattFromFile(AR_CODE_FILE_Y); codeZ.loadARPattFromFile(AR_CODE_FILE_Z); codeBall.loadARPattFromFile(AR_CODE_FILE_BALL); codeSword.loadARPattFromFile(AR_CODE_FILE_SWORD); codeCar.loadARPattFromFile(AR_CODE_FILE_CAR); codeBrigadier.loadARPattFromFile(AR_CODE_FILE_BRIGADIER); codeFork.loadARPattFromFile(AR_CODE_FILE_FORK); codePen.loadARPattFromFile(AR_CODE_FILE_PEN); codeFish.loadARPattFromFile(AR_CODE_FILE_FISH); double[] WidthArray = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 }; NyARCode[] arrayCodes = { codeKanji, codeA, codeB, codeC, codeD, codeE, codeF, codeG, codeH, codeI, codeJ, codeK, codeL, codeM, codeN, codeO, codeP, codeQ, codeR, codeS, codeT, codeU, codeV, codeW, codeX, codeY, codeZ }; double[] WidthArrayImages = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 }; NyARCode[] arrayCodesImage = { codeBall, codeSword, codeCar, codeBrigadier, codeFork, codePen, codeFish }; //Seta propriedades da câmera try { Core.cap.SetCaptureListener(this); } catch (Exception e) { MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente. Favor, reinicie a aplicação.", "Erro!"); Environment.Exit(0); } Core.cap.PrepareCapture(640, 480, 30); //Create a cluster - Instanciando o Raster, passando os parâmetros do vídeo encontrado no CaptureDevice Core.raster = Core.InstanceRaster(Core.cap.video_width, Core.cap.video_height); //Instanciando os detectores únicos this.ballMarkerDetector = new NyARSingleDetectMarker(ap, codeBall, 80.0, Core.raster.getBufferType()); this.ballMarkerDetector.setContinueMode(true); this.brigadierlMarkerDetector = new NyARSingleDetectMarker(ap, codeBrigadier, 80.0, Core.raster.getBufferType()); this.brigadierlMarkerDetector.setContinueMode(true); this.carMarkerDetector = new NyARSingleDetectMarker(ap, codeCar, 80.0, Core.raster.getBufferType()); this.carMarkerDetector.setContinueMode(true); this.forkMarkerDetector = new NyARSingleDetectMarker(ap, codeFork, 80.0, Core.raster.getBufferType()); this.forkMarkerDetector.setContinueMode(true); this.penMarkerDetector = new NyARSingleDetectMarker(ap, codePen, 80.0, Core.raster.getBufferType()); this.penMarkerDetector.setContinueMode(true); this.swordMarkerDetector = new NyARSingleDetectMarker(ap, codeSword, 80.0, Core.raster.getBufferType()); this.swordMarkerDetector.setContinueMode(true); this.fishMarkerDetector = new NyARSingleDetectMarker(ap, codeFish, 80.0, Core.raster.getBufferType()); this.fishMarkerDetector.setContinueMode(true); //Instanciando o detector de todas as letras this.markerDetectorLetters = new NyARDetectMarker(ap, arrayCodes, WidthArray, 27, Core.raster.getBufferType()); this.markerDetectorLetters.setContinueMode(true); //Instanciando o detector das imagens que representam a palavra na cartela this.markerDetectorImages = new NyARDetectMarker(ap, arrayCodesImage, WidthArrayImages, 7, Core.raster.getBufferType()); this.markerDetectorImages.setContinueMode(true); //Inicia a captura //Inicia a captura try { Core.cap.StartCapture(); } catch (Exception e) { MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente."); Environment.Exit(0); } //Abaixo, são as funções que preparam todo o dispositivo e cenário para renderização 3D //Necessário descobrir mais detalhes do funcionamento. //Preparing the 3D device this._device = Core.PrepareD3dDevice(pbx); //Prepara o dispositivo em cima do PictureBox this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; //Projection Camera Settings Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp); this._device.Transform.Projection = tmp; // View conversion settings (set in the left-handed view matrix). //From 0,0,0, and facing Z +, Y-axis direction on this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; //Set viewport this._device.Viewport = vp; //Draw a color cube instance - Instância de um cubo colorido, padrão da biblioteca NyAR this._cube = new ColorCube(this._device, 40); //Create a background surface this._surface = new NyARSurface_XRGB32(this._device, 640, 480); //Carregando os meshs (objetos 3D) LoadMeshes(); }
/** * この関数は、ARToolKitスタイルのカメラパラメータから、 CameraFrustamを計算します。 * カメラパラメータの要素のうち、ProjectionMatrix成分のみを使います。 * @param i_arparam * ARToolKitスタイルのカメラパラメータ。 * @param i_scale * スケール値を指定します。1=1mmです。10ならば1=1cm,1000ならば1=1mです。 * 2.53以前のNyARToolkitと互換性を持たせるときは、{@link #SCALE_FACTOR_toCameraFrustumRH_NYAR2}を指定してください。 * @param i_near * 視錐体のnearPointを指定します。単位は、i_scaleに設定した値で決まります。 * @param i_far * 視錐体のfarPointを指定します。単位は、i_scaleに設定した値で決まります。 * @param o_gl_projection * OpenGLスタイルのProjectionMatrixです。double[16]を指定します。 */ public static void toCameraFrustumRH(NyARParam i_arparam, double i_scale, double i_near, double i_far, ref Matrix4x4 o_mat) { toCameraFrustumRH(i_arparam.getPerspectiveProjectionMatrix(), i_arparam.getScreenSize(), i_scale, i_near, i_far, ref o_mat); return; }
public void Test() { try { NyARParam param = NyARParam.createFromARParamFile(new StreamReader(PARAM_FILE)); param.changeScreenSize(320, 240); NyARReality reality = new NyARReality(param.getScreenSize(), 10, 1000, param.getPerspectiveProjectionMatrix(), null, 10, 10); NyARRealitySource reality_in = new NyARRealitySource_Reference(320, 240, null, 2, 100, NyARBufferType.BYTE1D_B8G8R8X8_32); //試験イメージの読み出し(320x240 BGRAのRAWデータ) StreamReader sr = new StreamReader(DATA_FILE); BinaryReader bs = new BinaryReader(sr.BaseStream); byte[] raw = bs.ReadBytes(320 * 240 * 4); Array.Copy(raw, (byte[])reality_in.refRgbSource().getBuffer(), raw.Length); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 1000; i++) { reality.progress(reality_in); } sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds + "[ms]"); Console.WriteLine(reality.getNumberOfKnown()); Console.WriteLine(reality.getNumberOfUnknown()); Console.WriteLine(reality.getNumberOfDead()); NyARRealityTarget[] rt = new NyARRealityTarget[10]; reality.selectUnKnownTargets(rt); reality.changeTargetToKnown(rt[0], 2, 80); Console.WriteLine(rt[0]._transform_matrix.m00 + "," + rt[0]._transform_matrix.m01 + "," + rt[0]._transform_matrix.m02 + "," + rt[0]._transform_matrix.m03); Console.WriteLine(rt[0]._transform_matrix.m10 + "," + rt[0]._transform_matrix.m11 + "," + rt[0]._transform_matrix.m12 + "," + rt[0]._transform_matrix.m13); Console.WriteLine(rt[0]._transform_matrix.m20 + "," + rt[0]._transform_matrix.m21 + "," + rt[0]._transform_matrix.m22 + "," + rt[0]._transform_matrix.m23); Console.WriteLine(rt[0]._transform_matrix.m30 + "," + rt[0]._transform_matrix.m31 + "," + rt[0]._transform_matrix.m32 + "," + rt[0]._transform_matrix.m33); } catch (Exception e) { Console.WriteLine(e.StackTrace); } return; }
public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device) { topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT); i_cap_device.SetCaptureListener(this); i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30); this._cap = i_cap_device; //this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32); #region my code try { byte[] bimg = service.getb(); //if(bimg != null) { Image img = byteToImage(bimg); if (img != null) { //frm.textBox1.Text = img.ToString(); this._raster = new NyARBitmapRaster((Bitmap)img); } } //else } catch (Exception x) { //MessageBox.Show(x.ToString()); } #endregion NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE)); ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT); NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE), 16, 16); this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT); this._ar.setContinueMode(true); this._device = PrepareD3dDevice(topLevelForm); this._device.RenderState.ZBufferEnable = true; this._device.RenderState.Lighting = false; Matrix tmp = new Matrix(); NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp); this._device.Transform.Projection = tmp; this._device.Transform.View = Matrix.LookAtLH( new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Height = ap.getScreenSize().h; vp.Width = ap.getScreenSize().w; vp.MaxZ = 1.0f; this._device.Viewport = vp; this._cube = new ColorCube(this._device, 40); this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT); this._is_marker_enable = false; return(true); }