Ver Fonte

重构相机标定接口及实现,移除旧模型

重构ICameraCalibrationService接口,新增多种标定方法及自动化流程,采用异步Task和回调机制。实现层同步调整,详细补充各类标定业务逻辑,移除CameraCalibrationResult相关代码与文件,项目结构更清晰,标定流程更灵活可扩展。
孝锋 徐 há 8 meses atrás
pai
commit
69bab2d81b

+ 115 - 27
TeamAAS-VM/Interfaces/ICameraCalibrationService.cs

@@ -1,7 +1,12 @@
+using MathNet.Numerics.LinearAlgebra;
+using OpenCvSharp;
 using System;
+using System.Drawing;
+using System.Threading;
 using System.Threading.Tasks;
-using OpenCvSharp;
 using TeamAAS_VP.Models;
+using TeamAAS_VP.Models.Calibration;
+using TeamAAS_VP.Models.Robot;
 
 namespace TeamAAS_VP.Interfaces
 {
@@ -12,50 +17,133 @@ namespace TeamAAS_VP.Interfaces
     public interface ICameraCalibrationService : IDisposable
     {
         /// <summary>
-        /// 使用一组棋盘格或标定图像执行相机标定。返回是否成功。
+        /// 触发相机拍照并进行图像处理的回调函数
+        /// 在标定过程中需要获取图像特征点时调用此回调
+        /// Tuple 字段含义:
+        /// Item1 - IsSuccess: 拍照及图像处理是否成功;
+        /// Item2 - X: 图像处理后得到的机器人目标 X(mm);
+        /// Item3 - Y: 图像处理后得到的机器人目标 Y(mm);
+        /// Item4 - U: 图像处理后得到的机器人目标 U(工具朝向)。
+        /// </summary>
+        Func<Task<(bool IsSuccess, double X, double Y, double U,int ImageWidth,int ImageHeight)>> CaptureAndProcessCallback { get; set; }
+
+        /// <summary>
+        /// 固定向下相机校准工具坐标。
+        /// 该方法用于在相机固定、朝下安装且工具不随 J4 移动的情况下标定相机与机器人工具坐标系之间的关系。
+        /// </summary>
+        /// <param name="calibrationInfo">包含标定时所需的相机参数、图像处理配置与标定点信息的对象。</param>
+        /// <param name="robot">实现了 <see cref="IRobot"/> 的机器人抽象,用于获取/移动机器人位姿。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 一个包含以下字段的元组:
+        /// IsSuccess - 标定是否成功;
+        /// Matrix<double> - 图像与像素坐标系之间的旋转(或仿射)矩阵(行列顺序与具体实现约定);
+        /// ToolX - 标定得到的工具坐标系在机器人基坐标系下的 X(单位与机器人一致);
+        /// ToolY - 标定得到的工具坐标系在机器人基坐标系下的 Y(单位与机器人一致);
+        /// PixelScaleX - 像素到物理距离在 X 方向的缩放因子(如 mm/px);
+        /// PixelScaleY - 像素到物理距离在 Y 方向的缩放因子(如 mm/px)。
+        /// </returns>
+        Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateFixedDownCameraTool(CalibrationInfo calibrationInfo, IRobot robot,CancellationToken cancellationToken);
+
+        /// <summary>
+        /// J4 移动的向下相机校准工具坐标。
+        /// 用于相机或工具随机器人第 4 轴(J4)运动时的标定,需考虑 J4 引入的偏转影响。
+        /// </summary>
+        /// <param name="calibrationInfo">标定所需配置信息。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>同 <see cref="CalibrateFixedDownCameraTool"/> 的返回约定。</returns>
+        Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateJ4MovingDownCameraTool(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// 固定向上相机校准工具坐标。
+        /// 该方法用于相机固定、朝上安装的情况,标定过程与向下相机类似但需要考虑图像翻转/镜像等差异。
         /// </summary>
-        /// <param name="images">用于标定的灰度或彩色图像阵列。</param>
-        /// <param name="patternSize">棋盘格内角点数(cols, rows)。</param>
-        /// <param name="squareSize">物理上每格的尺寸(单位:毫米或用户约定单位)。</param>
-        /// <returns>如果标定成功,返回标定结果对象;否则返回 null 或抛出异常(视实现而定)。</returns>
-        Task<CameraCalibrationResult> CalibrateAsync(Mat[] images, OpenCvSharp.Size patternSize, double squareSize);
+        /// <param name="calibrationInfo">标定配置信息。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>同 <see cref="CalibrateFixedDownCameraTool"/> 的返回约定。</returns>
+        Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateFixedUpCameraTool(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken);
 
         /// <summary>
-        /// 根据已标定的相机参数,将像素坐标转换到相机坐标系(例如相机局部三维坐标)。
+        /// 通过未标定的相机校准工具坐标。
+        /// 当相机内参未知或未可靠标定时,通过已知机器人位姿与图像特征的对应关系反推工具坐标与像素尺度。
         /// </summary>
-        /// <param name="pixel">像素坐标(x,y)。</param>
-        /// <param name="depth">该像素的深度(或Z)值,若无则由实现者定义默认行为。</param>
-        /// <returns>相机坐标系下的三维点。</returns>
-        System.Numerics.Vector3 PixelToCameraPoint(System.Numerics.Vector2 pixel, double depth = 1.0);
+        /// <param name="calibrationInfo">标定配置信息(可能包含初始猜测或参考点)。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>同 <see cref="CalibrateFixedDownCameraTool"/> 的返回约定。</returns>
+        Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateUncalibratedCameraTool(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken);
 
         /// <summary>
-        /// 将相机坐标系中的三维点变换到机器人坐标系,使用当前估计的外参/变换矩阵。
+        /// 自动识别机器人与相机图像坐标系的旋转矩阵。
+        /// 使用若干已知的机器人位姿与对应图像坐标点,估计二者之间的旋转变换与像素尺度。
         /// </summary>
-        /// <param name="cameraPoint">相机坐标系三维点。</param>
-        /// <returns>机器人坐标系三维点。</returns>
-        System.Numerics.Vector3 CameraToRobotPoint(System.Numerics.Vector3 cameraPoint);
+        /// <param name="calibrationInfo">包含用于识别的点集与图像处理配置。</param>
+        /// <param name="robot">机器人接口,用于获取对应位姿或移动机器人到指定位置以采集数据。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 元组字段:
+        /// IsSuccess - 是否成功识别;
+        /// Matrix<double> - 旋转(或仿射)矩阵;
+        /// PixelScaleX - X 方向像素尺度(如 mm/px);
+        /// PixelScaleY - Y 方向像素尺度(如 mm/px)。
+        /// </returns>
+        Task<(bool IsSuccess, Matrix<double> RotationMatrix, double PixelScaleX, double PixelScaleY)> AutoIdentifyRobotCameraRotationMatrix(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken);
 
         /// <summary>
-        /// 将机器人坐标系中的三维点变换到相机坐标系。
+        /// 根据图像上的三个点计算图像坐标系的旋转矩阵。
+        /// 通常通过已知三点在像素坐标系中的位置计算出局部旋转/仿射变换,用于后续坐标换算。
         /// </summary>
-        /// <param name="robotPoint">机器人坐标系三维点。</param>
-        /// <returns>相机坐标系三维点。</returns>
-        System.Numerics.Vector3 RobotToCameraPoint(System.Numerics.Vector3 robotPoint);
+        /// <param name="P0">图像中的点 0(像素坐标)。</param>
+        /// <param name="P1">图像中的点 1(像素坐标)。</param>
+        /// <param name="P2">图像中的点 2(像素坐标)。</param>
+        /// <returns>表示图像旋转或仿射变换的 3x3 或 2x2 矩阵(具体尺寸由实现决定)。</returns>
+        Matrix<double> CalculateImageRotationMatrix(PointF P0, PointF P1, PointF P2);
 
         /// <summary>
-        /// 估算相机中心(相机在机器人坐标系下的位置),通常基于标定得到的外参或一组已知对应点。
+        /// 自动移动机器人至图像中心点位置。
+        /// 典型用例为将相机视野中心对应的工作点转换为机器人坐标并移动机器人到该点以便校准或抓取。
         /// </summary>
-        /// <returns>机器人坐标系下的相机中心位置。</returns>
-        System.Numerics.Vector3 EstimateCameraCenter();
+        /// <param name="robot">机器人接口,用于执行移动命令并返回当前位置。</param>
+        /// <param name="matrix">图像坐标系到机器人坐标系的转换矩阵(旋转/仿射)。</param>
+        /// <param name="PixelScaleX">像素到物理距离在 X 方向的缩放因子(如 mm/px)。</param>
+        /// <param name="PixelScaleY">像素到物理距离在 Y 方向的缩放因子(如 mm/px)。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 元组字段:
+        /// IsSuccess - 是否成功移动到图像中心;
+        /// X - 移动后机器人在基坐标系下的 X;
+        /// Y - 移动后机器人在基坐标系下的 Y;
+        /// U - 移动后机器人的朝向(工具角度)。
+        /// </returns>
+        Task<(bool IsSuccess, double X, double Y, double U)> AutoMoveRobotToImageCenter(IRobot robot, Matrix<double> matrix, double PixelScaleX, double PixelScaleY, CancellationToken cancellationToken);
 
         /// <summary>
-        /// 获取当前标定结果(如果存在)。
+        /// 自动九点标定。
+        /// 使用 9 个采样点进行仿射/透视变换求解,以提高标定精度并生成验证用的九点数据结构。
         /// </summary>
-        CameraCalibrationResult CurrentCalibration { get; }
+        /// <param name="calibrationInfo">九点标定的配置信息(点列、采集顺序、图像处理参数等)。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 元组字段:
+        /// IsSuccess - 标定是否成功;
+        /// AffineTransformationMaterial - 求解得到的仿射变换矩阵;
+        /// NinePoint - 九点标定结果封装(像素点与对应的机器人位姿);
+        /// Result - 详细的标定结果与统计信息(误差、残差等)。
+        /// </returns>
+        Task<(bool IsSuccess, Matrix<double> AffineTransformationMaterial, RobotPixelPoint NinePoint, CalibrationResult Result)> AutoNinePointCalibration(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken);
 
         /// <summary>
-        /// 清除/重置当前的标定结果与内部状态。
+        /// 执行校准验证。
+        /// 使用当前标定参数在一组验证点上计算误差并返回测试结果,用于评估标定质量。
         /// </summary>
-        void Reset();
+        /// <param name="calibrationInfo">用于验证的点集与验收标准配置。</param>
+        /// <param name="robot">机器人接口,用于在验证过程中获取或移动到参考位姿。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>元组字段:IsSuccess 表示验证是否通过;Result 包含详细的验证统计与误差分析。</returns>
+        Task<(bool IsSuccess, CalibrationTestResult Result)> ExecuteCalibrationValidation(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken);
+
     }
 }

+ 0 - 58
TeamAAS-VM/Models/CameraCalibrationResult.cs

@@ -1,58 +0,0 @@
-using System;
-
-namespace TeamAAS_VP.Models
-{
-    /// <summary>
-    /// 相机标定结果数据传输对象。
-    /// 包含内参、畸变系数、外参等可选字段,供服务与 ViewModel 交换使用。
-    /// </summary>
-    public class CameraCalibrationResult
-    {
-        /// <summary>
-        /// 标定是否成功
-        /// </summary>
-        public bool Success { get; set; }
-
-        /// <summary>
-        /// 说明性消息或错误信息
-        /// </summary>
-        public string Message { get; set; }
-
-        /// <summary>
-        /// 相机内参矩阵(3x3),按行主序展开(长度应为9)。
-        /// 如果为空表示未设置。
-        /// </summary>
-        public double[] CameraMatrix { get; set; }
-
-        /// <summary>
-        /// 畸变系数(可包含 k1,k2,p1,p2,k3 ...)
-        /// </summary>
-        public double[] DistCoeffs { get; set; }
-
-        /// <summary>
-        /// 旋转向量或旋转矩阵的压缩表示(视实现而定)。
-        /// </summary>
-        public double[] Rotation { get; set; }
-
-        /// <summary>
-        /// 平移向量(tx,ty,tz)
-        /// </summary>
-        public double[] Translation { get; set; }
-
-        /// <summary>
-        /// 标定时间戳
-        /// </summary>
-        public DateTime Timestamp { get; set; }
-
-        public CameraCalibrationResult()
-        {
-            Success = false;
-            Message = string.Empty;
-            CameraMatrix = null;
-            DistCoeffs = null;
-            Rotation = null;
-            Translation = null;
-            Timestamp = DateTime.UtcNow;
-        }
-    }
-}

+ 733 - 49
TeamAAS-VM/Services/CameraCalibrationService.cs

@@ -1,9 +1,20 @@
+using MaterialDesignThemes.Wpf;
+using MathNet.Numerics;
+using MathNet.Numerics.LinearAlgebra;
+using OpenCvSharp;
+using Prism.Services.Dialogs;
 using System;
+using System.Drawing;
+using System.Security.Cryptography;
+using System.Threading;
 using System.Threading.Tasks;
-using OpenCvSharp;
-using TeamAAS_VP.Models;
-using System.Numerics;
+using TeamAAS_VP.Controls;
+using TeamAAS_VP.Core;
 using TeamAAS_VP.Interfaces;
+using TeamAAS_VP.Models;
+using TeamAAS_VP.Models.Calibration;
+using TeamAAS_VP.Models.Robot;
+using TeamAAS_VP.Resources.Languages;
 
 namespace TeamAAS_VP.Services
 {
@@ -12,83 +23,756 @@ namespace TeamAAS_VP.Services
     /// </summary>
     public class CameraCalibrationService : ICameraCalibrationService
     {
-        private bool _disposed;
 
-        public CameraCalibrationResult CurrentCalibration { get; private set; }
+        /// <summary>
+        /// 触发相机拍照并进行图像处理的回调函数
+        /// 在标定过程中需要获取图像特征点时调用此回调
+        /// Tuple 字段含义:
+        /// Item1 - IsSuccess: 拍照及图像处理是否成功;
+        /// Item2 - X: 图像处理后得到的机器人目标 X(mm);
+        /// Item3 - Y: 图像处理后得到的机器人目标 Y(mm);
+        /// Item4 - U: 图像处理后得到的机器人目标 U(工具朝向)。
+        /// </summary>
+        public Func<Task<(bool IsSuccess, double X, double Y, double U, int ImageWidth, int ImageHeight)>> CaptureAndProcessCallback { get; set; }
 
-        public CameraCalibrationService()
+        /// <summary>
+        /// 固定向下相机校准工具坐标。
+        /// 该方法用于在相机固定、朝下安装且工具不随 J4 移动的情况下标定相机与机器人工具坐标系之间的关系。
+        /// </summary>
+        /// <param name="calibrationInfo">包含标定时所需的相机参数、图像处理配置与标定点信息的对象。</param>
+        /// <param name="robot">实现了 <see cref="IRobot"/> 的机器人抽象,用于获取/移动机器人位姿。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 一个包含以下字段的元组:
+        /// IsSuccess - 标定是否成功;
+        /// Matrix<double> - 图像与像素坐标系之间的旋转(或仿射)矩阵(行列顺序与具体实现约定);
+        /// ToolX - 标定得到的工具坐标系在机器人基坐标系下的 X(单位与机器人一致);
+        /// ToolY - 标定得到的工具坐标系在机器人基坐标系下的 Y(单位与机器人一致);
+        /// PixelScaleX - 像素到物理距离在 X 方向的缩放因子(如 mm/px);
+        /// PixelScaleY - 像素到物理距离在 Y 方向的缩放因子(如 mm/px)。
+        /// </returns>
+        public async Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateFixedDownCameraTool(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken)
         {
-            // 初始化内部状态
-            CurrentCalibration = null;
+            double pixelScaleX = 0;
+            double pixelScaleY = 0;
+            Matrix<double> RobotCameraRotationMatrix = null;
+
+            //移动机器人至待机位置
+            await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+
+            if (calibrationInfo.Pick.PickPlaceModel == Enums.PickPlaceModel.Inhal)
+            {
+                //打开吸气
+                await robot.CalibOutIOAsync(true);
+            }
+            else
+            {
+                //张开夹爪
+                //夹爪张开为false,夹爪闭合为True
+                await robot.CalibOutIOAsync(false);
+            }
+            var view = new ShowMessage(Lang.提示, Lang.请将校准块放置在吸嘴中心);
+            var result = await DialogHost.Show(view, "CalibToolDialog", null, null, null);
+            if (!((bool)result)) return (false, null, 0, 0, 0, 0);
+            if (calibrationInfo.Pick.PickPlaceModel == Enums.PickPlaceModel.Clamp)
+            {
+                //夹紧夹爪
+                await robot.CalibOutIOAsync(true);
+            }
+
+            //计算相机与机器人坐标系的旋转矩阵
+            var robotCameraRotationMatrix = await AutoIdentifyRobotCameraRotationMatrix(calibrationInfo, robot, cancellationToken);
+            if (!robotCameraRotationMatrix.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            pixelScaleX = robotCameraRotationMatrix.PixelScaleX;
+            pixelScaleY = robotCameraRotationMatrix.PixelScaleY;
+            RobotCameraRotationMatrix = robotCameraRotationMatrix.Item2;
+            //相机拍照并处理图像
+            var photoResult = await CaptureAndProcessCallback();
+            if (!photoResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            PointF P0 = new PointF((float)(photoResult.X), (float)(photoResult.Y));
+
+            RPoint RobotU = calibrationInfo.CenterPoint.Clone();
+            RobotU.U += (float)calibrationInfo.Angle;
+            //移动机器人中心点
+            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            //打开吸气
+            await robot.CalibOutIOAsync(true);
+
+            //机器人U轴旋转
+            await robot.CalibMotionAsync(RobotU, 0);
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+
+            //关闭吸气
+            await robot.CalibOutIOAsync(false);
+            //移动机器人至待机位置
+            await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+
+            //相机拍照并处理图像
+            photoResult = await CaptureAndProcessCallback();
+            if (!photoResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            PointF curPixel = new PointF((float)(photoResult.X), (float)(photoResult.Y));
+
+            bool IsFinish = false;
+            for (int i = 0; i < 10; i++)
+            {
+                //计算需要移动的偏移量,目的是逼近中心点
+                double offsetx = (P0.X - curPixel.X) * pixelScaleX;
+                double offsety = (P0.Y - curPixel.Y) * pixelScaleY;
+                var pos = RobotCameraRotationMatrix.Inverse() * Vector<double>.Build.Dense(new double[] { offsetx, offsety });
+                //移动机器人取标定块
+                await robot.CalibMotionAsync(RobotU, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
+                //打开吸气
+                await robot.CalibOutIOAsync(true);
+
+                RobotU.X += (float)pos[0];
+                RobotU.Y += (float)pos[1];
+                //机器人移动
+                await robot.CalibMotionAsync(RobotU, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
+
+                //关闭吸气
+                await robot.CalibOutIOAsync(false);
+                //移动机器人至待机位置
+                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
+
+                photoResult = await CaptureAndProcessCallback();
+                if (!photoResult.IsSuccess)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
+                curPixel = new PointF((float)(photoResult.X), (float)(photoResult.Y));
+                offsetx = P0.X - curPixel.X;
+                offsety = P0.Y - curPixel.Y;
+                //await Console.Out.WriteLineAsync($"移动后的差异:{offsetx},{offsety}");
+                if (Math.Abs(offsetx) < 1 && Math.Abs(offsetx) < 1)
+                {
+                    //移动机器人取标定块
+                    await robot.CalibMotionAsync(RobotU, 0);
+                    if (cancellationToken.IsCancellationRequested)
+                    {
+                        return (false, null, 0, 0, 0, 0);
+                    }
+                    //打开吸气
+                    await robot.CalibOutIOAsync(true);
+                    //移动机器人至待机位置
+                    await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+                    IsFinish = true;
+                    break;
+                }
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0, 0, 0);
+                }
+            }
+
+            if (IsFinish)
+            {
+                Vector<double> p0 = Vector<double>.Build.Dense(new double[] { calibrationInfo.CenterPoint.X, calibrationInfo.CenterPoint.Y });
+                Vector<double> p1 = Vector<double>.Build.Dense(new double[] { RobotU.X, RobotU.Y });
+                ToolCoord toolCoord = new ToolCoord();
+                double u1 = calibrationInfo.CenterPoint.U;
+                double u2 = RobotU.U;
+                if (robot.Brand == Enums.RobotBrand.Schneider)
+                {
+                    u1 *= -1;
+                    u2 *= -1;
+                }
+                toolCoord.ComputeTool(p0, p1, u1, u2);
+                if (calibrationInfo.Tool == null)
+                {
+                    calibrationInfo.Tool = new RobotTool();
+                }
+                calibrationInfo.Tool.X = toolCoord.X;
+                calibrationInfo.Tool.Y = toolCoord.Y;
+                return (true, RobotCameraRotationMatrix, calibrationInfo.Tool.X, calibrationInfo.Tool.Y, pixelScaleX, pixelScaleY);
+            }
+            else
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
         }
 
-        public async Task<CameraCalibrationResult> CalibrateAsync(Mat[] images, OpenCvSharp.Size patternSize, double squareSize)
+        /// <summary>
+        /// J4 移动的向下相机校准工具坐标。
+        /// 用于相机或工具随机器人第 4 轴(J4)运动时的标定,需考虑 J4 引入的偏转影响。
+        /// </summary>
+        /// <param name="calibrationInfo">标定所需配置信息。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>同 <see cref="CalibrateFixedDownCameraTool"/> 的返回约定。</returns>
+        public async Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateJ4MovingDownCameraTool(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken)
         {
-            // 占位实现:调用者将补充真实标定实现。
-            // 做最小的参数检查以避免误用。
-            if (images == null) throw new ArgumentNullException(nameof(images));
-            if (images.Length == 0) throw new ArgumentException("images 不能为空", nameof(images));
+            double pixelScaleX = 0;
+            double pixelScaleY = 0;
+            Matrix<double> RobotCameraRotationMatrix = null;
 
-            // 在后台线程上执行耗时计算的占位符
-            return await Task.Run(() =>
+            //移动机器人至中心位置
+            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+
+            //计算相机与机器人坐标系的旋转矩阵
+            var robotCameraRotationMatrix = await AutoIdentifyRobotCameraRotationMatrix(calibrationInfo, robot, cancellationToken);
+            if (!robotCameraRotationMatrix.IsSuccess)
             {
-                // TODO: 在此实现相机标定(使用 OpenCvSharp.CalibrateCamera 等)
-                // 当前返回空结果,表示尚未实现。
-                CurrentCalibration = new CameraCalibrationResult
-                {
-                    Timestamp = DateTime.UtcNow,
-                    Success = false,
-                    Message = "未实现:请在 CameraCalibrationService 中补充标定算法。"
-                };
+                return (false, null, 0, 0, 0, 0);
+            }
+            pixelScaleX = robotCameraRotationMatrix.PixelScaleX;
+            pixelScaleY = robotCameraRotationMatrix.PixelScaleY;
+            RobotCameraRotationMatrix = robotCameraRotationMatrix.Item2;
+
+            //自动移动机器人至图像中心点位置
+            var autoMoveResult = await AutoMoveRobotToImageCenter(robot, RobotCameraRotationMatrix, pixelScaleX, pixelScaleY, cancellationToken);
+            if (!autoMoveResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            calibrationInfo.CenterPoint.X = (float)autoMoveResult.X;
+            calibrationInfo.CenterPoint.Y = (float)autoMoveResult.Y;
+
+            RPoint RobotU = calibrationInfo.CenterPoint.Clone();
+            RobotU.U += (float)calibrationInfo.Angle;
+
+            //机器人U轴旋转
+            await robot.CalibMotionAsync(RobotU, RobotU.Z);
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+
+            //相机拍照并处理图像
+            var photoResult = await CaptureAndProcessCallback();
+            if (!photoResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            PointF curPixel = new PointF((float)(photoResult.X), (float)(photoResult.Y));
+
+            autoMoveResult = await AutoMoveRobotToImageCenter(robot, RobotCameraRotationMatrix, pixelScaleX, pixelScaleY, cancellationToken);
+            if (!autoMoveResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            RobotU.X = (float)autoMoveResult.X;
+            RobotU.Y = (float)autoMoveResult.Y;
+
+            Vector<double> p0 = Vector<double>.Build.Dense(new double[] { calibrationInfo.CenterPoint.X, calibrationInfo.CenterPoint.Y });
+            Vector<double> p1 = Vector<double>.Build.Dense(new double[] { RobotU.X, RobotU.Y });
+            ToolCoord toolCoord = new ToolCoord();
+            double u1 = calibrationInfo.CenterPoint.U;
+            double u2 = RobotU.U;
+            if (robot.Brand == Enums.RobotBrand.Schneider)
+            {
+                u1 *= -1;
+                u2 *= -1;
+            }
+            toolCoord.ComputeTool(p0, p1, u1, u2);
+            if (calibrationInfo.Tool == null)
+            {
+                calibrationInfo.Tool = new RobotTool();
+            }
+
+            calibrationInfo.Tool.X = toolCoord.X;
+            calibrationInfo.Tool.Y = toolCoord.Y;
+
+            return (true, RobotCameraRotationMatrix, calibrationInfo.Tool.X, calibrationInfo.Tool.Y, pixelScaleX, pixelScaleY);
+        }
+
+        /// <summary>
+        /// 固定向上相机校准工具坐标。
+        /// 该方法用于相机固定、朝上安装的情况,标定过程与向下相机类似但需要考虑图像翻转/镜像等差异。
+        /// </summary>
+        /// <param name="calibrationInfo">标定配置信息。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>同 <see cref="CalibrateFixedDownCameraTool"/> 的返回约定。</returns>
+        public async Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateFixedUpCameraTool(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken)
+        {
+            double pixelScaleX = 0;
+            double pixelScaleY = 0;
+            Matrix<double> RobotCameraRotationMatrix = null;
+
+            //移动机器人至中心位置
+            await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+
+            if (calibrationInfo.Pick.PickPlaceModel == Enums.PickPlaceModel.Inhal)
+            {
+                //打开吸气
+                await robot.CalibOutIOAsync(true);
+            }
+            else
+            {
+                //张开夹爪
+                await robot.CalibOutIOAsync(false);
+            }
+
+            var view = new ShowMessage(Lang.提示, Lang.请将校准块放置在吸嘴中心);
+            var result = await DialogHost.Show(view, "CalibToolDialog", null, null, null);
+            if (!((bool)result)) return (false, null, 0, 0, 0, 0);
+            if (calibrationInfo.Pick.PickPlaceModel == Enums.PickPlaceModel.Clamp)
+            {
+                //夹紧夹爪
+                await robot.CalibOutIOAsync(true);
+            }
+
+            //计算相机与机器人坐标系的旋转矩阵
+            var robotCameraRotationMatrix= await AutoIdentifyRobotCameraRotationMatrix(calibrationInfo, robot, cancellationToken);
+            if (!robotCameraRotationMatrix.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            pixelScaleX= robotCameraRotationMatrix.PixelScaleX;
+            pixelScaleY= robotCameraRotationMatrix.PixelScaleY;
+            RobotCameraRotationMatrix= robotCameraRotationMatrix.Item2;
+
+            //自动移动机器人至图像中心点位置
+            var autoMoveResult = await AutoMoveRobotToImageCenter(robot, RobotCameraRotationMatrix, pixelScaleX, pixelScaleY, cancellationToken);
+            if (!autoMoveResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            calibrationInfo.CenterPoint.X= (float)autoMoveResult.X;
+            calibrationInfo.CenterPoint.Y= (float)autoMoveResult.Y;
+
 
-                return CurrentCalibration;
-            });
+            RPoint RobotU = calibrationInfo.CenterPoint.Clone();
+            RobotU.U += (float)calibrationInfo.Angle;
+
+            //机器人U轴旋转
+            await robot.CalibMotionAsync(RobotU, RobotU.Z);
+            if(cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+
+            //相机拍照并处理图像
+            var photoResult = await CaptureAndProcessCallback();
+            if (!photoResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            PointF curPixel = new PointF((float)(photoResult.X), (float)(photoResult.Y));
+
+            autoMoveResult = await AutoMoveRobotToImageCenter(robot, RobotCameraRotationMatrix, pixelScaleX, pixelScaleY, cancellationToken);
+            if (!autoMoveResult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            RobotU.X = (float)autoMoveResult.X;
+            RobotU.Y = (float)autoMoveResult.Y;
+
+            Vector<double> p0 = Vector<double>.Build.Dense(new double[] { calibrationInfo.CenterPoint.X, calibrationInfo.CenterPoint.Y });
+            Vector<double> p1 = Vector<double>.Build.Dense(new double[] { RobotU.X, RobotU.Y });
+            ToolCoord toolCoord = new ToolCoord();
+            double u1 = calibrationInfo.CenterPoint.U;
+            double u2 = RobotU.U;
+            if (robot.Brand == Enums.RobotBrand.Schneider)
+            {
+                u1 *= -1;
+                u2 *= -1;
+            }
+            toolCoord.ComputeTool(p0, p1, u1, u2);
+            if (calibrationInfo.Tool == null)
+            {
+                calibrationInfo.Tool = new RobotTool();
+            }
+
+            calibrationInfo.Tool.X = toolCoord.X;
+            calibrationInfo.Tool.Y = toolCoord.Y;
+
+            return (true, RobotCameraRotationMatrix, calibrationInfo.Tool.X, calibrationInfo.Tool.Y, pixelScaleX, pixelScaleY);
         }
 
-        public Vector3 PixelToCameraPoint(Vector2 pixel, double depth = 1.0)
+        /// <summary>
+        /// 通过未标定的相机校准工具坐标。
+        /// 当相机内参未知或未可靠标定时,通过已知机器人位姿与图像特征的对应关系反推工具坐标与像素尺度。
+        /// </summary>
+        /// <param name="calibrationInfo">标定配置信息(可能包含初始猜测或参考点)。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>同 <see cref="CalibrateFixedDownCameraTool"/> 的返回约定。</returns>
+        public async Task<(bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY)> CalibrateUncalibratedCameraTool(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken)
         {
-            // 占位:如果没有标定参数则抛出异常,避免误用
-            if (CurrentCalibration == null || !CurrentCalibration.Success) throw new InvalidOperationException("当前没有有效的标定结果。");
+            if (calibrationInfo == null) return (false, null, 0, 0, 0, 0);
+            if (robot == null || !robot.IsConnected) return (false, null, 0, 0, 0, 0);
+
+            double pixelScaleX = 0;
+            double pixelScaleY = 0;
+            Matrix<double> RobotCameraRotationMatrix = null;
+
+            //发送校准的参数
+            await robot.CalibParameAsync(calibrationInfo.Pick, calibrationInfo.Speed, calibrationInfo.Accel, calibrationInfo.Power, calibrationInfo.WaitSuction, calibrationInfo.WaitBlow);
+            (bool IsSuccess, Matrix<double> RotationMatrix, double ToolX, double ToolY, double PixelScaleX, double PixelScaleY) calibresult;
+            if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
+            {
+                calibresult = await CalibrateFixedDownCameraTool(calibrationInfo,robot,cancellationToken);
+            }
+            else if (calibrationInfo.CameraMount == Enums.CameraMount.FixedUp)
+            {
+                calibresult = await CalibrateFixedUpCameraTool(calibrationInfo, robot, cancellationToken);
+            }
+            else if (calibrationInfo.CameraMount == Enums.CameraMount.MobileJ4)
+            {
+                calibresult = await CalibrateJ4MovingDownCameraTool(calibrationInfo, robot, cancellationToken);
+            }
+            else
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            if (!calibresult.IsSuccess)
+            {
+                return (false, null, 0, 0, 0, 0);
+            }
+            
+            pixelScaleX= calibresult.PixelScaleX;
+            pixelScaleY= calibresult.PixelScaleY;
+            RobotCameraRotationMatrix= calibresult.RotationMatrix;
 
-            // TODO: 根据内参和畸变校正将像素映射到相机坐标系
-            return new Vector3((float)pixel.X, (float)pixel.Y, (float)depth);
+            return (true, RobotCameraRotationMatrix, calibresult.ToolX, calibresult.ToolY, pixelScaleX, pixelScaleY);
         }
 
-        public Vector3 CameraToRobotPoint(Vector3 cameraPoint)
+        /// <summary>
+        /// 自动识别机器人与相机图像坐标系的旋转矩阵。
+        /// 使用若干已知的机器人位姿与对应图像坐标点,估计二者之间的旋转变换与像素尺度。
+        /// </summary>
+        /// <param name="calibrationInfo">包含用于识别的点集与图像处理配置。</param>
+        /// <param name="robot">机器人接口,用于获取对应位姿或移动机器人到指定位置以采集数据。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 元组字段:
+        /// IsSuccess - 是否成功识别;
+        /// Matrix<double> - 旋转(或仿射)矩阵;
+        /// PixelScaleX - X 方向像素尺度(如 mm/px);
+        /// PixelScaleY - Y 方向像素尺度(如 mm/px)。
+        /// </returns>
+        public async Task<(bool IsSuccess, Matrix<double> RotationMatrix, double PixelScaleX, double PixelScaleY)> AutoIdentifyRobotCameraRotationMatrix(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken)
         {
-            if (CurrentCalibration == null || !CurrentCalibration.Success) throw new InvalidOperationException("当前没有有效的标定结果。");
+            //移动距离,单位mm
+            float distance = ((float)calibrationInfo.Height) / 3;
+
+            //-------------------------------------------P0-----------------------------------
+            //移动机器人至中心点
+
+            if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
+            {
+                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, 0);
+                //关闭吸气
+                await robot.CalibOutIOAsync(false);
+            }
+            else
+            {
+                await robot.CalibMotionAsync(calibrationInfo.CenterPoint, calibrationInfo.CenterPoint.Z);
+            }
+
+
+            RPoint RobotP0 = await robot.GetRobotPosAsync();
+            RPoint RobotP1 = RobotP0.Clone();
+            RPoint RobotP2 = RobotP0.Clone();
+            RobotP1.X += distance;
+            RobotP2.Y += distance;
+
+            if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
+            {
+                //移动机器人至待机位置
+                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            }
 
-            // TODO: 使用外参(旋转+平移)将相机点变换至机器人坐标系
-            return cameraPoint;
+            //相机拍照并处理图像
+            var result = await CaptureAndProcessCallback();
+            if (!result.IsSuccess)
+            {
+                return (false, null, 0, 0);
+            }
+            PointF P0 = new PointF((float)result.X, (float)result.Y);
+
+            //-------------------------------------------P1-----------------------------------
+            if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
+            {
+                //移动机器人至P0
+                await robot.CalibMotionAsync(RobotP0, 0);
+                if(cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0);
+                }
+                //打开吸气
+                await robot.CalibOutIOAsync(true);
+                //移动机器人至P1
+                await robot.CalibMotionAsync(RobotP1, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0);
+                }
+                //关闭吸气
+                await robot.CalibOutIOAsync(false);
+                //移动机器人至待机位置
+                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            }
+            else
+            {
+                //移动机器人至P1
+                await robot.CalibMotionAsync(RobotP1, RobotP1.Z);
+            }
+
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0);
+            }
+
+            //相机拍照并处理图像
+            result = await CaptureAndProcessCallback();
+            if (!result.IsSuccess)
+            {
+                return (false, null, 0, 0);
+            }
+            PointF P1 = new PointF((float)result.X, (float)result.Y);
+
+            //-------------------------------------------P2-----------------------------------
+            if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
+            {
+                //移动机器人至P1
+                await robot.CalibMotionAsync(RobotP1, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0);
+                }
+                //打开吸气
+                await robot.CalibOutIOAsync(true);
+                //移动机器人至P2
+                await robot.CalibMotionAsync(RobotP2, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0);
+                }
+                //关闭吸气
+                await robot.CalibOutIOAsync(false);
+                //移动机器人至待机位置
+                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            }
+            else
+            {
+                //移动机器人至P2
+                await robot.CalibMotionAsync(RobotP2, RobotP2.Z);
+            }
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0);
+            }
+
+            //相机拍照并处理图像
+            result = await CaptureAndProcessCallback();
+            if (!result.IsSuccess)
+            {
+                return (false, null, 0, 0);
+            }
+
+            PointF P2 = new PointF((float)result.X, (float)result.Y);
+
+            //-------------------------------------------P0--------------------------------------
+            if (calibrationInfo.CameraMount == Enums.CameraMount.FixedDown)
+            {
+                //移动机器人至P2
+                await robot.CalibMotionAsync(RobotP2, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0);
+                }
+                //打开吸气
+                await robot.CalibOutIOAsync(true);
+                //移动机器人至P0
+                await robot.CalibMotionAsync(RobotP0, 0);
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, null, 0, 0);
+                }
+                //关闭吸气
+                await robot.CalibOutIOAsync(false);
+                //移动机器人至待机位置
+                await robot.CalibMotionAsync(calibrationInfo.HomePoint, 0);
+            }
+            else
+            {
+                //移动机器人至P0
+                await robot.CalibMotionAsync(RobotP0, RobotP0.Z);
+            }
+            if (cancellationToken.IsCancellationRequested)
+            {
+                return (false, null, 0, 0);
+            }
+
+            //-----------------------------------------计算旋转矩阵------------------------------
+            Matrix<double> M = CalculateImageRotationMatrix(P0, P1, P2);
+            //Theta = Acos(M11)
+            //相机与机器人坐标系角度:Theta * 180 / PI
+            //-----------------------------------------计算像素和毫米比例-----------------------
+            Vector<double> P11 = Vector<double>.Build.Dense(new double[] { distance, 0 });
+            Vector<double> P21 = Vector<double>.Build.Dense(new double[] { P1.X, P1.Y }) - Vector<double>.Build.Dense(new double[] { P0.X, P0.Y });
+            double PixelScaleX = Math.Abs((M * P11)[0] / P21[0]);       //mm/pixel
+
+            double PixelScaleY = Math.Abs((M * P11)[1] / P21[1]);      //mm/pixel
+            return (true, M, PixelScaleX, PixelScaleY);
         }
 
-        public Vector3 RobotToCameraPoint(Vector3 robotPoint)
+        /// <summary>
+        /// 根据图像上的三个点计算图像坐标系的旋转矩阵。
+        /// 通常通过已知三点在像素坐标系中的位置计算出局部旋转/仿射变换,用于后续坐标换算。
+        /// </summary>
+        /// <param name="P0">图像中的点 0(像素坐标)。</param>
+        /// <param name="P1">图像中的点 1(像素坐标)。</param>
+        /// <param name="P2">图像中的点 2(像素坐标)。</param>
+        /// <returns>表示图像旋转或仿射变换的 3x3 或 2x2 矩阵(具体尺寸由实现决定)。</returns>
+        public Matrix<double> CalculateImageRotationMatrix(PointF P0, PointF P1, PointF P2)
         {
-            if (CurrentCalibration == null || !CurrentCalibration.Success) throw new InvalidOperationException("当前没有有效的标定结果。");
+            //1.将点转换为向量表示:
+            Vector<double> Point0 = Vector<double>.Build.Dense(new double[] { (double)P0.X, (double)P0.Y });
+            Vector<double> Point1 = Vector<double>.Build.Dense(new double[] { (double)P1.X, (double)P1.Y });
+            Vector<double> Point2 = Vector<double>.Build.Dense(new double[] { (double)P2.X, (double)P2.Y });
 
-            // TODO: 使用外参逆变换
-            return robotPoint;
+            //2.计算坐标系的基向量:
+            Vector<double> E1 = (Point1 - Point0) / (Point1 - Point0).L2Norm();
+            Vector<double> E2 = (Point2 - Point0 - E1.DotProduct(Point2 - Point0) * E1) / (Point2 - Point0 - E1.DotProduct(Point2 - Point0) * E1).L2Norm();
+
+            //3.计算旋转矩阵:我们可以使用基向量组成的矩阵作为旋转矩阵。具体地,我们可以将基向量 e1 和 e2 分别作为新坐标系下的 $x$ 和 $y$ 轴,然后组成一个矩阵,再对这个矩阵求逆即可得到旋转矩阵。代码实现:
+            Matrix<double> R = Matrix<double>.Build.DenseOfColumnVectors(E1, E2);
+            return R;
         }
 
-        public Vector3 EstimateCameraCenter()
+        /// <summary>
+        /// 自动移动机器人至图像中心点位置。
+        /// 典型用例为将相机视野中心对应的工作点转换为机器人坐标并移动机器人到该点以便校准或抓取。
+        /// </summary>
+        /// <param name="robot">机器人接口,用于执行移动命令并返回当前位置。</param>
+        /// <param name="matrix">图像坐标系到机器人坐标系的转换矩阵(旋转/仿射)。</param>
+        /// <param name="PixelScaleX">像素到物理距离在 X 方向的缩放因子(如 mm/px)。</param>
+        /// <param name="PixelScaleY">像素到物理距离在 Y 方向的缩放因子(如 mm/px)。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 元组字段:
+        /// IsSuccess - 是否成功移动到图像中心;
+        /// X - 移动后机器人在基坐标系下的 X;
+        /// Y - 移动后机器人在基坐标系下的 Y;
+        /// U - 移动后机器人的朝向(工具角度)。
+        /// </returns>
+        public async Task<(bool IsSuccess, double X, double Y, double U)> AutoMoveRobotToImageCenter(IRobot robot, Matrix<double> matrix, double PixelScaleX, double PixelScaleY, CancellationToken cancellationToken)
         {
-            if (CurrentCalibration == null || !CurrentCalibration.Success) throw new InvalidOperationException("当前没有有效的标定结果。");
+            bool IsFinish = false;
+
+            //相机拍照并处理图像
+            var result = await CaptureAndProcessCallback();
+            if (!result.IsSuccess)
+            {
+                return (false, 0, 0, 0);
+            }
+            PointF curPixel = new PointF((float)result.X, (float)result.Y);
+            //中心点像素坐标
+            PointF P0 = new PointF((float)(result.ImageWidth / 2), (float)(result.ImageHeight / 2));
+
+            var curpos = robot.GetRobotPos();
+            for (int i = 0; i < 10; i++)
+            {
+                //计算需要移动的偏移量,目的是逼近中心点
+                double offsetx = (P0.X - curPixel.X) * PixelScaleX;
+                double offsety = (P0.Y - curPixel.Y) * PixelScaleY;
+                var pos = matrix.Inverse() * Vector<double>.Build.Dense(new double[] { offsetx, offsety });
+                curpos.X += (float)pos[0];
+                curpos.Y += (float)pos[1];
+                //机器人移动
+                await robot.CalibMotionAsync(curpos, curpos.Z);
+
+                result = await CaptureAndProcessCallback();
+                if (!result.IsSuccess)
+                {
+                    return (false, 0, 0, 0);
+                }
+                curPixel = new PointF((float)result.X, (float)result.Y);
+
+                offsetx = P0.X - curPixel.X;
+                offsety = P0.Y - curPixel.Y;
+                //await Console.Out.WriteLineAsync($"移动后的差异:{offsetx},{offsety}");
+                if (Math.Abs(offsetx) < 1 && Math.Abs(offsetx) < 1)
+                {
+                    IsFinish = true;
+                    break;
+                }
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return (false, 0, 0, 0);
+                }
+            }
+            if (IsFinish)
+            {
+                var finalPos = robot.GetRobotPos();
+                return (true, finalPos.X, finalPos.Y, finalPos.U);
+            }
+            else
+            {
+                return (false, 0, 0, 0);
+            }
 
-            // TODO: 根据外参估算相机在机器人坐标系中的位置
-            return new Vector3(0, 0, 0);
         }
 
-        public void Reset()
+        /// <summary>
+        /// 自动九点标定。
+        /// 使用 9 个采样点进行仿射/透视变换求解,以提高标定精度并生成验证用的九点数据结构。
+        /// </summary>
+        /// <param name="calibrationInfo">九点标定的配置信息(点列、采集顺序、图像处理参数等)。</param>
+        /// <param name="robot">机器人接口。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>
+        /// 元组字段:
+        /// IsSuccess - 标定是否成功;
+        /// AffineTransformationMaterial - 求解得到的仿射变换矩阵;
+        /// NinePoint - 九点标定结果封装(像素点与对应的机器人位姿);
+        /// Result - 详细的标定结果与统计信息(误差、残差等)。
+        /// </returns>
+        public async Task<(bool IsSuccess, Matrix<double> AffineTransformationMaterial, RobotPixelPoint NinePoint, CalibrationResult Result)> AutoNinePointCalibration(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken)
         {
-            CurrentCalibration = null;
+
         }
 
-        public void Dispose()
+        /// <summary>
+        /// 执行校准验证。
+        /// 使用当前标定参数在一组验证点上计算误差并返回测试结果,用于评估标定质量。
+        /// </summary>
+        /// <param name="calibrationInfo">用于验证的点集与验收标准配置。</param>
+        /// <param name="robot">机器人接口,用于在验证过程中获取或移动到参考位姿。</param>
+        /// <param name="cancellationToken">用于取消操作的标记。</param>
+        /// <returns>元组字段:IsSuccess 表示验证是否通过;Result 包含详细的验证统计与误差分析。</returns>
+        public async Task<(bool IsSuccess, CalibrationTestResult Result)> ExecuteCalibrationValidation(CalibrationInfo calibrationInfo, IRobot robot, CancellationToken cancellationToken)
         {
-            if (_disposed) return;
-            _disposed = true;
-            // 释放任何非托管资源(如果有)
-            GC.SuppressFinalize(this);
+
         }
     }
 }

+ 0 - 1
TeamAAS-VM/TeamAAS-VP.csproj

@@ -590,7 +590,6 @@
     <Compile Include="Models\AlarmRecord.cs" />
     <Compile Include="Models\AnalysisParameters.cs" />
     <Compile Include="Models\AnalysisResult.cs" />
-    <Compile Include="Models\CameraCalibrationResult.cs" />
     <Compile Include="Models\ChessboardInfo.cs" />
     <Compile Include="Models\DataPoint.cs" />
     <Compile Include="Models\Lights\ChannelConfig.cs" />