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.

212 lines
5.3 KiB

1 month ago
#include "S732.h"
#include <iostream>
#include "API_UnderStitch.h"
#include "PlatformDefine.h"
#include <string.h>
#include "opencv2/opencv.hpp"
#include <random>
#include <string>
using namespace cv;
using namespace std;
void ProcessVL(string filePath)
{
auto stitcher = API_UnderStitch::Create("D:/cache");
1 month ago
stitcher->SetOutput("BT", "google_tiles");
GD_VIDEO_FRAME_S frame = { 0 };//输入帧
GD_VIDEO_FRAME_S pan = { 0 };//输出全景
cv::Mat mat_pan;//全景显示
FILE* file = fopen(filePath.c_str(), "rb");
cv::VideoWriter output;
int i = 0;
SINT32 nVLFrameSize = 1.5 * (S732_VL_W * S732_VL_H + S732_VL_W * PARA_VL_LINE_S732);
unsigned char* pFrameVL = new unsigned char[nVLFrameSize];
bool stitchInit = false;
std::deque<FrameInfo> infoBuffer;
const int delayFrames = 5; // 假设延迟3帧
std::deque<cv::Mat> MatBuffer;
const int matdelayFrames = 2; // 假设延迟3帧
fseek(file, nVLFrameSize * 80, SEEK_SET);
1 month ago
while (!feof(file))
{
fread(pFrameVL, 1, nVLFrameSize, file);
STD_DTArith_Record732 Paras_VL = { 0 };
memcpy(&Paras_VL, (unsigned char*)(pFrameVL + int(1.5 * S732_VL_W * S732_VL_H)), sizeof(STD_DTArith_Record732));
FrameInfo info_rev = { 0 };
info_rev.nFrmID = i;
1 month ago
info_rev.camInfo.fPixelSize = Paras_VL.trackInputPara.stCameraInfo.fPixelSize;
1 month ago
info_rev.camInfo.nFocus = Paras_VL.trackInputPara.stCameraInfo.nFocus;
1 month ago
info_rev.craft.stAtt.fYaw = Paras_VL.trackInputPara.stAirCraftInfo.stAtt.fYaw;
info_rev.craft.stAtt.fPitch = Paras_VL.trackInputPara.stAirCraftInfo.stAtt.fPitch;
info_rev.craft.stAtt.fRoll = Paras_VL.trackInputPara.stAirCraftInfo.stAtt.fRoll;
1 month ago
info_rev.craft.stPos.B = Paras_VL.trackInputPara.stAirCraftInfo.stPos.B;
info_rev.craft.stPos.L = Paras_VL.trackInputPara.stAirCraftInfo.stPos.L;
info_rev.craft.stPos.H = Paras_VL.trackInputPara.stAirCraftInfo.stPos.H;
1 month ago
info_rev.nEvHeight = info_rev.craft.stPos.H - 1360;
1 month ago
info_rev.servoInfo.fServoAz = Paras_VL.trackInputPara.stServoInfo.fServoAz;
info_rev.servoInfo.fServoPt = Paras_VL.trackInputPara.stServoInfo.fServoPt;
1 month ago
info_rev.nWidth = S732_VL_W;
info_rev.nHeight = S732_VL_H;
1 month ago
FrameInfo info = info_rev;
1 month ago
cv::Mat mat_src(S732_VL_H * 1.5, S732_VL_W, CV_8UC1, pFrameVL);
cv::Mat IMG;
cv::cvtColor(mat_src, IMG, cv::COLOR_YUV2GRAY_NV21);
1 month ago
cv::Mat f;
IMG.convertTo(f, CV_32F, 1.0 / 255.0);
cv::pow(f, 0.8, f); // gamma < 1 => 变亮
cv::Mat bright;
f.convertTo(bright, CV_8U, 255.0);
cv::cvtColor(bright, bright, cv::COLOR_GRAY2BGR);
1 month ago
cv::namedWindow("IMG_show", cv::WINDOW_NORMAL);
imshow("IMG_show", IMG);
1 month ago
MatBuffer.push_back(bright.clone());
if (MatBuffer.size() < matdelayFrames)
{
continue;
}
cv::Mat matuse = MatBuffer.front();
MatBuffer.pop_front();
frame.enPixelFormat = GD_PIXEL_FORMAT_RGB_PACKED;
1 month ago
frame.u32Width = S732_VL_W;
frame.u32Height = S732_VL_H;
frame.u64VirAddr[0] = matuse.data;
1 month ago
//imwrite("D:/imgVL_u.jpg", IMG);
if (!stitchInit)
1 month ago
{
stitchInit = true;
1 month ago
stitcher->Init(info);
UPanConfig cfg = { 0 };
cfg.bOutGoogleTile = 0;
1 month ago
cfg.bOutFrameTile = 0;
cfg.bUseBA = 0;
1 month ago
stitcher->SetConfig(cfg);
stitcher->SetOutput("baotou","F:/google_tiles");
1 month ago
pan = stitcher->ExportPanAddr();
mat_pan = cv::Mat(pan.u32Height, pan.u32Width, CV_8UC4, pan.u64VirAddr[0]);
output.open("output.mp4", VideoWriter::fourcc('M', 'P', '4', 'V'), 50, Size(pan.u32Width / 8, pan.u32Height / 8), true);
1 month ago
if (!output.isOpened())
{
cout << "打开视频失败" << endl;
return;
}
}
else
{
std::cout << info.nFrmID << " " <<info.craft.stPos.B << " " << info.craft.stPos.L << " " << info.craft.stPos.H << " "
1 month ago
<< info.craft.stAtt.fYaw << " " << info.craft.stAtt.fPitch << " " << info.craft.stAtt.fRoll << " "
<< info.servoInfo.fServoAz << " " << info.servoInfo.fServoPt + 90
<< std::endl;
cv::TickMeter tm;
tm.start();
// 基于外参的快拼
stitcher->Run(frame, info);
tm.stop();
cout << "time:" << tm.getTimeMilli() << endl;
}
Mat pan_ds;
Mat pan_rgb_ds(cv::Size(mat_pan.cols / 8, mat_pan.rows / 8),CV_8UC3);
cv::resize(mat_pan, pan_ds, cv::Size(mat_pan.cols / 8, mat_pan.rows / 8));
cv::cvtColor(pan_ds, pan_rgb_ds, cv::COLOR_BGRA2BGR);
1 month ago
output.write(pan_rgb_ds);
cv::namedWindow("pan_opt",0);
1 month ago
imshow("pan_opt", pan_rgb_ds);
if (cv::waitKey(1) == 27)
{
break;
}
1 month ago
i = i + 1;
1 month ago
}
//cv::TickMeter tm;
//tm.start();
//// 处理帧
//stitcher->OptAndOutCurrPan();
1 month ago
//tm.stop();
1 month ago
//cout << "time opt:" << tm.getTimeMilli() << endl;
1 month ago
waitKey(1);
output.release();
}
int main()
{
ProcessVL("F:/包头/20251101/20251101_092143724_3.yuv");
1 month ago
return 0;
}