Nodes/comfyui_cv/CV Rasterize Mesh
ComfyUI Node

CV Rasterize Mesh

Renders a mesh that already lives in the graph (pts3d + tris, not a model file) through an OpenCV camera, and returns what the rest of the pack actually needs from a render: the SILHOUETTE as a MASK and METRIC camera-space depth. Shares its z-buffer with 'CV Preview 3D (Calibrated Camera)' - on the shipped truck the two silhouettes agree at IoU 1.0000 - so the mask you composite with and the picture you look at can never drift apart. rvec/tvec accept a single pose OR the Bx3x1 stacks 'CV Rapid Track (Sequence)' emits, so one node turns a tracked clip into a per-frame matte and a per-frame depth map. The depth output is the metric map 'CV Preview 3D (Calibrated Camera)'.scene_depth wants, which is how a tracked real object occludes a virtual one. Pinhole only: lens distortion is NOT applied (undistort the frames first, or use the viewer node when you need the lens). Triangles only, no texture, no shading - this node emits geometry, not a picture.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Rasterize Mesh
  • pts3d
  • tris
  • K
  • rvec
  • tvec
  • silhouette
  • depth
  • coverage
width800
height600
Categoryimage/CV/low-level

Inputs (7)

NameTypeDefaultDescription
pts3dNPARRAYNx3 vertices in OPENCV object space, from 'CV Mesh From 3D Model' (optionally through 'CV Mesh Split Long Edges' or 'CV Transform Points 3D').
trisNPARRAYMx3 int triangle indices into pts3d. Indices past the end of pts3d yield an empty render rather than reading out of bounds the way cv2.rapid.drawWireframe does.
KNPARRAY3x3 camera matrix of the frames being matched. Must be the SAME K the pose was solved with, or the silhouette lands in the wrong place.
rvecNPARRAYRotation, Rodrigues 3x1 - or a Bx3x1 STACK to render a whole tracked sequence in one execution.
tvecNPARRAYTranslation 3x1, or the matching Bx3x1 stack. Its units are the units the depth output is in.
widthINT8008–8192Output width in pixels. Use the frame's own size so the mask lines up with the footage; K must match it (halving the render means halving fx/fy/cx/cy too).
heightINT6008–8192Output height in pixels, matching the frames.

Outputs (3)

NameTypeDescription
silhouetteMASKOne 0/1 MASK per pose (a MASK batch): 1 where the mesh covers the frame. Hard-edged - there is no supersampling here; blur it if you need a soft matte. This is the per-frame roto of a tracked object, ready for compositing, inpainting or a ControlNet.
depthNPARRAYMETRIC camera-space Z in the mesh's own units, float32, and `inf` where the mesh does not cover the pixel - which is exactly what 'CV Preview 3D (Calibrated Camera)'.scene_depth reads as 'no measurement here, never occlude'. Shape is HxW for a single pose and BxHxW for a pose stack; take one frame out with 'CV Index Batch'. Sample it at projected points ('CV Sample Array At Points') to test whether an annotation anchor is facing the camera.
coverageFLOATMean fraction of the frame the mesh covers, over all poses. A health signal: 0 means the model missed the frame entirely (wrong K, wrong units, pose behind the camera), not that the render failed.