2,新增“Apps”; 3,新增“Common”; 4,新增“FileList”; 5,新增“MediaX”; 6,新增“OpenSource”; 7,新增“Samples”; 8,新增“SoftwareBusinessLines”.
897 lines
26 KiB
C++
897 lines
26 KiB
C++
#include "mainwindow.h"
|
||
#include "ui_mainwindow.h"
|
||
|
||
#include <QFile>
|
||
#include <QMessageBox>
|
||
#include <QFileDialog>
|
||
#include <QString>
|
||
#include <QDebug>
|
||
|
||
#include "commonhelper.h"
|
||
#include "frameless_helper.h"
|
||
|
||
#include <mmsystem.h>
|
||
#pragma comment(lib, "winmm")
|
||
|
||
#define MaxSize_IRSensorTool (4096*2048)
|
||
|
||
MainWindow::MainWindow(QWidget *parent) :
|
||
QMainWindow(parent),
|
||
ui(new Ui::MainWindow)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
this->setWindowTitle(tr(" ") );
|
||
|
||
// OpenGLView
|
||
//this->setAttribute(Qt::WA_Mapped);
|
||
|
||
m_nImageWidth = 1280;
|
||
m_nImageHeight = 1024;
|
||
|
||
//
|
||
m_bMousePressed = false;
|
||
|
||
//
|
||
m_bThreadRunning_CaptureDeviceData = false;
|
||
m_ptrThread_CaptureDeviceData = nullptr;
|
||
|
||
m_bEnableCapture = false;
|
||
m_nImageMoveIndex = 0;
|
||
|
||
// 初始化界面
|
||
InitStyle();
|
||
|
||
//
|
||
//this->setFixedWidth(660);
|
||
//ui->wgtTitleBar->setFixedWidth(650);
|
||
|
||
//
|
||
m_varCaptureData.InitQueue(DefaultMaxImageSize, 6);
|
||
m_varY16Data.InitQueue(DefaultImageWidth*DefaultImageHeight*2, 6);
|
||
|
||
// 加载信号槽函数连接
|
||
Connect();
|
||
|
||
InitOpenGLView();
|
||
|
||
m_pTestDataBuffer = new byte[640*512*4*2 + 4096];
|
||
|
||
for (int h = 0; h < 512*2; h++)
|
||
{
|
||
memset(m_pTestDataBuffer + h*640*4, h, 640*4);
|
||
}
|
||
|
||
m_eIR = eIR_640_512;
|
||
|
||
//
|
||
m_pY16Data_B1 = new ushort[MaxSize_IRSensorTool+4096];
|
||
memset(m_pY16Data_B1, 0, MaxSize_IRSensorTool*2);
|
||
|
||
m_pY8Data_B1 = new byte[MaxSize_IRSensorTool+4096];
|
||
memset(m_pY8Data_B1, 0, MaxSize_IRSensorTool);
|
||
|
||
m_pY16Data_B2 = new ushort[MaxSize_IRSensorTool+4096];
|
||
memset(m_pY16Data_B2, 0, MaxSize_IRSensorTool*2);
|
||
|
||
m_pY8Data_B2 = new byte[MaxSize_IRSensorTool+4096];
|
||
memset(m_pY8Data_B2, 0, MaxSize_IRSensorTool);
|
||
|
||
m_pRGBA = new byte[MaxSize_IRSensorTool+4096];
|
||
memset(m_pRGBA, 0, MaxSize_IRSensorTool);
|
||
|
||
m_pY16Data_KList = new ushort[MaxSize_IRSensorTool+4096];
|
||
memset(m_pY16Data_KList, 0, MaxSize_IRSensorTool*2);
|
||
|
||
m_pY16Data_BPList = new ushort[MaxSize_IRSensorTool+4096];
|
||
memset(m_pY16Data_BPList, 0, MaxSize_IRSensorTool*2);
|
||
}
|
||
|
||
MainWindow::~MainWindow()
|
||
{
|
||
//
|
||
if(nullptr != m_pY16Data_B1)
|
||
{
|
||
delete [] m_pY16Data_B1;
|
||
m_pY16Data_B1 = nullptr;
|
||
}
|
||
|
||
if(nullptr != m_pY8Data_B1)
|
||
{
|
||
delete [] m_pY8Data_B1;
|
||
m_pY8Data_B1 = nullptr;
|
||
}
|
||
|
||
if(nullptr != m_pY16Data_B2)
|
||
{
|
||
delete [] m_pY16Data_B2;
|
||
m_pY16Data_B2 = nullptr;
|
||
}
|
||
|
||
if(nullptr != m_pY8Data_B2)
|
||
{
|
||
delete [] m_pY8Data_B2;
|
||
m_pY8Data_B2 = nullptr;
|
||
}
|
||
|
||
if(nullptr != m_pRGBA)
|
||
{
|
||
delete [] m_pRGBA;
|
||
m_pRGBA = nullptr;
|
||
}
|
||
|
||
if(nullptr != m_pY16Data_KList)
|
||
{
|
||
delete [] m_pY16Data_KList;
|
||
m_pY16Data_KList = nullptr;
|
||
}
|
||
|
||
if(nullptr != m_pY16Data_BPList)
|
||
{
|
||
delete [] m_pY16Data_BPList;
|
||
m_pY16Data_BPList = nullptr;
|
||
}
|
||
|
||
//
|
||
if(nullptr != m_pTestDataBuffer)
|
||
{
|
||
delete [] m_pTestDataBuffer;
|
||
m_pTestDataBuffer = nullptr;
|
||
}
|
||
|
||
if(nullptr != m_pOpenGLView)
|
||
{
|
||
delete m_pOpenGLView;
|
||
m_pOpenGLView = nullptr;
|
||
}
|
||
|
||
//
|
||
StopThread_DealDeviceData();
|
||
|
||
Disconnect();
|
||
|
||
delete ui;
|
||
}
|
||
|
||
bool MainWindow::CaptureData(byte* pFrameData, int nFrameDataLen)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
void MainWindow::InitOpenGLView()
|
||
{
|
||
ui->m_openGLWidget_Capture->Init(640,512);
|
||
m_pOpenGLView = ui->m_openGLWidget_Capture;
|
||
}
|
||
|
||
void MainWindow::Connect()
|
||
{
|
||
// 通用
|
||
connect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
connect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
// 测试图像
|
||
connect(ui->m_pushButton_TestImage, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_TestImage);
|
||
|
||
// 分辨率切换
|
||
connect(ui->m_radioButton_Resolution_320_256, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
connect(ui->m_radioButton_Resolution_320_288, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
connect(ui->m_radioButton_Resolution_400_300, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
connect(ui->m_radioButton_Resolution_640_512, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
connect(ui->m_radioButton_Resolution_800_600, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
connect(ui->m_radioButton_Resolution_1280_1024, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
connect(ui->m_radioButton_Resolution_Other, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
connect(ui->m_radioButton_Resolution_TestImage, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
|
||
// 处理数据
|
||
connect(ui->m_pushButton_Browse_FileB1, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
connect(ui->m_pushButton_Display_FileB1, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
connect(ui->m_pushButton_Browse_FileB2, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
connect(ui->m_pushButton_Display_FileB2, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
|
||
connect(ui->m_pushButton_CalcKList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
connect(ui->m_pushButton_CalcBPList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
connect(ui->m_pushButton_CorrectKList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
connect(ui->m_pushButton_SaveBPList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
connect(ui->m_pushButton_SaveKList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
|
||
//
|
||
connect(&m_varTimer, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
m_varTimer.setTimerType(Qt::PreciseTimer);
|
||
m_varTimer.start(40);
|
||
}
|
||
|
||
void MainWindow::Disconnect()
|
||
{
|
||
// 通用
|
||
disconnect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
disconnect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
|
||
|
||
// 测试图像
|
||
disconnect(ui->m_pushButton_TestImage, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_TestImage);
|
||
|
||
// 分辨率切换
|
||
disconnect(ui->m_radioButton_Resolution_320_256, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
disconnect(ui->m_radioButton_Resolution_320_288, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
disconnect(ui->m_radioButton_Resolution_400_300, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
disconnect(ui->m_radioButton_Resolution_640_512, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
disconnect(ui->m_radioButton_Resolution_800_600, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
disconnect(ui->m_radioButton_Resolution_1280_1024, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
disconnect(ui->m_radioButton_Resolution_Other, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
disconnect(ui->m_radioButton_Resolution_TestImage, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_Radio);
|
||
|
||
// 处理数据
|
||
disconnect(ui->m_pushButton_Browse_FileB1, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
disconnect(ui->m_pushButton_Display_FileB1, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
disconnect(ui->m_pushButton_Browse_FileB2, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
disconnect(ui->m_pushButton_Display_FileB2, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
|
||
disconnect(ui->m_pushButton_CalcKList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
disconnect(ui->m_pushButton_CalcBPList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
disconnect(ui->m_pushButton_CorrectKList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
disconnect(ui->m_pushButton_SaveBPList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
disconnect(ui->m_pushButton_SaveKList, &QPushButton::clicked, this, &MainWindow::OnButtonClicked_ProcessData);
|
||
|
||
//
|
||
m_varTimer.stop();
|
||
disconnect(&m_varTimer, &QTimer::timeout, this, &MainWindow::OnTimer);
|
||
}
|
||
|
||
void MainWindow::OnButtonClicked()
|
||
{
|
||
// 最小化
|
||
if(sender() == ui->m_pushButton_MinMenu)
|
||
{
|
||
this->showMinimized();
|
||
}
|
||
|
||
// 退出程序
|
||
if(sender() == ui->m_pushButton_CloseMenu)
|
||
{
|
||
qApp->exit();
|
||
}
|
||
}
|
||
|
||
void MainWindow::OnButtonClicked_TestImage()
|
||
{
|
||
// 测试图像
|
||
if (sender() == ui->m_pushButton_TestImage)
|
||
{
|
||
m_bEnableCapture = !m_bEnableCapture;
|
||
|
||
if(m_bEnableCapture)
|
||
{
|
||
m_pOpenGLView->Init(640, 512);
|
||
m_nImageMoveIndex = 0;
|
||
|
||
ui->m_pushButton_TestImage->setText(tr("停止测试"));
|
||
|
||
//
|
||
{
|
||
ui->m_radioButton_Resolution_1280_1024->setEnabled(false);
|
||
ui->m_radioButton_Resolution_Other->setEnabled(false);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ui->m_pushButton_TestImage->setText(tr("测试图像"));
|
||
|
||
//
|
||
{
|
||
ui->m_radioButton_Resolution_1280_1024->setEnabled(true);
|
||
ui->m_radioButton_Resolution_Other->setEnabled(true);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void MainWindow::OnButtonClicked_Radio()
|
||
{
|
||
// 320*256
|
||
if(sender() == ui->m_radioButton_Resolution_320_256)
|
||
{
|
||
m_nImageWidth = 320;
|
||
m_nImageHeight = 256;
|
||
|
||
m_eIR = eIR_320_256;
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
}
|
||
|
||
// 320*288
|
||
if(sender() == ui->m_radioButton_Resolution_320_288)
|
||
{
|
||
m_nImageWidth = 320;
|
||
m_nImageHeight = 288;
|
||
|
||
m_eIR = eIR_320_288;
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
}
|
||
|
||
// 400*300
|
||
if(sender() == ui->m_radioButton_Resolution_400_300)
|
||
{
|
||
m_nImageWidth = 400;
|
||
m_nImageHeight = 300;
|
||
|
||
m_eIR = eIR_400_300;
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
}
|
||
|
||
// 640*512
|
||
if(sender() == ui->m_radioButton_Resolution_640_512)
|
||
{
|
||
m_nImageWidth = 640;
|
||
m_nImageHeight = 512;
|
||
|
||
m_eIR = eIR_640_512;
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
}
|
||
|
||
//
|
||
{
|
||
ui->m_pushButton_Browse_FileB1->setEnabled(false);
|
||
ui->m_pushButton_Display_FileB1->setEnabled(false);
|
||
ui->m_pushButton_Browse_FileB2->setEnabled(false);
|
||
ui->m_pushButton_Display_FileB2->setEnabled(false);
|
||
|
||
ui->m_pushButton_CalcKList->setEnabled(false);
|
||
ui->m_pushButton_CalcBPList->setEnabled(false);
|
||
ui->m_pushButton_CorrectKList->setEnabled(false);
|
||
ui->m_pushButton_SaveBPList->setEnabled(false);
|
||
ui->m_pushButton_SaveKList->setEnabled(false);
|
||
}
|
||
|
||
// 800*600
|
||
if(sender() == ui->m_radioButton_Resolution_800_600)
|
||
{
|
||
m_nImageWidth = 800;
|
||
m_nImageHeight = 600;
|
||
|
||
m_eIR = eIR_800_600;
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
}
|
||
|
||
// 1280*1024
|
||
if(sender() == ui->m_radioButton_Resolution_1280_1024)
|
||
{
|
||
m_nImageWidth = 1280;
|
||
m_nImageHeight = 1024;
|
||
|
||
m_eIR = eIR_1280_1024;
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
|
||
//
|
||
ui->m_pushButton_Browse_FileB1->setEnabled(true);
|
||
ui->m_pushButton_Display_FileB1->setEnabled(true);
|
||
ui->m_pushButton_Browse_FileB2->setEnabled(true);
|
||
ui->m_pushButton_Display_FileB2->setEnabled(true);
|
||
|
||
ui->m_pushButton_CalcKList->setEnabled(true);
|
||
ui->m_pushButton_CalcBPList->setEnabled(true);
|
||
ui->m_pushButton_CorrectKList->setEnabled(true);
|
||
ui->m_pushButton_SaveBPList->setEnabled(true);
|
||
ui->m_pushButton_SaveKList->setEnabled(true);
|
||
}
|
||
|
||
// other
|
||
if(sender() == ui->m_radioButton_Resolution_Other)
|
||
{
|
||
m_nImageWidth = ui->m_lineEdit_Other_Width->text().toInt();
|
||
m_nImageHeight = ui->m_lineEdit_Other_Height->text().toInt();
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
|
||
m_eIR = eIR_Other;
|
||
|
||
//
|
||
ui->m_lineEdit_Other_Width->setEnabled(true);
|
||
ui->m_lineEdit_Other_Height->setEnabled(true);
|
||
|
||
//
|
||
ui->m_pushButton_Browse_FileB1->setEnabled(true);
|
||
ui->m_pushButton_Display_FileB1->setEnabled(true);
|
||
ui->m_pushButton_Browse_FileB2->setEnabled(true);
|
||
ui->m_pushButton_Display_FileB2->setEnabled(true);
|
||
|
||
ui->m_pushButton_CalcKList->setEnabled(true);
|
||
ui->m_pushButton_CalcBPList->setEnabled(true);
|
||
ui->m_pushButton_CorrectKList->setEnabled(true);
|
||
ui->m_pushButton_SaveBPList->setEnabled(true);
|
||
ui->m_pushButton_SaveKList->setEnabled(true);
|
||
}
|
||
else
|
||
{
|
||
ui->m_lineEdit_Other_Width->setEnabled(false);
|
||
ui->m_lineEdit_Other_Height->setEnabled(false);
|
||
}
|
||
|
||
// TestImage
|
||
if(sender() == ui->m_radioButton_Resolution_TestImage)
|
||
{
|
||
m_nImageWidth = 640;
|
||
m_nImageHeight = 512;
|
||
|
||
m_eIR = eIR_TestImage;
|
||
|
||
m_pOpenGLView->Init(m_nImageWidth, m_nImageHeight);
|
||
|
||
//
|
||
ui->m_pushButton_TestImage->setEnabled(true);
|
||
}
|
||
else
|
||
{
|
||
ui->m_pushButton_TestImage->setEnabled(false);
|
||
}
|
||
}
|
||
|
||
void MainWindow::MakeKList(ushort** pKList, ushort* pY16DataB1, ushort* pY16DataB2, int nPixelSize)
|
||
{
|
||
long nZoom = 8192;
|
||
long nMeanH = 0;
|
||
long nMeanL = 0;
|
||
long nMeanDiff = 0;
|
||
|
||
for (int i = 0; i < nPixelSize; i++)
|
||
{
|
||
nMeanL += pY16DataB1[i];
|
||
nMeanH += pY16DataB2[i];
|
||
}
|
||
|
||
nMeanL /= nPixelSize;
|
||
nMeanH /= nPixelSize;
|
||
nMeanDiff = nMeanH - nMeanL;
|
||
|
||
for (int i = 0; i < nPixelSize; i++)
|
||
{
|
||
(*pKList)[i] = USHORT((nMeanDiff * nZoom) / (pY16DataB2[i] - pY16DataB1[i] + 0.1f));
|
||
}
|
||
}
|
||
|
||
void MainWindow::MakeBPList(ushort** pBPList, ushort* pKList, int nImageWidth, int nImageHeight)
|
||
{
|
||
long nLen = nImageWidth*nImageHeight;
|
||
long nZoom = 8192;
|
||
long nDetBadThre = (long)(0.2f * nZoom);
|
||
long p[5] = {0};
|
||
|
||
// 判断K值矩阵的初始点是否是坏点,确保其值非坏点,
|
||
// 前提是像素起始位置4个像素不能超过2个坏点
|
||
p[0] = *pKList;
|
||
p[1] = *(pKList + 1);
|
||
p[2] = *(pKList + nImageWidth);
|
||
p[3] = *(pKList + nImageWidth + 1);
|
||
|
||
if ((abs(p[1] - p[0]) > nDetBadThre)
|
||
|| (abs(p[2] - p[0]) > nDetBadThre)
|
||
|| (abs(p[3] - p[0]) > nDetBadThre))
|
||
{
|
||
// 排序p[1],p[2],p[3],目的是找到中值
|
||
p[4] = p[1];
|
||
if (p[2] > p[1])
|
||
{
|
||
p[1] = p[2];
|
||
p[2] = p[4];
|
||
p[4] = p[1];
|
||
}
|
||
if (p[3] > p[1])
|
||
{
|
||
p[1] = p[3];
|
||
p[3] = p[4];
|
||
}
|
||
if (p[3] > p[2])
|
||
{
|
||
p[2] = p[3];
|
||
}
|
||
|
||
// 通过初始值与中值差值判断
|
||
if (abs(p[0] - p[2]) > nDetBadThre)
|
||
{
|
||
*pKList = p[2];
|
||
}
|
||
}
|
||
|
||
// 判断初始列是否是坏点
|
||
for (int i = 1; i < nImageHeight; i++)
|
||
{
|
||
if (abs(*(pKList + i * nImageWidth) - *(pKList + (i - 1) * nImageWidth)) > nDetBadThre)
|
||
{
|
||
*((*pBPList) + i * nImageWidth) = 1;
|
||
*(pKList + i * nImageWidth) = *(pKList + (i - 1) * nImageWidth); // 直接替换K值矩阵的坏点位置的K值
|
||
}
|
||
|
||
// 找出坏点截止位置
|
||
for (int k = i + 1; k < nImageHeight; k++)
|
||
{
|
||
if (abs(*(pKList + k * nImageHeight) - *(pKList + (i - 1) * nImageHeight)) < nDetBadThre)
|
||
{
|
||
i = k + 1;
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
*((*pBPList) + k * nImageWidth) = 1;
|
||
*(pKList + k * nImageWidth) = *(pKList + (i - 1) * nImageWidth); // 直接替换K值矩阵的坏点位置的K值
|
||
}
|
||
}
|
||
}
|
||
|
||
// 按照行方向检测坏点
|
||
for (int i = 0; i < nImageHeight; i++)
|
||
{
|
||
for (int j = 1; j < nImageWidth; j++)
|
||
{
|
||
if (abs(*(pKList + i * nImageWidth + j) - *(pKList + i * nImageWidth + j - 1)) > nDetBadThre)
|
||
{
|
||
*((*pBPList) + i * nImageWidth + j) = 1;
|
||
|
||
// 找出坏点截止位置
|
||
for (int k = j + 1; k < nImageWidth; k++)
|
||
{
|
||
if (abs(*(pKList + i * nImageWidth + k) - *(pKList + i * nImageWidth + j - 1)) < nDetBadThre)
|
||
{
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
*((*pBPList) + i * nImageWidth + k) = 1;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
*((*pBPList) + i * nImageWidth + j) = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void MainWindow::CorrectKList(ushort** pKList, ushort* pBPList, int nPixelSize)
|
||
{
|
||
for(int i = 0; i < nPixelSize; i++)
|
||
{
|
||
if(1 == pBPList[i])
|
||
{
|
||
(*pKList)[i] |= 0x8000;
|
||
}
|
||
}
|
||
}
|
||
|
||
void MainWindow::OnButtonClicked_ProcessData()
|
||
{
|
||
/*
|
||
* 读取B1数据
|
||
*/
|
||
if(sender() == ui->m_pushButton_Browse_FileB1)
|
||
{
|
||
QFileDialog varFileDialog(this);
|
||
varFileDialog.setWindowTitle(QString("%1").arg(tr("打开视频文件") ) );
|
||
varFileDialog.setDirectory(tr(""));
|
||
//varFileDialog.setOption(QFileDialog::DontUseNativeDialog);
|
||
|
||
QString strExt = tr("Y16 files (*.dat *.raw);;all files (*.*) )");
|
||
varFileDialog.setNameFilter(strExt);
|
||
|
||
if (QFileDialog::Rejected == varFileDialog.exec())
|
||
{
|
||
return;
|
||
}
|
||
|
||
{
|
||
QString strFullPath = varFileDialog.selectedFiles()[0];
|
||
ui->m_lineEdit_FileB1->setText(strFullPath);
|
||
|
||
//
|
||
QFile varFile(strFullPath);
|
||
|
||
if(!varFile.open(QIODevice::ReadOnly) )
|
||
{
|
||
return;
|
||
}
|
||
|
||
int nWantedDataSize = m_nImageWidth*m_nImageHeight*2;
|
||
|
||
memset(m_pY16Data_B1, 0, MaxSize_IRSensorTool*2);
|
||
|
||
int nReadDataSize = varFile.read((char*)m_pY16Data_B1, nWantedDataSize);
|
||
|
||
varFile.close();
|
||
|
||
if(nReadDataSize != nWantedDataSize)
|
||
{
|
||
return;
|
||
}
|
||
|
||
GdImageLib::Map16BitTo8Bit(m_pY8Data_B1, (short*)m_pY16Data_B1, m_nImageWidth*m_nImageHeight, 100, 100);
|
||
}
|
||
}
|
||
|
||
if(sender() == ui->m_pushButton_Display_FileB1)
|
||
{
|
||
GdImageLib::Grey8ToRGBA(m_pRGBA, m_pY8Data_B1, m_nImageWidth, m_nImageHeight, 1);
|
||
m_pOpenGLView->UpdateImageData(m_pRGBA, true);
|
||
}
|
||
|
||
/*
|
||
* 读取B2数据
|
||
*/
|
||
if(sender() == ui->m_pushButton_Browse_FileB2)
|
||
{
|
||
QFileDialog varFileDialog(this);
|
||
varFileDialog.setWindowTitle(QString("%1").arg(tr("打开视频文件") ) );
|
||
varFileDialog.setDirectory(tr(""));
|
||
//varFileDialog.setOption(QFileDialog::DontUseNativeDialog);
|
||
|
||
QString strExt = tr("Y16 files (*.dat *.raw);;all files (*.*) )");
|
||
varFileDialog.setNameFilter(strExt);
|
||
|
||
if (QFileDialog::Rejected == varFileDialog.exec())
|
||
{
|
||
return;
|
||
}
|
||
|
||
{
|
||
QString strFullPath = varFileDialog.selectedFiles()[0];
|
||
ui->m_lineEdit_FileB2->setText(strFullPath);
|
||
|
||
//
|
||
QFile varFile(strFullPath);
|
||
|
||
if(!varFile.open(QIODevice::ReadOnly) )
|
||
{
|
||
return;
|
||
}
|
||
|
||
int nWantedDataSize = m_nImageWidth*m_nImageHeight*2;
|
||
|
||
memset(m_pY16Data_B2, 0, MaxSize_IRSensorTool*2);
|
||
|
||
int nReadDataSize = varFile.read((char*)m_pY16Data_B2, nWantedDataSize);
|
||
|
||
varFile.close();
|
||
|
||
if(nReadDataSize != nWantedDataSize)
|
||
{
|
||
return;
|
||
}
|
||
|
||
GdImageLib::Map16BitTo8Bit(m_pY8Data_B2, (short*)m_pY16Data_B2, m_nImageWidth*m_nImageHeight, 100, 100);
|
||
}
|
||
}
|
||
|
||
if(sender() == ui->m_pushButton_Display_FileB2)
|
||
{
|
||
GdImageLib::Grey8ToRGBA(m_pRGBA, m_pY8Data_B2, m_nImageWidth, m_nImageHeight, 1);
|
||
m_pOpenGLView->UpdateImageData(m_pRGBA, true);
|
||
}
|
||
|
||
///
|
||
|
||
/*
|
||
* 计算KList
|
||
*/
|
||
if(sender() == ui->m_pushButton_CalcKList)
|
||
{
|
||
memset(m_pY16Data_KList, 0, MaxSize_IRSensorTool*2);
|
||
MakeKList(&m_pY16Data_KList, m_pY16Data_B1, m_pY16Data_B2, m_nImageWidth*m_nImageHeight);
|
||
}
|
||
|
||
/*
|
||
* 计算BPList
|
||
*/
|
||
if(sender() == ui->m_pushButton_CalcBPList)
|
||
{
|
||
memset(m_pY16Data_BPList, 0, MaxSize_IRSensorTool*2);
|
||
MakeBPList(&m_pY16Data_BPList, m_pY16Data_KList, m_nImageWidth, m_nImageHeight);
|
||
}
|
||
|
||
/*
|
||
* 校正KList
|
||
*/
|
||
if(sender() == ui->m_pushButton_CorrectKList)
|
||
{
|
||
CorrectKList(&m_pY16Data_KList, m_pY16Data_BPList, m_nImageWidth*m_nImageHeight);
|
||
}
|
||
|
||
/*
|
||
* 保存BPList
|
||
*/
|
||
if(sender() == ui->m_pushButton_SaveBPList)
|
||
{
|
||
QString strFilePath = QString("BPListData_%1_%2.dat")
|
||
.arg(m_nImageWidth)
|
||
.arg(m_nImageHeight);
|
||
|
||
QFile varFile(strFilePath);
|
||
|
||
if(!varFile.open(QIODevice::WriteOnly) )
|
||
{
|
||
return;
|
||
}
|
||
|
||
int nWriteDataSize = m_nImageWidth*m_nImageHeight*2;
|
||
|
||
varFile.write((char*)m_pY16Data_BPList, nWriteDataSize);
|
||
varFile.close();
|
||
}
|
||
|
||
/*
|
||
* 保存KList
|
||
*/
|
||
if(sender() == ui->m_pushButton_SaveKList)
|
||
{
|
||
QString strFilePath = QString("KListData_%1_%2.dat")
|
||
.arg(m_nImageWidth)
|
||
.arg(m_nImageHeight);
|
||
|
||
QFile varFile(strFilePath);
|
||
|
||
if(!varFile.open(QIODevice::WriteOnly) )
|
||
{
|
||
return;
|
||
}
|
||
|
||
int nWriteDataSize = m_nImageWidth*m_nImageHeight*2;
|
||
|
||
varFile.write((char*)m_pY16Data_KList, nWriteDataSize);
|
||
varFile.close();
|
||
}
|
||
}
|
||
|
||
void MainWindow::OnComboxIndexChanged(int nIndex)
|
||
{
|
||
}
|
||
|
||
void MainWindow::InitStyle()
|
||
{
|
||
m_bMousePressed = false;
|
||
|
||
//安装事件监听器,让标题栏识别鼠标双击
|
||
ui->lblTitle->installEventFilter(this);
|
||
/*
|
||
this->setWindowFlags(/*Qt::FramelessWindowHint |*
|
||
Qt::WindowTitleHint |
|
||
Qt::WindowSystemMenuHint);
|
||
*/
|
||
FramelessHelper *pHelper = new FramelessHelper(this);
|
||
pHelper->activateOn(this); //激活当前窗体
|
||
pHelper->setTitleHeight(ui->wgtTitleBar->height()); //设置窗体的标题栏高度
|
||
|
||
CommonHelper::SetStyle("blue");//"blue"//"dark"
|
||
}
|
||
|
||
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
||
{
|
||
//if (ui->lblTitle == obj)
|
||
{
|
||
if (event->type() == QEvent::MouseButtonPress)
|
||
{
|
||
|
||
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||
|
||
if (mouseEvent->button() == Qt::LeftButton)
|
||
{
|
||
m_bMousePressed = true;
|
||
m_ptMouse = mouseEvent->globalPos() - pos();
|
||
mouseEvent->accept();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
else if (event->type() == QEvent::MouseMove)
|
||
{
|
||
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||
|
||
if (m_bMousePressed && this->windowState() != Qt::WindowMaximized)
|
||
{
|
||
if (mouseEvent->globalY() <= qApp->desktop()->availableGeometry().bottom())
|
||
{
|
||
move(mouseEvent->globalPos() - m_ptMouse);
|
||
mouseEvent->accept();
|
||
}
|
||
else
|
||
{
|
||
qApp->desktop()->cursor().setPos(
|
||
qApp->desktop()->cursor().pos().x(),
|
||
qApp->desktop()->availableGeometry().bottom()
|
||
);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
else if (event->type() == QEvent::MouseButtonRelease)
|
||
{
|
||
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||
|
||
if (mouseEvent->button() == Qt::LeftButton)
|
||
{
|
||
m_bMousePressed = false;
|
||
mouseEvent->accept();
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
return QMainWindow::eventFilter(obj, event);
|
||
}
|
||
|
||
void MainWindow::OnTimer()
|
||
{
|
||
if(m_bEnableCapture)
|
||
{
|
||
m_nImageMoveIndex += 1;
|
||
|
||
if(m_nImageMoveIndex >= 512)
|
||
{
|
||
m_nImageMoveIndex = 0;
|
||
}
|
||
|
||
m_pOpenGLView->UpdateImageData(&m_pTestDataBuffer[640*4*m_nImageMoveIndex]);
|
||
}
|
||
}
|
||
|
||
void MainWindow::ThreadEntry(ThreadRunFunPtr pRunFun, void* pOwner)
|
||
{
|
||
MainWindow* pThis = reinterpret_cast<MainWindow*>(pOwner);
|
||
|
||
if (NULL == pThis)
|
||
{
|
||
return;
|
||
}
|
||
|
||
(pThis->*pRunFun)();
|
||
}
|
||
|
||
void MainWindow::ThreadFun_CaptureDeviceData()
|
||
{
|
||
timeBeginPeriod(1);
|
||
|
||
byte* pReadData = new byte[2688*1024+4096];
|
||
|
||
std::chrono::system_clock::time_point tm2_2 = std::chrono::system_clock::now();
|
||
|
||
int nTimeOutCount = 0;
|
||
|
||
while(m_bThreadRunning_CaptureDeviceData)
|
||
{
|
||
int nRes = 0;
|
||
|
||
m_varCaptureData.PushBack(pReadData, DefaultMaxImageSize, nRes);
|
||
}
|
||
|
||
timeEndPeriod(1);
|
||
}
|
||
|
||
bool MainWindow::StartThread_DealDeviceData()
|
||
{
|
||
StopThread_DealDeviceData();
|
||
|
||
//
|
||
m_bThreadRunning_CaptureDeviceData = true;
|
||
m_ptrThread_CaptureDeviceData = new std::thread(std::bind(&MainWindow::ThreadEntry, &MainWindow::ThreadFun_CaptureDeviceData, (void*)this));
|
||
|
||
return true;
|
||
}
|
||
|
||
void MainWindow::StopThread_DealDeviceData()
|
||
{
|
||
//
|
||
if(m_bThreadRunning_CaptureDeviceData)
|
||
{
|
||
m_bThreadRunning_CaptureDeviceData = false;
|
||
|
||
if(nullptr != m_ptrThread_CaptureDeviceData)
|
||
{
|
||
m_ptrThread_CaptureDeviceData->join();
|
||
|
||
delete m_ptrThread_CaptureDeviceData;
|
||
m_ptrThread_CaptureDeviceData = nullptr;
|
||
}
|
||
}
|
||
}
|