add
1、采集深度、彩色、rgb点云,并存储到文件; 2、界面操作逻辑控制,防止用户错误操作;
This commit is contained in:
@ -1,24 +1,233 @@
|
||||
#include "DepthCameraWindow.h"
|
||||
#include "DepthCameraWindow.h"
|
||||
|
||||
DepthCameraWindow::DepthCameraWindow(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
m_DepthCameraThread = new QThread();
|
||||
m_DepthCameraOperation = new DepthCameraOperation();
|
||||
m_DepthCameraOperation->moveToThread(m_DepthCameraThread);
|
||||
m_DepthCameraThread->start();
|
||||
|
||||
connect(ui.openDepthCamera_btn, &QPushButton::clicked, this, &DepthCameraWindow::openDepthCamera);
|
||||
connect(ui.closeDepthCamera_btn, &QPushButton::clicked, this, &DepthCameraWindow::closeDepthCamera);
|
||||
|
||||
connect(this, &DepthCameraWindow::openDepthCameraSignal, m_DepthCameraOperation, &DepthCameraOperation::OpenDepthCamera);
|
||||
|
||||
connect(m_DepthCameraOperation, &DepthCameraOperation::CamOpenedSignal, this, &DepthCameraWindow::onCamOpened);
|
||||
connect(m_DepthCameraOperation, &DepthCameraOperation::CamClosedSignal, this, &DepthCameraWindow::onCamClosed);
|
||||
}
|
||||
|
||||
DepthCameraWindow::~DepthCameraWindow()
|
||||
{
|
||||
m_DepthCameraThread->quit();
|
||||
m_DepthCameraThread->wait();
|
||||
delete m_DepthCameraOperation;
|
||||
m_DepthCameraOperation = nullptr;
|
||||
}
|
||||
|
||||
void DepthCameraWindow::openDepthCamera()
|
||||
{
|
||||
if (!m_DepthCameraOperation->getRecordStatus())
|
||||
{
|
||||
emit openDepthCameraSignal();
|
||||
}
|
||||
}
|
||||
|
||||
void DepthCameraWindow::onCamOpened()
|
||||
{
|
||||
ui.openDepthCamera_btn->setEnabled(false);
|
||||
ui.closeDepthCamera_btn->setEnabled(true);
|
||||
|
||||
ui.openDepthCamera_btn->setText(QString::fromLocal8Bit("已打开"));
|
||||
}
|
||||
|
||||
void DepthCameraWindow::closeDepthCamera()
|
||||
{
|
||||
m_DepthCameraOperation->CloseDepthCamera();
|
||||
}
|
||||
|
||||
void DepthCameraWindow::onCamClosed()
|
||||
{
|
||||
ui.openDepthCamera_btn->setEnabled(true);
|
||||
ui.closeDepthCamera_btn->setEnabled(false);
|
||||
|
||||
ui.openDepthCamera_btn->setText(QString::fromLocal8Bit("打 开"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------
|
||||
DepthCameraOperation::DepthCameraOperation()
|
||||
{
|
||||
m_pipe = nullptr;
|
||||
m_func = nullptr;
|
||||
record = false;
|
||||
}
|
||||
|
||||
DepthCameraOperation::~DepthCameraOperation()
|
||||
{
|
||||
if (m_pipe)
|
||||
{
|
||||
m_pipe->stop();
|
||||
|
||||
delete m_pipe;
|
||||
m_pipe = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void DepthCameraOperation::OpenDepthCamera()
|
||||
{
|
||||
if (m_pipe)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_pipe = new ob::Pipeline();
|
||||
|
||||
std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();
|
||||
|
||||
// Get device from pipeline.
|
||||
auto device = m_pipe->getDevice();
|
||||
auto devInfo = device->getDeviceInfo();
|
||||
auto pid = devInfo->getPid();
|
||||
auto vid = devInfo->getVid();
|
||||
|
||||
//// Get sensorList from device.
|
||||
//auto sensorList = device->getSensorList();
|
||||
|
||||
//for (uint32_t index = 0; index < sensorList->getCount(); index++) {
|
||||
// // Query all supported infrared sensor type and enable the infrared stream.
|
||||
// // For dual infrared device, enable the left and right infrared streams.
|
||||
// // For single infrared device, enable the infrared stream.
|
||||
// OBSensorType sensorType = sensorList->getSensorType(index);
|
||||
// std::cout << "Supported Sensor type: " << sensorType << std::endl;
|
||||
|
||||
// // Enable the stream for the sensor type.
|
||||
// config->enableStream(sensorType);
|
||||
//}
|
||||
|
||||
config->enableVideoStream(OB_STREAM_DEPTH, 640, 480, 15, OB_FORMAT_Y16);
|
||||
config->enableVideoStream(OB_STREAM_COLOR, 640, 480, 15, OB_FORMAT_YUYV);
|
||||
config->setFrameAggregateOutputMode(OB_FRAME_AGGREGATE_OUTPUT_ALL_TYPE_FRAME_REQUIRE);
|
||||
config->setAlignMode(ALIGN_D2C_HW_MODE);
|
||||
|
||||
m_pipe->enableFrameSync();
|
||||
|
||||
// Create a format converter filter.
|
||||
auto formatConverter = std::make_shared<ob::FormatConvertFilter>();
|
||||
|
||||
m_pipe->start(config);
|
||||
|
||||
// Drop several frames
|
||||
for (int i = 0; i < 15; ++i) {
|
||||
auto lost = m_pipe->waitForFrameset(100);
|
||||
}
|
||||
|
||||
auto pointCloud = std::make_shared<ob::PointCloudFilter>();
|
||||
|
||||
int frameIndex = 0;
|
||||
record = true;
|
||||
QString fileNamePrefix = AppSettings::instance().dataFolder() + QDir::separator() + AppSettings::instance().fileName();
|
||||
while (record)
|
||||
{
|
||||
if(frameIndex==0)
|
||||
{
|
||||
emit CamOpenedSignal();
|
||||
std::cout << "Start recording..." << std::endl;
|
||||
}
|
||||
|
||||
auto frameSet = m_pipe->waitForFrameset(100);
|
||||
if (frameSet == nullptr)
|
||||
{
|
||||
std::cout << "No frames received in 100ms..." << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the depth and color frames.
|
||||
auto depthFrame = frameSet->getFrame(OB_FRAME_DEPTH)->as<ob::DepthFrame>();
|
||||
auto colorFrame = frameSet->getFrame(OB_FRAME_COLOR)->as<ob::ColorFrame>();
|
||||
|
||||
// Convert the color frame to RGB format.
|
||||
if (colorFrame->format() != OB_FORMAT_RGB) {
|
||||
if (colorFrame->format() == OB_FORMAT_MJPG) {
|
||||
formatConverter->setFormatConvertType(FORMAT_MJPG_TO_RGB);
|
||||
}
|
||||
else if (colorFrame->format() == OB_FORMAT_UYVY) {
|
||||
formatConverter->setFormatConvertType(FORMAT_UYVY_TO_RGB);
|
||||
}
|
||||
else if (colorFrame->format() == OB_FORMAT_YUYV) {
|
||||
formatConverter->setFormatConvertType(FORMAT_YUYV_TO_RGB);
|
||||
}
|
||||
else {
|
||||
std::cout << "Color format is not support!" << std::endl;
|
||||
continue;
|
||||
}
|
||||
colorFrame = formatConverter->process(colorFrame)->as<ob::ColorFrame>();
|
||||
}
|
||||
// Processed the color frames to BGR format, use OpenCV to save to disk.
|
||||
formatConverter->setFormatConvertType(FORMAT_RGB_TO_BGR);
|
||||
colorFrame = formatConverter->process(colorFrame)->as<ob::ColorFrame>();
|
||||
|
||||
saveDepthFrame(depthFrame, frameIndex, fileNamePrefix.toStdString());
|
||||
saveColorFrame(colorFrame, frameIndex, fileNamePrefix.toStdString());
|
||||
|
||||
pointCloud->setCreatePointFormat(OB_FORMAT_RGB_POINT);
|
||||
std::shared_ptr<ob::Frame> frame = pointCloud->process(frameSet);
|
||||
|
||||
QString plyPath = fileNamePrefix + "_"+ QString::number(frameIndex) + ".ply";
|
||||
ob::PointCloudHelper::savePointcloudToPly(plyPath.toStdString().c_str(), frame, false, false, 50);
|
||||
|
||||
frameIndex++;
|
||||
}
|
||||
|
||||
m_pipe->stop();
|
||||
|
||||
delete m_pipe;
|
||||
m_pipe = nullptr;
|
||||
}
|
||||
|
||||
void DepthCameraOperation::saveDepthFrame(const std::shared_ptr<ob::DepthFrame> depthFrame, const uint32_t frameIndex, std::string fileNamePrefix_)
|
||||
{
|
||||
std::vector<int> params;
|
||||
params.push_back(cv::IMWRITE_PNG_COMPRESSION);
|
||||
params.push_back(0);
|
||||
params.push_back(cv::IMWRITE_PNG_STRATEGY);
|
||||
params.push_back(cv::IMWRITE_PNG_STRATEGY_DEFAULT);
|
||||
std::string depthName = fileNamePrefix_ + "_Depth_" + std::to_string(depthFrame->width()) + "x" + std::to_string(depthFrame->height()) + "_" + std::to_string(frameIndex) + "_"
|
||||
+ std::to_string(depthFrame->timeStamp()) + "ms.png";
|
||||
cv::Mat depthMat(depthFrame->height(), depthFrame->width(), CV_16UC1, depthFrame->data());
|
||||
cv::imwrite(depthName, depthMat, params);
|
||||
std::cout << "Depth saved:" << depthName << std::endl;
|
||||
}
|
||||
|
||||
void DepthCameraOperation::saveColorFrame(const std::shared_ptr<ob::ColorFrame> colorFrame, const uint32_t frameIndex, std::string fileNamePrefix_)
|
||||
{
|
||||
std::vector<int> params;
|
||||
params.push_back(cv::IMWRITE_PNG_COMPRESSION);
|
||||
params.push_back(0);
|
||||
params.push_back(cv::IMWRITE_PNG_STRATEGY);
|
||||
params.push_back(cv::IMWRITE_PNG_STRATEGY_DEFAULT);
|
||||
std::string colorName = fileNamePrefix_ + "_Color_" + std::to_string(colorFrame->width()) + "x" + std::to_string(colorFrame->height()) + "_" + std::to_string(frameIndex) + "_"
|
||||
+ std::to_string(colorFrame->timeStamp()) + "ms.png";
|
||||
cv::Mat depthMat(colorFrame->height(), colorFrame->width(), CV_8UC3, colorFrame->data());
|
||||
cv::imwrite(colorName, depthMat, params);
|
||||
std::cout << "Color saved:" << colorName << std::endl;
|
||||
}
|
||||
|
||||
void DepthCameraOperation::OpenDepthCamera_callback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DepthCameraOperation::setCallback(void(*func)())
|
||||
{
|
||||
m_func = func;
|
||||
}
|
||||
|
||||
void DepthCameraOperation::CloseDepthCamera()
|
||||
{
|
||||
std::cout << "DepthCameraOperation::CloseDepthCamera,关闭深度相机" << std::endl;
|
||||
|
||||
record = false;
|
||||
|
||||
emit CamClosedSignal();
|
||||
}
|
||||
|
||||
@ -1,11 +1,56 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QImage>
|
||||
#include <Qthread>
|
||||
#include <QDir>
|
||||
|
||||
#include <iostream>
|
||||
#include "ui_DepthCamera.h"
|
||||
#include "AppSettings.h"
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <libobsensor/ObSensor.hpp>
|
||||
#include "libobsensor/hpp/Utils.hpp"
|
||||
typedef void(*func)();
|
||||
|
||||
class DepthCameraOperation :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DepthCameraOperation();
|
||||
~DepthCameraOperation();
|
||||
|
||||
QImage m_qImage;
|
||||
void setCallback(void(*func)());
|
||||
bool getRecordStatus() const { return record; }
|
||||
|
||||
private:
|
||||
ob::Pipeline* m_pipe;
|
||||
cv::Mat frame;
|
||||
|
||||
func m_func;
|
||||
|
||||
void saveDepthFrame(const std::shared_ptr<ob::DepthFrame> depthFrame, const uint32_t frameIndex, std::string fileNamePrefix_);
|
||||
void saveColorFrame(const std::shared_ptr<ob::ColorFrame> colorFrame, const uint32_t frameIndex, std::string fileNamePrefix_);
|
||||
|
||||
bool record;
|
||||
|
||||
public slots:
|
||||
void OpenDepthCamera();
|
||||
void OpenDepthCamera_callback();//不使用信号而使用回调函数来通知界面刷新视频
|
||||
void CloseDepthCamera();
|
||||
|
||||
signals:
|
||||
void PlotSignal();
|
||||
|
||||
void CamOpenedSignal();
|
||||
void CamClosedSignal();
|
||||
};
|
||||
|
||||
class DepthCameraWindow : public QDialog
|
||||
{
|
||||
@ -15,13 +60,19 @@ public:
|
||||
DepthCameraWindow(QWidget* parent = nullptr);
|
||||
~DepthCameraWindow();
|
||||
|
||||
DepthCameraOperation* m_DepthCameraOperation;
|
||||
|
||||
public Q_SLOTS:
|
||||
void PlotRgbImageSignal();
|
||||
void CamClosedSignal();
|
||||
void openDepthCamera();
|
||||
void onCamOpened();
|
||||
void closeDepthCamera();
|
||||
void onCamClosed();
|
||||
|
||||
signals:
|
||||
void openDepthCameraSignal();
|
||||
|
||||
private:
|
||||
Ui::DepthCameraClass ui;
|
||||
QThread* m_DepthCameraThread;
|
||||
|
||||
};
|
||||
|
||||
@ -55,8 +55,8 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;D:\cpp_library\vincecontrol_vs2017;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Debug;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\HPPA\x64\Debug;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\x64\Debug;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;D:\cpp_library\vincecontrol_vs2017;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\IrisMultiMotorController;D:\cpp_library\eigen-3.4-rc1;C:\Program Files\OrbbecSDK 2.7.6\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Debug;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\HPPA\x64\Debug;C:\XIMEA\API\xiAPI;D:\cpp_project_vs2022\HPPA\IrisMultiMotorController\x64\Debug;C:\Program Files\OrbbecSDK 2.7.6\lib;$(LibraryPath)</LibraryPath>
|
||||
<TargetName>Spectral Insight</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
@ -66,7 +66,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>opencv_world3411.lib;opencv_world3411d.lib;gdal_i.lib;resonon-basler.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++d.lib;vincecontrol.lib;resonon-allied.lib;xiapi64.lib;IrisMultiMotorController.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>opencv_world3411.lib;opencv_world3411d.lib;gdal_i.lib;resonon-basler.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++d.lib;vincecontrol.lib;resonon-allied.lib;xiapi64.lib;IrisMultiMotorController.lib;OrbbecSDK.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>D:\cpp_project_vs2022\HPPA\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<ClCompile>
|
||||
|
||||
@ -30,7 +30,7 @@ void RgbCameraOperation::OpenCamera()
|
||||
|
||||
cam->release();
|
||||
|
||||
emit CamClosed();
|
||||
emit CamOpenedSignal();
|
||||
|
||||
}
|
||||
|
||||
@ -65,4 +65,6 @@ void RgbCameraOperation::CloseCamera()
|
||||
std::cout << "关闭摄像头+++++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||||
|
||||
record = false;
|
||||
|
||||
emit CamClosedSignal();
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ public slots:
|
||||
signals:
|
||||
void PlotSignal();
|
||||
|
||||
void CamClosed();
|
||||
void CamOpenedSignal();
|
||||
void CamClosedSignal();
|
||||
};
|
||||
#endif // !RGBCAMERAOPERATION_H
|
||||
|
||||
@ -18,7 +18,7 @@ rgbCameraWindow::rgbCameraWindow(QWidget* parent)
|
||||
//connect(this->ui.open_rgb_camera_btn, SIGNAL(clicked()), m_RgbCamera, SLOT(OpenCamera_callback()));//ʹ<>ûص<C3BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3>ui<75>̣߳<DFB3><CCA3>ϵ<EFBFBD><CFB5><EFBFBD>Ƶ <20><> ʧ<><CAA7>
|
||||
|
||||
connect(ui.close_rgb_camera_btn, SIGNAL(clicked()), this, SLOT(onCloseRgbCamera()));//<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
connect(m_RgbCamera, SIGNAL(CamClosed()), this, SIGNAL(CamClosedSignal()));
|
||||
connect(m_RgbCamera, SIGNAL(CamClosedSignal()), this, SIGNAL(CamClosedSignal()));
|
||||
}
|
||||
|
||||
rgbCameraWindow::~rgbCameraWindow()
|
||||
|
||||
Reference in New Issue
Block a user