From 7adf9378ede81319345f379021388cf944e5770b Mon Sep 17 00:00:00 2001 From: tangchao Date: Fri, 20 May 2022 19:21:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=862=E7=A7=8D=E6=AF=94?= =?UTF-8?q?=E5=80=BC=E6=B3=95=E8=AE=A1=E7=AE=97=E4=BA=91=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloudage.cpp | 194 ++++++++++++++++++++++++++++ cloudage.h | 32 +++++ cloudage.pro | 35 ++++++ cloudage.pro.user | 315 ++++++++++++++++++++++++++++++++++++++++++++++ cloudage_global.h | 12 ++ 5 files changed, 588 insertions(+) create mode 100644 cloudage.cpp create mode 100644 cloudage.h create mode 100644 cloudage.pro create mode 100644 cloudage.pro.user create mode 100644 cloudage_global.h diff --git a/cloudage.cpp b/cloudage.cpp new file mode 100644 index 0000000..6b1a02a --- /dev/null +++ b/cloudage.cpp @@ -0,0 +1,194 @@ +#include "cloudage.h" + + +Cloudage::Cloudage(int radius) +{ + m_iRadius = radius; +} + +void Cloudage::setRadius(int radius) +{ + m_iRadius = radius; +} + +QImage Cloudage::readImage(QString imagePath) +{ + QImage qImage; + qImage.load(imagePath); + + m_qImgPath = imagePath; + + return qImage; +} + +QImage Cloudage::createGrayscaleImage(int width, int height) +{ + QImage grayscaleImage(width, height, QImage::Format_Indexed8);//提问:如果使用QImage::Format_Grayscale8怎么实现? + QVector grayTable; //设置颜色表 + for (int i = 0; i < 256; i++) + grayTable.push_back(qRgb(i, i, i)); + grayscaleImage.setColorTable(grayTable); + + return grayscaleImage; +} + +void Cloudage::getPosOfCenterpixel(int width, int height, int &widthCenter,int &heightCenter) +{ + widthCenter = width/2; + heightCenter = height/2; +} + +bool Cloudage::isValidPos(int x1, int y1, int x2, int y2) +{ + float tmp =pow((x1 - x2), 2) + pow((y1 - y2), 2); + float distance = sqrt(tmp); + + if(distance > m_iRadius) + return false; + else + return true; +} + +float Cloudage::getcloudage1(QImage image, bool saveBinaryImg) +{ + int width=image.width(); + int height=image.height(); + + int widthCenter; + int heightCenter; + getPosOfCenterpixel(width,height,widthCenter,heightCenter); + + QImage cloudQImage = createGrayscaleImage(width, height); + + +// int cloudInt[width][height] = {0};//错误:不能用变量在栈上定义数组 → 只能定义在堆上! + + //申请空间 + int** cloudInt = new int*[width]; + for(int i=0;i0.6) + { + cloudQImage.setPixel(i,j,255); + cloudInt[i][j] = 1; + cloudPixelCounter++; + } + else + { + cloudQImage.setPixel(i,j,150); + } + } + } + + //计算云量 + float cloudage = cloudPixelCounter / totalPixelCountor; + + if(saveBinaryImg) + { + QStringList imgPathTMP = m_qImgPath.split("."); + QString name = imgPathTMP[0] + "_BinaryImg_ratio1." + imgPathTMP[1]; + cloudQImage.save(name); + } + + + //释放空间 + for(int i=0;i +#include +#include + +class CLOUDAGESHARED_EXPORT Cloudage +{ + +public: + Cloudage(int radius); + void setRadius(int radius); + + QImage readImage(QString imagePath); + QImage createGrayscaleImage(int width, int height); + + void getPosOfCenterpixel(int width, int height, int &widthCenter, int &heightCenter); + bool isValidPos(int x1, int y1, int x2, int y2); + + float getcloudage1(QImage image, bool saveBinaryImg = false); + float getcloudage2(QImage image, bool saveBinaryImg = false); + + + +private: + int m_iRadius; + QString m_qImgPath; +}; + +#endif // CLOUDAGE_H diff --git a/cloudage.pro b/cloudage.pro new file mode 100644 index 0000000..365e113 --- /dev/null +++ b/cloudage.pro @@ -0,0 +1,35 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2022-05-19T17:18:09 +# +#------------------------------------------------- + +TARGET = cloudage +TEMPLATE = lib + +QT += core + +DEFINES += CLOUDAGE_LIBRARY + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + cloudage.cpp + +HEADERS += \ + cloudage.h \ + cloudage_global.h + +unix { + target.path = /usr/lib + INSTALLS += target +} diff --git a/cloudage.pro.user b/cloudage.pro.user new file mode 100644 index 0000000..4d12a6c --- /dev/null +++ b/cloudage.pro.user @@ -0,0 +1,315 @@ + + + + + + EnvironmentId + {56086c13-0edc-4f1a-858f-f609f6cc63b1} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.9.0 MSVC2017 64bit + Desktop Qt 5.9.0 MSVC2017 64bit + qt.59.win64_msvc2017_64_kit + 0 + 0 + 0 + + D:/cpp_qtcreator/cloudage-build + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/cpp_qtcreator/build-cloudage-Desktop_Qt_5_9_0_MSVC2017_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/cpp_qtcreator/build-cloudage-Desktop_Qt_5_9_0_MSVC2017_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 在本地部署 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/cloudage_global.h b/cloudage_global.h new file mode 100644 index 0000000..a5e7785 --- /dev/null +++ b/cloudage_global.h @@ -0,0 +1,12 @@ +#ifndef CLOUDAGE_GLOBAL_H +#define CLOUDAGE_GLOBAL_H + +#include + +#if defined(CLOUDAGE_LIBRARY) +# define CLOUDAGESHARED_EXPORT Q_DECL_EXPORT +#else +# define CLOUDAGESHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // CLOUDAGE_GLOBAL_H