You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.7 KiB

#include "utils.h"
Utils::Utils()
{
}
Utils::~Utils()
{
}
int Utils::open(const std::string & folder)
{
this->m_order = 0;
this->folder = folder;
std::ifstream file(folder + "/list.txt");
if (!file.is_open())
{
std::cout << "错误:无法打开文件 " << folder + "list.txt" << std::endl;
return 0;
}
std::string line;
int lineCount = 0;
int successCount = 0;
while (getline(file, line))
{
// 跳过空行
if (line.empty())
{
continue;
}
lineCount++;
// 按照文件名-经纬高-角度-内参读取到frameInfoList中
FrameInfo frameInfo = {0};
// 解析每行数据Frame 序号,纬度,经度,绝对高,相对高,偏航,俯仰,横滚,伺服方位,伺服俯仰,焦距,像素大小
int frameId;
double lat, lon, height1, height2;
double angle1, angle2, angle3, angle4, angle5;
float param1, param2;
// 使用sscanf解析字符串
if (sscanf(line.c_str(), "Frame %d,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%f,%f",
&frameId, &lat, &lon, &height1, &height2,
&angle1, &angle2, &angle3, &angle4, &angle5,
&param1, &param2) == 12)
{
// 解析Frame序号
frameInfo.nFrmID = frameId;
// 解析经纬度
frameInfo.craft.stPos.B = lat; // 纬度
frameInfo.craft.stPos.L = lon; // 经度
// 解析高度(取第一个高度值)
frameInfo.craft.stPos.H = height1;
frameInfo.nEvHeight = height2;
// 解析角度信息
frameInfo.craft.stAtt.fRoll = angle3; // 横滚角
frameInfo.craft.stAtt.fPitch = angle2; // 俯仰角
frameInfo.craft.stAtt.fYaw = angle1; // 方位角
// 解析伺服信息
frameInfo.servoInfo.fServoAz = angle4; // 伺服方位角
frameInfo.servoInfo.fServoPt = angle5; // 伺服俯仰角
// 解析内参信息
frameInfo.camInfo.fPixelSize = param2; // 像元尺寸
frameInfo.camInfo.nFocus = param1; // 焦距
// 设置默认值
frameInfo.craft.nPlaneID = 1;
frameInfo.camInfo.dCamx = 0; // 像主点偏移x
frameInfo.camInfo.dCamy = 0; // 像主点偏移y
frameInfo.servoInfo.fServoAzSpeed = 0.0f; // 伺服方位角速度
frameInfo.servoInfo.fServoPtSpeed = 0.0f; // 伺服俯仰角速度
//frameInfo.nWidth = 1920; // 默认图像宽度
//frameInfo.nHeight = 1080; // 默认图像高度
// 添加到列表中
frameInfoList.push_back(frameInfo);
successCount++;
}
else
{
std::cout << "警告:第 " << lineCount << " 行解析失败: " << line << std::endl;
}
}
file.close();
std::cout << "读取完成:总共 " << lineCount << " 行,成功解析 " << successCount << "" << std::endl;
return lineCount;
}
std::pair<FrameInfo, cv::Mat> Utils::readInfoAndMat()
{
FrameInfo info = frameInfoList[m_order];
// 读取图片
std::string picPath = folder + "/" + "frame_" + std::to_string(info.nFrmID) + ".jpg";
cv::Mat mat = cv::imread(picPath);
m_order++;
// 如果读取失败,则返回空
if (mat.empty())
{
std::cout << "读取失败:" << picPath << std::endl;
return std::make_pair(info, cv::Mat());
}
info.nWidth = mat.cols;
info.nHeight = mat.rows;
return std::make_pair(info, mat.clone());
}