Exemplo n.º 1
0
 /**
  * コンストラクタです。
  * 座標計算に必要なオブジェクトの参照値を元に、インスタンスを生成します。
  * @param i_ref_distfactor
  * 樽型歪み矯正オブジェクトの参照値です。歪み矯正が不要な時は、nullを指定します。
  * @param i_ref_projmat
  * 射影変換オブジェクトの参照値です。
  * @
  */
 public NyARTransMat(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_projection_mat_ref
         * 射影変換オブジェクトの参照値です。
         */
        public NyARTransportVectorSolver_ARToolKit(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
        {
            this._projection_mat = i_projection_mat_ref;
            //aとb(aの転置行列)の固定部分を設定。
            double[][] mata = this._mat_a.getArray();
            double[][] matat = this._mat_at.getArray();

            //変換用行列のcpara部分を先に作成
            for (int i = 0; i < 4; i++)
            {
                int x2 = i * 2;
                mata[x2][0] = matat[0][x2] = i_projection_mat_ref.m00;// mat_a->m[j*6+0]=mat_b->m[num*0+j*2] =cpara[0][0];
                mata[x2][1] = matat[1][x2] = i_projection_mat_ref.m01;// mat_a->m[j*6+1]=mat_b->m[num*2+j*2]=cpara[0][1];
                mata[x2 + 1][0] = matat[0][x2 + 1] = 0.0;// mat_a->m[j*6+3] =mat_b->m[num*0+j*2+1]= 0.0;
                mata[x2 + 1][1] = matat[1][x2 + 1] = i_projection_mat_ref.m11;// mat_a->m[j*6+4] =mat_b->m[num*2+j*2+1]= cpara[1][1];
            }
            return;
        }
 /**
  * コンストラクタです。
  * 参照する射影変換オブジェクトを指定して、インスタンスを生成します。
  * @param i_matrix
  * 参照する射影変換オブジェクト
  * @
  */
 public NyARRotMatrix_ARToolKit(NyARPerspectiveProjectionMatrix i_matrix)
     : base(i_matrix)
 {
     this._angle = new NyARDoublePoint3d();
     return;
 }
Exemplo n.º 4
0
 /**
  * この関数は、ARToolKitスタイルのProjectionMatrixから、 CameraFrustamを計算します。
  * @param i_promat
  * @param i_size
  * スクリーンサイズを指定します。
  * @param i_scale
  * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。
  * @param i_near
  * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。
  * @param i_far
  * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。
  * @param o_gl_projection
  * {@link #toCameraFrustumRH(NyARParam i_arparam,double i_scale,double i_near,double i_far,double[] o_gl_projection)}を参照。
  */
 public static void ToCameraFrustumRH(NyARPerspectiveProjectionMatrix i_promat, NyARIntSize i_size, double i_scale, double i_near, double i_far, ref Matrix4x4 o_mat)
 {
     NyARDoubleMatrix44 m = new NyARDoubleMatrix44();
       i_promat.makeCameraFrustumRH(i_size.w, i_size.h, i_near * i_scale, i_far * i_scale, m);
       o_mat.m00 = (float)m.m00;
       o_mat.m01 = (float)m.m01;
       o_mat.m02 = (float)m.m02;
       o_mat.m03 = (float)m.m03;
       o_mat.m10 = (float)m.m10;
       o_mat.m11 = (float)m.m11;
       o_mat.m12 = (float)m.m12;
       o_mat.m13 = (float)m.m13;
       o_mat.m20 = (float)m.m20;
       o_mat.m21 = (float)m.m21;
       o_mat.m22 = (float)m.m22;
       o_mat.m23 = (float)m.m23;
       o_mat.m30 = (float)m.m30;
       o_mat.m31 = (float)m.m31;
       o_mat.m32 = (float)m.m32;
       o_mat.m33 = (float)m.m33;
       return;
 }
 /**
  * コンストラクタです。
  * 射影変換オブジェクトの参照値を設定して、インスタンスを生成します。
  * @param i_projection_mat_ref
  * 射影変換オブジェクトの参照値。
  */
 public NyARRotMatrixOptimize_O2(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
 {
     this._projection_mat_ref = i_projection_mat_ref;
     return;
 }
 /**
  * コンストラクタです。
  * 参照する射影変換オブジェクトを指定して、インスタンスを生成します。
  * @param i_matrix
  * 参照する射影変換オブジェクト
  * @
  */
 public NyARRotMatrix_ARToolKit_O2(NyARPerspectiveProjectionMatrix i_matrix)
     : base(i_matrix)
 {
     return;
 }
Exemplo n.º 7
0
            /**
             * ストリームから読み出したデータでインスタンスを初期化します。
             * @param i_stream
             * @throws NyARException
             */
            public ParamLoader(StreamReader i_stream)
            {
                //読み出し
                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);
            }
Exemplo n.º 8
0
        /**
         * コンストラクタから呼び出す共通な初期化部分です。
         * @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;
        }
Exemplo n.º 9
0
 /**
  * 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());
 }
Exemplo n.º 10
0
 /**
  * 標準パラメータでインスタンスを初期化します。
  * @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_projection_mat_ref
  * 射影変換オブジェクトの参照値。
  */
 public NyARPartialDifferentiationOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
 {
     this._projection_mat_ref = i_projection_mat_ref;
     return;
 }
Exemplo n.º 12
0
 /**
  * コンストラクタです。
  * 参照する射影変換オブジェクトを指定して、インスタンスを生成します。
  * @param i_matrix
  * 参照する射影変換オブジェクト
  * @
  */
 public NyARRotMatrix(NyARPerspectiveProjectionMatrix i_matrix)
 {
     this.__initRot_vec1 = new NyARRotVectorV2(i_matrix);
     this.__initRot_vec2 = new NyARRotVectorV2(i_matrix);
     return;
 }
Exemplo n.º 13
0
 /**
  * コンストラクタです。
  * 射影変換オブジェクトの参照値を設定して、インスタンスを作成します。
  * @param i_cmat
  * 射影変換オブジェクト。この値はインスタンスの生存中は変更しないでください。
  * @throws NyARException
  */
 public NyARRotVectorV2(NyARPerspectiveProjectionMatrix i_cmat)
     : base()
 {
     this._inv_cpara.inverse(i_cmat);
     this._projection_mat_ref = i_cmat;
 }
Exemplo n.º 14
0
 /**
  * この関数は、ARToolKitスタイルの射影変換行列から視錐台を作成してセットします。
  * @param i_artk_perspective_mat
  * ARToolKitスタイルの射影変換行列
  * @param i_width
  * スクリーンサイズです。
  * @param i_height
  * スクリーンサイズです。
  * @param i_near
  * nearポイントをmm単位で指定します。
  * @param i_far
  * farポイントをmm単位で指定します。
  */
 public void setValue(NyARPerspectiveProjectionMatrix i_artk_perspective_mat, int i_width, int i_height, double i_near, double i_far)
 {
     i_artk_perspective_mat.makeCameraFrustumRH(i_width, i_height, i_near, i_far, this._frustum_rh);
     this._inv_frustum_rh.inverse(this._frustum_rh);
     this._screen_size.setValue(i_width, i_height);
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
 /**
  * コンストラクタです。
  * ARToolkitの射影変換行列から、インスタンスを作ります。
  * @param i_perspective_mat
  * @param i_width
  * スクリーンサイズです。
  * @param i_height
  * スクリーンサイズです。
  * @param i_near
  * 近平面までの距離です。単位はmm
  * @param i_far
  * 遠平面までの距離です。単位はmm
  */
 public NyARFrustum(NyARPerspectiveProjectionMatrix i_perspective_mat, int i_width, int i_height, double i_near, double i_far)
 {
     this.setValue(i_perspective_mat, i_width, i_height, i_near, i_far);
 }
Exemplo n.º 17
0
 /**
  * コンストラクタ。
  * @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);
 }