Drawing a numpy array with triangulation [closed]

asked 2016-03-29 04:42:37 -0500

marcoE gravatar image

updated 2016-03-30 08:36:01 -0500

Hello, I've have this array :


How can I draw it with opencv and make it look like this:

image description


This image is a plot of the same array with matplotlib.

Python Code:

from stl import mesh
from matplotlib import collections
from matplotlib import pyplot

# Create a figure and axes
figure, axes = pyplot.subplots()

# Read the STL file
your_mesh = mesh.Mesh.from_file('stlMidPoint.stl')

# Scale the image to the STL dimensions
axes.set_xlim(your_mesh.min_[0], your_mesh.max_[0])
axes.set_ylim(your_mesh.min_[1], your_mesh.max_[1])

# Add the polygons, but only the X and Y axis since it's 2D
axes.add_collection(collections.PolyCollection(your_mesh.vectors[:, :, :2]))

# Make sure the aspect ratio stays correct

# Render!

And I want to use this mesh to overlay in other images, for example this one:


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-04 03:06:00.223229



If your data is already formatted to display the mesh, you can use cv::line to draw the lines.

Otherwise, you should add the Python code to see if there is a triangulation option in the plot function or if you did it yourself.

Eduardo gravatar imageEduardo ( 2016-03-29 11:22:55 -0500 )edit

I have the "points" coordinates.

marcoE gravatar imagemarcoE ( 2016-03-30 03:52:20 -0500 )edit

@Eduardo I've updated the code. I need to draw the mesh with opencv in order to be simpler using the mesh as mask for other images. For instance, I want to use this mesh in this image.


marcoE gravatar imagemarcoE ( 2016-03-30 09:53:31 -0500 )edit

Sorry, I can't help you more as I don't know how meshes are represented in .stl file format nor how Python will display them.

If you manage to get the triplets, then you can iterate over the list of triplets and display them with cv::line.

Also, I am not able to understand your data file:

  • it looks like a file full of raw 3D points coordinates and not a mesh.
  • there are lot of identical points, at least in the beginning of the file.
Eduardo gravatar imageEduardo ( 2016-03-30 11:38:53 -0500 )edit

@Eduardo a stl mesh is a 3D file. I've used the numpy-stl module in order to extract the vectors. On the file there are only the "top" face vector coordinates. I've created a question to having an alternative solving to the same problem http://answers.opencv.org/question/91...

marcoE gravatar imagemarcoE ( 2016-04-01 04:10:49 -0500 )edit