Transform TopoDS_Shape or the content or V3d_View into cv::Mat


Is there any way of passing from TopoDS_Shape to Mat(OpenCV) directly? I mean, without having to save images in external folders. Now, I'm doing it saving the content of the V3d_View as an image by the method::Dump and then reading it with OpenCV. However, the resolution of the saved image is very poor and this is not an efficient method. Any idea?


Kirill Gavrilov's picture

There is not need to save image to the file for dumping V3d_View - look onto V3d_View::ToPixmap() method taking Image_PixMap for storing image snapshot. You can then either wrap Image_PixMap into cv::Mat or in opposite way - both classes provide an interface for wrapping external memory pointer, you need to find the appropriate pixel format / CV array type pair suitable for your application. RGBA8 is a native format used by 3D Viewer by default.

Have no idea if TopoDS_Shape can be mapped somehow directly to cv::Mat.

Adriana Costas's picture

It works! Thank you!