Subdiv2D subtract holes (black pixels) from mesh

I’m trying to convert a stack of images to a 3D mesh.
First as test i’m trying to convert just 1 layer, i’m using Subdiv2D to get the triangles from the scanned contours, but it render the holes as positive areas in the mesh which i can understand why.

Source image:


My question: It is possible to subtract the holes to the mesh?

My code:

 using var mat = CvInvoke.Imread(@"D:\layer0.png", ImreadModes.Grayscale);
        var contours = mat.FindContours(out var hierarchy, RetrType.Tree, ChainApproxMethod.ChainApproxTc89Kcos);

        using var mesh = new STLMeshFile(@"D:\test.stl", FileMode.Create);

        var groups = EmguContours.GetPositiveContoursInGroups(contours, hierarchy);

        foreach (var group in groups)
            for (int i = 0; i < group.Size; i++)
                var list = new List<PointF>();
                for (int x = 0; x < contours[i].Size; x++)

                using var sub = new Subdiv2D(list.ToArray());
                var triangles = sub.GetDelaunayTriangles();

                foreach (var triangle2Df in triangles)
                        new Vector3(triangle2Df.V0.X, triangle2Df.V0.Y, 1f),
                        new Vector3(triangle2Df.V1.X, triangle2Df.V1.Y, 1f),
                        new Vector3(triangle2Df.V2.X, triangle2Df.V2.Y, 1f),


EmguContours.GetPositiveContoursInGroups: Groups contours into separate objects, eg, index 0 contains all the contours to correctly draw 1 cog (including the holes)

different approach: stay with raster graphics. stack the layers. you get a 3D voxel grid. apply marching cubes. there you have your mesh.

Is there any sample? I have saw some in python but those require some libraries other than openCV. I’m with C# and trying to make this with openCV.