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


C# IplImage.SetZero方法代码示例

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


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

示例1: Kalman

        public unsafe Kalman()
        {
            // cvKalmanPredict, cvKalmanCorrect
            // カルマンフィルタを用いて回転する点を追跡する

            // A matrix data
            float[] A = new float[] { 1, 1, 0, 1 };

            using (IplImage img = new IplImage(500, 500, BitDepth.U8, 3))
            using (CvKalman kalman = new CvKalman(2, 1, 0))
            using (CvWindow window = new CvWindow("Kalman", WindowMode.AutoSize))
            {
                // state is (phi, delta_phi) - angle and angle increment
                CvMat state = new CvMat(2, 1, MatrixType.F32C1);
                CvMat process_noise = new CvMat(2, 1, MatrixType.F32C1);
                // only phi (angle) is measured
                CvMat measurement = new CvMat(1, 1, MatrixType.F32C1);

                measurement.SetZero();
                CvRandState rng = new CvRandState(0, 1, -1, DistributionType.Uniform);
                int code = -1;

                for (; ; )
                {
                    Cv.RandSetRange(rng, 0, 0.1, 0);
                    rng.DistType = DistributionType.Normal;

                    Marshal.Copy(A, 0, kalman.TransitionMatrix.Data, A.Length);
                    kalman.MeasurementMatrix.SetIdentity(1);
                    kalman.ProcessNoiseCov.SetIdentity(1e-5);
                    kalman.MeasurementNoiseCov.SetIdentity(1e-1);
                    kalman.ErrorCovPost.SetIdentity(1);
                    // choose random initial state
                    Cv.Rand(rng, kalman.StatePost);
                    rng.DistType = DistributionType.Normal;

                    for (; ; )
                    {
                        float state_angle = state.DataSingle[0];
                        CvPoint state_pt = CalcPoint(img, state_angle);

                        // predict point position
                        CvMat prediction = kalman.Predict(null);
                        float predict_angle = prediction.DataSingle[0];
                        CvPoint predict_pt = CalcPoint(img, predict_angle);

                        Cv.RandSetRange(rng, 0, Math.Sqrt(kalman.MeasurementNoiseCov.DataSingle[0]), 0);
                        Cv.Rand(rng, measurement);

                        // generate measurement
                        Cv.MatMulAdd(kalman.MeasurementMatrix, state, measurement, measurement);

                        float measurement_angle = measurement.DataArraySingle[0];
                        CvPoint measurement_pt = CalcPoint(img, measurement_angle);

                        img.SetZero();
                        DrawCross(img, state_pt, CvColor.White, 3);
                        DrawCross(img, measurement_pt, CvColor.Red, 3);
                        DrawCross(img, predict_pt, CvColor.Green, 3);
                        img.Line(state_pt, measurement_pt, new CvColor(255, 0, 0), 3, LineType.AntiAlias, 0);
                        img.Line(state_pt, predict_pt, new CvColor(255, 255, 0), 3, LineType.AntiAlias, 0);

                        // adjust Kalman filter state
                        kalman.Correct(measurement);

                        Cv.RandSetRange(rng, 0, Math.Sqrt(kalman.ProcessNoiseCov.DataSingle[0]), 0);
                        Cv.Rand(rng, process_noise);
                        Cv.MatMulAdd(kalman.TransitionMatrix, state, process_noise, state);

                        window.ShowImage(img);
                        // break current simulation by pressing a key
                        code = CvWindow.WaitKey(100);
                        if (code > 0)
                        {
                            break;
                        }
                    }
                    // exit by ESCAPE
                    if (code == 27)
                    {
                        break;
                    }
                }
            }
        }
开发者ID:neoxeo,项目名称:opencvsharp,代码行数:85,代码来源:Kalman.cs

示例2: DrawHist

        public static IplImage DrawHist(float[] hist, int scaleX = 1, int scaleY = 1)
        {
            int histMax = 0;
            histMax = (int)hist.Max();
            IplImage imgHist = new IplImage((int)(256 * scaleX), (int)(64 * scaleY), BitDepth.U8, 3);
            imgHist.SetZero();
            for (int i = 0; i < 255; i++)
            {
                int histValue = (int)hist[i];
                int nextValue = (int)hist[i + 1];

                CvPoint pt1 = new CvPoint(i * scaleX, 64 * scaleY);
                CvPoint pt2 = new CvPoint(i * scaleX + scaleX, 64 * scaleY);
                CvPoint pt3 = new CvPoint(i * scaleX + scaleX, (64 - nextValue * 64 / histMax) * scaleY);
                CvPoint pt4 = new CvPoint(i * scaleX, (64 - histValue * 64 / histMax) * scaleY);
                int numPts = 5;
                CvPoint[] pts = { pt1, pt2, pt3, pt4, pt1 };
                CvInvoke.cvFillConvexPoly(imgHist.CvPtr, pts, numPts, CvColor.Red, LineType.Link8, 0);
            }

            return imgHist;
        }
开发者ID:pyephyomaung,项目名称:som-ar,代码行数:22,代码来源:OpenCVSharpHelper.cs


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