public CamService(CamWindow camWindow) { this.camWindow = camWindow; logger = MainWindow.ServiceContainer.Resolve <Logger>(); drawService = MainWindow.ServiceContainer.Resolve <DrawService>(); configService = MainWindow.ServiceContainer.Resolve <ConfigService>(); runtimeCapturing = configService.Read <bool>("RuntimeCapturingCheckBox"); withDetection = configService.Read <bool>("WithDetectionCheckBox"); surfacePoint1 = new PointF(); surfacePoint2 = new PointF(); camNumber = camWindow.camNumber; setupPoint = new PointF(configService.Read <float>($"Cam{camNumber}X"), configService.Read <float>($"Cam{camNumber}Y")); resolutionWidth = configService.Read <int>("ResolutionWidth"); resolutionHeight = configService.Read <int>("ResolutionHeight"); movesExtraction = configService.Read <int>("MovesExtraction"); movesDart = configService.Read <int>("MovesDart"); movesNoise = configService.Read <int>("MovesNoise"); smoothGauss = configService.Read <int>("SmoothGauss"); toCamDistance = configService.Read <double>($"ToCam{camNumber}Distance"); toBullAngle = MeasureService.FindAngle(setupPoint, drawService.projectionCenterPoint); videoCapture = new VideoCapture(GetCamIndex(camNumber), VideoCapture.API.DShow); videoCapture.SetCaptureProperty(CapProp.FrameWidth, resolutionWidth); videoCapture.SetCaptureProperty(CapProp.FrameHeight, resolutionHeight); GetSlidersData(); RefreshImageBoxes(); }
public void CalculateAndSaveThrow() { logger.Debug($"Calculate throw start"); if (rays.Count < 2) { logger.Debug($"Rays count < 2. Calculate throw end."); rays.Clear(); return; } foreach (var ray in rays) { logger.Info($"Ray:'{ray}'"); } var firstBestRay = rays.OrderByDescending(i => i.ContourArc).ElementAt(0); var secondBestRay = rays.OrderByDescending(i => i.ContourArc).ElementAt(1); rays.Clear(); logger.Info($"Best rays:'{firstBestRay}' and '{secondBestRay}'"); var poi = MeasureService.FindLinesIntersection(firstBestRay.CamPoint, firstBestRay.RayPoint, secondBestRay.CamPoint, secondBestRay.RayPoint); var anotherThrow = PrepareThrowData(poi); throwsCollection.Enqueue(anotherThrow); drawService.ProjectionDrawLine(firstBestRay.CamPoint, firstBestRay.RayPoint, new Bgr(Color.Aqua).MCvScalar, true); drawService.ProjectionDrawLine(secondBestRay.CamPoint, secondBestRay.RayPoint, new Bgr(Color.Aqua).MCvScalar, false); drawService.ProjectionDrawThrow(poi, false); drawService.PrintThrow(anotherThrow); logger.Info($"Throw:{anotherThrow}"); logger.Debug($"Calculate throw end."); }
private Throw PrepareThrowData(PointF poi) { var sectors = new List <int>() { 14, 9, 12, 5, 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11 }; var angle = MeasureService.FindAngle(drawService.projectionCenterPoint, poi); var distance = MeasureService.FindDistance(drawService.projectionCenterPoint, poi); var sector = 0; var type = ThrowType.Single; if (distance >= drawService.projectionCoefficent * 95 && distance <= drawService.projectionCoefficent * 105) { type = ThrowType.Tremble; } else if (distance >= drawService.projectionCoefficent * 160 && distance <= drawService.projectionCoefficent * 170) { type = ThrowType.Double; } // Find sector if (distance <= drawService.projectionCoefficent * 7) { sector = 50; type = ThrowType.Bull; } else if (distance > drawService.projectionCoefficent * 7 && distance <= drawService.projectionCoefficent * 17) { sector = 25; type = ThrowType._25; } else if (distance > drawService.projectionCoefficent * 170) { sector = 0; type = ThrowType.Zero; } else { var startRadSector = -2.9845105; var radSectorStep = 0.314159; var radSector = startRadSector; foreach (var proceedSector in sectors) { if (angle >= radSector && angle < radSector + radSectorStep) { sector = proceedSector; break; } sector = 11; // todo - works, but not looks pretty radSector += radSectorStep; } } return(new Throw(poi, sector, type, drawService.projectionFrameSide)); }