How to transform a 3D bounding box from pointclouds to matched RGB frames in ROS? - rgb

i am doing SLAM with depth camera realsense D455 on ROS (https://github.com/IntelRealSense/realsense-ros/wiki/SLAM-with-D435i) and I am able to create 3D point clouds of the environment.
I am new in ROS and my goal is to bound a 3d box in a region of global pointcloud then transform the same box on RGB frames that are matched with that points(at the same coordinates) in the global point cloud.
now i have RGB, depth, and point cloud topic and tf but since i am new in this field i do not know how can i find RGB frames that are matched with each point in the global point cloud?
and how do the same operation from point cloud to RGB frames?
i would be grateful if someone can help me with that

Get 3D bounding box points.
Transform them into camera's frame (z is depth).
Generate your camera's calibration model (intrinsic and extrinsic parameters of the camera, focal length etc.) -> Check openCV model, Scaramuzza Model or another stereo camera calibration model
Project 3D points to 2D pixels. (openCV has one projectPoints() function).

Related

Kinect Azure Body Tracking Coordinate Mapping

I am wondering, is there is a way to get Joint Position in color and depth space, similar to the v2 coordinate mapper MapCameraPointToColorSpace and MapCameraPointToDepthSpace?
Also how can I map the body index image to color image?
Thanks
The k4abt_skeleton_t from Azure Kinect Body Tracking SDK provides 3D joint locations in the depth camera space. You can project the skeleton joints into the color sensor space using the provided 3d to 2d conversion APIs from the Azure Kinect Sensor SDK.
k4a_calibration_3d_to_2d
k4a::calibration::convert_3d_to_2d
"Transform a 3D point of a source coordinate system into a 2D pixel coordinate of the target camera."
For transforming the body index image to the RGB image, take a look at the following APIs in the Azure Kinect Sensor SDK:
k4a::transformation::depth_image_to_color_camera_custom
k4a_transformation_depth_image_to_color_camera_custom
"Transforms depth map and a custom image into the geometry of the color camera."
It seems that MapCameraPointToColorSpace and MapCameraPointToDepthSpace are replaced by Calibration TransfromTo2D.
I haven't found a solution for mapping the body index image.

Terrain rendering on mobile device

I have downloaded NASA SRTM files. Each files contains about 4000x4000 points. Each point value is altimetry. Gap between points is about 90m. We know GPS coordinates of corners point corresponding to file.
I want do display terrain on a phone screen. I have tried OpenGL and scenekit (iOS), but it is very slow to load vertex.
I have about 2000x2000 Points. I create 2 triangles per square. It is not very big but it is very slow to load those points in OpenGL buffers (idem for scenekit).
I am wondering how are working games like GTA because i think they have a big number of vertex and it is not very slow...
Any idea to speed up vertex loading ?
Thanks

Mapping Lat And Lon on a blank page

VB.net, WPF
Been researching for a while and come across nothing that is exactly what im looking for
Basically I am required to make a program that can map area covered by a machine this map can be either be a polygon covering a white screen or a polygon overlaying an offline satellite/Street map.
I have the NMEA serial GPS setup and running perfectly however I am now required to store the Lat and lon data of the machine for each second tick and then overlay this as a polygon map for area covered.
The machine width will be set by the user and map area covered with the GPS.
My Question.
Is there a way I can overlay a gps generated coverage map on either a white screen or an offline street map?
I think I understand what you're trying to achieve here.
You can draw the coverage of your machine as a circle of machine width on a canvas. See here for a tutorial
When it comes to converting your lat/long to pixels for the centre of your machine you need to account for the projection of the chart. Lat/Long describes a location on the surface of a sphere. However your map is a flat 2d shape. To enable us to plot these points the maps are squished using a projection, the most common of which is the mercator projection
Here's an example of transforming lat / long for mercator: Covert latitude/longitude point to a pixels (x,y) on mercator projection

Rotate Camera in the Direction behind object in OpenGL

I'm making a game in OpenGL, using freeglut.
I have a car, which I am able to move back and forward using keys and the camera follows it. Now, when I turn the car(glRotate in xz plane), I want the camera to change the Camera position(using gluLookAt) so it always points to the back of the car.
Any suggestions how do I do that?
For camera follow I use the object transform matrix
get object transform matrix
camera=object
use glGetMatrix or whatever for that
shift rotate the position so Z axis is directing where you want to look
I use object aligned to forward on Z axis, but not all mesh models are like this so rotate by (+/-)90 deg around x,y or z to match this:
Z-axis is forward (or backward depends on your projection matrix and depth function)
X-axis is Right
Y-axis is Up
with respect to your camera/screen coordinate system (projection matrix). Then translate to behind position
apply POV rotation (optional)
if you can slightly rotate camera view from forward direction (mouse look) then do it at this step
camera*=rotation_POV
convert matrix to camera
camera matrix is usually inverse of the coordinate system matrix it represents so:
camera=Inverse(camera)
For more info look here understanding transform matrices the OpenGL inverse matrix computation in C++ is included there.

how do I do "reverse" texture mapping from texture image x,y to 3d space?

I am using WPF 3D, but I think this question should apply to any 3d texture mapping.
Suppose I have a model of a cow, and I want to draw a circular spot on the cow (and I want to do this dynamically -- supposed I don't know the location of the spot until run-time). I could do this by coloring the vertexes (vertexes are assigned a color based on their distance from the center of the spot), but if the model is fairly low-poly, that will give a pretty jagged-edged circle.
I could do it using a pixel shader, where the shader colors each pixel based on its distance from the center of the spot. But suppose I don't have access to pixel shaders (since I don't in WPF).
So, it seems that what I want to do is dynamically create a texture with the circle pattern on it, and texture the cow with it.
The question is: As I'm drawing that texture, how can I know what 3d coordinate in model space a given xy coordinate on the texture image corresponds to?
That is, suppose I have already textured my model with a plain white texture -- I've set up texture coordinates, done texture mapping, but don't have the texture image yet. So I have this 1000x1000 (or whatever) pixel image that gets draped nicely over the cow according to some nice texture coordinates that have been set up on the model beforehand. I understand that when the 3D hardware goes to draw a given triangle, it uses the texture coordinates of the vertexes of the triangle to find the corresponding triangular region of the image, and then interpolates across the surface of the triangle to fill displayed model pixels with colors from that triangular region of the image.
How do I go the other way? How do I say, for this given xy point on my texture image, and given the texture coordinates that have already been set up on the model, what's the 3d coordinate in model space that this image pixel is going to correspond to once texture mapping happens?
If I had such a function, I could color my texture map image such that all the points (in 3d space) within a certain distance of the circle center point on the cow would get one color, and all points outside that distance would get another color, and I'd end up with a nice, crisp circular spot on the cow, even with a relatively low-poly model. Does that sound right?
I do understand that given the texture coordinates for the vertexes of each triangle, I can step through the triangles in my model, find the corresponding triangle on the texture image, and do my own interpolation, across the texture pixels in that triangle, by interpolating across the 3d plane determined by the vertex points. And that doesn't sound too hard. But I'm just trying to understand if there is some standard 3d concept/function where I can just call a ready-made function to give me the model space coordinates for a given texture xy.
I did end up getting this working. I walk every point on the texture (1024 x 1024 points). Using the model's texture coordinates, I determine which polygon face, if any, the given u,v point is inside of. If it's inside of a face, I get the model coordinates for each point on that face. I then do a barycentric interpolation as described here: http://paulbourke.net/texture_colour/interpolation/
That is, for each u,v point on the texture, I use an inside-polygon check to determine which quad it's in on the 2D texture sheet and then I use an interpolation on that same 2D geometry as described in the link above, but instead of interpolating colors or normals I'm interpolating 3D coordinates.
I can then use the 3D coordinate to color the point on the texture (e.g., to color a circular spot on the cow based on how far in model space the given texture point is from the spot center point). And then I can apply the texture to the model, and it works.
Again, it seems like this must be a standard procedure with a name...
One issue is that the result is very sensitive to the quality of the the texturing as set up by the modeler. For instance, if a relatively large quad on the cow corresponds to a small quad on the texture image, there just aren't enough pixels to work with to get a smooth curve within that model quad once the texture is applied. You can of course use a higher-res texture, such as 2048x2048, but then your loop time is 4x.
It's actually a rasterization process if I didn't misunderstand your question. In lightmapping, one may also need to find the corresponding positions and normals in world space for each texel in the lightmap space and then baking irradiance. (which seems similar to your goal)
You can use standard Graphics API to do this task instead of writing your own implementation. Let:
Size of texture -> Size of G-buffers
UVs of each mesh triangle -> Vertex positions vec3(u, v, 0) of the input stage
Indices of each mesh triangle -> Indices of the input stage
Positions (and normals, etc.) of each mesh triangle -> Attributes of the input stage
After the rasterizer stage of the graphics pipeline, all fragments that lie within the UV triangle are generated, and the attributes that have been supplied are interpolated automatically. You can do whatever you want now in pixel shader!

Resources