From b1b59a6e07bc65acd065b627b20016eb524efef9 Mon Sep 17 00:00:00 2001 From: wangchongwu <759291707@qq.com> Date: Fri, 7 Feb 2025 10:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=843?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 4 +- stitch/src/Arith_BATask.cpp | 4 +- stitch/src/Arith_GeoSolver.cpp | 84 ++++++-------------------------- stitch/src/Arith_GeoSolver.h | 18 ++----- stitch/src/Arith_VideoStitch.cpp | 9 +++- 5 files changed, 29 insertions(+), 90 deletions(-) diff --git a/main.cpp b/main.cpp index a4e7300..751e237 100644 --- a/main.cpp +++ b/main.cpp @@ -187,10 +187,10 @@ int main(int, char**) << std::endl; // 基于地理系的拼接 - //stitcher->GeoStitch(frame,info); + stitcher->GeoStitch(frame,info); // 基于地理+BA拼接 - auto nNum = stitcher->BAStitch(frame,info); + //auto nNum = stitcher->BAStitch(frame,info); // test接口 //if (info.nFrmID == 30 || info.nFrmID == 40) diff --git a/stitch/src/Arith_BATask.cpp b/stitch/src/Arith_BATask.cpp index 23b1e18..114109d 100644 --- a/stitch/src/Arith_BATask.cpp +++ b/stitch/src/Arith_BATask.cpp @@ -95,8 +95,8 @@ SINT32 BA_Task::addFrame(GD_VIDEO_FRAME_S img, FrameInfo para) _paraVec.push_back(para); // 缓存初始H - Proj t_Proj = _GeoStitcher->AnlayseTform(para); - auto H = _GeoStitcher->findHomography(t_Proj); + //Proj t_Proj = _GeoStitcher->AnlayseTform(para); + auto H = _GeoStitcher->findHomography(para); _origMatrix.push_back(H.clone()); _currMatrix.push_back(H.clone()); diff --git a/stitch/src/Arith_GeoSolver.cpp b/stitch/src/Arith_GeoSolver.cpp index 2b783b3..cfb494b 100644 --- a/stitch/src/Arith_GeoSolver.cpp +++ b/stitch/src/Arith_GeoSolver.cpp @@ -15,21 +15,21 @@ GeoSolver::~GeoSolver() -cv::Point2f GeoSolver::project(cv::Point2f pos_pan, Proj m_Proj, PanInfo pan) -{ - cv::Point2f pos_geo = Trans_pan2Geo(pos_pan, pan); - cv::Point2f pos_frame = Trans_Geo2uv(pos_geo, m_Proj.tf_g2p); - return pos_frame; -} - -cv::Point2f GeoSolver::back_project(cv::Point2f pos_frame, Proj m_Proj, PanInfo pan) -{ - cv::Point2f pos_geo = Trans_uv2Geo(pos_frame, m_Proj.tf_p2g); - - cv::Point2f pos_pan = Trans_Geo2pan(pos_geo, pan); - - return pos_pan; -} +//cv::Point2f GeoSolver::project(cv::Point2f pos_pan, Proj m_Proj, PanInfo pan) +//{ +// cv::Point2f pos_geo = Trans_pan2Geo(pos_pan, pan); +// cv::Point2f pos_frame = Trans_Geo2uv(pos_geo, m_Proj.tf_g2p); +// return pos_frame; +//} +// +//cv::Point2f GeoSolver::back_project(cv::Point2f pos_frame, Proj m_Proj, PanInfo pan) +//{ +// cv::Point2f pos_geo = Trans_uv2Geo(pos_frame, m_Proj.tf_p2g); +// +// cv::Point2f pos_pan = Trans_Geo2pan(pos_geo, pan); +// +// return pos_pan; +//} void GeoSolver::SetOriginPoint(FrameInfo info) { @@ -182,61 +182,7 @@ Proj GeoSolver::AnlayseTform(FrameInfo info) return projection; } -cv::Mat GeoSolver::findHomography(Proj proj, PanInfo pan) -{ - // 同名点计算,从像方到全景 - cv::Point2f leftTop_map = back_project(cv::Point2f(0,0), proj, pan); - cv::Point2f rightTop_map = back_project(cv::Point2f(1000,0), proj, pan); - cv::Point2f rightBottom_map = back_project(cv::Point2f(1000,1000), proj, pan); - cv::Point2f leftBottom_map = back_project(cv::Point2f(0,1000), proj, pan); - - - 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)); - - // 目标图像(全景图)的四个顶点坐标 - 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; -} - -cv::Mat GeoSolver::findHomography(Proj proj) -{ - 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; -} cv::Mat GeoSolver::findHomography(FrameInfo info) { diff --git a/stitch/src/Arith_GeoSolver.h b/stitch/src/Arith_GeoSolver.h index f690908..ce8617b 100644 --- a/stitch/src/Arith_GeoSolver.h +++ b/stitch/src/Arith_GeoSolver.h @@ -41,21 +41,6 @@ public: - // 投影:从全景图到帧 - cv::Point2f project(cv::Point2f pos_pan, Proj m_Proj, PanInfo pan); - - // 反投影:从帧到全景图 - cv::Point2f back_project(cv::Point2f pos_frame, Proj m_Proj, PanInfo pan); - - - // 计算当前帧像方-地理坐标系R t(反投影关系) - Proj AnlayseTform(FrameInfo info); - - // 建立H矩阵,经验证与上述反投影过程完全等效,该过程应该可以通过解析直接获得,此处不再深入研究 - cv::Mat findHomography(Proj proj,PanInfo pan); - - // 建立全景图与归一化地理系的H矩阵 - cv::Mat findHomography(Proj proj); // 建立全景图与归一化地理系的H矩阵 cv::Mat findHomography(FrameInfo info); @@ -64,6 +49,9 @@ public: void SetOriginPoint(FrameInfo info); public: + // 计算当前帧像方-地理坐标系R t(反投影关系) + Proj AnlayseTform(FrameInfo info); + // 帧像方-地理坐标 cv::Point2f Trans_uv2Geo(cv::Point2f pos_frame, TForm form); diff --git a/stitch/src/Arith_VideoStitch.cpp b/stitch/src/Arith_VideoStitch.cpp index 70dcc8d..fc05887 100644 --- a/stitch/src/Arith_VideoStitch.cpp +++ b/stitch/src/Arith_VideoStitch.cpp @@ -56,6 +56,12 @@ PanInfo VideoStitch::InitMap(FrameInfo info) // 直接无平移解算 auto cur = _GeoStitcher->Trans_Geo2pan(ct_geo, panPara); + + auto cur2 = warpPointWithH(getAffineFromGeo2Pan(panPara), cv::Point2f(info.nWidth / 2, info.nHeight / 2)); + + + + // 计算平移到全景图固定点的平移量,从此处开始拼接 int planX = 200; int planY = 200; @@ -139,10 +145,9 @@ PanInfo VideoStitch::Init(FrameInfo info) BYTE8 VideoStitch::GeoStitch(GD_VIDEO_FRAME_S img, FrameInfo para) { - Proj t_Proj = _GeoStitcher->AnlayseTform(para); // uv2Geo H - cv::Mat H1 = _GeoStitcher->findHomography(t_Proj); + cv::Mat H1 = _GeoStitcher->findHomography(para); // Geo2Pan H cv::Mat H2 = getAffineFromGeo2Pan(_panPara);