modify some logical bugs,add remove point function
This commit is contained in:
@@ -16,11 +16,11 @@ Calibrator::~Calibrator()
|
||||
|
||||
}
|
||||
|
||||
void Calibrator::addFrameSequence(std::vector<cv::Mat> &frameSeq)
|
||||
void Calibrator::addFrameSequence(std::vector<Mat> &frameSeq)
|
||||
{
|
||||
int n = frameSeqs.size();
|
||||
frameSeqs.resize(n+1);
|
||||
std::vector<cv::Mat> &frame = frameSeqs[n];
|
||||
std::vector<Mat> &frame = frameSeqs[n];
|
||||
for(int i = 0; i < frameSeq.size(); i++)
|
||||
{
|
||||
frame.push_back(frameSeq[i]);
|
||||
@@ -38,17 +38,17 @@ void Calibrator::reset()
|
||||
|
||||
void Calibrator::setBoardRows(int rows) {
|
||||
board_rows = rows;
|
||||
board_size = cv::Size(board_rows, board_cols);
|
||||
board_size = Size(board_rows, board_cols);
|
||||
}
|
||||
|
||||
void Calibrator::setBoardCols(int cols) {
|
||||
board_cols = cols;
|
||||
board_size = cv::Size(board_rows, board_cols);
|
||||
board_size = Size(board_rows, board_cols);
|
||||
}
|
||||
|
||||
void Calibrator::setCornerSize(double cornerSize) {
|
||||
dot_dis = cornerSize;
|
||||
corner_size = cv::Size2f(cornerSize, cornerSize);
|
||||
corner_size = Size2f(cornerSize, cornerSize);
|
||||
}
|
||||
|
||||
void Calibrator::setDotDiameter(double dotDiameter) {
|
||||
@@ -66,7 +66,7 @@ CalibrationData* Calibrator::calibrate()
|
||||
// detect corners ////////////////////////////////////
|
||||
for(int i = 0; i < frameSeqs.size(); i++)
|
||||
{
|
||||
std::vector<cv::Point2f> corners = extract_board_corners( frameSeqs[i][0] );
|
||||
std::vector<Point2f> corners = extract_board_corners( frameSeqs[i][0] );
|
||||
board_corners.push_back(corners);
|
||||
// std::cout<<i<<" corners: "<<corners.size()<<std::endl;
|
||||
// for(int j = 0; j < corners.size(); j++) {
|
||||
@@ -75,12 +75,12 @@ CalibrationData* Calibrator::calibrate()
|
||||
}
|
||||
|
||||
// collect projector correspondences
|
||||
std::vector<cv::Point2f> pcorners;
|
||||
std::vector<Point2f> pcorners;
|
||||
for(int i = 0; i < frameSeqs.size(); i++)
|
||||
{
|
||||
std::vector<cv::Point2f> const& corners = board_corners[i];
|
||||
cv::Mat pattern_image;
|
||||
cv::Mat min_max_image;
|
||||
std::vector<Point2f> const& corners = board_corners[i];
|
||||
Mat pattern_image;
|
||||
Mat min_max_image;
|
||||
if(corners.size()==0)
|
||||
{
|
||||
projector_corners.push_back(pcorners);
|
||||
@@ -95,25 +95,25 @@ CalibrationData* Calibrator::calibrate()
|
||||
}
|
||||
|
||||
pattern_list.push_back(pattern_image);
|
||||
for (std::vector<cv::Point2f>::const_iterator iter=corners.begin(); iter!=corners.end(); iter++)
|
||||
for (std::vector<Point2f>::const_iterator iter=corners.begin(); iter!=corners.end(); iter++)
|
||||
{
|
||||
const cv::Point2f & p = *iter;
|
||||
cv::Point2f q;
|
||||
const Point2f & p = *iter;
|
||||
Point2f q;
|
||||
//find an homography around p
|
||||
unsigned WINDOW_SIZE = 30;
|
||||
std::vector<cv::Point2f> img_points , proj_points;
|
||||
std::vector<Point2f> img_points , proj_points;
|
||||
if (p.x>WINDOW_SIZE && p.y>WINDOW_SIZE && p.x+WINDOW_SIZE<pattern_image.cols && p.y+WINDOW_SIZE<pattern_image.rows)
|
||||
{
|
||||
for (unsigned h=p.y-WINDOW_SIZE; h<p.y+WINDOW_SIZE; h++)
|
||||
{
|
||||
register const cv::Vec2f * row = pattern_image.ptr<cv::Vec2f>(h);
|
||||
register const cv::Vec2b * min_max_row = min_max_image.ptr<cv::Vec2b>(h);
|
||||
//cv::Vec2f * out_row = out_pattern_image.ptr<cv::Vec2f>(h);
|
||||
register const Vec2f * row = pattern_image.ptr<Vec2f>(h);
|
||||
register const Vec2b * min_max_row = min_max_image.ptr<Vec2b>(h);
|
||||
//Vec2f * out_row = out_pattern_image.ptr<Vec2f>(h);
|
||||
for (unsigned w=p.x-WINDOW_SIZE; w<p.x+WINDOW_SIZE; w++)
|
||||
{
|
||||
const cv::Vec2f & pattern = row[w];
|
||||
const cv::Vec2b & min_max = min_max_row[w];
|
||||
//cv::Vec2f & out_pattern = out_row[w];
|
||||
const Vec2f & pattern = row[w];
|
||||
const Vec2b & min_max = min_max_row[w];
|
||||
//Vec2f & out_pattern = out_row[w];
|
||||
if (std::isnan(pattern[0])>0 || std::isnan(pattern[1])>0)
|
||||
{
|
||||
continue;
|
||||
@@ -123,16 +123,16 @@ CalibrationData* Calibrator::calibrate()
|
||||
continue;
|
||||
}
|
||||
|
||||
img_points.push_back(cv::Point2f(w, h));
|
||||
proj_points.push_back(cv::Point2f(pattern));
|
||||
img_points.push_back(Point2f(w, h));
|
||||
proj_points.push_back(Point2f(pattern));
|
||||
|
||||
//out_pattern = pattern;
|
||||
}
|
||||
}
|
||||
cv::Mat H = cv::findHomography(img_points , proj_points, cv::RANSAC);
|
||||
Mat H = findHomography(img_points , proj_points, RANSAC);
|
||||
// std::cout << " H:\n" << H << std::endl;
|
||||
cv::Point3d Q = cv::Point3d(cv::Mat(H*cv::Mat(cv::Point3d(p.x , p.y , 1.0))));
|
||||
q = cv::Point2f(Q.x/Q.z ,Q.y/Q.z);
|
||||
Point3d Q = Point3d(Mat(H*Mat(Point3d(p.x , p.y , 1.0))));
|
||||
q = Point2f(Q.x/Q.z ,Q.y/Q.z);
|
||||
// jiuzheng
|
||||
// q.y += 118;
|
||||
pcorners.push_back(q);
|
||||
@@ -159,15 +159,15 @@ CalibrationData* Calibrator::calibrate()
|
||||
count++;
|
||||
}
|
||||
}
|
||||
std::vector<cv::Point3f> world_corners;
|
||||
std::vector<Point3f> world_corners;
|
||||
for (int h=0; h<board_size.height; h++)
|
||||
{
|
||||
for (int w=0; w<board_size.width; w++)
|
||||
{
|
||||
world_corners.push_back(cv::Point3f(corner_size.width * w, corner_size.height * h , 0.f));
|
||||
world_corners.push_back(Point3f(corner_size.width * w, corner_size.height * h , 0.f));
|
||||
}
|
||||
}
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints;
|
||||
std::vector<std::vector<Point3f> > objectPoints;
|
||||
objectPoints.reserve(count);
|
||||
for (unsigned i=0; i<count; i++)
|
||||
{
|
||||
@@ -175,16 +175,16 @@ CalibrationData* Calibrator::calibrate()
|
||||
}
|
||||
|
||||
//generate world object coordinates
|
||||
std::vector<cv::Point3f> world_corners_p;
|
||||
std::vector<Point3f> world_corners_p;
|
||||
for (int h=0; h<board_size.height; h++)
|
||||
{
|
||||
for (int w=0; w<board_size.width; w++)
|
||||
{
|
||||
world_corners_p.push_back(cv::Point3f(corner_size.width * w , corner_size.height * h ,0.f));
|
||||
world_corners_p.push_back(Point3f(corner_size.width * w , corner_size.height * h ,0.f));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<cv::Point3f> > objectPoints_p;
|
||||
std::vector<std::vector<Point3f> > objectPoints_p;
|
||||
objectPoints_p.reserve(count);
|
||||
for (unsigned i=0; i<count; i++)
|
||||
{
|
||||
@@ -196,48 +196,48 @@ CalibrationData* Calibrator::calibrate()
|
||||
pattern_list.resize(count);
|
||||
|
||||
int cal_flags = 0
|
||||
//+ cv::CALIB_FIX_K1
|
||||
//+ cv::CALIB_FIX_K2
|
||||
//+ cv::CALIB_ZERO_TANGENT_DIST
|
||||
+ cv::CALIB_FIX_K3
|
||||
//+ CALIB_FIX_K1
|
||||
//+ CALIB_FIX_K2
|
||||
//+ CALIB_ZERO_TANGENT_DIST
|
||||
+ CALIB_FIX_K3
|
||||
;
|
||||
//calibrate the camera ////////////////////////////////////
|
||||
std::vector<cv::Mat> cam_rvecs , cam_tvecs;
|
||||
std::vector<Mat> cam_rvecs , cam_tvecs;
|
||||
int cam_flags = cal_flags;
|
||||
cv::Size imageSize = frameSeqs[0][0].size();
|
||||
res->cam_error = cv::calibrateCamera(objectPoints , board_corners , imageSize , res->Kc , res->kc ,cam_rvecs , cam_tvecs);
|
||||
Size imageSize = frameSeqs[0][0].size();
|
||||
res->cam_error = calibrateCamera(objectPoints , board_corners , imageSize , res->Kc , res->kc ,cam_rvecs , cam_tvecs);
|
||||
std::cout<<"calibrate the camera !"<<std::endl;
|
||||
|
||||
//calibrate the projector ////////////////////////////////////
|
||||
std::vector<cv::Mat> proj_rvecs , proj_tvecs;
|
||||
std::vector<Mat> proj_rvecs , proj_tvecs;
|
||||
int proj_flags = cal_flags;
|
||||
cv::Size projector_size(912, 1140);
|
||||
res->proj_error = cv::calibrateCamera(objectPoints_p , projector_corners, projector_size , res->Kp , res->kp , proj_rvecs , proj_tvecs);
|
||||
Size projector_size(912, 1140);
|
||||
res->proj_error = calibrateCamera(objectPoints_p , projector_corners, projector_size , res->Kp , res->kp , proj_rvecs , proj_tvecs);
|
||||
|
||||
std::cout<<"calibrate the projector !"<<std::endl;
|
||||
//stereo calibration
|
||||
cv::Mat E, F;
|
||||
res->stereo_error = cv::stereoCalibrate(objectPoints , board_corners , projector_corners ,
|
||||
Mat E, F;
|
||||
res->stereo_error = stereoCalibrate(objectPoints , board_corners , projector_corners ,
|
||||
res->Kc , res->kc , res->Kp ,res->kp ,imageSize /*ignored*/ ,
|
||||
res->Rp , res->Tp , E , F );
|
||||
// res->stereo_error = cv::stereoCalibrate(objectPoints , board_corners , projector_corners , res->Kc , res->kc , res->Kp ,res->kp ,imageSize /*ignored*/ , res->Rp , res->Tp , E , F ,
|
||||
// cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS ,50 ,DBL_EPSILON) ,
|
||||
// cv::CALIB_FIX_INTRINSIC /*cv::CALIB_USE_INTRINSIC_GUESS + cal_flags*/);
|
||||
// res->stereo_error = stereoCalibrate(objectPoints , board_corners , projector_corners , res->Kc , res->kc , res->Kp ,res->kp ,imageSize /*ignored*/ , res->Rp , res->Tp , E , F ,
|
||||
// TermCriteria(TermCriteria::COUNT + TermCriteria::EPS ,50 ,DBL_EPSILON) ,
|
||||
// CALIB_FIX_INTRINSIC /*CALIB_USE_INTRINSIC_GUESS + cal_flags*/);
|
||||
std::cout<<"stereo calibration !"<<std::endl;
|
||||
|
||||
|
||||
cv::FileStorage fsc("rtc.xml", cv::FileStorage::WRITE);
|
||||
cv::FileStorage fsp("rtp.xml", cv::FileStorage::WRITE);
|
||||
FileStorage fsc("rtc.xml", FileStorage::WRITE);
|
||||
FileStorage fsp("rtp.xml", FileStorage::WRITE);
|
||||
|
||||
// objectPoints projector_corners board_corners
|
||||
std::ofstream opout("objectPoints.txt");
|
||||
std::ofstream pcout("projector_corners.txt");
|
||||
std::ofstream ccout("board_corners.txt");
|
||||
for (int i = 0; i < objectPoints.size(); i++) {
|
||||
fsc << "R" + std::to_string(i) << cv::Mat(cam_rvecs[i]);
|
||||
fsc << "T" + std::to_string(i) << cv::Mat(cam_tvecs[i]);
|
||||
fsp << "R" + std::to_string(i) << cv::Mat(proj_rvecs[i]);
|
||||
fsp << "T" + std::to_string(i) << cv::Mat(proj_tvecs[i]);
|
||||
fsc << "R" + std::to_string(i) << Mat(cam_rvecs[i]);
|
||||
fsc << "T" + std::to_string(i) << Mat(cam_tvecs[i]);
|
||||
fsp << "R" + std::to_string(i) << Mat(proj_rvecs[i]);
|
||||
fsp << "T" + std::to_string(i) << Mat(proj_tvecs[i]);
|
||||
for (int j = 0; j < objectPoints[i].size(); j++) {
|
||||
opout << objectPoints[i][j] << std::endl;
|
||||
pcout << projector_corners[i][j] << std::endl;
|
||||
@@ -254,24 +254,24 @@ CalibrationData* Calibrator::calibrate()
|
||||
|
||||
}
|
||||
|
||||
std::vector<cv::Point2f> Calibrator::extract_board_corners(cv::Mat &gray_image)
|
||||
std::vector<Point2f> Calibrator::extract_board_corners(Mat &gray_image)
|
||||
{
|
||||
std::vector<cv::Point2f> corners;
|
||||
std::vector<Point2f> corners;
|
||||
int image_scale = 1;
|
||||
if (gray_image.rows<1)
|
||||
{
|
||||
return corners;
|
||||
}
|
||||
cv::Size imageSize = gray_image.size();
|
||||
Size imageSize = gray_image.size();
|
||||
if (imageSize.width>1024)
|
||||
{
|
||||
image_scale = imageSize.width/1024;
|
||||
}
|
||||
|
||||
cv::Mat small_img;
|
||||
Mat small_img;
|
||||
if (image_scale>1)
|
||||
{
|
||||
cv::resize(gray_image , small_img , cv::Size(gray_image.cols/image_scale , gray_image.rows/image_scale));
|
||||
resize(gray_image , small_img , Size(gray_image.cols/image_scale , gray_image.rows/image_scale));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -279,27 +279,27 @@ std::vector<cv::Point2f> Calibrator::extract_board_corners(cv::Mat &gray_image)
|
||||
}
|
||||
|
||||
if(board_type == Chessboard) {
|
||||
cv::findChessboardCorners(small_img, board_size, corners);
|
||||
findChessboardCorners(small_img, board_size, corners);
|
||||
}
|
||||
else if(board_type == Circular) {
|
||||
cv::findCirclesGrid(small_img, board_size, corners);
|
||||
findCirclesGrid(small_img, board_size, corners);
|
||||
}
|
||||
|
||||
if (corners.size())
|
||||
{
|
||||
for (std::vector<cv::Point2f>::iterator iter=corners.begin(); iter!=corners.end(); iter++)
|
||||
for (std::vector<Point2f>::iterator iter=corners.begin(); iter!=corners.end(); iter++)
|
||||
{
|
||||
*iter = image_scale*(*iter);
|
||||
}
|
||||
cv::cornerSubPix(gray_image , corners , cv::Size(11 , 11) , cv::Size(-1 , -1) ,
|
||||
cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 30 , 0.1));
|
||||
cornerSubPix(gray_image , corners , Size(11 , 11) , Size(-1 , -1) ,
|
||||
TermCriteria(TermCriteria::EPS + TermCriteria::MAX_ITER, 30 , 0.1));
|
||||
}
|
||||
|
||||
return corners;
|
||||
}
|
||||
|
||||
|
||||
bool Calibrator::decode_gray_set(int ind , cv::Mat & pattern_image, cv::Mat & min_max_image)
|
||||
bool Calibrator::decode_gray_set(int ind , Mat & pattern_image, Mat & min_max_image)
|
||||
{
|
||||
if (ind >= frameSeqs.size())
|
||||
{ //out of bounds
|
||||
@@ -308,7 +308,7 @@ bool Calibrator::decode_gray_set(int ind , cv::Mat & pattern_image, cv::Mat & m
|
||||
|
||||
//estimate direct component
|
||||
//b = config.value("robust_estimation/b" DEFAULT_B).toFloat();
|
||||
std::vector<cv::Mat> images;
|
||||
std::vector<Mat> images;
|
||||
// QList<unsigned> direct_component_images(QList<unsigned>() << 15 << 16 << 17 << 18 << 35 << 36 << 37 << 38);
|
||||
int total_images = frameSeqs[ind].size();
|
||||
int total_patterns = total_images/2 - 1;
|
||||
@@ -326,12 +326,12 @@ bool Calibrator::decode_gray_set(int ind , cv::Mat & pattern_image, cv::Mat & m
|
||||
{
|
||||
images.push_back(frameSeqs[ind][i]);
|
||||
}
|
||||
cv::Mat direct_light = sl::estimate_direct_light(images, b);
|
||||
Mat direct_light = sl::estimate_direct_light(images, b);
|
||||
|
||||
//m = config.value("robust_estimation/m" DEFAULT_M).toUInt();
|
||||
// return sl::decode_pattern(frameSeqs[ind] , pattern_image , min_max_image , sl::RobustDecode|sl::GrayPatternDecode , direct_light, m);
|
||||
|
||||
cv::Size projector_size(912, 1140);
|
||||
Size projector_size(912, 1140);
|
||||
bool rv = sl::decode_pattern(frameSeqs[ind], pattern_image, min_max_image, projector_size, sl::RobustDecode|sl::GrayPatternDecode, direct_light, m);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ void MyThread::run()
|
||||
io::loadPCDFile(pcd, *cloudPtr);
|
||||
cloud = *cloudPtr;
|
||||
}
|
||||
|
||||
auto pclData = PointCloudData::getInstance(cloud);
|
||||
pclData->setCloud(cloud);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <qthread.h>
|
||||
#include <pcl/point_types.h>
|
||||
#include <pcl/io/vtk_lib_io.h>
|
||||
#include "PointCloudData.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace pcl;
|
||||
|
||||
70
Classes/PointCloudData.cpp
Normal file
70
Classes/PointCloudData.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "PointCloudData.h"
|
||||
|
||||
PointCloudData* PointCloudData::instance = nullptr;
|
||||
|
||||
PointCloudData::PointCloudData(PointCloud<PointXYZRGB> cloudArg)
|
||||
{
|
||||
cloud = cloudArg;
|
||||
num = 0;
|
||||
}
|
||||
|
||||
PointCloudData* PointCloudData::getInstance(PointCloud<PointXYZRGB> cloudArg)
|
||||
{
|
||||
if (instance == nullptr) instance = new PointCloudData(cloudArg);
|
||||
return instance;
|
||||
}
|
||||
|
||||
PointCloudData* PointCloudData::getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
PointCloud<PointXYZRGB> PointCloudData::getCloud() const{
|
||||
return cloud;
|
||||
}
|
||||
|
||||
void PointCloudData::setCloud(PointCloud<PointXYZRGB> cloudArg){
|
||||
cloud= cloudArg;
|
||||
}
|
||||
|
||||
boost::shared_ptr<visualization::PCLVisualizer> PointCloudData::getViewer()
|
||||
{
|
||||
return viewer;
|
||||
}
|
||||
|
||||
|
||||
void PointCloudData::setViewer(boost::shared_ptr<visualization::PCLVisualizer> viewerArg)
|
||||
{
|
||||
viewer = viewerArg;
|
||||
}
|
||||
|
||||
std::vector<int> PointCloudData::getIndices()
|
||||
{
|
||||
return indices;
|
||||
}
|
||||
|
||||
void PointCloudData::setIndices(std::vector<int> indicesArg)
|
||||
{
|
||||
indices = indicesArg;
|
||||
}
|
||||
|
||||
Ui::ReconstructionClass PointCloudData::getUI()
|
||||
{
|
||||
return ui;
|
||||
}
|
||||
|
||||
void PointCloudData::setUI(Ui::ReconstructionClass uiArg)
|
||||
{
|
||||
ui = uiArg;
|
||||
}
|
||||
|
||||
int PointCloudData::getNum()
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
void PointCloudData::setNum()
|
||||
{
|
||||
num++;
|
||||
}
|
||||
|
||||
35
Classes/PointCloudData.h
Normal file
35
Classes/PointCloudData.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <pcl/point_types.h>
|
||||
#include <pcl/io/pcd_io.h>
|
||||
#include <pcl/visualization/pcl_visualizer.h>
|
||||
#include <pcl/io/vtk_lib_io.h>
|
||||
#include "Reconstruction.h"
|
||||
|
||||
using namespace pcl;
|
||||
|
||||
class PointCloudData
|
||||
{
|
||||
private:
|
||||
PointCloudData(PointCloud<PointXYZRGB> cloudArg);
|
||||
~PointCloudData(){};
|
||||
PointCloud<PointXYZRGB> cloud;
|
||||
boost::shared_ptr<visualization::PCLVisualizer> viewer;
|
||||
std::vector<int> indices;
|
||||
Ui::ReconstructionClass ui;
|
||||
int num;// 用于框选删除点云的名称
|
||||
|
||||
public:
|
||||
static PointCloudData* getInstance();
|
||||
static PointCloudData* getInstance(PointCloud<PointXYZRGB> cloudArg);
|
||||
static PointCloudData* instance ;
|
||||
PointCloud<PointXYZRGB> getCloud() const;
|
||||
void setCloud(PointCloud<PointXYZRGB> cloudArg);
|
||||
boost::shared_ptr<visualization::PCLVisualizer> getViewer();
|
||||
void setViewer(boost::shared_ptr<visualization::PCLVisualizer> viewerArg);
|
||||
std::vector<int> getIndices();
|
||||
void setIndices(std::vector<int> indicesArg);
|
||||
Ui::ReconstructionClass getUI();
|
||||
void setUI(Ui::ReconstructionClass uiArg);
|
||||
int getNum();
|
||||
void setNum();
|
||||
};
|
||||
@@ -134,42 +134,98 @@ void Reconstruction::on_pushButton_3_clicked()
|
||||
#pragma endregion
|
||||
|
||||
#pragma region 多线程
|
||||
// 点云框选回调函数
|
||||
void pp_callback(const visualization::AreaPickingEvent& event, void* args)
|
||||
{
|
||||
auto pclData = PointCloudData::getInstance();
|
||||
PointCloud<PointXYZRGB>::Ptr cloudPtr(new PointCloud<PointXYZRGB>);
|
||||
cloudPtr = pclData->getCloud().makeShared();
|
||||
int num = pclData->getNum();
|
||||
std::vector<int> indices;
|
||||
|
||||
if (event.getPointsIndices(indices) == -1)
|
||||
return;
|
||||
// cout << indices.size() << "\n";
|
||||
PointCloud<PointXYZRGB>::Ptr clicked_points_3d(new PointCloud<PointXYZRGB>);
|
||||
for (int i = 0; i < indices.size(); ++i)
|
||||
{
|
||||
clicked_points_3d->points.push_back(cloudPtr->points.at(indices[i]));
|
||||
}
|
||||
visualization::PointCloudColorHandlerCustom<PointXYZRGB> red(clicked_points_3d, 255, 0, 0);
|
||||
std::stringstream ss;
|
||||
std::string cloudName;
|
||||
pclData->setNum();
|
||||
ss <<num++;
|
||||
ss >> cloudName;
|
||||
cloudName += "_cloudName";
|
||||
|
||||
pclData->getViewer()->addPointCloud(clicked_points_3d, red, cloudName);
|
||||
pclData->getViewer()->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 10, cloudName);
|
||||
// pclData->getViewer()->updatePointCloud(clicked_points_3d,"cloudName");
|
||||
pclData->setIndices(indices);
|
||||
pclData->getUI().qvtkWidget->SetRenderWindow(pclData->getViewer()->getRenderWindow());
|
||||
pclData->getUI().qvtkWidget->update();
|
||||
|
||||
}
|
||||
|
||||
void Reconstruction::setCloud()
|
||||
{
|
||||
cout << cloud.width;
|
||||
ui.label_9->setVisible(false);
|
||||
|
||||
if(loadingStatus)
|
||||
|
||||
if (loadingStatus)
|
||||
{
|
||||
cloud = t->getCloud();
|
||||
loadingStatus = false;
|
||||
}
|
||||
|
||||
if(reconstructStatus)
|
||||
if (reconstructStatus)
|
||||
{
|
||||
reconstructStatus = false;
|
||||
}
|
||||
cout << cloud[0].r;
|
||||
|
||||
|
||||
updateQVTK(cloud, color);
|
||||
}
|
||||
|
||||
void Reconstruction::updateQVTK(PointCloud<PointXYZRGB> cloud, QColor color)
|
||||
{
|
||||
boost::shared_ptr<visualization::PCLVisualizer> viewer(new visualization::PCLVisualizer("3D Viewer"));
|
||||
viewer->setBackgroundColor(0.458, 0.529, 0.844);
|
||||
viewer->setPointCloudRenderingProperties(visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
|
||||
boost::shared_ptr<visualization::PCLVisualizer> viewer;
|
||||
visualization::Camera camera;
|
||||
if (PointCloudData::getInstance() != nullptr)
|
||||
{
|
||||
auto pclData = PointCloudData::getInstance();
|
||||
pclData->setCloud(cloud);
|
||||
pclData->getViewer()->getCameraParameters(camera);
|
||||
cout<<cloud.size()<<"," << camera.pos[0] << "," << camera.pos[1] << "," << camera.pos[2] << "," << camera.view[0] <<
|
||||
"," << camera.view[1] << "," << camera.view[2] << "\n";
|
||||
viewer = pclData->getViewer();
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::shared_ptr<visualization::PCLVisualizer> viewerArg(new visualization::PCLVisualizer("3D Viewer"));
|
||||
viewer=viewerArg;
|
||||
viewer->setBackgroundColor(0.458, 0.529, 0.844);
|
||||
auto pclData = PointCloudData::getInstance(cloud);
|
||||
pclData->setViewer(viewer);
|
||||
pclData->setUI(ui);
|
||||
}
|
||||
double size=1;
|
||||
viewer->getPointCloudRenderingProperties(visualization::PCL_VISUALIZER_POINT_SIZE, size, "cloud");
|
||||
viewer->removeAllPointClouds();
|
||||
// viewer->setPointCloudRenderingProperties(visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
|
||||
if (cloud.size() != 0)
|
||||
{
|
||||
PointCloud<PointXYZRGB>::Ptr cloudPtr(new PointCloud<PointXYZRGB>);
|
||||
cloudPtr = cloud.makeShared();
|
||||
|
||||
int x = int(color.redF() * 255);
|
||||
int y = int(color.greenF() * 255);
|
||||
int z = int(color.blueF() * 255);
|
||||
visualization::PointCloudColorHandlerCustom<PointXYZRGB> cloud_color(cloudPtr, x, y, z);// 统一处理点云颜色
|
||||
visualization::PointCloudColorHandlerCustom<PointXYZRGB> cloud_color(cloudPtr, x, y, z); // 统一处理点云颜色
|
||||
viewer->addPointCloud(cloudPtr, cloud_color, "cloud");
|
||||
viewer->setPointCloudRenderingProperties(visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
|
||||
viewer->setPointCloudRenderingProperties(visualization::PCL_VISUALIZER_POINT_SIZE, size, "cloud");
|
||||
// viewer->setCameraPosition(camera.pos[0], camera.pos[1], camera.pos[2], camera.view[0], camera.view[1], camera.view[2],0,0,1);
|
||||
viewer->registerAreaPickingCallback(pp_callback, (void*)&cloud);
|
||||
}
|
||||
ui.qvtkWidget->SetRenderWindow(viewer->getRenderWindow());
|
||||
ui.qvtkWidget->update();
|
||||
@@ -562,7 +618,7 @@ void Reconstruction::on_pushButton_10_clicked()
|
||||
|
||||
screen->grabWindow(ui.label_21->winId()).save(fileName);
|
||||
|
||||
|
||||
|
||||
// QImage iim(picPath); //创建一个图片对象,存储源图片
|
||||
// QPainter painter(&iim); //设置绘画设备
|
||||
// QFile file(fileName); //创建一个文件对象,存储用户选择的文件
|
||||
@@ -582,7 +638,6 @@ void Reconstruction::on_pushButton_10_clicked()
|
||||
QMessageBox mesg;
|
||||
mesg.warning(this, "WARNING", "Haven't taken picture!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 开始重建
|
||||
@@ -610,15 +665,31 @@ void Reconstruction::on_pushButton_11_clicked()
|
||||
void Reconstruction::on_pushButton_12_clicked()
|
||||
{
|
||||
// todo 异常点剔除
|
||||
auto pclData = PointCloudData::getInstance();
|
||||
// cloud = pclData->getCloud();
|
||||
auto indices = pclData->getIndices();
|
||||
for (auto i = 0; i < indices.size(); ++i)
|
||||
{
|
||||
// cout << "i:" << i << " indices:" << indices[i] << " diff:" << indices[i]-i << "\n";
|
||||
auto index = cloud.begin() + (indices[i] - i);
|
||||
// cout << "size:" << cloudPtr->size() << ",index:" << indices[i] - i<<"\n" ;
|
||||
if (indices[i] - i >= cloud.size())break;
|
||||
cloud.erase(index);
|
||||
}
|
||||
indices.clear();
|
||||
pclData->setIndices(indices);
|
||||
pclData->setCloud(cloud);
|
||||
updateQVTK(cloud, color);
|
||||
// pclData->getViewer()->updatePointCloud();
|
||||
}
|
||||
|
||||
// 导入点云
|
||||
void Reconstruction::on_pushButton_13_clicked()
|
||||
{
|
||||
if (loadingStatus)
|
||||
if (loadingStatus || reconstructStatus)
|
||||
{
|
||||
QMessageBox mesg;
|
||||
mesg.warning(this, "WARNING", "正在加载… ");
|
||||
mesg.warning(this, "WARNING", "There is a Point Cloud Loading.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -632,7 +703,11 @@ void Reconstruction::on_pushButton_13_clicked()
|
||||
mesg.warning(this, "WARNING", "Failed to open file");
|
||||
return;
|
||||
}
|
||||
|
||||
boost::shared_ptr<visualization::PCLVisualizer> viewer(new visualization::PCLVisualizer("3D Viewer"));
|
||||
viewer->setBackgroundColor(0.458, 0.529, 0.844);
|
||||
ui.qvtkWidget->SetRenderWindow(viewer->getRenderWindow());
|
||||
auto pclData = PointCloudData::getInstance(cloud);
|
||||
pclData->setViewer(viewer);
|
||||
ui.label_9->setVisible(true);
|
||||
QCoreApplication::processEvents();
|
||||
t->setPcd(fileName);
|
||||
@@ -667,8 +742,10 @@ void Reconstruction::on_pushButton_15_clicked()
|
||||
// 颜色选取
|
||||
void Reconstruction::on_pushButton_16_clicked()
|
||||
{
|
||||
auto pclData = PointCloudData::getInstance(cloud);
|
||||
QColor colortmp = QColorDialog::getColor(Qt::black);
|
||||
if (colortmp.isValid()) {
|
||||
if (colortmp.isValid())
|
||||
{
|
||||
color = colortmp;
|
||||
updateQVTK(cloud, color);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "CoreAlgorithm.h"
|
||||
#include "MyThread.h"
|
||||
#include "YourThread.h"
|
||||
#include "PointCloudData.h"
|
||||
#include "Help.h"
|
||||
#include <iostream>
|
||||
using namespace pcl;
|
||||
|
||||
@@ -63,4 +63,7 @@ void YourThread::run()
|
||||
cloud->points[i].z = coordinates[index].at<float>(0, 2);
|
||||
index++;
|
||||
}
|
||||
|
||||
auto pclData = PointCloudData::getInstance(*cloud);
|
||||
pclData->setCloud(*cloud);
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <pcl/point_types.h>
|
||||
#include <pcl/io/vtk_lib_io.h>
|
||||
#include "CoreAlgorithm.h"
|
||||
#include "PointCloudData.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace pcl;
|
||||
|
||||
Reference in New Issue
Block a user