Merge remote-tracking branch 'refs/remotes/origin/master'

This commit is contained in:
Norah
2020-02-05 11:08:44 +08:00
33 changed files with 246 additions and 36 deletions

156
Classes/CoreAlgorithm.cpp Normal file
View File

@@ -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<uchar>(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<Vec3b>(i, j)[0] == 255)
{
minX = i;
minY = j;
min = true;
}
}
if (tmp.at<Vec3b>(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<Vec3b>(i, j) = 0.2989 * channel.at(2).at<Vec3b>(i, j) +
0.5907 * channel.at(1).at<Vec3b>(i, j) +
0.1140 * channel.at(0).at<Vec3b>(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++)
{
}
}
}

22
Classes/CoreAlgorithm.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include <opencv2/opencv.hpp>
#include <string>
#include <math.h>
using namespace std;
using namespace cv;
class CoreAlgorithm
{
private:
Mat image, tmp;
vector<Mat> 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();
};

View File

@@ -1,5 +1,4 @@
#include "Loading.h"
#include "Classes/Reconstruction.h"
Loading::Loading(QWidget *parent)
: QWidget(parent)

View File

@@ -2,6 +2,7 @@
#include <QWidget>
#include "ui_Loading.h"
#include "Reconstruction.h"
#include <QMouseEvent>
class Loading : public QWidget

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 KiB

View File

@@ -85,10 +85,15 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<QtUic Include="UI\DisplayPic.ui" />
<QtUic Include="UI\Loading.ui" />
<QtUic Include="UI\Reconstruction.ui" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Classes\CoreAlgorithm.cpp" />
<ClCompile Include="Classes\CameraArguments.cpp" />
<ClCompile Include="Classes\DisplayPic.cpp" />
<ClCompile Include="Classes\Loading.cpp" />
<ClCompile Include="Classes\main.cpp" />
<ClCompile Include="Classes\Reconstruction.cpp" />
<ClCompile Include="Lib\projector\LC4500API\API.cpp" />
@@ -103,7 +108,10 @@
<QtRcc Include="Resources\Reconstruction.qrc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Classes\CoreAlgorithm.h" />
<ClInclude Include="Classes\CameraArguments.h" />
<QtMoc Include="Classes\Loading.h" />
<QtMoc Include="Classes\DisplayPic.h" />
<ClInclude Include="Lib\projector\LC4500API\API.h" />
<ClInclude Include="Lib\projector\LC4500API\Common.h" />
<ClInclude Include="Lib\projector\LC4500API\hidapi.h" />

View File

@@ -50,16 +50,17 @@
<Filter Include="resource\font">
<UniqueIdentifier>{ec183521-b5e0-408b-9e24-aa9910874ed3}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
<ParseFiles>true</ParseFiles>
</Filter>
</ItemGroup>
<ItemGroup>
<QtUic Include="UI\Reconstruction.ui">
<Filter>ui</Filter>
</QtUic>
<QtUic Include="UI\DisplayPic.ui">
<Filter>ui</Filter>
</QtUic>
<QtUic Include="UI\Loading.ui">
<Filter>ui</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Classes\main.cpp">
@@ -83,11 +84,26 @@
<ClCompile Include="Classes\CameraArguments.cpp">
<Filter>src\reconstruction</Filter>
</ClCompile>
<ClCompile Include="Classes\Loading.cpp">
<Filter>src\scene\loadingscene</Filter>
</ClCompile>
<ClCompile Include="Classes\DisplayPic.cpp">
<Filter>src\scene\resultscene</Filter>
</ClCompile>
<ClCompile Include="Classes\CoreAlgorithm.cpp">
<Filter>src\reconstruction</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="Classes\Reconstruction.h">
<Filter>src</Filter>
</QtMoc>
<QtMoc Include="Classes\Loading.h">
<Filter>src\scene\loadingscene</Filter>
</QtMoc>
<QtMoc Include="Classes\DisplayPic.h">
<Filter>src\scene\resultscene</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<QtRcc Include="Resources\Reconstruction.qrc">
@@ -116,5 +132,8 @@
<ClInclude Include="Classes\CameraArguments.h">
<Filter>src\reconstruction</Filter>
</ClInclude>
<ClInclude Include="Classes\CoreAlgorithm.h">
<Filter>src\reconstruction</Filter>
</ClInclude>
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.

View File

@@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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<int*>(_a[0]) = -1;
_id -= 16;
_id -= 17;
}
return _id;
}

Binary file not shown.

Binary file not shown.

View File

@@ -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);

Binary file not shown.