cliff_detector_test.cpp
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 #include <gtest/gtest.h>
6 
7 class CliffDetectorTest : public ::testing::Test {
8  public:
9  sensor_msgs::ImagePtr depth_msg;
10  sensor_msgs::CameraInfoPtr info_msg;
12 
13  unsigned img_height { 480 };
14  unsigned img_width { 640 };
15  unsigned scan_height { 420 };
16 
19 
20  // Configuration
21  detector.setDepthImgStepCol(8);
22  detector.setDepthImgStepRow(8);
23  detector.setBlockSize(16);
24  detector.setRangeLimits(0.5, 5.0);
25  detector.setSensorMountHeight(0.5);
26  detector.setSensorTiltAngle(10);
27  }
28 
30  info_msg.reset(new sensor_msgs::CameraInfo);
31  info_msg->header.frame_id = "depth_frame";
32  info_msg->header.seq = 100;
33  info_msg->height = img_height;
34  info_msg->width = img_width;
35  info_msg->distortion_model = "plumb_bob";
36  info_msg->D.resize(5);
37  info_msg->K[0] = 570;
38  info_msg->K[2] = 314;
39  info_msg->K[4] = 570;
40  info_msg->K[5] = 239;
41  info_msg->K[8] = 1.0;
42  info_msg->R[0] = 1.0;
43  info_msg->R[4] = 1.0;
44  info_msg->R[8] = 1.0;
45  info_msg->P[0] = 570;
46  info_msg->P[2] = 314;
47  info_msg->P[5] = 570;
48  info_msg->P[6] = 235;
49  info_msg->P[10] = 1.0;
50  }
51 
52  template<typename T>
53  void setDefaultDepthMsg(T value) {
54  depth_msg.reset(new sensor_msgs::Image);
55  depth_msg->header.frame_id = "depth_frame";
56  depth_msg->header.seq = 100;
57  depth_msg->header.stamp.fromSec(10.0);
58  depth_msg->height = img_height;
59  depth_msg->width = img_width;
60  depth_msg->is_bigendian = false;
61  depth_msg->step = depth_msg->width * sizeof(T);
62 
63  if (typeid(T) == typeid(uint16_t)) {
64  depth_msg->encoding = sensor_msgs::image_encodings::TYPE_16UC1;
65  }
66  else if (typeid(T) == typeid(float)) {
67  depth_msg->encoding = sensor_msgs::image_encodings::TYPE_32FC1;
68  }
69 
70  depth_msg->data.resize(depth_msg->width * depth_msg->height * sizeof(T));
71  T* depth_row = reinterpret_cast<T*>(&depth_msg->data[0]);
72  for (size_t i = 0; i < depth_msg->width * depth_msg->height; ++i) {
73  depth_row[i] = value;
74  }
75  }
76 };
77 
78 TEST_F(CliffDetectorTest, encodingSupport)
79 {
80  setDefaultDepthMsg<uint16_t>(1);
82 
83  setDefaultDepthMsg<float>(1);
85 }
86 
87 TEST_F(CliffDetectorTest, unsupportedEncoding)
88 {
89  setDefaultDepthMsg<uint16_t>(1);
91  EXPECT_ANY_THROW(detector.detectCliff(depth_msg, info_msg));
92 }
93 
94 int main(int argc, char **argv)
95 {
96  testing::InitGoogleTest(&argc, argv);
97  return RUN_ALL_TESTS();
98 }
sensor_msgs::CameraInfoPtr info_msg
void setDepthImgStepCol(const int step)
setDepthImgStepCol
int main(int argc, char **argv)
void detectCliff(const sensor_msgs::ImageConstPtr &depth_msg, const sensor_msgs::CameraInfoConstPtr &info_msg)
detectCliff detects descending stairs based on the information in a depth image
TEST_F(CliffDetectorTest, encodingSupport)
void setDepthImgStepRow(const int step)
setDepthImgStepRow
void setSensorMountHeight(const float height)
setSensorMountHeight sets the height of sensor mount (in meters) from ground
void setBlockSize(const int size)
setBlockSize sets size of square block (subimage) used in cliff detector
const std::string TYPE_32FC1
void setDefaultDepthMsg(T value)
const std::string TYPE_16UC1
const std::string MONO16
cliff_detector::CliffDetector detector
sensor_msgs::ImagePtr depth_msg
The CliffDetector class detect cliff based on depth image.
void setSensorTiltAngle(const float angle)
setSensorTiltAngle sets the sensor tilt angle (in degrees)
void setRangeLimits(const float rmin, const float rmax)
setRangeLimits sets the minimum and maximum range of depth value from RGBD sensor.


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