diff --git a/Classes/CoreAlgorithm.cpp b/Classes/CoreAlgorithm.cpp new file mode 100644 index 0000000..65b73b0 --- /dev/null +++ b/Classes/CoreAlgorithm.cpp @@ -0,0 +1,156 @@ +#include "CoreAlgorithm.h" + +CoreAlgorithm::CoreAlgorithm(std::string path = "../Data/image/reconstruction/tq.png") +{ + image = cv::imread(path, cv::IMREAD_COLOR); + tmp = image.clone(); // É±´ + split(image, channel); //b,g,r +} + +CoreAlgorithm::~CoreAlgorithm() +{ +} + +Mat CoreAlgorithm::OSTU(Mat src) +{ + const auto width = src.cols; + const auto height = src.rows; + int hisData[256] = {0}; + + for (auto j = 0; j < height; j++) + { + auto* data = src.ptr(j); + for (auto i = 0; i < width; i++) + hisData[data[i]]++; + } + + auto t0 = 0; + + for (auto i = 0; i < 256; i++) + { + t0 += i * hisData[i]; + } + + t0 /= width * height; + + auto t1 = 0, t2 = 0; + auto num1 = 0, num2 = 0; + auto t = 0; + + while (true) + { + for (auto i = 0; i < t0 + 1; i++) + { + t1 += i * hisData[i]; + num1 += hisData[i]; + } + + if (num1 == 0) continue; + + for (auto i = t0 + 1; i < 256; i++) + { + t2 += i * hisData[i]; + num2 += hisData[i]; + } + + if (num2 == 0) continue; + + t = (t1 / num1 + t2 / num2) / 2; + + if (t != t0) t0 = t; + else break; + } + + Mat dst; + + threshold(src, dst, t, 255, 0); + + return dst; +} + +void CoreAlgorithm::Rgb2Hsv(float r, float g, float b, float& h, float& s, float& v) +{ + // r,g,b values are from 0 to 1 + // h = [0,360], s = [0,1], v = [0,1] + // if s == 0, then h = -1 (undefined) + float min, max, delta, temp; + temp = r > g ? g : r; + min = temp > b ? b : temp; + temp = r > g ? r : g; + max = temp > b ? temp : b; + v = max; // v + delta = max - min; + if (max != 0) + s = delta / max; // s + else + { + // r = g = b = 0 // s = 0, v is undefined + s = 0; + h = 0; + return; + } + if (delta == 0) + { + h = 0; + return; + } + else if (r == max) + { + if (g >= b) + h = (g - b) / delta; // between yellow & magenta + else + h = (g - b) / delta + 6.0; + } + else if (g == max) + h = (b - r) / delta + 2.0; // between cyan & yellow + else if (b == max) + h = (r - g) / delta + 4.0; // between magenta & cyan + h *= 60.0; // degrees +} + +void CoreAlgorithm::run() +{ + tmp = OSTU(image); + auto min = false; + for (auto i = 0; i < 1024; i++) + { + for (auto j = 0; j < 1280; j++) + { + if (!min) + { + if (tmp.at(i, j)[0] == 255) + { + minX = i; + minY = j; + min = true; + } + } + + if (tmp.at(i, j)[0] == 255) + { + if (i > maxX) maxX = i; + if (j > maxY) maxY = j; + } + } + } + + Mat grayImage = Mat::zeros(cv::Size(1024, 1280), CV_32FC1); + for (auto i = 0; i < 1024; i++) + { + for (auto j = 0; j < 1280; j++) + { + grayImage.at(i, j) = 0.2989 * channel.at(2).at(i, j) + + 0.5907 * channel.at(1).at(i, j) + + 0.1140 * channel.at(0).at(i, j); + } + } + + Mat featurePoint = Mat::zeros(cv::Size(1024, 1280), CV_32FC1); + + for (auto i = minX; i < maxX; i++) + { + for (auto j = minY; j < maxY; j++) + { + } + } +} diff --git a/Classes/CoreAlgorithm.h b/Classes/CoreAlgorithm.h new file mode 100644 index 0000000..a8fd51a --- /dev/null +++ b/Classes/CoreAlgorithm.h @@ -0,0 +1,22 @@ +#pragma once +#include +#include +#include + +using namespace std; +using namespace cv; + +class CoreAlgorithm +{ +private: + Mat image, tmp; + vector channel; + const int neighborhood = 5; + int minX = 0, maxX = 0, minY = 0, maxY = 0; +public: + CoreAlgorithm(std::string path); + ~CoreAlgorithm(); + Mat OSTU(Mat src); + void Rgb2Hsv(float r, float g, float b, float& h, float& s, float& v); + void run(); +}; diff --git a/DisplayPic.cpp b/Classes/DisplayPic.cpp similarity index 100% rename from DisplayPic.cpp rename to Classes/DisplayPic.cpp diff --git a/DisplayPic.h b/Classes/DisplayPic.h similarity index 100% rename from DisplayPic.h rename to Classes/DisplayPic.h diff --git a/Loading.cpp b/Classes/Loading.cpp similarity index 93% rename from Loading.cpp rename to Classes/Loading.cpp index b3caa1a..133a73f 100644 --- a/Loading.cpp +++ b/Classes/Loading.cpp @@ -1,5 +1,4 @@ #include "Loading.h" -#include "Classes/Reconstruction.h" Loading::Loading(QWidget *parent) : QWidget(parent) diff --git a/Loading.h b/Classes/Loading.h similarity index 92% rename from Loading.h rename to Classes/Loading.h index e0852fd..e3f0ba9 100644 --- a/Loading.h +++ b/Classes/Loading.h @@ -2,6 +2,7 @@ #include #include "ui_Loading.h" +#include "Reconstruction.h" #include class Loading : public QWidget diff --git a/Data/image/reconstruction/tq.png b/Data/image/reconstruction/tq.png new file mode 100644 index 0000000..45ebe1a Binary files /dev/null and b/Data/image/reconstruction/tq.png differ diff --git a/Reconstruction.vcxproj b/Reconstruction.vcxproj index 6d3c903..c3b492f 100644 --- a/Reconstruction.vcxproj +++ b/Reconstruction.vcxproj @@ -85,10 +85,15 @@ + + + + + @@ -103,7 +108,10 @@ + + + diff --git a/Reconstruction.vcxproj.filters b/Reconstruction.vcxproj.filters index 770b150..b599a14 100644 --- a/Reconstruction.vcxproj.filters +++ b/Reconstruction.vcxproj.filters @@ -50,16 +50,17 @@ {ec183521-b5e0-408b-9e24-aa9910874ed3} - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - true - ui + + ui + + + ui + @@ -83,11 +84,26 @@ src\reconstruction + + src\scene\loadingscene + + + src\scene\resultscene + + + src\reconstruction + src + + src\scene\loadingscene + + + src\scene\resultscene + @@ -116,5 +132,8 @@ src\reconstruction + + src\reconstruction + \ No newline at end of file diff --git a/DisplayPic.ui b/UI/DisplayPic.ui similarity index 100% rename from DisplayPic.ui rename to UI/DisplayPic.ui diff --git a/Loading.ui b/UI/Loading.ui similarity index 100% rename from Loading.ui rename to UI/Loading.ui diff --git a/x64/Debug/Reconstruction.exe b/x64/Debug/Reconstruction.exe index 3dd09fd..9ce47f3 100644 Binary files a/x64/Debug/Reconstruction.exe and b/x64/Debug/Reconstruction.exe differ diff --git a/x64/Debug/Reconstruction.ilk b/x64/Debug/Reconstruction.ilk index 010b053..5445db0 100644 Binary files a/x64/Debug/Reconstruction.ilk and b/x64/Debug/Reconstruction.ilk differ diff --git a/x64/Debug/Reconstruction.log b/x64/Debug/Reconstruction.log index 5579849..4988b1a 100644 --- a/x64/Debug/Reconstruction.log +++ b/x64/Debug/Reconstruction.log @@ -1,4 +1,4 @@  Reading Qt configuration (D:\Qt\5.12.3\msvc2017_64\bin\qmake.exe) - CameraArguments.cpp + CoreAlgorithm.cpp 正在创建库 D:\BJTU\Reconstruction\x64\Debug\Reconstruction.lib 和对象 D:\BJTU\Reconstruction\x64\Debug\Reconstruction.exp Reconstruction.vcxproj -> D:\BJTU\Reconstruction\x64\Debug\Reconstruction.exe diff --git a/x64/Debug/Reconstruction.obj b/x64/Debug/Reconstruction.obj index 0bcf67e..1690de4 100644 Binary files a/x64/Debug/Reconstruction.obj and b/x64/Debug/Reconstruction.obj differ diff --git a/x64/Debug/Reconstruction.pdb b/x64/Debug/Reconstruction.pdb index 1de7f17..560e2ee 100644 Binary files a/x64/Debug/Reconstruction.pdb and b/x64/Debug/Reconstruction.pdb differ diff --git a/x64/Debug/Reconstruction.tlog/CL.command.1.tlog b/x64/Debug/Reconstruction.tlog/CL.command.1.tlog index de3b1ea..8480953 100644 Binary files a/x64/Debug/Reconstruction.tlog/CL.command.1.tlog and b/x64/Debug/Reconstruction.tlog/CL.command.1.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/CL.read.1.tlog b/x64/Debug/Reconstruction.tlog/CL.read.1.tlog index c67752d..e17df3b 100644 Binary files a/x64/Debug/Reconstruction.tlog/CL.read.1.tlog and b/x64/Debug/Reconstruction.tlog/CL.read.1.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/CL.write.1.tlog b/x64/Debug/Reconstruction.tlog/CL.write.1.tlog index 1274dac..bc4dbd9 100644 Binary files a/x64/Debug/Reconstruction.tlog/CL.write.1.tlog and b/x64/Debug/Reconstruction.tlog/CL.write.1.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/Reconstruction.write.1u.tlog b/x64/Debug/Reconstruction.tlog/Reconstruction.write.1u.tlog index 9279b2e..44e8ef7 100644 Binary files a/x64/Debug/Reconstruction.tlog/Reconstruction.write.1u.tlog and b/x64/Debug/Reconstruction.tlog/Reconstruction.write.1u.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/link.command.1.tlog b/x64/Debug/Reconstruction.tlog/link.command.1.tlog index 0649e37..40d4628 100644 Binary files a/x64/Debug/Reconstruction.tlog/link.command.1.tlog and b/x64/Debug/Reconstruction.tlog/link.command.1.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/link.read.1.tlog b/x64/Debug/Reconstruction.tlog/link.read.1.tlog index dc79d5a..8a147ee 100644 Binary files a/x64/Debug/Reconstruction.tlog/link.read.1.tlog and b/x64/Debug/Reconstruction.tlog/link.read.1.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/link.write.1.tlog b/x64/Debug/Reconstruction.tlog/link.write.1.tlog index 65d574f..dbaf36f 100644 Binary files a/x64/Debug/Reconstruction.tlog/link.write.1.tlog and b/x64/Debug/Reconstruction.tlog/link.write.1.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/moc.read.1u.tlog b/x64/Debug/Reconstruction.tlog/moc.read.1u.tlog index d964e04..cb0070b 100644 Binary files a/x64/Debug/Reconstruction.tlog/moc.read.1u.tlog and b/x64/Debug/Reconstruction.tlog/moc.read.1u.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/moc.write.1u.tlog b/x64/Debug/Reconstruction.tlog/moc.write.1u.tlog index 95547b4..492e7a2 100644 Binary files a/x64/Debug/Reconstruction.tlog/moc.write.1u.tlog and b/x64/Debug/Reconstruction.tlog/moc.write.1u.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/uic.read.1u.tlog b/x64/Debug/Reconstruction.tlog/uic.read.1u.tlog index f8f6848..2a73b72 100644 Binary files a/x64/Debug/Reconstruction.tlog/uic.read.1u.tlog and b/x64/Debug/Reconstruction.tlog/uic.read.1u.tlog differ diff --git a/x64/Debug/Reconstruction.tlog/uic.write.1u.tlog b/x64/Debug/Reconstruction.tlog/uic.write.1u.tlog index 496f384..9155053 100644 Binary files a/x64/Debug/Reconstruction.tlog/uic.write.1u.tlog and b/x64/Debug/Reconstruction.tlog/uic.write.1u.tlog differ diff --git a/x64/Debug/main.obj b/x64/Debug/main.obj index 4e7df50..cd2e936 100644 Binary files a/x64/Debug/main.obj and b/x64/Debug/main.obj differ diff --git a/x64/Debug/moc/Classes/moc_Reconstruction.cpp b/x64/Debug/moc/Classes/moc_Reconstruction.cpp index af0d555..36a44c0 100644 --- a/x64/Debug/moc/Classes/moc_Reconstruction.cpp +++ b/x64/Debug/moc/Classes/moc_Reconstruction.cpp @@ -21,8 +21,8 @@ QT_BEGIN_MOC_NAMESPACE QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED struct qt_meta_stringdata_Reconstruction_t { - QByteArrayData data[18]; - char stringdata0[405]; + QByteArrayData data[20]; + char stringdata0[425]; }; #define QT_MOC_LITERAL(idx, ofs, len) \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ @@ -48,7 +48,9 @@ QT_MOC_LITERAL(13, 280, 24), // "on_pushButton_12_clicked" QT_MOC_LITERAL(14, 305, 24), // "on_pushButton_13_clicked" QT_MOC_LITERAL(15, 330, 24), // "on_pushButton_14_clicked" QT_MOC_LITERAL(16, 355, 24), // "on_pushButton_15_clicked" -QT_MOC_LITERAL(17, 380, 24) // "on_pushButton_16_clicked" +QT_MOC_LITERAL(17, 380, 24), // "on_pushButton_16_clicked" +QT_MOC_LITERAL(18, 405, 12), // "setPicAction" +QT_MOC_LITERAL(19, 418, 6) // "action" }, "Reconstruction\0on_pushButton_clicked\0" @@ -63,7 +65,8 @@ QT_MOC_LITERAL(17, 380, 24) // "on_pushButton_16_clicked" "on_pushButton_13_clicked\0" "on_pushButton_14_clicked\0" "on_pushButton_15_clicked\0" - "on_pushButton_16_clicked" + "on_pushButton_16_clicked\0setPicAction\0" + "action" }; #undef QT_MOC_LITERAL @@ -73,7 +76,7 @@ static const uint qt_meta_data_Reconstruction[] = { 8, // revision 0, // classname 0, 0, // classinfo - 16, 14, // methods + 17, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -81,22 +84,23 @@ static const uint qt_meta_data_Reconstruction[] = { 0, // signalCount // slots: name, argc, parameters, tag, flags - 1, 0, 94, 2, 0x08 /* Private */, - 3, 0, 95, 2, 0x08 /* Private */, - 4, 0, 96, 2, 0x08 /* Private */, - 5, 0, 97, 2, 0x08 /* Private */, - 6, 0, 98, 2, 0x08 /* Private */, - 7, 0, 99, 2, 0x08 /* Private */, - 8, 0, 100, 2, 0x08 /* Private */, - 9, 0, 101, 2, 0x08 /* Private */, - 10, 0, 102, 2, 0x08 /* Private */, - 11, 0, 103, 2, 0x08 /* Private */, - 12, 0, 104, 2, 0x08 /* Private */, - 13, 0, 105, 2, 0x08 /* Private */, - 14, 0, 106, 2, 0x08 /* Private */, - 15, 0, 107, 2, 0x08 /* Private */, - 16, 0, 108, 2, 0x08 /* Private */, - 17, 0, 109, 2, 0x08 /* Private */, + 1, 0, 99, 2, 0x08 /* Private */, + 3, 0, 100, 2, 0x08 /* Private */, + 4, 0, 101, 2, 0x08 /* Private */, + 5, 0, 102, 2, 0x08 /* Private */, + 6, 0, 103, 2, 0x08 /* Private */, + 7, 0, 104, 2, 0x08 /* Private */, + 8, 0, 105, 2, 0x08 /* Private */, + 9, 0, 106, 2, 0x08 /* Private */, + 10, 0, 107, 2, 0x08 /* Private */, + 11, 0, 108, 2, 0x08 /* Private */, + 12, 0, 109, 2, 0x08 /* Private */, + 13, 0, 110, 2, 0x08 /* Private */, + 14, 0, 111, 2, 0x08 /* Private */, + 15, 0, 112, 2, 0x08 /* Private */, + 16, 0, 113, 2, 0x08 /* Private */, + 17, 0, 114, 2, 0x08 /* Private */, + 18, 1, 115, 2, 0x08 /* Private */, // slots: parameters QMetaType::Void, @@ -115,6 +119,7 @@ static const uint qt_meta_data_Reconstruction[] = { QMetaType::Void, QMetaType::Void, QMetaType::Void, + QMetaType::Void, QMetaType::QString, 19, 0 // eod }; @@ -141,10 +146,10 @@ void Reconstruction::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _ case 13: _t->on_pushButton_14_clicked(); break; case 14: _t->on_pushButton_15_clicked(); break; case 15: _t->on_pushButton_16_clicked(); break; + case 16: _t->setPicAction((*reinterpret_cast< QString(*)>(_a[1]))); break; default: ; } } - Q_UNUSED(_a); } QT_INIT_METAOBJECT const QMetaObject Reconstruction::staticMetaObject = { { @@ -176,13 +181,13 @@ int Reconstruction::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 16) + if (_id < 17) qt_static_metacall(this, _c, _id, _a); - _id -= 16; + _id -= 17; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { - if (_id < 16) + if (_id < 17) *reinterpret_cast(_a[0]) = -1; - _id -= 16; + _id -= 17; } return _id; } diff --git a/x64/Debug/moc_Reconstruction.obj b/x64/Debug/moc_Reconstruction.obj index 615258e..adae8d2 100644 Binary files a/x64/Debug/moc_Reconstruction.obj and b/x64/Debug/moc_Reconstruction.obj differ diff --git a/x64/Debug/qt_work.log b/x64/Debug/qt_work.log index 3178a5f..63b6135 100644 Binary files a/x64/Debug/qt_work.log and b/x64/Debug/qt_work.log differ diff --git a/x64/Debug/uic/UI/ui_Reconstruction.h b/x64/Debug/uic/UI/ui_Reconstruction.h index 084523b..0604c6c 100644 --- a/x64/Debug/uic/UI/ui_Reconstruction.h +++ b/x64/Debug/uic/UI/ui_Reconstruction.h @@ -108,7 +108,7 @@ public: { if (ReconstructionClass->objectName().isEmpty()) ReconstructionClass->setObjectName(QString::fromUtf8("ReconstructionClass")); - ReconstructionClass->resize(1111, 604); + ReconstructionClass->resize(1111, 601); centralWidget = new QWidget(ReconstructionClass); centralWidget->setObjectName(QString::fromUtf8("centralWidget")); line = new QFrame(centralWidget); @@ -118,7 +118,7 @@ public: line->setFrameShadow(QFrame::Sunken); stackedWidget = new QStackedWidget(centralWidget); stackedWidget->setObjectName(QString::fromUtf8("stackedWidget")); - stackedWidget->setGeometry(QRect(249, -1, 851, 551)); + stackedWidget->setGeometry(QRect(249, -1, 851, 531)); page = new QWidget(); page->setObjectName(QString::fromUtf8("page")); label_2 = new QLabel(page); @@ -467,7 +467,7 @@ public: retranslateUi(ReconstructionClass); - stackedWidget->setCurrentIndex(2); + stackedWidget->setCurrentIndex(0); QMetaObject::connectSlotsByName(ReconstructionClass); diff --git a/x64/Debug/vc142.pdb b/x64/Debug/vc142.pdb index 7ee4a5d..6e35df7 100644 Binary files a/x64/Debug/vc142.pdb and b/x64/Debug/vc142.pdb differ