@@ -12,8 +12,8 @@ using namespace std;
1212using namespace rs ::core;
1313
1414// helper functions
15- void get_depth_coordinates_from_rectangle_on_depth_image (custom_image & depthImage, vector<point3dF32> &depthCoordinates);
16- void get_color_coordinates_from_rectangle_on_color_image (custom_image & colorImage, vector<pointF32> &colorCoordinates);
15+ void get_depth_coordinates_from_rectangle_on_depth_image (std::shared_ptr<image_interface> depthImage, vector<point3dF32> &depthCoordinates);
16+ void get_color_coordinates_from_rectangle_on_color_image (std::shared_ptr<image_interface> colorImage, vector<pointF32> &colorCoordinates);
1717
1818int main ()
1919{
@@ -53,27 +53,27 @@ int main ()
5353 ColorInfo.format = rs::utils::convert_pixel_format (colorFormat);
5454 ColorInfo.pitch = color_pixel_size * colorWidth;
5555
56- custom_image colorImage (&ColorInfo,
56+ std::shared_ptr<image_interface> colorImage ( image_interface::create_instance_from_raw_data (&ColorInfo,
5757 device->get_frame_data (rs::stream::color),
5858 stream_type::color,
5959 image_interface::flag::any,
6060 device->get_frame_timestamp (rs::stream::color),
6161 device->get_frame_number (rs::stream::color),
62- nullptr , nullptr );
62+ nullptr , nullptr )) ;
6363
6464 image_info DepthInfo;
6565 DepthInfo.width = depthWidth;
6666 DepthInfo.height = depthHeight;
6767 DepthInfo.format = rs::utils::convert_pixel_format (depthFormat);
6868 DepthInfo.pitch = depth_pixel_size * depthWidth;
6969
70- custom_image depthImage (&DepthInfo,
70+ std::shared_ptr<image_interface> depthImage ( image_interface::create_instance_from_raw_data (&DepthInfo,
7171 device->get_frame_data (rs::stream::depth),
7272 stream_type::depth,
7373 image_interface::flag::any,
7474 device->get_frame_timestamp (rs::stream::depth),
7575 device->get_frame_number (rs::stream::depth),
76- nullptr , nullptr );
76+ nullptr , nullptr )) ;
7777
7878 /* *
7979 * MapDepthToColor example.
@@ -99,7 +99,7 @@ int main ()
9999 get_color_coordinates_from_rectangle_on_color_image (colorImage, colorCoordinates);
100100
101101 vector<pointF32> mappedDepthCoordinates (colorCoordinates.size ());
102- if (projection_->map_color_to_depth (& depthImage, colorCoordinates.size (), colorCoordinates.data (), mappedDepthCoordinates.data ()) < status_no_error)
102+ if (projection_->map_color_to_depth (depthImage. get () , colorCoordinates.size (), colorCoordinates.data (), mappedDepthCoordinates.data ()) < status_no_error)
103103 {
104104 cerr<<" failed to map the color coordinates to depth" << endl;
105105 return -1 ;
@@ -168,9 +168,9 @@ int main ()
168168 * QueryUVMap Example.
169169 * Retrieve the UV map for the specific depth image. The UVMap is a pointF32 array of depth size width*height.
170170 */
171- auto depthImageInfo = depthImage. query_info ();
171+ auto depthImageInfo = depthImage-> query_info ();
172172 vector<pointF32> uvmap (depthImageInfo.width * depthImageInfo.height );
173- if (projection_->query_uvmap (& depthImage, uvmap.data ()) < status_no_error)
173+ if (projection_->query_uvmap (depthImage. get () , uvmap.data ()) < status_no_error)
174174 {
175175 cerr<<" failed to query UV map" << endl;
176176 return -1 ;
@@ -181,9 +181,9 @@ int main ()
181181 * Retrieve the inverse UV map for the specific depth image. The inverse UV map maps color coordinates
182182 * back to the depth coordinates. The inverse UVMap is a pointF32 array of color size width*height.
183183 */
184- auto colorImageInfo = colorImage. query_info ();
184+ auto colorImageInfo = colorImage-> query_info ();
185185 vector<pointF32> invUVmap (colorImageInfo.width * colorImageInfo.height );
186- if (projection_->query_invuvmap (& depthImage, invUVmap.data ()) < status_no_error)
186+ if (projection_->query_invuvmap (depthImage. get () , invUVmap.data ()) < status_no_error)
187187 {
188188 cerr<<" failed to query invariant UV map" << endl;
189189 return -1 ;
@@ -195,7 +195,7 @@ int main ()
195195 * size width*height. The world coordiantes units are in mm.
196196 */
197197 vector<point3dF32> vertices (depthImageInfo.width * depthImageInfo.height );
198- if (projection_->query_vertices (& depthImage, vertices.data ()) < status_no_error)
198+ if (projection_->query_vertices (depthImage. get () , vertices.data ()) < status_no_error)
199199 {
200200 cerr<<" failed to query vertices" << endl;
201201 return -1 ;
@@ -206,7 +206,7 @@ int main ()
206206 * Get the color pixel for every depth pixel using the UV map, and output a color image, aligned in space
207207 * and resolution to the depth image.
208208 */
209- std::unique_ptr<image_interface> colorImageMappedToDepth = std::unique_ptr<image_interface>(projection_->create_color_image_mapped_to_depth (& depthImage, & colorImage));
209+ std::unique_ptr<image_interface> colorImageMappedToDepth = std::unique_ptr<image_interface>(projection_->create_color_image_mapped_to_depth (depthImage. get (), colorImage. get () ));
210210 // use the mapped image...
211211
212212 // The application must release the instance after use. (e.g. use smart ptr)
@@ -216,7 +216,7 @@ int main ()
216216 * Map every depth pixel to the color image resolution, and output a depth image, aligned in space
217217 * and resolution to the color image. The color image size may be different from original.
218218 */
219- std::unique_ptr<image_interface> depthImageMappedToColor = std::unique_ptr<image_interface>(projection_->create_depth_image_mapped_to_color (& depthImage, & colorImage));
219+ std::unique_ptr<image_interface> depthImageMappedToColor = std::unique_ptr<image_interface>(projection_->create_depth_image_mapped_to_color (depthImage. get (), colorImage. get () ));
220220 // use the mapped image...
221221
222222 // The application must release the instance after use. (e.g. use smart ptr)
@@ -226,12 +226,18 @@ int main ()
226226 return 0 ;
227227}
228228
229- void get_depth_coordinates_from_rectangle_on_depth_image (custom_image & depthImage, vector<point3dF32> &depthCoordinates)
229+ void get_depth_coordinates_from_rectangle_on_depth_image (std::shared_ptr<image_interface> depthImage, vector<point3dF32> &depthCoordinates)
230230{
231- auto depthImageInfo = depthImage.query_info ();
231+ if (!depthImage)
232+ {
233+ cerr<<" cant use null image" << endl;
234+ return ;
235+ }
236+
237+ auto depthImageInfo = depthImage->query_info ();
232238
233239 // get read access to the detph image data
234- const void * depthImageData = depthImage. query_data ();
240+ const void * depthImageData = depthImage-> query_data ();
235241 if (!depthImageData)
236242 {
237243 cerr<<" failed to get depth image data" << endl;
@@ -254,9 +260,15 @@ void get_depth_coordinates_from_rectangle_on_depth_image(custom_image &depthImag
254260
255261}
256262
257- void get_color_coordinates_from_rectangle_on_color_image (custom_image & colorImage, vector<pointF32> &colorCoordinates)
263+ void get_color_coordinates_from_rectangle_on_color_image (std::shared_ptr<image_interface> colorImage, vector<pointF32> &colorCoordinates)
258264{
259- auto colorImageInfo = colorImage.query_info ();
265+ if (!colorImage)
266+ {
267+ cerr<<" cant use null image" << endl;
268+ return ;
269+ }
270+
271+ auto colorImageInfo = colorImage->query_info ();
260272
261273 // create a pointF32 array for the color coordinates you would like to project, for example the central rectangle
262274 const int startX = colorImageInfo.width / 4 ; const int endX = (colorImageInfo.width * 3 ) / 4 ;
0 commit comments