rgbd
test_utils.h
Go to the documentation of this file.
1 #ifndef RGBD_TEST_UTILS_H_
2 #define RGBD_TEST_UTILS_H_
3 
4 #include <opencv2/core.hpp>
5 
6 #include <rgbd/image.h>
7 
8 #include <image_geometry/pinhole_camera_model.h>
9 #include <sensor_msgs/CameraInfo.h>
10 #include <sensor_msgs/distortion_models.h>
11 
12 #include <random>
13 #include <string>
14 
15 namespace rgbd {
16 
17 std::string randomString(size_t length=10)
18 {
19  static std::mt19937 generator{std::random_device{}()};
20  //modify range according to your need "A-Z","a-z" or "0-9" or whatever you need.
21  static std::uniform_int_distribution<int> distribution{'a', 'z'};
22  std::string rand_str(length, '\0');
23  for (char& dis: rand_str)
24  dis = distribution(generator);
25 
26  return rand_str;
27 }
28 
29 double randomDouble(double min=0, double max=1000000)
30 {
32  std::uniform_real_distribution<double> dis(min, max); // range min - max
33  return dis(e);
34 }
35 
37 {
38  cv::Mat rgb_image(480, 640, CV_8UC3);
39  cv::randu(rgb_image, 0, 255);
40  cv::Mat depth_image(480, 640, CV_32FC1);
41  cv::randu(depth_image, 0., 100.);
42  sensor_msgs::CameraInfo cam_info;
43  cam_info.D.resize(5, 0.0);
44  cam_info.K = {554.2559327880068, 0.0, 320.5,
45  0.0, 554.2559327880068, 240.5,
46  0.0, 0.0, 1.0};
47  cam_info.R.fill(0.0);
48  cam_info.R[0] = 1.0;
49  cam_info.R[4] = 1.0;
50  cam_info.R[8] = 1.0;
51  cam_info.P = {554.2559327880068, 0.0, 320.5, 0.0,
52  0.0, 554.2559327880068, 240.5, 0.0,
53  0.0, 0.0, 1.0, 0.0};
54  cam_info.distortion_model = sensor_msgs::distortion_models::PLUMB_BOB;
55  cam_info.width = 640;
56  cam_info.height = 480;
57  image_geometry::PinholeCameraModel cam_model;
58  cam_model.fromCameraInfo(cam_info);
59 
60  return rgbd::Image(rgb_image, depth_image, cam_model, randomString(), randomDouble());
61 }
62 
63 }
64 
65 #endif // RGBD_TEST_UTILS_H_
std::string
std::uniform_int_distribution
rgb_image
cv::Mat rgb_image
Definition: record_to_video.cpp:24
random
std::uniform_real_distribution
std::mt19937
rgbd::Image
Definition: image.h:43
std::random_device
rgbd
Definition: client.h:24
image.h
rgbd::randomString
std::string randomString(size_t length=10)
Definition: test_utils.h:17
rgbd::generateRandomImage
rgbd::Image generateRandomImage()
Definition: test_utils.h:36
rgbd::randomDouble
double randomDouble(double min=0, double max=1000000)
Definition: test_utils.h:29
string