internal static List <ClickPositionOnImage> GetDiscEdgeClickPositions(Bitmap image, AutoConfigureImgPointsParams inputParams)
        {
            var positionList = new List <ClickPositionOnImage>();

            var calculator = new ClickPositionCalculator(image, inputParams);
            var helper     = new AddClickPositionHelper(image.Width, image.Height);

            var discTopLeftEnd = calculator.GetDiscTopLeftEnd();

            if (discTopLeftEnd.HasValue)
            {
                var position = helper.GetClickPositionObject(discTopLeftEnd.Value, ClickPositionOnImageTypes.LeftEndOfRotatingDisc);
                positionList.Add(position);
            }

            var discTopRightEnd = calculator.GetDiscTopRightEnd();

            if (discTopRightEnd.HasValue)
            {
                var position = helper.GetClickPositionObject(discTopRightEnd.Value, ClickPositionOnImageTypes.RightEndOfRotatingDisc);
                positionList.Add(position);
            }

            return(positionList);
        }
예제 #2
0
        public static ImageClickInputDetails GetImgClickInputDetails(string filePath, AutoConfigureImgPointsParams inputParams, bool firstImage)
        {
            var imageName = Path.GetFileName(filePath);

            var image = GetProcessedImage(filePath, inputParams);

            var clickPositionList = DiscEdgeClickPositionsHelper.GetDiscEdgeClickPositions(image, inputParams);

            var rotateImageBy = 0.0f;

            //if left and right ends of the disc were found, rotate the image and try to identify the markers
            var leftEdge  = clickPositionList.FirstOrDefault(x => x.PositionType == ClickPositionOnImageTypes.LeftEndOfRotatingDisc);
            var rightEdge = clickPositionList.FirstOrDefault(x => x.PositionType == ClickPositionOnImageTypes.RightEndOfRotatingDisc);

            if (leftEdge != null && rightEdge == null)
            {
                return(new ImageClickInputDetails
                {
                    ImageName = imageName,
                    RotateImageBy = 0.0,
                    ClickPositionListForImages = clickPositionList
                });
            }

            if (leftEdge != null && rightEdge != null)
            {
                rotateImageBy = MainProcessor.GetRotationAngleToRealign(leftEdge, rightEdge);

                //rotate the positions before trying to find the markers
                var origLeftPt          = new Point(leftEdge.ClickXPos, leftEdge.ClickYPos);
                var newLeftEdgePosition = RotationHelper.GetRotatedPosition(rotateImageBy, origLeftPt);
                if (newLeftEdgePosition == null || !(0 <= newLeftEdgePosition.Value.X && newLeftEdgePosition.Value.X < image.Width) ||
                    !(0 <= newLeftEdgePosition.Value.Y && newLeftEdgePosition.Value.Y < image.Height))
                {
                    return(new ImageClickInputDetails
                    {
                        ImageName = imageName,
                        RotateImageBy = 0.0,
                        ClickPositionListForImages = new List <ClickPositionOnImage>()
                    });
                }

                var origRightPt          = new Point(rightEdge.ClickXPos, rightEdge.ClickYPos);
                var newRightEdgePosition = RotationHelper.GetRotatedPosition(rotateImageBy, origRightPt);
                if (newRightEdgePosition == null || !(0 <= newRightEdgePosition.Value.X && newRightEdgePosition.Value.X < image.Width) ||
                    !(0 <= newRightEdgePosition.Value.Y && newRightEdgePosition.Value.Y < image.Height))
                {
                    return(new ImageClickInputDetails
                    {
                        ImageName = imageName,
                        RotateImageBy = 0.0,
                        ClickPositionListForImages = new List <ClickPositionOnImage>()
                    });
                }

                //update values in the original collection
                rightEdge.ClickXPos = newRightEdgePosition.Value.X;
                rightEdge.ClickYPos = newRightEdgePosition.Value.Y;

                leftEdge.ClickXPos = newLeftEdgePosition.Value.X;
                leftEdge.ClickYPos = newLeftEdgePosition.Value.Y;

                image = MainProcessor.RotateImg(image, rotateImageBy, inputParams.BackgroundColor);

                var helper = new AddClickPositionHelper(image.Width, image.Height);

                //add marker positions
                var y = MarkerProcessor.GetMiddlePosition((int)leftEdge.ClickYPos, image.Height - 1);
                var markerPositions = MarkerProcessor.GetLeftAndRightMarkerPositions(image, (int)leftEdge.ClickXPos,
                                                                                     (int)rightEdge.ClickXPos, (int)y, inputParams.MarkerProcessingParams);
                if (markerPositions != null && markerPositions.Count == 2)
                {
                    //add left marker
                    var leftX        = markerPositions[0];
                    var leftPosition = helper.GetClickPositionObject(leftX, y, ClickPositionOnImageTypes.MarkerLeftFromCenter);
                    clickPositionList.Add(leftPosition);

                    //add right marker
                    var rightX        = markerPositions[1];
                    var rightPosition = helper.GetClickPositionObject(rightX, y, ClickPositionOnImageTypes.MarkerRightFromCenter);
                    clickPositionList.Add(rightPosition);

                    if (firstImage)
                    {
                        //add bottommost part
                        var middleXPt      = MarkerProcessor.GetMiddlePosition((int)leftEdge.ClickXPos, (int)rightEdge.ClickXPos);
                        var bottomMostPart = helper.GetClickPositionObject(middleXPt, leftEdge.ClickYPos, ClickPositionOnImageTypes.BottomMostPartOfModel);
                        clickPositionList.Add(bottomMostPart);
                    }
                }
            }

            return(new ImageClickInputDetails
            {
                ImageName = imageName,
                RotateImageBy = rotateImageBy,
                ClickPositionListForImages = clickPositionList
            });
        }