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.

229 lines
3.9 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 "GlobalFunc.h"
#include "Markup.h"
#include "OpencvImgShell.h" // opencv支持
// 图像处理函数
#include "QB_ImgProcessFun.h"
// 功能:获取软件当前工作目录
CString GetSoftwareCurrentDirectory()
{
char exeFullPath[MAX_PATH];
GetModuleFileName(NULL, exeFullPath, MAX_PATH);
CString Directy;
Directy.Format("%s", exeFullPath);
int index = Directy.ReverseFind('\\');
Directy.Delete(index, Directy.GetLength() - index);
return Directy;
}
//功能:在文件夹中查找文件,看其是否存在
bool SearchDirectory(const CString &strDir)
{
CFileFind fileFind;
if (fileFind.FindFile(strDir))
{
fileFind.Close();
return true;
}
else
{
fileFind.Close();
return false;
}
}
// 功能:克隆情报数据
void CloneQBData(const QBStru &src, QBStru &dst)
{
try
{
// 首先释放dst包含清零
ReleaseQBData(&dst);
dst.framePart = src.framePart;
// dst.frameAll = src.frameAll;
// 2图像数据复制
if (src.image.bValid == true) // 图像数据有效
{
dst.image.bValid = true;
CloneImgStru(src.image.srcImg, dst.image.srcImg);
CloneImgStru(src.image.dstImg, dst.image.dstImg);
CloneImgStru(src.image.geoImg, dst.image.geoImg);
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:克隆图像数据
void CloneImgStru(const ImgStru &src, ImgStru &dst)
{
try
{
if (src.ImgWidth > 0 && src.ImgHeight > 0 && (src.bitcount == 24 || src.bitcount == 8) && src.buff != nullptr)
{
// 图像属性复制
dst.ImgWidth = src.ImgWidth;
dst.ImgHeight = src.ImgHeight;
dst.bitcount = src.bitcount;
dst.BoundingBox = src.BoundingBox;
// 数据复制
SAFE_DELETE_ARRAY(dst.buff);
// 步长:每行像素所占字节数
int lineByte = (dst.ImgWidth * dst.bitcount / 8);
// 位图数据缓冲区的大小,即图像大小
int imgBufSize = dst.ImgHeight * lineByte;
// 分配内存空间
if (imgBufSize > 0)
{
dst.buff = new BYTE[imgBufSize];
if (dst.buff != NULL)
{
memcpy(dst.buff, src.buff, static_cast<size_t>(imgBufSize)); // 图像数据复制
}
}
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:释放情报数据
void ReleaseQBData(QBStru *pQBData)
{
try
{
// 指针为空判断
if (pQBData != NULL)
{
SAFE_DELETE_ARRAY(pQBData->image.srcImg.buff);
SAFE_DELETE_ARRAY(pQBData->image.dstImg.buff);
SAFE_DELETE_ARRAY(pQBData->image.geoImg.buff);
// 清零
memset(pQBData, 0, sizeof(QBStru));
}
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}
// 功能:旋转并平移一个坐标点
POINT RotateShiftPoint(const POINT &src, double angle, const POINT &shift)
{
POINT dst;
// 转换为弧度
angle = angle/180.0 * 3.1415926535;
// 旋转
dst.x = static_cast<LONG>(src.x * cos(angle) - src.y * sin(angle) + 0.5);
dst.y = static_cast<LONG>(src.x * sin(angle) + src.y * cos(angle) + 0.5);
// 平移
dst.x += shift.x;
dst.y += shift.y;
return dst;
}
// 功能:垂直+水平反转 ImgStru中的 图像数据
// 输入img图像数据反转前
// 输出img图像数据反转后
void FlipImgStru(ImgStru* img)
{
try
{
// 有效性判断
if (img == NULL ||
img->ImgWidth <= 0 ||
img->ImgHeight <= 0 ||
img->bitcount <=0 ||
img->buff == NULL)
{
return;
}
// 数据位数判断
if (img->bitcount != 8 && img->bitcount != 24)
{
return;
}
// 图像属性提取
int imgWidth = img->ImgWidth;
int imgHeight = img->ImgHeight;
int nBitCount = img->bitcount;
// 内存复制机制
int realLineByte = (imgWidth * nBitCount / 8);
cv::Mat src;
if (nBitCount == 8)
{
src = cv::Mat(imgHeight, imgWidth, CV_8UC1);
}
else
{
src = cv::Mat(imgHeight, imgWidth, CV_8UC3);
}
// 位图数据缓冲区的大小,即图像大小
int imgBufSize = imgHeight * realLineByte;
memcpy(src.data, img->buff, imgBufSize); // 图像数据复制
cv::flip(src, src, 0);
memcpy(img->buff, src.data, imgBufSize); // 图像数据复制
}
catch(cv::Exception &e)
{
e.msg;
return;
}
catch(...)
{
return;
}
}