depth_sensor_pose_test.cpp
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 #include <gtest/gtest.h>
6 
8 };
9 
10 class DepthSensorPoseTest : public ::testing::Test {
11  public:
12  sensor_msgs::ImagePtr depth_msg;
13  sensor_msgs::CameraInfoPtr info_msg;
15 
16  unsigned img_height { 480 };
17  unsigned img_width { 640 };
18  unsigned scan_height { 420 };
19 
21  setDefaultInfoMsg();
22 
23  // Configuration
24  estimator.setDepthImgStepCol(8);
25  estimator.setDepthImgStepRow(8);
26  estimator.setGroundMaxPoints(2000);
27  estimator.setRansacMaxIter(1000);
28  }
29 
31  info_msg.reset(new sensor_msgs::CameraInfo);
32  info_msg->header.frame_id = "depth_frame";
33  info_msg->header.seq = 100;
34  info_msg->height = img_height;
35  info_msg->width = img_width;
36  info_msg->distortion_model = "plumb_bob";
37  info_msg->D.resize(5);
38  info_msg->K[0] = 570;
39  info_msg->K[2] = 314;
40  info_msg->K[4] = 570;
41  info_msg->K[5] = 239;
42  info_msg->K[8] = 1.0;
43  info_msg->R[0] = 1.0;
44  info_msg->R[4] = 1.0;
45  info_msg->R[8] = 1.0;
46  info_msg->P[0] = 570;
47  info_msg->P[2] = 314;
48  info_msg->P[5] = 570;
49  info_msg->P[6] = 235;
50  info_msg->P[10] = 1.0;
51  }
52 
53  template<typename T>
54  void setDefaultDepthMsg(T value) {
55  depth_msg.reset(new sensor_msgs::Image);
56  depth_msg->header.frame_id = "depth_frame";
57  depth_msg->header.seq = 100;
58  depth_msg->header.stamp.fromSec(10.0);
59  depth_msg->height = img_height;
60  depth_msg->width = img_width;
61  depth_msg->is_bigendian = false;
62  depth_msg->step = depth_msg->width * sizeof(T);
63 
64  if (typeid(T) == typeid(uint16_t)) {
65  depth_msg->encoding = sensor_msgs::image_encodings::TYPE_16UC1;
66  }
67  else if (typeid(T) == typeid(float)) {
68  depth_msg->encoding = sensor_msgs::image_encodings::TYPE_32FC1;
69  }
70 
71  depth_msg->data.resize(depth_msg->width * depth_msg->height * sizeof(T));
72  T* depth_row = reinterpret_cast<T*>(&depth_msg->data[0]);
73  for (size_t i = 0; i < depth_msg->width * depth_msg->height; ++i) {
74  depth_row[i] = value;
75  }
76  }
77 };
78 
79 TEST_F(DepthSensorPoseTest, encodingSupport)
80 {
81  setDefaultDepthMsg<uint16_t>(1);
82  estimator.estimateParams(depth_msg, info_msg);
83 
84  setDefaultDepthMsg<float>(1);
85  estimator.estimateParams(depth_msg, info_msg);
86 }
87 
88 TEST_F(DepthSensorPoseTest, unsupportedEncoding)
89 {
90  setDefaultDepthMsg<uint16_t>(1);
91  depth_msg->encoding = sensor_msgs::image_encodings::MONO16;
92  EXPECT_ANY_THROW(estimator.estimateParams(depth_msg, info_msg));
93 }
94 
95 int main(int argc, char **argv)
96 {
97  testing::InitGoogleTest(&argc, argv);
98  return RUN_ALL_TESTS();
99 }
void setRansacMaxIter(const unsigned u)
sensor_msgs::CameraInfoPtr info_msg
const std::string TYPE_32FC1
TEST_F(DepthSensorPoseTest, encodingSupport)
const std::string TYPE_16UC1
const std::string MONO16
sensor_msgs::ImagePtr depth_msg
void setDepthImgStepCol(const int step)
setDepthImgStepCol
void setDepthImgStepRow(const int step)
setDepthImgStepRow
int main(int argc, char **argv)
void setGroundMaxPoints(const unsigned u)
DepthSensorPoseTestable estimator


depth_sensor_pose
Author(s): Michal Drwiega (http://www.mdrwiega.com)
autogenerated on Wed May 5 2021 02:56:10