|
楼主 |
发表于 2023-2-19 21:10:36
|
显示全部楼层
// 读取图像
CogImage8Grey image = new CogImage8Grey();
image.Load("path/to/image.bmp");
// 创建拟合圆的工具
CogFitCircleTool fitCircle = new CogFitCircleTool();
fitCircle.InputImage = image;
fitCircle.Run();
// 获取拟合圆的圆心坐标
double centerX = fitCircle.Results.GetCircle().CenterX;
double centerY = fitCircle.Results.GetCircle().CenterY;
// 创建用于显示图形的容器
CogCompositeShape compositeShape = new CogCompositeShape();
// 创建圆心的十字线
CogLineSegment line1 = new CogLineSegment(centerX - 20, centerY, centerX + 20, centerY);
CogLineSegment line2 = new CogLineSegment(centerX, centerY - 20, centerX, centerY + 20);
line1.Color = CogColorConstants.Red;
line2.Color = CogColorConstants.Red;
// 将十字线添加到组合图形中
compositeShape.Add(line1, "");
compositeShape.Add(line2, "");
// 旋转点
double rotationAngle = 15; // 旋转角度
double pointX = centerX + 30; // 原始点的坐标
double pointY = centerY;
double radian = rotationAngle * Math.PI / 180; // 角度转弧度
double rotatedPointX = centerX + (pointX - centerX) * Math.Cos(radian) - (pointY - centerY) * Math.Sin(radian); // 旋转后点的X坐标
double rotatedPointY = centerY + (pointX - centerX) * Math.Sin(radian) + (pointY - centerY) * Math.Cos(radian); // 旋转后点的Y坐标
// 创建点的标记
CogGraphicLabel pointLabel = new CogGraphicLabel();
pointLabel.Color = CogColorConstants.Green;
pointLabel.Font = new Font("Arial", 10);
pointLabel.Text = "●";
pointLabel.SetXYText(rotatedPointX, rotatedPointY);
// 将标记添加到组合图形中
compositeShape.Add(pointLabel, "");
// 在图像上显示组合图形
CogDisplay cogDisplay = new CogDisplay();
cogDisplay.Image = image;
cogDisplay.StaticGraphics.Add(compositeShape, "");
// 显示图像
cogDisplay.Fit(true);
以上代码中,首先使用CogFitCircleTool类拟合一个圆,并获取拟合圆的圆心坐标。然后创建一个CogCompositeShape实例作为容器,将需要显示在图像上的图形(包括圆心的十字线和旋转后的点)添加到组合图形中。最后,在CogDisplay控件上显示图像和组合图形。
注意,CogCompositeShape的Add()方法的第二个参数是图形的名字,可以为空字符串。 |
|