From d6dc1e073be87902b672ab2ca4dd00d1fca6b9bd Mon Sep 17 00:00:00 2001 From: wangchongwu <759291707@qq.com> Date: Fri, 7 Feb 2025 10:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=842?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 4 ++-- stitch/src/Arith_BATask.cpp | 2 +- stitch/src/Arith_GeoSolver.cpp | 28 ++++++++++++++++++++++++++++ stitch/src/Arith_GeoSolver.h | 3 +++ stitch/src/Arith_VideoStitch.cpp | 6 +++--- stitch/src/Arith_VideoStitch.h | 2 +- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index d49c544..a4e7300 100644 --- a/main.cpp +++ b/main.cpp @@ -206,8 +206,8 @@ int main(int, char**) //waitKey(1); } - //imshow("pan", mat_pan); - // waitKey(1); + imshow("pan", mat_pan); + waitKey(1); diff --git a/stitch/src/Arith_BATask.cpp b/stitch/src/Arith_BATask.cpp index c5980f0..23b1e18 100644 --- a/stitch/src/Arith_BATask.cpp +++ b/stitch/src/Arith_BATask.cpp @@ -250,7 +250,7 @@ void BA_Task::optimizeBA(cv::Mat H_pan) // 配置求解器 ceres::Solver::Options options; - options.max_num_iterations = 3; // 增加最大迭代次数 + options.max_num_iterations = 1; // 增加最大迭代次数 options.function_tolerance = 1e-8; // 设置更严格的函数值容忍度 options.gradient_tolerance = 1e-10; // 设置更严格的梯度容忍度 options.parameter_tolerance = 1e-10; // 设置更严格的参数容忍度 diff --git a/stitch/src/Arith_GeoSolver.cpp b/stitch/src/Arith_GeoSolver.cpp index 83d55fa..2b783b3 100644 --- a/stitch/src/Arith_GeoSolver.cpp +++ b/stitch/src/Arith_GeoSolver.cpp @@ -238,6 +238,34 @@ cv::Mat GeoSolver::findHomography(Proj proj) return H; } +cv::Mat GeoSolver::findHomography(FrameInfo info) +{ + Proj _proj = AnlayseTform(info); + + std::vector srcPoints; + srcPoints.push_back(cv::Point2f(0, 0)); + srcPoints.push_back(cv::Point2f(1000, 0)); + srcPoints.push_back(cv::Point2f(1000, 1000)); + srcPoints.push_back(cv::Point2f(0, 1000)); + + // 同名点计算,从像方到全景 + cv::Point2f leftTop_map = Trans_uv2Geo(srcPoints[0], _proj.tf_p2g); + cv::Point2f rightTop_map = Trans_uv2Geo(srcPoints[1], _proj.tf_p2g); + cv::Point2f rightBottom_map = Trans_uv2Geo(srcPoints[2], _proj.tf_p2g); + cv::Point2f leftBottom_map = Trans_uv2Geo(srcPoints[3], _proj.tf_p2g); + + // 目标图像(全景图)的四个顶点坐标 + std::vector dstPoints; + dstPoints.push_back(leftTop_map); // 左 + dstPoints.push_back(rightTop_map); // 右上 + dstPoints.push_back(rightBottom_map); // 右下 + dstPoints.push_back(leftBottom_map); // 左下 + + // 计算单应性矩阵 H + cv::Mat H = cv::findHomography(srcPoints, dstPoints); + return H; +} + // 计算多边形的面积 double polygonArea(const vector& points) diff --git a/stitch/src/Arith_GeoSolver.h b/stitch/src/Arith_GeoSolver.h index d940aad..f690908 100644 --- a/stitch/src/Arith_GeoSolver.h +++ b/stitch/src/Arith_GeoSolver.h @@ -57,6 +57,9 @@ public: // 建立全景图与归一化地理系的H矩阵 cv::Mat findHomography(Proj proj); + // 建立全景图与归一化地理系的H矩阵 + cv::Mat findHomography(FrameInfo info); + // 设置起始拼接点外参 void SetOriginPoint(FrameInfo info); diff --git a/stitch/src/Arith_VideoStitch.cpp b/stitch/src/Arith_VideoStitch.cpp index 74351b8..70dcc8d 100644 --- a/stitch/src/Arith_VideoStitch.cpp +++ b/stitch/src/Arith_VideoStitch.cpp @@ -145,7 +145,7 @@ BYTE8 VideoStitch::GeoStitch(GD_VIDEO_FRAME_S img, FrameInfo para) cv::Mat H1 = _GeoStitcher->findHomography(t_Proj); // Geo2Pan H - cv::Mat H2 = getHFromGeo2Pan(_panPara); + cv::Mat H2 = getAffineFromGeo2Pan(_panPara); cv::Mat H = H2 * H1; @@ -175,7 +175,7 @@ SINT32 VideoStitch::BAStitch(GD_VIDEO_FRAME_S img, FrameInfo para) SINT32 VideoStitch::BAOpt() { - _BATask->optimizeBA(getHFromGeo2Pan(_panPara)); + _BATask->optimizeBA(getAffineFromGeo2Pan(_panPara)); return 0; } @@ -232,7 +232,7 @@ GD_VIDEO_FRAME_S VideoStitch::ExportPanAddr() return pan_out; } -cv::Mat VideoStitch::getHFromGeo2Pan(PanInfo _pan) +cv::Mat VideoStitch::getAffineFromGeo2Pan(PanInfo _pan) { Mat H = (Mat_(3, 3) << _pan.scale, 0, _pan.map_shiftX, 0, -_pan.scale, _panPara.m_pan_height + _pan.map_shiftY, diff --git a/stitch/src/Arith_VideoStitch.h b/stitch/src/Arith_VideoStitch.h index a8a9bff..129496b 100644 --- a/stitch/src/Arith_VideoStitch.h +++ b/stitch/src/Arith_VideoStitch.h @@ -44,7 +44,7 @@ private: PanInfo _panPara;//全景图配置 - cv::Mat getHFromGeo2Pan(PanInfo _pan);//计算全景图投影,从地理系到全景地图,统一计算 + cv::Mat getAffineFromGeo2Pan(PanInfo _pan);//计算全景图投影,从地理系到全景地图,统一计算 cv::Mat _pan;