device_tof3d.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include <thread>
  3. #include <boost/chrono/duration.hpp>
  4. #include <opencv2/opencv.hpp>
  5. #include <Eigen/Core>
  6. #include <Eigen/Geometry>
  7. #include <pcl/point_types.h>
  8. #include <pcl/point_cloud.h>
  9. #include <pcl/filters/statistical_outlier_removal.h>
  10. #include <pcl/filters/approximate_voxel_grid.h>
  11. #include <pcl/filters/voxel_grid.h>
  12. #include <pcl/visualization/pcl_visualizer.h>
  13. #include "log/log.h"
  14. #include "error_code/error_code.hpp"
  15. #include "VzenseNebula_api.h"
  16. #include "thread/thread_condition.h"
  17. #include "tool/timedlockdata.hpp"
  18. #include "pcl/point3D_tool.h"
  19. #include "proto/vzense.pb.h"
  20. #include "communication/transitData.h"
  21. class DeviceTof3D {
  22. public:
  23. struct DeviceTof3DSaveInfo {
  24. cv::Mat irMat; // 灰度图
  25. cv::Mat pointMat; // 点云坐标信息
  26. DeviceTof3DSaveInfo() {
  27. irMat = cv::Mat::zeros(480, 640, CV_8UC1);
  28. pointMat = cv::Mat::zeros(480, 640, CV_32FC4);
  29. }
  30. DeviceTof3DSaveInfo& operator=(const DeviceTof3DSaveInfo &p) {
  31. this->pointMat = p.pointMat.clone();
  32. this->irMat = p.irMat.clone();
  33. return *this;
  34. }
  35. };
  36. public:
  37. static DeviceTof3D *iter() {
  38. static DeviceTof3D *instance = nullptr;
  39. if (instance == nullptr) {
  40. instance = new DeviceTof3D();
  41. }
  42. return instance;
  43. }
  44. ~DeviceTof3D() = default;
  45. Error_manager Init(const google::protobuf::RepeatedPtrField<tof3dVzenseEtc> &tof_devices);
  46. Error_manager updateTrans(const DeviceAzimuth &azimuth, const CoordinateTransformation3D &trans);
  47. cv::Mat getDeviceIrMat();
  48. cv::Mat getDevicePointsMat(const DeviceAzimuth &azimuth);
  49. DeviceTof3DSaveInfo getDeviceSaveInfo(const DeviceAzimuth &azimuth);
  50. Error_manager getDeviceStatus();
  51. protected:
  52. // bool
  53. Error_manager SearchDevice(const double &time = 10);
  54. bool isAllDevicesFound(uint32_t deviceCount);
  55. Error_manager setTof3dParams(VzDeviceHandle handle, const Tof3dVzenseBuiltInParams &params);
  56. Error_manager getTof3dParams(VzDeviceHandle handle, Tof3dVzenseBuiltInParams &params);
  57. Error_manager ConnectDevice(const DeviceAzimuth &azimuth);
  58. Error_manager DisConnectDevice(VzDeviceHandle handle);
  59. Error_manager getDepthAndIrPicture(VzDeviceHandle handle, VzFrame &depthFrame, VzFrame &irFrame);
  60. static Error_manager DepthFrame2Mat(VzFrame &frame, cv::Mat &mat);
  61. static Error_manager IrFrame2Mat(VzFrame &frame, cv::Mat &mat);
  62. static Error_manager Frame2Mat(VzFrame &frame, cv::Mat &mat);
  63. static void HotPlugStateCallback(const VzDeviceInfo *pInfo, int status, void *contex);
  64. void run(const DeviceAzimuth &azimuth);
  65. private:
  66. struct DeviceTof3DStatusInfo {
  67. bool connected = false;
  68. bool found = false;
  69. };
  70. struct DeviceTof3DParamsInfo {
  71. DeviceTof3DStatusInfo status;
  72. std::thread *t = nullptr;
  73. VzDeviceHandle handle = nullptr;
  74. Thread_condition *condit = nullptr;
  75. const tof3dVzenseEtc *etc = nullptr;
  76. std::mutex *handle_mutex = new std::mutex();
  77. };
  78. private:
  79. TimedLockData<DeviceTof3DSaveInfo> m_device_mat[DeviceAzimuth::DEVICE_AZIMUTH_MAX];
  80. std::vector<DeviceTof3DParamsInfo> m_devices_list;
  81. TimedLockData<int> m_devices_status[DeviceAzimuth::DEVICE_AZIMUTH_MAX];
  82. std::mutex rotation_mutex;
  83. Eigen::Matrix3f rotation_matrix3[4];
  84. Eigen::Vector3f move[4];
  85. };