|
|
|
@ -1,58 +1,28 @@
|
|
|
|
|
#include "Arith_GeoStitcher.h"
|
|
|
|
|
#include "Arith_GeoSolver.h"
|
|
|
|
|
#include "Arith_VideoStitch.h"
|
|
|
|
|
#include "Arith_Utils.h"
|
|
|
|
|
#include "Arith_CoordModule.h"
|
|
|
|
|
#include "Arith_SysStruct.h"
|
|
|
|
|
using namespace cv;
|
|
|
|
|
|
|
|
|
|
GeoStitcher::GeoStitcher()
|
|
|
|
|
GeoSolver::GeoSolver()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GeoStitcher::~GeoStitcher()
|
|
|
|
|
GeoSolver::~GeoSolver()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PanInfo GeoStitcher::InitMap(FrameInfo info)
|
|
|
|
|
{
|
|
|
|
|
// 设置拼接原点
|
|
|
|
|
SetOriginPoint(info);
|
|
|
|
|
|
|
|
|
|
// 转换关系计算
|
|
|
|
|
Proj t_Proj = AnlayseTform(info);
|
|
|
|
|
|
|
|
|
|
// 帧中心的大地坐标,将其平移到全景图中心
|
|
|
|
|
cv::Point2f ct_geo = Trans_uv2Geo(cv::Point2f(info.nWidth / 2, info.nHeight / 2), t_Proj.tf_p2g);
|
|
|
|
|
|
|
|
|
|
// 全景图初始化
|
|
|
|
|
PanInfo panPara = {0};
|
|
|
|
|
panPara.m_pan_width = 1000;//全景宽
|
|
|
|
|
panPara.m_pan_height = 1000;//全景高
|
|
|
|
|
panPara.scale = 0.5;//比例尺,1m = ?pix
|
|
|
|
|
|
|
|
|
|
// 直接无平移解算
|
|
|
|
|
auto cur = Trans_Geo2pan(ct_geo, panPara);
|
|
|
|
|
|
|
|
|
|
// 计算平移到全景图固定点的平移量,从此处开始拼接
|
|
|
|
|
int planX = 200;
|
|
|
|
|
int planY = 200;
|
|
|
|
|
|
|
|
|
|
panPara.map_shiftX = planX - (cur.x);//平移X
|
|
|
|
|
panPara.map_shiftY = planY - (cur.y);//平移Y
|
|
|
|
|
|
|
|
|
|
return panPara;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv::Point2f GeoStitcher::project(cv::Point2f pos_pan, Proj m_Proj, PanInfo 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 GeoStitcher::back_project(cv::Point2f pos_frame, Proj m_Proj, PanInfo pan)
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
@ -61,12 +31,12 @@ cv::Point2f GeoStitcher::back_project(cv::Point2f pos_frame, Proj m_Proj, PanInf
|
|
|
|
|
return pos_pan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeoStitcher::SetOriginPoint(FrameInfo info)
|
|
|
|
|
void GeoSolver::SetOriginPoint(FrameInfo info)
|
|
|
|
|
{
|
|
|
|
|
originPoint = getXYZFromBLH(info.craft.stPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Point2f GeoStitcher::Trans_uv2Geo(cv::Point2f pos_frame, TForm form)
|
|
|
|
|
cv::Point2f GeoSolver::Trans_uv2Geo(cv::Point2f pos_frame, TForm form)
|
|
|
|
|
{
|
|
|
|
|
Mat point = (Mat_<double>(3, 1) << pos_frame.x, pos_frame.y, 1);
|
|
|
|
|
Mat result = form.R * point;
|
|
|
|
@ -80,7 +50,7 @@ cv::Point2f GeoStitcher::Trans_uv2Geo(cv::Point2f pos_frame, TForm form)
|
|
|
|
|
return cv::Point2f(warpedX, warpedY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Point2f GeoStitcher::Trans_Geo2uv(cv::Point2f pos_geo, TForm form_inv)
|
|
|
|
|
cv::Point2f GeoSolver::Trans_Geo2uv(cv::Point2f pos_geo, TForm form_inv)
|
|
|
|
|
{
|
|
|
|
|
// 先平移到当前相机位置
|
|
|
|
|
cv::Point2f pos_cam = pos_geo;
|
|
|
|
@ -97,7 +67,7 @@ cv::Point2f GeoStitcher::Trans_Geo2uv(cv::Point2f pos_geo, TForm form_inv)
|
|
|
|
|
return cv::Point2f(warpedX, warpedY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Point2f GeoStitcher::Trans_pan2Geo(cv::Point2f pos_pan, PanInfo panPara)
|
|
|
|
|
cv::Point2f GeoSolver::Trans_pan2Geo(cv::Point2f pos_pan, PanInfo panPara)
|
|
|
|
|
{
|
|
|
|
|
double x = (pos_pan.x - panPara.map_shiftX) / panPara.scale;
|
|
|
|
|
double y = (panPara.m_pan_height - (pos_pan.y - panPara.map_shiftY)) / panPara.scale;
|
|
|
|
@ -105,7 +75,7 @@ cv::Point2f GeoStitcher::Trans_pan2Geo(cv::Point2f pos_pan, PanInfo panPara)
|
|
|
|
|
return cv::Point2f(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Point2f GeoStitcher::Trans_Geo2pan(cv::Point2f pos_geo, PanInfo panPara)
|
|
|
|
|
cv::Point2f GeoSolver::Trans_Geo2pan(cv::Point2f pos_geo, PanInfo panPara)
|
|
|
|
|
{
|
|
|
|
|
double pan_x = pos_geo.x * panPara.scale + panPara.map_shiftX;
|
|
|
|
|
double pan_y = (panPara.m_pan_height - pos_geo.y * panPara.scale) + panPara.map_shiftY;
|
|
|
|
@ -114,7 +84,7 @@ cv::Point2f GeoStitcher::Trans_Geo2pan(cv::Point2f pos_geo, PanInfo panPara)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat GeoStitcher::Mat_TransENGMove(FrameInfo info)
|
|
|
|
|
Mat GeoSolver::Mat_TransENGMove(FrameInfo info)
|
|
|
|
|
{
|
|
|
|
|
PointXYZ ptCurr = getXYZFromBLH(info.craft.stPos);
|
|
|
|
|
PointXYZ diff = getNUEXYZFromCGCSXYZ(ptCurr, originPoint);
|
|
|
|
@ -127,7 +97,7 @@ Mat GeoStitcher::Mat_TransENGMove(FrameInfo info)
|
|
|
|
|
return move;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mat GeoStitcher::Mat_TransENG2uv(FrameInfo info)
|
|
|
|
|
Mat GeoSolver::Mat_TransENG2uv(FrameInfo info)
|
|
|
|
|
{
|
|
|
|
|
//从地理坐标系转像素坐标
|
|
|
|
|
|
|
|
|
@ -198,7 +168,7 @@ Mat GeoStitcher::Mat_TransENG2uv(FrameInfo info)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Proj GeoStitcher::AnlayseTform(FrameInfo info)
|
|
|
|
|
Proj GeoSolver::AnlayseTform(FrameInfo info)
|
|
|
|
|
{
|
|
|
|
|
Proj projection;
|
|
|
|
|
// 从像方->地理
|
|
|
|
@ -212,7 +182,7 @@ Proj GeoStitcher::AnlayseTform(FrameInfo info)
|
|
|
|
|
return projection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Mat GeoStitcher::findHomography(Proj proj, PanInfo pan)
|
|
|
|
|
cv::Mat GeoSolver::findHomography(Proj proj, PanInfo pan)
|
|
|
|
|
{
|
|
|
|
|
// 同名点计算,从像方到全景
|
|
|
|
|
cv::Point2f leftTop_map = back_project(cv::Point2f(0,0), proj, pan);
|
|
|
|
@ -241,7 +211,7 @@ cv::Mat GeoStitcher::findHomography(Proj proj, PanInfo pan)
|
|
|
|
|
return H;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Mat GeoStitcher::findHomography(Proj proj)
|
|
|
|
|
cv::Mat GeoSolver::findHomography(Proj proj)
|
|
|
|
|
{
|
|
|
|
|
std::vector<cv::Point2f> srcPoints;
|
|
|
|
|
srcPoints.push_back(cv::Point2f(0, 0));
|