99#include " statistics.h"
1010#include " rpc/rpc_error.h"
1111#include < cv_bridge/cv_bridge.h>
12-
12+ # include < math.h >
1313
1414
1515
@@ -96,6 +96,30 @@ cv::Mat manual_decode_depth(const ImageResponse& img_response)
9696 return mat;
9797}
9898
99+ float roundUp (float numToRound, float multiple)
100+ {
101+ assert (multiple);
102+ return ((numToRound + multiple - 1 ) / multiple) * multiple;
103+ }
104+
105+ cv::Mat noisify_depthimage (cv::Mat in)
106+ {
107+ cv::Mat out = in.clone ();
108+
109+ // Blur
110+ cv::Mat kernel = cv::Mat::ones ( 7 , 7 , CV_32F ) / (float )(7 * 7 );
111+ cv::filter2D (in, out, -1 , kernel, cv::Point ( -1 , -1 ), 0 , cv::BORDER_DEFAULT );
112+
113+ // Decrease depth resolution
114+ for (int row = 0 ; row < in.rows ; row++) {
115+ for (int col = 0 ; col < in.cols ; col++) {
116+ float roundtarget = ceil (std::min (std::max (out.at <float >(row, col), 1 .0f ), 10 .0f ));
117+ out.at <float >(row, col) = roundUp (out.at <float >(row, col), roundtarget);
118+ }
119+ }
120+
121+ return out;
122+ }
99123
100124void doDepthImageUpdate (const ros::TimerEvent&) {
101125 auto img_responses = getImage (ImageRequest (camera_name, ImageType::DepthPerspective, true , false ));
@@ -106,7 +130,7 @@ void doDepthImageUpdate(const ros::TimerEvent&) {
106130
107131 ImageResponse img_response = img_responses[0 ];
108132
109- cv::Mat depth_img = manual_decode_depth (img_response);
133+ cv::Mat depth_img = noisify_depthimage ( manual_decode_depth (img_response) );
110134 sensor_msgs::ImagePtr img_msg = cv_bridge::CvImage (std_msgs::Header (), " 32FC1" , depth_img).toImageMsg ();
111135 img_msg->header .stamp = make_ts (img_response.time_stamp );
112136 img_msg->header .frame_id = " /fsds/camera/" +camera_name;
0 commit comments