当前位置: 首页>>代码示例>>C#>>正文


C# CvMat.Transpose方法代码示例

本文整理汇总了C#中CvMat.Transpose方法的典型用法代码示例。如果您正苦于以下问题:C# CvMat.Transpose方法的具体用法?C# CvMat.Transpose怎么用?C# CvMat.Transpose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CvMat的用法示例。


在下文中一共展示了CvMat.Transpose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyCalibrationToUnityCamera

 private void ApplyCalibrationToUnityCamera(CvMat intrinsic, CvMat rotation, CvMat translation)
 {
     CvMat rotationInverse = GetRotationMatrixFromRotationVector(rotation).Transpose(); // transpose is same as inverse for rotation matrix
     CvMat transFinal = (rotationInverse * -1) * translation.Transpose();
     _mainCamera.projectionMatrix = LoadProjectionMatrix((float)intrinsic[0, 0], (float)intrinsic[1, 1], (float)intrinsic[0, 2], (float)intrinsic[1, 2]);
     ApplyTranslationAndRotationToCamera(transFinal, RotationConversion.RotationMatrixToEulerZXY(rotationInverse));
 }
开发者ID:guozanhua,项目名称:UnityProjectionMapping,代码行数:7,代码来源:Calibration.cs

示例2: Solve

        public CvMat Solve()
        {
            // 重心の計算
            CvPoint3D64f fromCenter = new CvPoint3D64f();
            CvPoint3D64f toCenter = new CvPoint3D64f();
            double weightSum = 0;
            foreach (var tuple in _correspondings)
            {
                fromCenter += tuple.Item1 * tuple.Item3;
                toCenter += tuple.Item2 * tuple.Item3;
                weightSum += tuple.Item3;
            }
            if (weightSum != 0)
            {
                fromCenter *= 1.0 / weightSum;
                toCenter *= 1.0 / weightSum;
            }
            // q: quaternion; 4x1
            // fn, tn: from[n], to[n]; 3x1                
            // Xn: (tn - fn, (tn+fn)×[1,0,0], (tn+fn)×[0,1,0], (tn+fn)×[0,0,1]); 3x4
            // M: Σi(Xi^t Wi Xi); 4x4
            // Wi: I; 3x3
            // J = q^t Mq -> min

            // 最小二乗法
            using (CvMat M = new CvMat(4, 4, MatrixType.F64C1))
            {
                M.Zero();
                foreach (var tuple in _correspondings)
                {
                    // 重心からの距離
                    CvPoint3D64f fromVector = tuple.Item1 - fromCenter;
                    CvPoint3D64f toVector = tuple.Item2 - toCenter;

                    using (CvMat Xi = new CvMat(3, 4, MatrixType.F64C1))
                    {
                        CvPoint3D64f diff = toVector - fromVector;
                        CvPoint3D64f sum = toVector + fromVector;
                        CvPoint3D64f second = CvEx.Cross(sum, new CvPoint3D64f(1, 0, 0));
                        CvPoint3D64f third = CvEx.Cross(sum, new CvPoint3D64f(0, 1, 0));
                        CvPoint3D64f fourth = CvEx.Cross(sum, new CvPoint3D64f(0, 0, 1));
                        CvEx.FillCvMat(Xi, new double[] { diff.X, second.X, third.X, fourth.X, diff.Y, second.Y, third.Y, fourth.Y, diff.Z, second.Z, third.Z, fourth.Z });
                        using (CvMat XiTranspose = Xi.Transpose())
                        using (CvMat addend = XiTranspose * Xi * tuple.Item3)
                        {
                            M.Add(addend, M);
                        }
                    }
                }
                using (CvMat MTemp = CvEx.CloneCvMat(M))
                using (CvMat eVals = new CvMat(4, 1, MatrixType.F64C1))
                using (CvMat eVects = new CvMat(4, 4, MatrixType.F64C1))
                {

                    //Cv.EigenVV(MTemp, eVects, eVals, 0.000001);
                    Cv.SVD(MTemp, eVals, eVects, null, SVDFlag.U_T | SVDFlag.ModifyA);
                    int minEIndex = 3;
                    /*
                    if (false)
                    {
                        double minE = double.MaxValue;
                        for (int i = 0; i < 4; i++)
                        {
                            double eVal = Math.Abs(eVals[i, 0]);
                            if (eVal < minE)
                            {
                                minE = eVal;
                                minEIndex = i;
                            }
                        }
                    }
                     */
                    CvMat ret = new CvMat(4, 4, MatrixType.F64C1);
                    ret.Zero();
                    ret[3, 3] = 1.0;
                    CvMat rotateConversion;
                    /*
                    if (false)
                    {
                        // こっちの変換はほとんど恒等のときに誤差が大きい
                        CvMat q = eVects.GetRow(minEIndex);

                        // クォータニオンから回転ベクトルを計算
                        double theta = Math.Acos(q[0, 0]) * 2;
                        double sin = Math.Sin(theta / 2);
                        CvPoint3D64f rot = new CvPoint3D64f(q[0, 1] / sin * theta, q[0, 2] / sin * theta, q[0, 3] / sin * theta);
                        // 回転ベクトルから回転行列を計算
                        ret.GetSubRect(out rotateConversion, new CvRect(0, 0, 3, 3));
                        using (CvMat rotVector = new CvMat(1, 3, MatrixType.F64C1))
                        {
                            rotVector[0, 0] = rot.X;
                            rotVector[0, 1] = rot.Y;
                            rotVector[0, 2] = rot.Z;
                            Cv.Rodrigues2(rotVector, rotateConversion);
                        }
                    }
                    else
                    {*/
                        CvMat rotationMat = CvEx.QuaternionToMat3D(eVects[minEIndex, 0], eVects[minEIndex, 1], eVects[minEIndex, 2], eVects[minEIndex, 3]);
                        ret.GetSubRect(out rotateConversion, new CvRect(0, 0, 3, 3));
//.........这里部分代码省略.........
开发者ID:guozanhua,项目名称:KinectMotionCapture,代码行数:101,代码来源:CoordRotTransConversion.cs


注:本文中的CvMat.Transpose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。