|
@@ -34,6 +34,9 @@
|
|
|
#include <QDateTime>
|
|
#include <QDateTime>
|
|
|
#include <QDebug>
|
|
#include <QDebug>
|
|
|
#include <QFileInfo>
|
|
#include <QFileInfo>
|
|
|
|
|
+#include <QImage>
|
|
|
|
|
+#include <QPainter>
|
|
|
|
|
+#include <QFont>
|
|
|
#include <QtConcurrent/QtConcurrent>
|
|
#include <QtConcurrent/QtConcurrent>
|
|
|
#include <m_workthread.h>
|
|
#include <m_workthread.h>
|
|
|
#include <mserial.h>
|
|
#include <mserial.h>
|
|
@@ -207,18 +210,89 @@ cv::Mat enhanceResultImage(OpencvFunc &func, const cv::Mat &image)
|
|
|
return func.enhanceContrast(sharp, 0);
|
|
return func.enhanceContrast(sharp, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//保存结果图片(jpg,质量95,与拍照图片一致):左上角红色文件名水印
|
|
|
|
|
|
|
+//结果图片水印(左上角,红色两行):
|
|
|
|
|
+// 第1行: 2026年09月20日 15:02:37 z0x1_5.jpg (文件名前14位时间戳 + 其后步进与序号)
|
|
|
|
|
+// 第2行: 位置[113.44245,34.22586] 温湿度 [20℃,65%RH]
|
|
|
|
|
+//cv::putText 只能画 ASCII,无法渲染中文/℃,故改用 QPainter 绘制
|
|
|
|
|
+void drawWatermark(cv::Mat &image, const QString &filePath)
|
|
|
|
|
+{
|
|
|
|
|
+ if(image.empty()) return;
|
|
|
|
|
+ if(image.channels() == 4) cv::cvtColor(image, image, cv::COLOR_BGRA2BGR);
|
|
|
|
|
+ if(image.channels() != 3) return;
|
|
|
|
|
+
|
|
|
|
|
+ //直接用 cv::Mat 像素作为 QImage 画布(Format_BGR888 与 OpenCV 的 BGR 字节序一致)
|
|
|
|
|
+ QImage canvas(image.data, image.cols, image.rows,
|
|
|
|
|
+ static_cast<int>(image.step), QImage::Format_BGR888);
|
|
|
|
|
+ if(canvas.isNull()) return;
|
|
|
|
|
+
|
|
|
|
|
+ const QString fileName = QFileInfo(filePath).fileName();
|
|
|
|
|
+ const QString base = QFileInfo(filePath).completeBaseName();
|
|
|
|
|
+ const QString suffix = QFileInfo(filePath).suffix();
|
|
|
|
|
+ //文件名形如 20260920150237z0x1_5.jpg:前14位为时间戳,其后为 z/x 步进与序号
|
|
|
|
|
+ QString timeText;
|
|
|
|
|
+ QString tailText = fileName;
|
|
|
|
|
+ if(base.size() > 14){
|
|
|
|
|
+ const QDateTime dt = QDateTime::fromString(base.left(14), "yyyyMMddhhmmss");
|
|
|
|
|
+ if(dt.isValid()){
|
|
|
|
|
+ timeText = dt.toString(QStringLiteral("yyyy年MM月dd日 hh:mm:ss"));
|
|
|
|
|
+ tailText = base.mid(14) + (suffix.isEmpty() ? QString() : "." + suffix);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(timeText.isEmpty()){
|
|
|
|
|
+ timeText = QDateTime::currentDateTime().toString(QStringLiteral("yyyy年MM月dd日 hh:mm:ss"));
|
|
|
|
|
+ }
|
|
|
|
|
+ const QString line1 = timeText + " " + tailText;
|
|
|
|
|
+
|
|
|
|
|
+ //位置:优先GPS,回退基站定位;经纬度保留5位小数(约1米精度)
|
|
|
|
|
+ auto fmtCoord = [](const QString &v) -> QString {
|
|
|
|
|
+ const QString t = v.trimmed();
|
|
|
|
|
+ if(t.isEmpty() || t == QStringLiteral("0")) return QString();
|
|
|
|
|
+ bool ok = false;
|
|
|
|
|
+ const double d = t.toDouble(&ok);
|
|
|
|
|
+ return ok ? QString::number(d, 'f', 5) : QString();
|
|
|
|
|
+ };
|
|
|
|
|
+ QString lng = fmtCoord(param::gps_lng);
|
|
|
|
|
+ QString lat = fmtCoord(param::gps_lat);
|
|
|
|
|
+ if(lng.isEmpty() || lat.isEmpty()){
|
|
|
|
|
+ const QString lbsLng = fmtCoord(param::lbs_lng);
|
|
|
|
|
+ const QString lbsLat = fmtCoord(param::lbs_lat);
|
|
|
|
|
+ if(lng.isEmpty()) lng = lbsLng;
|
|
|
|
|
+ if(lat.isEmpty()) lat = lbsLat;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(lng.isEmpty()) lng = QStringLiteral("--");
|
|
|
|
|
+ if(lat.isEmpty()) lat = QStringLiteral("--");
|
|
|
|
|
+ //温湿度:MCU 上报的环境温度/湿度(ext.at/ah),无数据时以 -- 占位
|
|
|
|
|
+ const QString tempText = param::env_temp.trimmed().isEmpty()
|
|
|
|
|
+ ? QStringLiteral("--") : param::env_temp.trimmed();
|
|
|
|
|
+ const QString humiText = param::env_humi.trimmed().isEmpty()
|
|
|
|
|
+ ? QStringLiteral("--") : param::env_humi.trimmed();
|
|
|
|
|
+ const QString line2 = QStringLiteral("位置[%1,%2] 温湿度 [%3℃,%4%RH]")
|
|
|
|
|
+ .arg(lng, lat, tempText, humiText);
|
|
|
|
|
+
|
|
|
|
|
+ QPainter painter(&canvas);
|
|
|
|
|
+ painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
|
+ painter.setRenderHint(QPainter::TextAntialiasing, true);
|
|
|
|
|
+ QFont font = painter.font();
|
|
|
|
|
+ //字号随图像宽度自适应:2592宽 -> 约52px,与旧 putText fontScale=3.0 视觉接近
|
|
|
|
|
+ const int fontSize = qBound(16, image.cols / 50, 96);
|
|
|
|
|
+ font.setPixelSize(fontSize);
|
|
|
|
|
+ font.setBold(true);
|
|
|
|
|
+ painter.setFont(font);
|
|
|
|
|
+ painter.setPen(QColor(255, 0, 0)); //红色,与旧水印一致
|
|
|
|
|
+ const int margin = qMax(10, image.cols / 160);
|
|
|
|
|
+ const int lineHeight = static_cast<int>(fontSize * 1.5);
|
|
|
|
|
+ painter.drawText(margin, margin + fontSize, line1);
|
|
|
|
|
+ painter.drawText(margin, margin + fontSize + lineHeight, line2);
|
|
|
|
|
+ painter.end();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+//保存结果图片(jpg,质量95,与拍照图片一致):左上角红色水印(时间/文件名/位置/温湿度)
|
|
|
bool saveResultImage(const QString &path, const cv::Mat &image)
|
|
bool saveResultImage(const QString &path, const cv::Mat &image)
|
|
|
{
|
|
{
|
|
|
QDir().mkpath(QFileInfo(path).absolutePath());
|
|
QDir().mkpath(QFileInfo(path).absolutePath());
|
|
|
cv::Mat out = image.clone();
|
|
cv::Mat out = image.clone();
|
|
|
- cv::putText(out,
|
|
|
|
|
- QFileInfo(path).fileName().toStdString(),
|
|
|
|
|
- cv::Point(15, 50),
|
|
|
|
|
- cv::FONT_HERSHEY_SIMPLEX,
|
|
|
|
|
- 3.0, //增大水印字体大小
|
|
|
|
|
- cv::Scalar(0,0,255), //红色 red
|
|
|
|
|
- 3);
|
|
|
|
|
|
|
+ if(out.channels() == 4) cv::cvtColor(out, out, cv::COLOR_BGRA2BGR);
|
|
|
|
|
+ drawWatermark(out, path);
|
|
|
std::vector<int> params = {cv::IMWRITE_JPEG_QUALITY, 95};
|
|
std::vector<int> params = {cv::IMWRITE_JPEG_QUALITY, 95};
|
|
|
if(!cv::imwrite(path.toStdString(), out, params)){
|
|
if(!cv::imwrite(path.toStdString(), out, params)){
|
|
|
ERROR("saveResultImage: 保存失败:{}",path.toStdString());
|
|
ERROR("saveResultImage: 保存失败:{}",path.toStdString());
|
|
@@ -943,14 +1017,8 @@ Frames::saveMatAsJpeg(const QVideoFrame &frame){
|
|
|
cv::Mat fused_sharp = m_opencvfunc.unsharpMask(image, 2.0, 3.0);
|
|
cv::Mat fused_sharp = m_opencvfunc.unsharpMask(image, 2.0, 3.0);
|
|
|
//对比度
|
|
//对比度
|
|
|
cv::Mat Contrast_Image = m_opencvfunc.enhanceContrast(fused_sharp,0);
|
|
cv::Mat Contrast_Image = m_opencvfunc.enhanceContrast(fused_sharp,0);
|
|
|
- //左上角水印:红色字体,文字为图片名称(不含目录)
|
|
|
|
|
- cv::putText(Contrast_Image,
|
|
|
|
|
- QFileInfo(name_sharp).fileName().toStdString(),
|
|
|
|
|
- cv::Point(15, 50),
|
|
|
|
|
- cv::FONT_HERSHEY_SIMPLEX,
|
|
|
|
|
- 3.0, //增大水印字体大小
|
|
|
|
|
- cv::Scalar(0,0,255), //红色 red
|
|
|
|
|
- 3);
|
|
|
|
|
|
|
+ //左上角水印:红色两行(时间+文件名 / 位置+温湿度)
|
|
|
|
|
+ drawWatermark(Contrast_Image, name_sharp);
|
|
|
std::vector<int> jpegParams = {cv::IMWRITE_JPEG_QUALITY, 95};
|
|
std::vector<int> jpegParams = {cv::IMWRITE_JPEG_QUALITY, 95};
|
|
|
if (!cv::imwrite(name_sharp.toStdString(), Contrast_Image, jpegParams)) {
|
|
if (!cv::imwrite(name_sharp.toStdString(), Contrast_Image, jpegParams)) {
|
|
|
ERROR("Failed to save fused image:{}",name_sharp.toStdString());
|
|
ERROR("Failed to save fused image:{}",name_sharp.toStdString());
|