{"action":"created","issue":{"url":"https://api.github.com/repos/IntelRealSense/librealsense/issues/2584","repository_url":"https://api.github.com/repos/IntelRealSense/librealsense","labels_url":"https://api.github.com/repos/IntelRealSense/librealsense/issues/2584/labels{/name}","comments_url":"https://api.github.com/repos/IntelRealSense/librealsense/issues/2584/comments","events_url":"https://api.github.com/repos/IntelRealSense/librealsense/issues/2584/events","html_url":"https://github.com/IntelRealSense/librealsense/issues/2584","id":373266683,"node_id":"MDU6SXNzdWUzNzMyNjY2ODM=","number":2584,"title":"Is depth.get_distance(x,y) a time consuming function on C++?","user":{"login":"HippoEug","id":21957042,"node_id":"MDQ6VXNlcjIxOTU3MDQy","avatar_url":"https://avatars1.githubusercontent.com/u/21957042?v=4","gravatar_id":"","url":"https://api.github.com/users/HippoEug","html_url":"https://github.com/HippoEug","followers_url":"https://api.github.com/users/HippoEug/followers","following_url":"https://api.github.com/users/HippoEug/following{/other_user}","gists_url":"https://api.github.com/users/HippoEug/gists{/gist_id}","starred_url":"https://api.github.com/users/HippoEug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HippoEug/subscriptions","organizations_url":"https://api.github.com/users/HippoEug/orgs","repos_url":"https://api.github.com/users/HippoEug/repos","events_url":"https://api.github.com/users/HippoEug/events{/privacy}","received_events_url":"https://api.github.com/users/HippoEug/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"RealSense-Customer-Engineering","id":34384799,"node_id":"MDQ6VXNlcjM0Mzg0Nzk5","avatar_url":"https://avatars0.githubusercontent.com/u/34384799?v=4","gravatar_id":"","url":"https://api.github.com/users/RealSense-Customer-Engineering","html_url":"https://github.com/RealSense-Customer-Engineering","followers_url":"https://api.github.com/users/RealSense-Customer-Engineering/followers","following_url":"https://api.github.com/users/RealSense-Customer-Engineering/following{/other_user}","gists_url":"https://api.github.com/users/RealSense-Customer-Engineering/gists{/gist_id}","starred_url":"https://api.github.com/users/RealSense-Customer-Engineering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RealSense-Customer-Engineering/subscriptions","organizations_url":"https://api.github.com/users/RealSense-Customer-Engineering/orgs","repos_url":"https://api.github.com/users/RealSense-Customer-Engineering/repos","events_url":"https://api.github.com/users/RealSense-Customer-Engineering/events{/privacy}","received_events_url":"https://api.github.com/users/RealSense-Customer-Engineering/received_events","type":"User","site_admin":false},"assignees":[{"login":"RealSense-Customer-Engineering","id":34384799,"node_id":"MDQ6VXNlcjM0Mzg0Nzk5","avatar_url":"https://avatars0.githubusercontent.com/u/34384799?v=4","gravatar_id":"","url":"https://api.github.com/users/RealSense-Customer-Engineering","html_url":"https://github.com/RealSense-Customer-Engineering","followers_url":"https://api.github.com/users/RealSense-Customer-Engineering/followers","following_url":"https://api.github.com/users/RealSense-Customer-Engineering/following{/other_user}","gists_url":"https://api.github.com/users/RealSense-Customer-Engineering/gists{/gist_id}","starred_url":"https://api.github.com/users/RealSense-Customer-Engineering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RealSense-Customer-Engineering/subscriptions","organizations_url":"https://api.github.com/users/RealSense-Customer-Engineering/orgs","repos_url":"https://api.github.com/users/RealSense-Customer-Engineering/repos","events_url":"https://api.github.com/users/RealSense-Customer-Engineering/events{/privacy}","received_events_url":"https://api.github.com/users/RealSense-Customer-Engineering/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2018-10-24T01:24:20Z","updated_at":"2018-10-30T02:20:23Z","closed_at":null,"author_association":"NONE","body":"| Required Info                         |                                                                |\r\n|---------------------------------|------------------------------------------- |\r\n| Camera Model                       | D400 | \r\n| Firmware Version                   | 05.09.02.00 | \r\n| Operating System & Version | Win 10 | \r\n| Kernel Version (Linux Only)    |                                       | \r\n| Platform                                 | PC |\r\n| SDK Version                            | 2.16.1 | \r\n| Language                            | C++  | \r\n| Segment\t\t\t| others                   | \r\n\r\n# Introduction\r\nHello all again! I have asked a similar [question](https://github.com/IntelRealSense/librealsense/issues/2469) here three weeks ago, but there wasn't any satisfactory answers. \r\n\r\n# Goal\r\nThe x and y columns are (x, y) coordinates respectively, while the last column is the depth column for each corresponding (x, y) coordinate. There are 921,600 data which represents 921,600 pixels from a photo resolution of 1280x720.\r\n\r\n![image](https://user-images.githubusercontent.com/21957042/47348449-194a7e00-d6e4-11e8-82af-8ab9236f0d5c.png)\r\n![image](https://user-images.githubusercontent.com/21957042/47348703-a4c40f00-d6e4-11e8-878e-fc0215da5a7b.png)\r\n\r\n# Issue\r\nTo achieve this, I wrote a `for` loop that loops for 921,600 times just writing to a CSV format file. \r\n\r\n#### CSV Loop - V1\r\n```\r\nfor (int y = 0; y < 921600; y++) {\r\n\tmyfile << \"x,y,c\\n\";\r\n}\r\n```\r\nIn my own testing, this loop took ~512ms to complete.\r\n\r\n#### CSV Loop - V2\r\n```\r\nfor (int y = 0; y < 720; y++) {\r\n    for (int x = 0; x < 1280; x++) {\r\n        myfile << x << \",\" << y << \",\" << \"c\\n\";\r\n    }\r\n}\r\n```\r\nIn my own testing, this loop took ~8709ms to complete.\r\n\r\n#### CSV Loop - V3\r\n```\r\ndo {\r\n    for (int x = 0; x < 1280; x++) {\r\n        myfile << x << \",\" << y << \",\" << \"c\\n\";\r\n    }\r\n    y++;\r\n} while (y < 720);\r\n```\r\nIn my own testing, this loop took ~8317ms to complete.\r\n\r\n## Implementation Idea (Need Advice)\r\nI am thinking of capturing a single frame using the rosbag `rs-record-playback` CPP example, then using the `depth.get_distance(x,y);` CPP function to loop 921,600 times for every pixel. Something like this:\r\n```\r\nfor (int y = 0; y < 720; y++) {\r\n    for (int x = 0; x < 1280; x++) {\r\n        c = depth.get_distance(x,y);\r\n        myfile << x << \",\" << y << \",\" << c << \"\\n\";\r\n    }\r\n}\r\n```\r\n\r\nDo you think the function is fast enough to loop? Or will it take very long and is impossible? I have tried taking a look at the `rs-pointcloud` example.. where Dorodnic has mentioned \"the output of pointcloud object is a collection of {x,y,z} coordinates in the real world\". Here is a snippet of the pointcloud code from `example.hpp`:\r\n```\r\n/* this segment actually prints the pointcloud */\r\nauto vertices = points.get_vertices();              // get vertices\r\nauto tex_coords = points.get_texture_coordinates(); // and texture coordinate\r\nfor (int i = 0; i < points.size(); i++)\r\n{\r\n    if (vertices[i].z)\r\n    {\r\n        // upload the point and texture coordinates only for points we have depth data for\r\n\t      glVertex3fv(vertices[i]);\r\n        glTexCoord2fv(tex_coords[i]);\r\n    }\r\n}\r\n```\r\nI know from this segment, `points.size()` is actually 921,600, so this function does loop 921,600 times in order to draw the pointcloud. However, do you think this can be applied to the function of getting depth for each individual pixel without the function taking too long (ie more than a few minutes)?\r\n\r\nThank you very much.. looking forward to the suggestions or solutions. 😄 "},"comment":{"url":"https://api.github.com/repos/IntelRealSense/librealsense/issues/comments/434147781","html_url":"https://github.com/IntelRealSense/librealsense/issues/2584#issuecomment-434147781","issue_url":"https://api.github.com/repos/IntelRealSense/librealsense/issues/2584","id":434147781,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNDE0Nzc4MQ==","user":{"login":"HippoEug","id":21957042,"node_id":"MDQ6VXNlcjIxOTU3MDQy","avatar_url":"https://avatars1.githubusercontent.com/u/21957042?v=4","gravatar_id":"","url":"https://api.github.com/users/HippoEug","html_url":"https://github.com/HippoEug","followers_url":"https://api.github.com/users/HippoEug/followers","following_url":"https://api.github.com/users/HippoEug/following{/other_user}","gists_url":"https://api.github.com/users/HippoEug/gists{/gist_id}","starred_url":"https://api.github.com/users/HippoEug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HippoEug/subscriptions","organizations_url":"https://api.github.com/users/HippoEug/orgs","repos_url":"https://api.github.com/users/HippoEug/repos","events_url":"https://api.github.com/users/HippoEug/events{/privacy}","received_events_url":"https://api.github.com/users/HippoEug/received_events","type":"User","site_admin":false},"created_at":"2018-10-30T02:20:23Z","updated_at":"2018-10-30T02:20:23Z","author_association":"NONE","body":"> Hi @HippoEug\r\n> Using `get_distance` in a loop is not recommended. It is more suitable when you need to check the distance of couple of specific interest points. The main reason for the slowdown is that the compiler has no way to inline the call (since you are passing library boundaries) so instead of just going to the depth value in memory, the compiler is forced to generate a bunch of function calls and exception handling blocks. A better way is to multiply the raw data by the value of `RS2_OPTION_DEPTH_UNITS` option.\r\n\r\nHello @dorodnic and everyone, I read the above and the other thread, [Error compiling librealsense/wrappers/opencv/dnn](https://github.com/IntelRealSense/librealsense/issues/2632). Having a little difficulty understanding the solutions you mentioned. Anyways, was wondering of alternative solutions while I figure out the solutions you mentioned.\r\n\r\n### Alternative Solution:\r\nI would like to bring up part of the original question again.. since the `rs-pointcloud.cpp` or pointclouds in general are made up of (x, y, z) coordinates, why can't we just extract the (x, y, z) coordinates from the function which draws the pointcloud in `rs-pointcloud.cpp`?\r\n\r\n#### `Here is a snippet of the pointcloud code from example.hpp:`\r\n```\r\n/* this segment actually prints the pointcloud */\r\nauto vertices = points.get_vertices();              // get vertices\r\nauto tex_coords = points.get_texture_coordinates(); // and texture coordinate\r\nfor (int i = 0; i < points.size(); i++)\r\n{\r\n    if (vertices[i].z)\r\n    {\r\n        // upload the point and texture coordinates only for points we have depth data for\r\n\t    glVertex3fv(vertices[i]);\r\n        glTexCoord2fv(tex_coords[i]);\r\n    }\r\n}\r\n```\r\nThe problem I have currently is that I am unable to get any (x, y, z) coodinates from the above function, just do not know where the code is \"hiding\"!\r\n\r\n\r\nThank you for reading! 😃 😄 "}}
{"actor":{"display_login":"HippoEug"}}