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

1102 lines
18 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "StdAfx.h"
#include "ExportImgShowBase.h"
#include "ImgShowDlg.h"
#include "QB_ImgProcessFun.h"
#include "GlobalFunc.h"
// 构造函数
CExportImgShowBase::CExportImgShowBase(void)
{
m_ShowDlg = NULL;
}
// 析构函数
CExportImgShowBase::~CExportImgShowBase(void)
{
try
{
ClearMemory();
// 销毁窗口
DestroyWnd();
m_ShowDlg = NULL;
}
catch(cv::Exception &e)
{
e.what();
std::abort();
}
catch(...)
{
std::abort();
}
}
// 功能:创建视频显示窗口
BOOL CExportImgShowBase::CreateWnd(const HWND hParentWnd)
{
BOOL ret = FALSE;
try
{
// 输入父窗口有效性验证
if (hParentWnd == NULL)
{
return FALSE;
}
// 基于窗口句柄,获取窗口指针
CWnd* pParWnd = CWnd::FromHandle(hParentWnd);
// 当m_ShowDlg为空时创建dialog
if (m_ShowDlg == NULL)
{
//return TRUE;
// 新建视频显示窗口对象
m_ShowDlg = new CImgShowDlg();
if (pParWnd != NULL)
{
// 创建窗口
ret = m_ShowDlg->Create(IDD_IMG_SHOW_DIALOG, pParWnd);
}
else
{
// 释放对象
SAFE_DELETE(m_ShowDlg);
m_ShowDlg = NULL;
}
}
return ret;
}
catch(cv::Exception &e)
{
e.msg;
return FALSE;
}
catch(...)
{
return FALSE;
}
}
// 功能:移动(设置)窗口(整个视频显示窗口)至指定位置
void CExportImgShowBase::MoveWnd(const CRect &clientRect)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
// 移动窗口至指定位置
m_ShowDlg->MoveWindow(clientRect);
// 设置指北针中心坐标
// CRect rect;
// m_ShowDlg->GetClientRect(&rect);
// POINT center;
// center.x = 60L;
// center.y = 60L;
//
// m_ShowDlg->SetNorthDirectionCenter(center);
}
}
catch (...)
{
return;
}
}
// 功能显示或隐藏窗口由nCmdShow决定
// #define SW_HIDE 0
// #define SW_SHOWNORMAL 1
// #define SW_NORMAL 1
// #define SW_SHOWMINIMIZED 2
// #define SW_SHOWMAXIMIZED 3
// #define SW_MAXIMIZE 3
// #define SW_SHOWNOACTIVATE 4
// #define SW_SHOW 5
// #define SW_MINIMIZE 6
// #define SW_SHOWMINNOACTIVE 7
// #define SW_SHOWNA 8
// #define SW_RESTORE 9
// #define SW_SHOWDEFAULT 10
// #define SW_FORCEMINIMIZE 11
// #define SW_MAX 11
// 功能显示SW_SHOW 或隐藏 SW_HIDE 窗口 已验证
void CExportImgShowBase::ShowWnd(const int nCmdShow)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
m_ShowDlg->ShowWindow(nCmdShow);
}
}
catch(...)
{
}
}
// 功能:显示一帧图像
BOOL CExportImgShowBase::ShowImage(const BITMAPINFO* pImgInfo,
BYTE* pImgData,
GeoBoundingBox LBbox,
BOOL isNeedFlip,
BOOL isNeedClip,
const CRect* pShowRegion,
float Strecth_Ratio,
POINT xyShift)
{
BOOL ret = FALSE;
try
{
if (m_ShowDlg == NULL && m_ShowDlg->GetSafeHwnd() == NULL)
{
return FALSE;
}
// 数据有效性验证
if ( (pImgInfo == NULL) || (pImgData == NULL))
{
return FALSE;
}
// 设置一路输入正在输入标识
m_ShowDlg->SetFirstSignal(TRUE);
// biBitCount 验证
if(pImgInfo->bmiHeader.biBitCount != 24 && pImgInfo->bmiHeader.biBitCount != 8)
{
m_ShowDlg->SetFirstSignal(FALSE);
return FALSE;
}
// 更新数据至全局变量LatestQBData
if (pImgInfo->bmiHeader.biWidth > 0 &&
pImgInfo->bmiHeader.biHeight > 0 &&
pImgData != NULL)
{
// 设置一路输入正在输入标识
m_ShowDlg->SetFirstSignal(TRUE);
// 构建临时对象
QBStru local;
local.image.srcImg.ImgWidth = pImgInfo->bmiHeader.biWidth;
local.image.srcImg.ImgHeight = pImgInfo->bmiHeader.biHeight;
local.image.srcImg.bitcount = pImgInfo->bmiHeader.biBitCount;
// 步长:每行像素所占字节数
int lineByte = (pImgInfo->bmiHeader.biWidth * pImgInfo->bmiHeader.biBitCount / 8);
// 位图数据缓冲区的大小,即图像大小
int imgBufSize = pImgInfo->bmiHeader.biHeight * lineByte;
if ( imgBufSize > 0)
{
local.image.srcImg.buff = new BYTE[imgBufSize];
if (local.image.srcImg.buff != NULL)
{
// 复制实际字节数
memcpy(local.image.srcImg.buff, pImgData, static_cast<size_t>(imgBufSize)); // 图像数据复制
// 设置图像数据有效
local.image.bValid = true;
// 是否需要反转
if (isNeedFlip == TRUE)
{
FlipImgStru(&local.image.srcImg);
}
}
}
local.image.srcImg.BoundingBox = LBbox;
// 将 local 复制到 m_LatestQBData
m_ShowDlg->SetLatestQBData(local);
m_ShowDlg->SetBoundingBox(LBbox);
// 释放 local
if (local.image.srcImg.buff != NULL)
{
SAFE_DELETE_ARRAY(local.image.srcImg.buff);
}
// 显示图像
if (m_ShowDlg != NULL)
{
// 接口转换
CRect ShowRegion;
if (pShowRegion != NULL)
{
ShowRegion = *pShowRegion;
}
ret = m_ShowDlg->ShowOneImage(const_cast<BITMAPINFO*>(pImgInfo), pImgData, isNeedClip, ShowRegion, isNeedFlip, Strecth_Ratio, xyShift);
}
// 图像去雾 亮度调节 对比度调节 清晰度调节 复位
m_ShowDlg->SetiLatest(0); // 最近的一次
m_ShowDlg->SetiPreLatest(0); // 最近的一次的前一次
// 关闭1路正在输入标识
m_ShowDlg->SetFirstSignal(FALSE);
}
return ret;
}
catch(cv::Exception &e)
{
e.msg;
return ret;
}
catch(...)
{
return ret;
}
}
// 功能:解压后的情报数据处理函数
void CExportImgShowBase::DisposeQBData(const QBStru* qbData)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal()) // 1路信号正在输入直接返回
{
return;
}
else // 关闭3路信号 输入2路信号
{
// 设置2路输入正在输入标识
m_ShowDlg->SetSecondSignal(TRUE);
// 输入二路信号
m_ShowDlg->DisposeQBData(qbData);
// 关闭2路输入正在输入标识
m_ShowDlg->SetSecondSignal(FALSE);
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:标绘目标,其中输入为目标点像素坐标
void CExportImgShowBase::SetTargetPixelCoordinate(const CPoint &pt)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
m_ShowDlg->SetTargetPixelCoordinate(pt);
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能标绘图像中的一块区域其中输入为4个像素坐标点
void CExportImgShowBase::SetQuadrangleCorners(const POINT* pts)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
m_ShowDlg->SetQuadrangleCorners(pts);
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:标绘目标,其中输入为经纬度坐标
void CExportImgShowBase::SetTgtLocLeadLonLat(double lon, double lat)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
m_ShowDlg->SetTgtLocLeadLonLat(lon, lat);
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:删除视频显示窗口,同时释放所有占用资源
void CExportImgShowBase::DestroyWnd()
{
try
{
// 释放MFC对话框资源
if (m_ShowDlg != NULL)
{
m_ShowDlg->DestroyWindow();
}
// 释放对象
SAFE_DELETE(m_ShowDlg);
m_ShowDlg = NULL;
}
catch(...)
{
return;
}
}
// 8 功能:清理内存及记忆
void CExportImgShowBase::ClearMemory()
{
try
{
// 输入函数指针callBackFun 有效性验证
if (m_ShowDlg != NULL)
{
m_ShowDlg->ClearMemory();
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:设置回调函数,双击像素坐标
BOOL CExportImgShowBase::SetCallBackFun(SendCoordinateProc proc)
{
BOOL ret = FALSE;
try
{
// 输入函数指针callBackFun 有效性验证
if ((m_ShowDlg != NULL) && (proc != NULL))
{
ret = m_ShowDlg->SetCallBackFun(proc);
}
return ret;
}
catch(cv::Exception &e)
{
e.msg;
return FALSE;
}
catch(...)
{
return FALSE;
}
}
// 功能设置回调函数像素信息传递到外部CSU中
BOOL CExportImgShowBase::SetCallBackFun(SendPixInfoProc proc)
{
BOOL ret = FALSE;
try
{
// 输入函数指针callBackFun 有效性验证
if ((m_ShowDlg != NULL) && (proc != NULL))
{
ret = m_ShowDlg->SetCallBackFun(proc);
}
return ret;
}
catch(cv::Exception &e)
{
e.msg;
return FALSE;
}
catch(...)
{
return FALSE;
}
}
// 功能设置回调函数传递保存文件路径到外部CSU中
BOOL CExportImgShowBase::SetCallBackFun(SendFilePath proc)
{
BOOL ret = FALSE;
try
{
// 输入函数指针callBackFun 有效性验证
if ((m_ShowDlg != NULL) && (proc != NULL))
{
ret = m_ShowDlg->SetCallBackFun(proc);
}
return ret;
}
catch(cv::Exception &e)
{
e.msg;
return FALSE;
}
catch(...)
{
return FALSE;
}
}
// 5 功能设置回调函数目标定位导引经纬度到外部CSU中
// 输入:
// 1.proc: 函数指针
//
// 输出: 设置成功返回TRUE否则返回FALSE
BOOL CExportImgShowBase::SetCallBackFun(SendTgrLocLeadLonLatProc proc)
{
BOOL ret = FALSE;
try
{
// 输入函数指针callBackFun 有效性验证
if ((m_ShowDlg != NULL) && (proc != NULL))
{
ret = m_ShowDlg->SetCallBackFun(proc);
}
return ret;
}
catch(cv::Exception &e)
{
e.msg;
return FALSE;
}
catch(...)
{
return FALSE;
}
}
// 6 功能设置回调函数火炮校射信息输出到外部CSU中
// 输入:
// 1.proc: 函数指针
//
// 输出: 设置成功返回TRUE否则返回FALSE
BOOL CExportImgShowBase::SetCallBackFun(SendArtilleryReviseInfoProc proc)
{
BOOL ret = FALSE;
try
{
// 输入函数指针callBackFun 有效性验证
if ((m_ShowDlg != NULL) && (proc != NULL))
{
ret = m_ShowDlg->SetCallBackFun(proc);
}
return ret;
}
catch(cv::Exception &e)
{
e.msg;
return FALSE;
}
catch(...)
{
return FALSE;
}
}
// 功能:保存当前帧至本地文件
void CExportImgShowBase::SaveCurrentFrame(CString sSaveFolder)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal() == FALSE || m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->SetSaveCurrentImgFolder(sSaveFolder);
m_ShowDlg->SaveCurrentDecodedFrame();
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能是否需要记忆前面多帧18帧图像信息
void CExportImgShowBase::MemPreMultiFrame(BOOL bMem)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
m_ShowDlg->MemPreMultiFrame(bMem);
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:通过鼠标滚轮,实现图像放大缩小
BOOL CExportImgShowBase::OnMouseWheelZoomInOutImg(UINT nFlags, short zDelta, CPoint pt)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd()/* && nFlags == MK_CONTROL*/)
{
// 调用VideoShowDlg里面的 OnMouseWheel 操作SrcFrame
return m_ShowDlg->OnMouseWheel(nFlags, zDelta, pt);
}
}
catch(cv::Exception &e)
{
e.msg;
return FALSE;
}
catch(...)
{
return FALSE;
}
return FALSE;
}
// 功能:取消目标标绘
void CExportImgShowBase::CancelTargetPlot()
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
m_ShowDlg->OnConcelTargetPlot();
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:图像去雾
void CExportImgShowBase::AdjustImgDehaze(BOOL bAdjust, int A_MAX, double degree)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal() == FALSE && m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->AdjustImgDehaze(bAdjust, A_MAX, degree);
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:图像亮度调节
void CExportImgShowBase::AdjustImgIntensity(BOOL bAdjust, int degree)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal() == FALSE && m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->AdjustImgIntensity(bAdjust, degree);
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:图像对比度调节
void CExportImgShowBase::AdjustImgContrast(BOOL bAdjust, int degree)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal() == FALSE && m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->AdjustImgContrast(bAdjust, degree);
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:图像清晰度调节
void CExportImgShowBase::AdjustImgDefinition(BOOL bAdjust, int degree)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal() == FALSE && m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->AdjustImgDefinition(bAdjust, degree);
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:返回图像调节上一步图像状态
void CExportImgShowBase::ReturnToPreImgState()
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal() == FALSE && m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->ReturnToPreImgState();
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:返回原始图像状态
void CExportImgShowBase::ReturnToSrcImgState()
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
if (m_ShowDlg->GetFirstSignal() == FALSE || m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->ReturnToSrcImgState();
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能保存当前图像为TIFF格式
void CExportImgShowBase::SaveImgToTiff()
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
// 无外部信号输入 本地操作
if (m_ShowDlg->GetFirstSignal() == FALSE && m_ShowDlg->GetSecondSignal() == FALSE)
{
m_ShowDlg->SaveToGeoTiff();
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 18 功能:设置图像编辑类型
void CExportImgShowBase::SetImgEditType(int type)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
m_ShowDlg->SetImgEditType(type);
}
}
catch(cv::Exception &e)
{
e.what();
}
catch (...)
{
}
}
// 19 功能:获取图像编辑模式
bool CExportImgShowBase::GetImgEditMode()
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd())
{
return m_ShowDlg->GetImgEditMode();
}
}
catch(cv::Exception &e)
{
e.what();
return true;
}
catch (...)
{
return true;
}
return true;
}
// 21 功能:几何校正图像并显示图像
// 输入:
// 无
// 返回:
// 无
void CExportImgShowBase::GeoCorrectAndShowImg()
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
return m_ShowDlg->GeoCorrectAndShowImg();
}
}
catch(cv::Exception &e)
{
e.what();
return;
}
catch (...)
{
return;
}
}
// 22 功能:获取当前显示图像
// 输入:
// 无
// 返回:
// 无
bool CExportImgShowBase::GetCurrentImg(int &imgWidth, int &imgHeight, int& bitCount, uchar* &pImgData)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
cv::Mat img = m_ShowDlg->GetCurrentImg();
if (img.empty() == true)
{
return false;
}
else
{
imgWidth = img.cols;
imgHeight = img.rows;
if (img.type() == CV_8UC1)
{
bitCount = 8;
}
else if (img.type() == CV_8UC3)
{
bitCount = 24;
}
else
{
return false;
}
pImgData = nullptr;
pImgData = new uchar[imgHeight * imgWidth * bitCount];
if (pImgData != nullptr)
{
memcpy(pImgData, img.data, imgHeight * imgWidth * (bitCount / 8));
}
return true;
}
}
}
catch(cv::Exception &e)
{
e.what();
return false;
}
catch (...)
{
return false;
}
return false;
}
// 23 功能:获取图像边界地理坐标
// 输入:
// 无
// 输出:
// 1leftLon 西经
// 2topLat 北纬
// 3rigtLon 东经
// 4bottomLat 南纬
// 返回值:
// 成功返回true,失败返回false
bool CExportImgShowBase::GetImgBoundingBox(double &leftLon, double &topLat, double &rigtLon, double &bottomLat)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
return m_ShowDlg->GetImgBoundingBox(leftLon, topLat, rigtLon, bottomLat);
}
}
catch(cv::Exception &e)
{
e.what();
return false;
}
catch (...)
{
return false;
}
return false;
}
// 23 功能:获取当前显示图像中心经纬度
// 输入:
// 无
// 输出:
// 1lon 经度
// 2lat 纬度
// 返回值:
// 成功返回true,失败返回false
bool CExportImgShowBase::GetCurrentImgCerterLonLat(double &lon, double &lat)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
return m_ShowDlg->GetCurrentImgCenterLonLat(lon, lat);
}
}
catch(cv::Exception &e)
{
e.what();
return false;
}
catch (...)
{
return false;
}
return false;
}
// 24 功能:标注图像(矩形、区域边缘)
// 输入:
// 1. 区域边缘点 集合
// 输出:
// 无
// 返回值:
// 无
void CExportImgShowBase::MarkRegionOnImg(std::vector<std::vector<cv::Point>> &valisContours)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
m_ShowDlg->MarkRegionOnImg(valisContours);
}
}
catch(cv::Exception &e)
{
e.what();
}
catch (...)
{
}
}
// 25 功能:屏蔽右键菜单
// 输入:
// 1. bClose 默认true关闭
// 输出:
// 无
// 返回值:
// 无
void CExportImgShowBase::CloseRightBtnDownMenu(bool bClose)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
m_ShowDlg->CloseRightBtnDownMenu(bClose);
}
}
catch(cv::Exception &e)
{
e.what();
}
catch (...)
{
}
}
// 26 功能:设置空屏文字
// 输入:
// 1. str 主题文字
// 输出:
// 无
// 返回值:
// 无
void CExportImgShowBase::SetThemeText(CString str)
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
m_ShowDlg->SetThemeText(str);
}
}
catch(cv::Exception &e)
{
e.what();
}
catch (...)
{
}
}
// 28 功能:图像位置导引(同内部目标定位导引)
void CExportImgShowBase::LeadImgLoc()
{
try
{
if (m_ShowDlg != NULL && m_ShowDlg->GetSafeHwnd() != NULL)
{
m_ShowDlg->LeadImgLoc();
}
}
catch(cv::Exception &e)
{
e.what();
}
catch (...)
{
}
}