當前位置: 首頁>>代碼示例>>C#>>正文


C# IplImage.DrawPolyLine方法代碼示例

本文整理匯總了C#中OpenCvSharp.IplImage.DrawPolyLine方法的典型用法代碼示例。如果您正苦於以下問題:C# IplImage.DrawPolyLine方法的具體用法?C# IplImage.DrawPolyLine怎麽用?C# IplImage.DrawPolyLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenCvSharp.IplImage的用法示例。


在下文中一共展示了IplImage.DrawPolyLine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: routine

        /// <summary>
        /// Обработка изображения выполняющаяся в отдельном потоке
        /// </summary>
        private void routine()
        {
            IplImage cam = new IplImage(Camera.FrameSize, BitDepth.U8, 3);
            CvPoint[] mostLengthHole = new CvPoint[0];
            RoutineAction innerAction;
            bool innerIsRunOnce;

            while(isRunning)
            {
                // Копируем новое значение состояния
                innerAction = action;
                innerIsRunOnce = isRunOnce;

                // Определяем что будем делать в следующем цикле
                if (innerIsRunOnce) action = RoutineAction.Pause;

                // Если поток на паузе, то ничего не делаем
                if (innerAction == RoutineAction.Pause) continue;

                if (isRunning && BeforeProcessingEvent != null) BeforeProcessingEvent();

                // Захватываем изображение с камеры
                Camera.GetIplImage(ref cam);

                if (innerAction == RoutineAction.FindContour || innerAction == RoutineAction.Measure)
                {
                    mostLengthHole = Finder.FindMostLengthHole(cam);
                }

                if (innerAction == RoutineAction.DrawCorners || innerAction == RoutineAction.Calibrate)
                {
                    Calibrator.SetImage(cam);
                }

                switch (innerAction)
                {
                    case RoutineAction.GetImage:
                    {
                        if (isRunning && GetImageEvent != null) GetImageEvent(cam.ToBitmap());
                        break;
                    }

                    case RoutineAction.DrawCorners:
                    {
                        Calibrator.FindCorners();
                        if (isRunning && DrawCornersEvent != null) DrawCornersEvent(cam.ToBitmap());
                        break;
                    }

                    case RoutineAction.Calibrate:
                    {
                        bool result = Calibrator.TryToCalibrate(out Transformer);
                        if (isRunning && CalibrateEvent != null) CalibrateEvent(result);
                        break;
                    }

                    case RoutineAction.FindContour:
                    {
                        if (mostLengthHole.Length > 0) cam.DrawPolyLine(new CvPoint[][] { mostLengthHole }, true, Cv.RGB(0, 255, 0), 2);
                        if (isRunning && FindContoursEvent != null) FindContoursEvent(cam.ToBitmap());
                        break;
                    }

                    case RoutineAction.Measure:
                    {
                        if (mostLengthHole.Length > 0)
                        {
                            CvPoint2D32f[] realPoints = Transformer.GetRealPoints(mostLengthHole);
                            CvCircleSegment realCircle = CircleApproximator.Approximate(realPoints);
                            CvCircleSegment imageCircle = CircleApproximator.Approximate(mostLengthHole);

                            // Вносим поправки
                            float ratio = imageCircle.Radius / realCircle.Radius;
                            realCircle.Radius = realCircle.Radius * CorrectionMultiplier + CorrectionOffset;
                            imageCircle.Radius = imageCircle.Radius * CorrectionMultiplier + CorrectionOffset * ratio;

                            int circleRadius = (int)Math.Round(imageCircle.Radius);
                            CvPoint circleCenter = new CvPoint
                            (
                                (int)Math.Round(imageCircle.Center.X),
                                (int)Math.Round(imageCircle.Center.Y)
                            );

                            // Обводим внутреннюю границу кольца
                            if (circleRadius > 0) cam.DrawCircle(circleCenter, circleRadius, Cv.RGB(0, 0, 255), 2);

                            // Отмечаем откалиброванную зону
                            cam.DrawPolyLine(new CvPoint[][] { Calibrator.CalibratedZone }, true, Cv.RGB(255, 255, 0), 2);

                            if (isRunning && MeasureEvent != null) MeasureEvent(cam.ToBitmap(), realCircle.Radius);
                        }

                        break;
                    }
                }
            }

//.........這裏部分代碼省略.........
開發者ID:Goshik92,項目名稱:RingMeter,代碼行數:101,代碼來源:ImageProcessingRoutine.cs


注:本文中的OpenCvSharp.IplImage.DrawPolyLine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。