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();
};

38
Classes/DisplayPic.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include "DisplayPic.h"
DisplayPic::DisplayPic(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
}
DisplayPic::~DisplayPic()
{
}
void DisplayPic::setPicPath(QString pic)
{
picUrl = pic;
if(picUrl.isEmpty())
{
ui.label->setText("No Photo Taken");
}else
{
ui.label->setPixmap(QPixmap(picUrl));
}
}
// È·¶¨
void DisplayPic::on_pushButton_clicked()
{
emit getPicAction("confirmed");
this->close();
}
// È¡Ïû
void DisplayPic::on_pushButton_2_clicked()
{
emit getPicAction("canceled");
this->close();
}

25
Classes/DisplayPic.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <QWidget>
#include "ui_DisplayPic.h"
class DisplayPic : public QWidget
{
Q_OBJECT
public:
DisplayPic(QWidget *parent = Q_NULLPTR);
~DisplayPic();
void setPicPath(QString pic);
private:
Ui::DisplayPic ui;
QString picUrl;
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
signals:
void getPicAction(QString action);
};

37
Classes/Loading.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "Loading.h"
Loading::Loading(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.label_2->hide();
ui.progressBar->setValue(0);
// todo ¼ÓÔØ
ui.progressBar->setValue(100);
ui.label_2->show();
ready2Enter = true;
}
Loading::~Loading()
{
}
void Loading::updateSlot()
{
ui.progressBar->setValue(currentValue);
}
void Loading::mousePressEvent(QMouseEvent *event)
{
if(ready2Enter)
{
if (event->button() == Qt::LeftButton)
{
this->hide();
Reconstruction *w = new Reconstruction();
w->show();
}
}
}

25
Classes/Loading.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <QWidget>
#include "ui_Loading.h"
#include "Reconstruction.h"
#include <QMouseEvent>
class Loading : public QWidget
{
Q_OBJECT
public:
Loading(QWidget *parent = Q_NULLPTR);
~Loading();
private:
Ui::Loading ui;
bool ready2Enter = false;
int currentValue = 0;
void updateSlot();
protected:
void mousePressEvent(QMouseEvent *);
};