36 #include <visp3/core/vpConfig.h> 38 #if defined(VISP_HAVE_OCCIPITAL_STRUCTURE) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 46 #include <ST/Utilities.h> 48 #include <visp3/core/vpImageConvert.h> 49 #include <visp3/core/vpMeterPixelConversion.h> 50 #include <visp3/core/vpPoint.h> 51 #include <visp3/sensor/vpOccipitalStructure.h> 53 #define MANUAL_POINTCLOUD 1 59 : m_invalidDepthValue(0.0f), m_maxZ(15000.0f)
110 reinterpret_cast<unsigned char *>(rgb.
bitmap),
117 reinterpret_cast<unsigned char *>(rgb.
bitmap),
121 reinterpret_cast<unsigned char *>(rgb.
bitmap),
142 bool undistorted,
double *ts)
152 reinterpret_cast<unsigned char *>(rgb->
bitmap),
159 reinterpret_cast<unsigned char *>(rgb->
bitmap),
163 reinterpret_cast<unsigned char *>(rgb->
bitmap),
175 if(acceleration_data != NULL)
178 acceleration_data[0] = accel.x; acceleration_data[1] = accel.y; acceleration_data[2] = accel.z;
181 if(gyroscope_data != NULL)
184 gyroscope_data[0] = gyro_data.x; gyroscope_data[1] = gyro_data.y; gyroscope_data[2] = gyro_data.z;
204 bool undistorted,
double *ts)
224 if(acceleration_data != NULL)
227 acceleration_data[0] = accel.x; acceleration_data[1] = accel.y; acceleration_data[2] = accel.z;
230 if(gyroscope_data != NULL)
233 gyroscope_data[0] = gyro_data.x; gyroscope_data[1] = gyro_data.y; gyroscope_data[2] = gyro_data.z;
254 std::vector<vpColVector> *
const data_pointCloud,
255 unsigned char *
const data_infrared,
vpColVector *acceleration_data,
256 vpColVector *gyroscope_data,
bool undistorted,
double *ts)
269 reinterpret_cast<unsigned char*>(data_image),
276 reinterpret_cast<unsigned char *>(data_image),
280 reinterpret_cast<unsigned char *>(data_image),
288 if(data_pointCloud != NULL)
291 if(acceleration_data != NULL)
294 acceleration_data[0] = accel.x; acceleration_data[1] = accel.y; acceleration_data[2] = accel.z;
297 if(gyroscope_data != NULL)
300 gyroscope_data[0] = gyro_data.x; gyroscope_data[1] = gyro_data.y; gyroscope_data[2] = gyro_data.z;
323 std::vector<vpColVector> *
const data_pointCloud, pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud,
324 unsigned char *
const data_infrared,
vpColVector *acceleration_data,
325 vpColVector *gyroscope_data,
bool undistorted,
double *ts)
334 reinterpret_cast<unsigned char *>(data_image),
341 reinterpret_cast<unsigned char *>(data_image),
345 reinterpret_cast<unsigned char *>(data_image),
356 if(data_pointCloud != NULL)
362 if(acceleration_data != NULL)
365 acceleration_data[0] = accel.x; acceleration_data[1] = accel.y; acceleration_data[2] = accel.z;
368 if(gyroscope_data != NULL)
371 gyroscope_data[0] = gyro_data.x; gyroscope_data[1] = gyro_data.y; gyroscope_data[2] = gyro_data.z;
393 std::vector<vpColVector> *
const data_pointCloud, pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud,
394 unsigned char *
const data_infrared,
vpColVector *acceleration_data,
395 vpColVector *gyroscope_data,
bool undistorted,
double *ts)
408 reinterpret_cast<unsigned char*>(data_image),
415 reinterpret_cast<unsigned char *>(data_image),
419 reinterpret_cast<unsigned char *>(data_image),
433 if(acceleration_data != NULL)
436 acceleration_data[0] = accel.x; acceleration_data[1] = accel.y; acceleration_data[2] = accel.z;
439 if(gyroscope_data != NULL)
442 gyroscope_data[0] = gyro_data.x; gyroscope_data[1] = gyro_data.y; gyroscope_data[2] = gyro_data.z;
481 imu_vel->
resize(3,
false);
483 (*imu_vel)[0] = imu_rotationRate.x; (*imu_vel)[1] = imu_rotationRate.y; (*imu_vel)[2] = imu_rotationRate.z;
520 imu_acc->
resize(3,
false);
522 (*imu_acc)[0] = imu_acceleration.x; (*imu_acc)[1] = imu_acceleration.y; (*imu_acc)[2] = imu_acceleration.z;
559 double imu_vel_timestamp, imu_acc_timestamp;
563 imu_vel->
resize(3,
false);
565 (*imu_vel)[0] = imu_rotationRate.x; (*imu_vel)[1] = imu_rotationRate.y; (*imu_vel)[2] = imu_rotationRate.z;
571 imu_acc->
resize(3,
false);
573 (*imu_acc)[0] = imu_acceleration.x; (*imu_acc)[1] = imu_acceleration.y; (*imu_acc)[2] = imu_acceleration.z;
578 *ts = std::max(imu_vel_timestamp, imu_acc_timestamp);
596 std::cout <<
"Failed to initialize capture session!" << std::endl;
606 if(var == std::cv_status::timeout)
644 case vpOccipitalStructureStream::visible :
649 case vpOccipitalStructureStream::depth :
654 case vpOccipitalStructureStream::infrared :
674 case vpOccipitalStructureStream::visible :
679 case vpOccipitalStructureStream::depth :
684 case vpOccipitalStructureStream::infrared :
729 return vpPoint(point_3D.x, point_3D.y, point_3D.z);
754 result[0][0] = v_M_d.m00; result[0][1] = v_M_d.m10; result[0][2] = v_M_d.m20; result[0][3] = v_M_d.m30;
755 result[1][0] = v_M_d.m01; result[1][1] = v_M_d.m11; result[1][2] = v_M_d.m21; result[1][3] = v_M_d.m31;
756 result[2][0] = v_M_d.m02; result[2][1] = v_M_d.m12; result[2][2] = v_M_d.m22; result[2][3] = v_M_d.m32;
761 ST::Matrix4 imu_M_d =
m_captureSession.getImuFromDepthExtrinsics().inversed();
763 result[0][0] = imu_M_d.m00; result[0][1] = imu_M_d.m10; result[0][2] = imu_M_d.m20; result[0][3] = imu_M_d.m30;
764 result[1][0] = imu_M_d.m01; result[1][1] = imu_M_d.m11; result[1][2] = imu_M_d.m21; result[1][3] = imu_M_d.m31;
765 result[2][0] = imu_M_d.m02; result[2][1] = imu_M_d.m12; result[2][2] = imu_M_d.m22; result[2][3] = imu_M_d.m32;
774 result[0][0] = d_M_v.m00; result[0][1] = d_M_v.m10; result[0][2] = d_M_v.m20; result[0][3] = d_M_v.m30;
775 result[1][0] = d_M_v.m01; result[1][1] = d_M_v.m11; result[1][2] = d_M_v.m21; result[1][3] = d_M_v.m31;
776 result[2][0] = d_M_v.m02; result[2][1] = d_M_v.m12; result[2][2] = d_M_v.m22; result[2][3] = d_M_v.m32;
781 ST::Matrix4 imu_M_v =
m_captureSession.getImuFromVisibleExtrinsics().inversed();
783 result[0][0] = imu_M_v.m00; result[0][1] = imu_M_v.m10; result[0][2] = imu_M_v.m20; result[0][3] = imu_M_v.m30;
784 result[1][0] = imu_M_v.m01; result[1][1] = imu_M_v.m11; result[1][2] = imu_M_v.m21; result[1][3] = imu_M_v.m31;
785 result[2][0] = imu_M_v.m02; result[2][1] = imu_M_v.m12; result[2][2] = imu_M_v.m22; result[2][3] = imu_M_v.m32;
797 result[0][0] = d_M_imu.m00; result[0][1] = d_M_imu.m10; result[0][2] = d_M_imu.m20; result[0][3] = d_M_imu.m30;
798 result[1][0] = d_M_imu.m01; result[1][1] = d_M_imu.m11; result[1][2] = d_M_imu.m21; result[1][3] = d_M_imu.m31;
799 result[2][0] = d_M_imu.m02; result[2][1] = d_M_imu.m12; result[2][2] = d_M_imu.m22; result[2][3] = d_M_imu.m32;
806 result[0][0] = v_M_imu.m00; result[0][1] = v_M_imu.m10; result[0][2] = v_M_imu.m20; result[0][3] = v_M_imu.m30;
807 result[1][0] = v_M_imu.m01; result[1][1] = v_M_imu.m11; result[1][2] = v_M_imu.m21; result[1][3] = v_M_imu.m31;
808 result[2][0] = v_M_imu.m02; result[2][1] = v_M_imu.m12; result[2][2] = v_M_imu.m22; result[2][3] = v_M_imu.m32;
825 ST::Intrinsics result;
868 ST::Intrinsics cam_intrinsics;
871 case vpOccipitalStructureStream::visible :
882 case vpOccipitalStructureStream::depth :
899 const int width = last_df.width();
900 const int height = last_df.height();
901 pointcloud.resize((
size_t)(width * height));
903 const float *p_depth_frame =
reinterpret_cast<const float *
>(last_df.depthInMillimeters());
907 #pragma omp parallel for schedule(dynamic) 908 for (
int i = 0; i < height; i++) {
909 auto depth_pixel_index = i * width;
911 for (
int j = 0; j < width; j++, depth_pixel_index++) {
912 if (std::isnan(p_depth_frame[depth_pixel_index])) {
913 pointcloud[(size_t)depth_pixel_index].resize(4,
false);
917 pointcloud[(size_t)depth_pixel_index][3] = 1.0;
922 auto pixels_distance = p_depth_frame[depth_pixel_index];
924 ST::Vector3f point_3D = last_df.unprojectPoint(i, j);
926 if (pixels_distance >
m_maxZ)
929 pointcloud[(size_t)depth_pixel_index].resize(4,
false);
930 pointcloud[(size_t)depth_pixel_index][0] = point_3D.x * 0.001;
931 pointcloud[(
size_t)depth_pixel_index][1] = point_3D.y * 0.001;
932 pointcloud[(size_t)depth_pixel_index][2] = point_3D.z * 0.001;
933 pointcloud[(
size_t)depth_pixel_index][3] = 1.0;
943 const int width = last_df.width();
944 const int height = last_df.height();
945 pointcloud->width = (uint32_t)width;
946 pointcloud->height = (uint32_t)height;
947 pointcloud->resize((
size_t)(width * height));
949 #if MANUAL_POINTCLOUD // faster to compute manually when tested 950 const float *p_depth_frame =
reinterpret_cast<const float *
>(last_df.depthInMillimeters());
954 #pragma omp parallel for schedule(dynamic) 955 for (
int i = 0; i < height; i++) {
956 auto depth_pixel_index = i * width;
958 for (
int j = 0; j < width; j++, depth_pixel_index++) {
959 if (p_depth_frame[depth_pixel_index] == 0) {
967 auto pixels_distance = p_depth_frame[depth_pixel_index];
970 ST::Vector3f point_3D = last_df.unprojectPoint(i, j);
972 if (pixels_distance >
m_maxZ)
975 pointcloud->points[(size_t)(depth_pixel_index)].x = point_3D.x * 0.001;
976 pointcloud->points[(size_t)(depth_pixel_index)].y = point_3D.y * 0.001;
977 pointcloud->points[(size_t)(depth_pixel_index)].z = point_3D.z * 0.001;
1003 const int depth_width = last_df.width();
1004 const int depth_height = last_df.height();
1005 pointcloud->width =
static_cast<uint32_t
>(depth_width);
1006 pointcloud->height =
static_cast<uint32_t
>(depth_height);
1007 pointcloud->resize(static_cast<uint32_t>(depth_width * depth_height));
1009 const int color_width = last_cf.width();
1010 const int color_height = last_cf.height();
1012 const float *p_depth_frame =
reinterpret_cast<const float *
>(last_df.depthInMillimeters());
1013 const ST::Matrix4 depth2ColorExtrinsics = last_df.visibleCameraPoseInDepthCoordinateFrame();
1015 const bool swap_rb =
false;
1016 unsigned int nb_color_pixel = 3;
1017 const uint8_t *p_color_frame =
static_cast<const uint8_t *
>(last_cf.rgbData());
1019 const bool registered_streams = last_df.isRegisteredTo(last_cf);
1023 #pragma omp parallel for schedule(dynamic) 1024 for (
int i = 0; i < depth_height; i++) {
1025 auto depth_pixel_index = i * depth_width;
1027 for (
int j = 0; j < depth_width; j++, depth_pixel_index++) {
1028 if (std::isnan(p_depth_frame[depth_pixel_index])) {
1034 #if PCL_VERSION_COMPARE(<, 1, 1, 0) 1035 unsigned int r = 0, g = 0, b = 0;
1036 uint32_t rgb = (
static_cast<uint32_t
>(r) << 16 | static_cast<uint32_t>(g) << 8 |
static_cast<uint32_t
>(b));
1038 pointcloud->points[(size_t)depth_pixel_index].rgb = *reinterpret_cast<float *>(&rgb);
1040 pointcloud->points[(size_t)depth_pixel_index].r = (uint8_t)0;
1041 pointcloud->points[(size_t)depth_pixel_index].g = (uint8_t)0;
1042 pointcloud->points[(size_t)depth_pixel_index].b = (uint8_t)0;
1048 auto pixels_distance = p_depth_frame[depth_pixel_index];
1050 ST::Vector3f depth_point_3D = last_df.unprojectPoint(i, j);
1052 if (pixels_distance >
m_maxZ)
1055 pointcloud->points[(size_t)depth_pixel_index].x = depth_point_3D.x * 0.001;
1056 pointcloud->points[(
size_t)depth_pixel_index].y = depth_point_3D.y * 0.001;
1057 pointcloud->points[(size_t)depth_pixel_index].z = depth_point_3D.z * 0.001;
1059 if (!registered_streams) {
1061 ST::Vector3f color_point_3D = depth2ColorExtrinsics * depth_point_3D;
1063 ST::Vector2f color_pixel;
1064 if(color_point_3D.z != 0)
1066 double x, y, pixel_x, pixel_y;
1067 x =
static_cast<double>(color_point_3D.y / color_point_3D.z);
1068 y =
static_cast<double>(color_point_3D.x / color_point_3D.z);
1070 color_pixel.x = pixel_x;
1071 color_pixel.y = pixel_y;
1074 if (color_pixel.y < 0 || color_pixel.y >= color_height || color_pixel.x < 0 || color_pixel.x >= color_width) {
1077 #if PCL_VERSION_COMPARE(<, 1, 1, 0) 1078 unsigned int r = 0, g = 0, b = 0;
1079 uint32_t rgb = (
static_cast<uint32_t
>(r) << 16 | static_cast<uint32_t>(g) << 8 |
static_cast<uint32_t
>(b));
1081 pointcloud->points[(size_t)depth_pixel_index].rgb = *reinterpret_cast<float *>(&rgb);
1083 pointcloud->points[(size_t)depth_pixel_index].r = (uint8_t)0;
1084 pointcloud->points[(size_t)depth_pixel_index].g = (uint8_t)0;
1085 pointcloud->points[(size_t)depth_pixel_index].b = (uint8_t)0;
1088 unsigned int i_ = (
unsigned int)color_pixel.x;
1089 unsigned int j_ = (
unsigned int)color_pixel.y;
1091 #if PCL_VERSION_COMPARE(<, 1, 1, 0) 1095 (
static_cast<uint32_t
>(p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel]) |
1096 static_cast<uint32_t>(p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 1]) << 8 |
1097 static_cast<uint32_t
>(p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 2]) << 16);
1099 rgb = (
static_cast<uint32_t
>(p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel]) << 16 |
1100 static_cast<uint32_t>(p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 1]) << 8 |
1101 static_cast<uint32_t
>(p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 2]));
1104 pointcloud->points[(size_t)(i * depth_width + j)].rgb = *
reinterpret_cast<float *
>(&rgb);
1107 pointcloud->points[(size_t)depth_pixel_index].b =
1108 p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel];
1109 pointcloud->points[(size_t)depth_pixel_index].g =
1110 p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 1];
1111 pointcloud->points[(size_t)depth_pixel_index].r =
1112 p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 2];
1114 pointcloud->points[(size_t)depth_pixel_index].r =
1115 p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel];
1116 pointcloud->points[(size_t)depth_pixel_index].g =
1117 p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 1];
1118 pointcloud->points[(size_t)depth_pixel_index].b =
1119 p_color_frame[(i_ * (
unsigned int)color_width + j_) * nb_color_pixel + 2];
1124 #if PCL_VERSION_COMPARE(<, 1, 1, 0) 1128 (
static_cast<uint32_t
>(p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel]) |
1129 static_cast<uint32_t>(p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 1]) << 8 |
1130 static_cast<uint32_t
>(p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 2]) << 16);
1132 rgb = (
static_cast<uint32_t
>(p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel]) << 16 |
1133 static_cast<uint32_t>(p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 1]) << 8 |
1134 static_cast<uint32_t
>(p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 2]));
1137 pointcloud->points[(size_t)(i * depth_width + j)].rgb = *
reinterpret_cast<float *
>(&rgb);
1140 pointcloud->points[(size_t)depth_pixel_index].b =
1141 p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel];
1142 pointcloud->points[(size_t)depth_pixel_index].g =
1143 p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 1];
1144 pointcloud->points[(size_t)depth_pixel_index].r =
1145 p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 2];
1147 pointcloud->points[(size_t)depth_pixel_index].r =
1148 p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel];
1149 pointcloud->points[(size_t)depth_pixel_index].g =
1150 p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 1];
1151 pointcloud->points[(size_t)depth_pixel_index].b =
1152 p_color_frame[(i * (
unsigned int)color_width + j) * nb_color_pixel + 2];
ST::CaptureSession m_captureSession
float getDepth(int x, int y)
float m_invalidDepthValue
vpCameraParameters m_visible_camera_parameters
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
Type * bitmap
points toward the bitmap
vpOccipitalStructureStream
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
void getIMUData(vpColVector *imu_vel, vpColVector *imu_acc, double *ts=NULL)
ST::StructureCoreCameraType m_cameraType
unsigned int getWidth(vpOccipitalStructureStream stream_type)
ST::CaptureSessionSettings m_captureSessionSettings
bool open(const ST::CaptureSessionSettings &settings)
void getPointcloud(std::vector< vpColVector > &pointcloud)
std::condition_variable cv_sampleLock
void getIMUVelocity(vpColVector *imu_vel, double *ts)
static void GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsigned int width, unsigned int height)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
SessionDelegate m_delegate
ST::DepthFrame m_depthFrame
void acquire(vpImage< unsigned char > &gray, bool undistorted=false, double *ts=NULL)
void saveDepthImageAsPointCloudMesh(std::string &filename)
vpCameraParametersProjType
Generic class defining intrinsic camera parameters.
vpHomogeneousMatrix getTransform(const vpOccipitalStructureStream from, const vpOccipitalStructureStream to)
vpCameraParameters m_depth_camera_parameters
void resize(unsigned int i, bool flagNullify=true)
vpCameraParameters getCameraParameters(const vpOccipitalStructureStream stream_type, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithoutDistortion)
Implementation of column vector and the associated operations.
void getIMUAcceleration(vpColVector *imu_acc, double *ts)
ST::GyroscopeEvent m_gyroscopeEvent
ST::InfraredFrame m_infraredFrame
vpPoint unprojectPoint(int row, int col)
unsigned int getHeight(vpOccipitalStructureStream stream_type)
void getColoredPointcloud(pcl::PointCloud< pcl::PointXYZRGB >::Ptr &pointcloud)
ST::AccelerometerEvent m_accelerometerEvent
ST::ColorFrame m_visibleFrame
ST::Intrinsics getIntrinsics(const vpOccipitalStructureStream stream_type) const