From b0462c2fc41aca56f83caaea8a63f5f7cea26907 Mon Sep 17 00:00:00 2001 From: 7799 <2158192875@qq.com> Date: Wed, 21 Jun 2023 11:24:41 +0800 Subject: [PATCH] Qt_update --- src/估算距离.cpp | 42 +++++++++++++++++++++++++++++++++++++++ src/标记火源.cpp | 36 +++++++++++++++++++++++++++++++++ src/火势预测.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/估算距离.cpp create mode 100644 src/标记火源.cpp create mode 100644 src/火势预测.cpp diff --git a/src/估算距离.cpp b/src/估算距离.cpp new file mode 100644 index 0000000..10b1744 --- /dev/null +++ b/src/估算距离.cpp @@ -0,0 +1,42 @@ +#include +#include +#include + +double calculateRegionSize(int pixel_size, int top_left_pixel_x, int top_left_pixel_y, int bottom_right_pixel_x, int bottom_right_pixel_y, int h, int size) +{ + // 计算选择区域内像素数 + int pixels_in_region = (bottom_right_pixel_x - top_left_pixel_x) * (bottom_right_pixel_y - top_left_pixel_y); + + // 计算像素对应实际大小 + double real_size = (h * 1000.0) * pixel_size / size; // 单位:mm/像素 + + // 计算选定区域的实际大小(单位:米) + double region_size = std::sqrt(pixels_in_region * real_size * real_size) / 1000.0; // 单位:m + + return region_size; +} + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + // 相机像素大小 像素与像素距离 + int pixel_size = 5; + + // 指定区域范围,左上角和右下角像素坐标 + int top_left_pixel_x = 100; + int top_left_pixel_y = 150; + int bottom_right_pixel_x = 200; + int bottom_right_pixel_y = 250; + + // 估计参数 + int h = 10; + int size = 100; + + // 计算选定区域的实际大小(单位:米) + double region_size = calculateRegionSize(pixel_size, top_left_pixel_x, top_left_pixel_y, bottom_right_pixel_x, bottom_right_pixel_y, h, size); + + qDebug() << "The selected region size is:" << region_size << "m."; + + return a.exec(); +} \ No newline at end of file diff --git a/src/标记火源.cpp b/src/标记火源.cpp new file mode 100644 index 0000000..a801f4d --- /dev/null +++ b/src/标记火源.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include + +// 将矩形范围内绘制为指定颜色的矩形,并添加透明度 +void drawRectWithTransparency(QPixmap& pixmap, const QRect& rect, const QColor& color, int transparency) +{ + QPainter painter(&pixmap); + painter.setCompositionMode(QPainter::CompositionMode_Clear); + painter.fillRect(rect, QColor(0, 0, 0, 0)); + painter.setCompositionMode(QPainter::CompositionMode_SourceOver); + painter.fillRect(rect, QColor(color.red(), color.green(), color.blue(), transparency)); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + // 创建窗口和标签 + QWidget window; + QLabel label(&window); + + // 加载图片 + QPixmap pixmap(":1.png"); + QRect rect(360, 360, 300, 250); + drawRectWithTransparency(pixmap, rect, QColor(255, 0, 0), 100); + label.setPixmap(pixmap); + + // 显示窗口和标签 + window.show(); + label.show(); + + return app.exec(); +} \ No newline at end of file diff --git a/src/火势预测.cpp b/src/火势预测.cpp new file mode 100644 index 0000000..d5dd4b1 --- /dev/null +++ b/src/火势预测.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include + +void drawRectOnImage(QString imagePath, QRect rect1, QRect rect2, QColor color1, QColor color2) +{ + // 加载图片 + QPixmap pixmap(imagePath); + + // 指定范围并绘制透明红色和黑色矩形 + QPainter painter(&pixmap); + painter.setCompositionMode(QPainter::CompositionMode_Clear); + painter.fillRect(rect1, QColor(0, 0, 0, 0)); + painter.fillRect(rect2, color2); // 黑色矩形 + painter.setCompositionMode(QPainter::CompositionMode_SourceOver); + painter.fillRect(rect1, color1); + + // 显示图片 + QWidget *mainWindow = new QWidget(); + QVBoxLayout *layout = new QVBoxLayout(mainWindow); + QLabel *label = new QLabel(mainWindow); + layout->addWidget(label); + label->setFixedSize(pixmap.size()); + label->setPixmap(pixmap); + mainWindow->show(); + + // 进入主事件循环 + QApplication::exec(); + delete mainWindow; +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + // 绘制矩形到图片中,并在标签上显示图片 + QRect rect1(360, 360, 300, 250); + QRect rect2(400, 400, 300, 250); + QColor color1(255, 0, 0, 100); + QColor color2(0, 0, 255, 100); + drawRectOnImage(":1.png", rect1, rect2, color1, color2); + + return 0; +} \ No newline at end of file