Rendering plane (from findPlaneAtHit()) information onto OpenCV image

Hi there,

I’m looking for some direction on how to overlay results returned by zed.findPlaneAtHit(coord, plane) onto OpenCV 2D image.

The array returned by plane.getBounds() contains negative values which I suppose need to be transformed to align with image’s 2D coordinate system. Similarly, mesh vertices associated with said plane also have negative values.

I’ve looked at some code samples but the solution (transformation logic) is not obvious.

Can some help me with that?

Sample code…
auto plane_location = sl::uint2(new_image_size.width/2, new_image_size.height/2);
Plane plane; // detected plane
zed.findPlaneAtHit(plane_location, plane);

		// Compute the indices of boundary vertices.
		// Returns: The indices of boundary vertices.
		planeBounds = plane.getBounds();
		cout << "#" << to_string(loop_counter) << ". Plane bounds size: " << planeBounds.size() << endl;
		cout << "#" << to_string(loop_counter) << ". Plane center: " << plane.getCenter() << endl;

		for (unsigned int j = 0; j < planeBounds.size(); j++) {
			cout << "	#" << j << ". " << planeBounds[j] << endl;
		}
		cout << endl;
		
		auto mesh = plane.extractMesh();
		std::vector<int> border = mesh.getBoundaries();
		auto vertices = mesh.vertices;
		
		cout << "#" << to_string(loop_counter) << ". Mesh-Border size: " << border.size() << endl;
		for (unsigned int j = 0; j < border.size(); j++) {
			cout << "	#" << j << ". indx: " << border[j] << " -> " << vertices[border[j]] << endl;
		}

Results…
#111. Plane center: -0.425711 -0.21516 0.948548
#0. -0.393699 -0.233309 0.952747
#1. -0.421367 -0.243732 0.953721
#2. -0.46118 -0.238079 0.951482
#3. -0.457191 -0.190691 0.943252
#4. -0.443484 -0.185561 0.942776

#111. Mesh-Border size: 7
#0. indx: 2 → -0.393699 -0.233309 0.952747
#1. indx: 11 → -0.443484 -0.185561 0.942776
#2. indx: 39 → -0.421367 -0.243732 0.953721
#3. indx: 58 → -0.457191 -0.190691 0.943252
#4. indx: 231 → -0.459929 -0.225212 0.949252
#5. indx: 236 → -0.46118 -0.238079 0.951482
#6. indx: 237 → -0.452748 -0.239241 0.95195

Hi @mazx
Welcome to the Stereolabs community.

You can convert 3D coordinates to 2D image coordinates by using the formulas available in this support page:

1 Like

Thanks Myzhar. The article helped me with solving the issue.

1 Like