main
wangchongwu 5 months ago
parent d6dc1e073b
commit b1b59a6e07

@ -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)

@ -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());

@ -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<cv::Point2f> 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<cv::Point2f> 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<cv::Point2f> 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<cv::Point2f> 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)
{

@ -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);

@ -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);

Loading…
Cancel
Save