Nodes/comfyui_cv/CV DNN Blob From Image
ComfyUI Node

CV DNN Blob From Image

Builds a cv2.dnn input blob from an IMAGE batch or a single image: an optional resize, per-channel mean subtraction, a scale factor and a BGR<->RGB swap, packed into the (N, C, H, W) NCHW float32 tensor a network's setInput() expects. Encodes every frame in the batch (single image gives N=1). Generic PREPROCESS step - feed the blob into 'CV DNN Forward'.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV DNN Blob From Image
  • image
  • blob
scale1.000
width0
height0
swap_rbtrue
mean_r0.0
mean_g0.0
mean_b0.0
cropfalse
Categoryimage/CV/dnn

Inputs (9)

NameTypeDefaultDescription
imageNPARRAY,IMAGEIMAGE batch to encode. Every frame is resized and encoded; an NPARRAY (gray/BGR/BGRA, any dtype) is treated as a single BGR frame. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
scaleFLOAT1.0000–1000000Multiplies every pixel (after mean subtraction). Use 1/255 = 0.003921 to map 0-255 pixels into the 0-1 range most ONNX models expect; 1.0 leaves them at 0-255.
widthINT00–8192Resize width the network wants, in px. 0 = keep the image's own width (for fully-convolutional models).
heightINT00–8192Resize height the network wants, in px. 0 = keep the image's own height.
swap_rbBOOLEANtrueSwap the R and B channels. OpenCV frames are BGR but most ONNX models are trained on RGB, so leave this on.
mean_roptFLOAT0.0-255–255Value subtracted from the RED channel before scaling (0 = none). Set the model's training mean if needed.
mean_goptFLOAT0.0-255–255Value subtracted from the GREEN channel before scaling (0 = none).
mean_boptFLOAT0.0-255–255Value subtracted from the BLUE channel before scaling (0 = none).
cropoptBOOLEANfalseOn: resize so the shorter side fits then centre-crop to (width, height). Off: resize the whole image (may change aspect ratio).

Outputs (1)

NameTypeDescription
blobNPARRAY(N, C, H, W) float32 NCHW blob for the whole batch. Feed 'CV DNN Forward'. Empty (0, 3, 1, 1) for an empty IMAGE batch.