move reconstruct progress to thread
This commit is contained in:
@@ -510,3 +510,8 @@ void CoreAlgorithm::saveCoordinate()
|
||||
}
|
||||
destFile.close();
|
||||
}
|
||||
|
||||
vector<Mat> CoreAlgorithm::getCoordinates()
|
||||
{
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
@@ -53,4 +53,6 @@ public:
|
||||
void run();
|
||||
|
||||
void saveCoordinate();
|
||||
|
||||
vector<Mat> getCoordinates();
|
||||
};
|
||||
|
||||
@@ -7,7 +7,9 @@ Reconstruction::Reconstruction(QWidget* parent)
|
||||
calibData = new CalibrationData();
|
||||
calibrator = new Calibrator();
|
||||
dirModel = new TreeModel(this);
|
||||
td = new YourThread(&cloud);
|
||||
t = new MyThread;
|
||||
connect(td, SIGNAL(finished()), this, SLOT(setCloud()));
|
||||
connect(t, SIGNAL(finished()), this, SLOT(setCloud()));
|
||||
device = Device::getInstance();
|
||||
setStyle();
|
||||
@@ -118,7 +120,7 @@ void Reconstruction::on_pushButton_3_clicked()
|
||||
{
|
||||
ui.stackedWidget->setCurrentIndex(2);
|
||||
updateQVTK(cloud, color);
|
||||
if (loadingStatus)
|
||||
if (loadingStatus || reconstructStatus)
|
||||
{
|
||||
ui.label_9->setVisible(true);
|
||||
}
|
||||
@@ -132,9 +134,21 @@ void Reconstruction::on_pushButton_3_clicked()
|
||||
#pragma region 多线程
|
||||
void Reconstruction::setCloud()
|
||||
{
|
||||
cout << cloud.width;
|
||||
ui.label_9->setVisible(false);
|
||||
loadingStatus = false;
|
||||
cloud = t->getCloud();
|
||||
|
||||
if(loadingStatus)
|
||||
{
|
||||
cloud = t->getCloud();
|
||||
loadingStatus = false;
|
||||
}
|
||||
|
||||
if(reconstructStatus)
|
||||
{
|
||||
reconstructStatus = false;
|
||||
}
|
||||
cout << cloud[0].r;
|
||||
|
||||
updateQVTK(cloud, color);
|
||||
}
|
||||
|
||||
@@ -207,7 +221,7 @@ void Reconstruction::on_pushButton_6_clicked()
|
||||
// Aquire frame
|
||||
auto frame = device->getCamera()->getFrame();
|
||||
auto frameCV = cvtools::camFrame2Mat(frame);
|
||||
cvtColor(frameCV, frameCV, cv::COLOR_BGR2GRAY);
|
||||
cvtColor(frameCV, frameCV, COLOR_BGR2GRAY);
|
||||
//parameter
|
||||
std::cout << cv::format("./config/calib/calib%.2d/%.2d.bmp", imgCount, i) << std::endl;
|
||||
imwrite(cv::format("./config/calib/calib%.2d/%.2d.bmp", imgCount, i), frameCV);
|
||||
@@ -377,7 +391,7 @@ void Reconstruction::setDirModel(const QString& dirname)
|
||||
continue;
|
||||
}
|
||||
|
||||
// add the childrens
|
||||
// add the childrens
|
||||
auto parent = dirModel->index(row, 0);
|
||||
dirModel->setData(parent, item, Qt::DisplayRole);
|
||||
|
||||
@@ -550,49 +564,11 @@ void Reconstruction::on_pushButton_10_clicked()
|
||||
void Reconstruction::on_pushButton_17_clicked()
|
||||
{
|
||||
// todo 开始重建
|
||||
// auto cArg = CameraArguments::getInstance();
|
||||
Mat r(3, 3, CV_32F);
|
||||
double m0[3][3] = {
|
||||
{9.7004457782050868e-001, 1.3447278830863673e-002, 2.4255450466457243e-001},
|
||||
{-8.7082927494022376e-003, 9.9974988338843274e-001, -2.0599424802792338e-002},
|
||||
{-2.4277084396282392e-001, 1.7870124701864658e-002, 9.6991905639837694e-001}
|
||||
};
|
||||
for (auto i = 0; i < r.rows; i++)
|
||||
for (auto j = 0; j < r.cols; j++)
|
||||
r.at<float>(i, j) = m0[i][j];
|
||||
|
||||
Mat t(1, 3, CV_32F);
|
||||
double m1[1][3] = {
|
||||
{-1.9511179496234658e+002, 1.2627509817628756e+001, -5.9345885017522171e+001}
|
||||
};
|
||||
|
||||
for (auto i = 0; i < t.rows; i++)
|
||||
for (auto j = 0; j < t.cols; j++)
|
||||
t.at<float>(i, j) = m1[i][j];
|
||||
|
||||
Mat kc(3, 3, CV_32F);
|
||||
double m2[3][3] = {
|
||||
{2.1536653255083029e+003, 0., 6.1886776197116581e+002},
|
||||
{0., 2.1484363899666910e+003, 5.0694898820460787e+002},
|
||||
{0., 0., 1.}
|
||||
};
|
||||
for (auto i = 0; i < kc.rows; i++)
|
||||
for (auto j = 0; j < kc.cols; j++)
|
||||
kc.at<float>(i, j) = m2[i][j];
|
||||
|
||||
Mat kp(3, 3, CV_32F);
|
||||
double m3[3][3] = {
|
||||
{1.7235093158297350e+003, 0., 4.4128195628736904e+002},
|
||||
{0., 3.4533404000869359e+003, 5.7316457428558715e+002},
|
||||
{0., 0., 1.}
|
||||
};
|
||||
for (auto i = 0; i < kp.rows; i++)
|
||||
for (auto j = 0; j < kp.cols; j++)
|
||||
kp.at<float>(i, j) = m3[i][j];
|
||||
|
||||
auto cArg = CameraArguments::getInstance(r, t, kc, kp);
|
||||
CoreAlgorithm testCase = CoreAlgorithm("./Data/image/reconstruction/tq.png", cArg);
|
||||
testCase.run();
|
||||
reconstructStatus = true;
|
||||
on_pushButton_3_clicked();
|
||||
ui.label_9->setVisible(true);
|
||||
QCoreApplication::processEvents();
|
||||
td->start();
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Device.h"
|
||||
#include "CoreAlgorithm.h"
|
||||
#include "MyThread.h"
|
||||
#include "YourThread.h"
|
||||
#include "Help.h"
|
||||
#include <iostream>
|
||||
using namespace pcl;
|
||||
@@ -50,15 +51,20 @@ private:
|
||||
QString picPath = "Result/result.png"; // 三维重建:拍摄照片的存储路径
|
||||
PointCloud<PointXYZRGB> cloud;
|
||||
bool confirmPic = false; // 三维重建:确定是否用所拍照片进行重建
|
||||
QColor color = Qt::black; // 点云渲染:颜色
|
||||
QColor color = Qt::yellow; // 点云渲染:颜色
|
||||
|
||||
// 标定相关变量
|
||||
int liveViewTimer;
|
||||
TreeModel* dirModel;
|
||||
CalibrationData* calibData;
|
||||
Calibrator* calibrator;
|
||||
int imgCount;
|
||||
|
||||
// 多线程
|
||||
// 重建多线程
|
||||
YourThread *td;
|
||||
bool reconstructStatus = false; // 点云渲染
|
||||
|
||||
// 点云多线程
|
||||
MyThread* t;
|
||||
bool loadingStatus = false; // 点云渲染
|
||||
void setStyle();
|
||||
|
||||
66
Classes/YourThread.cpp
Normal file
66
Classes/YourThread.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "YourThread.h"
|
||||
|
||||
YourThread::YourThread(PointCloud<PointXYZRGB> *cloudRef)
|
||||
{
|
||||
cloud = cloudRef;
|
||||
}
|
||||
|
||||
void YourThread::run()
|
||||
{
|
||||
// auto cArg = CameraArguments::getInstance();
|
||||
Mat r(3, 3, CV_32F);
|
||||
double m0[3][3] = {
|
||||
{9.7004457782050868e-001, 1.3447278830863673e-002, 2.4255450466457243e-001},
|
||||
{-8.7082927494022376e-003, 9.9974988338843274e-001, -2.0599424802792338e-002},
|
||||
{-2.4277084396282392e-001, 1.7870124701864658e-002, 9.6991905639837694e-001}
|
||||
};
|
||||
for (auto i = 0; i < r.rows; i++)
|
||||
for (auto j = 0; j < r.cols; j++)
|
||||
r.at<float>(i, j) = m0[i][j];
|
||||
|
||||
Mat t(1, 3, CV_32F);
|
||||
double m1[1][3] = {
|
||||
{-1.9511179496234658e+002, 1.2627509817628756e+001, -5.9345885017522171e+001}
|
||||
};
|
||||
|
||||
for (auto i = 0; i < t.rows; i++)
|
||||
for (auto j = 0; j < t.cols; j++)
|
||||
t.at<float>(i, j) = m1[i][j];
|
||||
|
||||
Mat kc(3, 3, CV_32F);
|
||||
double m2[3][3] = {
|
||||
{2.1536653255083029e+003, 0., 6.1886776197116581e+002},
|
||||
{0., 2.1484363899666910e+003, 5.0694898820460787e+002},
|
||||
{0., 0., 1.}
|
||||
};
|
||||
for (auto i = 0; i < kc.rows; i++)
|
||||
for (auto j = 0; j < kc.cols; j++)
|
||||
kc.at<float>(i, j) = m2[i][j];
|
||||
|
||||
Mat kp(3, 3, CV_32F);
|
||||
double m3[3][3] = {
|
||||
{1.7235093158297350e+003, 0., 4.4128195628736904e+002},
|
||||
{0., 3.4533404000869359e+003, 5.7316457428558715e+002},
|
||||
{0., 0., 1.}
|
||||
};
|
||||
for (auto i = 0; i < kp.rows; i++)
|
||||
for (auto j = 0; j < kp.cols; j++)
|
||||
kp.at<float>(i, j) = m3[i][j];
|
||||
|
||||
auto cArg = CameraArguments::getInstance(r, t, kc, kp);
|
||||
CoreAlgorithm testCase = CoreAlgorithm("./Data/image/reconstruction/tq.png", cArg);
|
||||
testCase.run();
|
||||
vector<Mat> coordinates=testCase.getCoordinates();
|
||||
cloud->width = coordinates.size();
|
||||
cloud->height = 1;
|
||||
cloud->is_dense = false;
|
||||
cloud->points.resize(cloud->width * cloud->height);
|
||||
auto index = 0;
|
||||
for (size_t i = 0; i < cloud->points.size(); ++i)
|
||||
{
|
||||
cloud->points[i].x = coordinates[index].at<float>(0, 0);
|
||||
cloud->points[i].y = coordinates[index].at<float>(0, 1);
|
||||
cloud->points[i].z = coordinates[index].at<float>(0, 2);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
22
Classes/YourThread.h
Normal file
22
Classes/YourThread.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <qthread.h>
|
||||
#include <pcl/point_types.h>
|
||||
#include <pcl/io/vtk_lib_io.h>
|
||||
#include "CoreAlgorithm.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace pcl;
|
||||
|
||||
class YourThread :
|
||||
public QThread
|
||||
{
|
||||
public:
|
||||
YourThread(PointCloud<PointXYZRGB> *cloud);
|
||||
~YourThread(){};
|
||||
|
||||
private:
|
||||
PointCloud<PointXYZRGB> *cloud;
|
||||
protected:
|
||||
void run();
|
||||
};
|
||||
Reference in New Issue
Block a user