From a1e3af7c19a59e451a4f29ef096d1282c0603637 Mon Sep 17 00:00:00 2001 From: RyanOnTheInside <7623207+ryanontheinside@users.noreply.github.com> Date: Sat, 3 May 2025 16:47:53 -0400 Subject: [PATCH] remove cropping this logic was duplicative. there are native nodes in comfyui for both resizing and cropping. --- node_wrappers/utils/misc_nodes.py | 21 +++++++++++---------- web/js/webcam.js | 12 ++++-------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/node_wrappers/utils/misc_nodes.py b/node_wrappers/utils/misc_nodes.py index d04a02e..cdac6de 100644 --- a/node_wrappers/utils/misc_nodes.py +++ b/node_wrappers/utils/misc_nodes.py @@ -55,9 +55,7 @@ class FastWebcamCapture: return { "required": { "image": ("WEBCAM", {}), - "width": ("INT", {"default": 640, "min": 0, "max": MAX_RESOLUTION, "step": 1}), - "height": ("INT", {"default": 480, "min": 0, "max": MAX_RESOLUTION, "step": 1}), - "capture_on_queue": ("BOOLEAN", {"default": True}), + "capture_on_queue": ("BOOLEAN", {"default": True, "tooltip": "Whether to capture the frame when the node is queued"}), } } @@ -66,7 +64,13 @@ class FastWebcamCapture: CATEGORY = "image" - def process_capture(self, image, width, height, capture_on_queue): + def process_capture(self, image, capture_on_queue): + """ + Process a webcam image at native resolution. + + This node simply captures the webcam feed at its native resolution. + For resizing or cropping, use standard ComfyUI nodes after this one. + """ # Check if we got a data URL if isinstance(image, str) and image.startswith("data:image/"): # Extract the base64 data after the comma @@ -75,16 +79,13 @@ class FastWebcamCapture: # Convert base64 to PIL Image buffer = BytesIO(base64.b64decode(base64_data)) pil_image = Image.open(buffer).convert("RGB") + + # Log the image size we're receiving from the webcam + print(f"Webcam image size: {pil_image.width}x{pil_image.height}") # Convert PIL to numpy array image = np.array(pil_image) - # Handle resize if requested - if width > 0 and height > 0: - import cv2 - - image = cv2.resize(image, (width, height), interpolation=cv2.INTER_AREA) - # Convert to float32 and normalize to 0-1 range image = image.astype(np.float32) / 255.0 diff --git a/web/js/webcam.js b/web/js/webcam.js index aef382e..1076fc4 100644 --- a/web/js/webcam.js +++ b/web/js/webcam.js @@ -66,9 +66,6 @@ app.registerExtension({ const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined; const camera = this.widgets.find((w) => w.name === "image"); - const w = this.widgets.find((w) => w.name === "width"); - const h = this.widgets.find((w) => w.name === "height"); - const canvas = document.createElement("canvas"); camera.serializeValue = async () => { @@ -82,20 +79,19 @@ app.registerExtension({ } console.log("Capturing frame from video:", { - paused: webcamVideo.paused, - readyState: webcamVideo.readyState, videoWidth: webcamVideo.videoWidth, videoHeight: webcamVideo.videoHeight }); - canvas.width = w.value || webcamVideo.videoWidth || 640; - canvas.height = h.value || webcamVideo.videoHeight || 480; + // Always use native webcam resolution + canvas.width = webcamVideo.videoWidth; + canvas.height = webcamVideo.videoHeight; const ctx = canvas.getContext("2d"); ctx.drawImage(webcamVideo, 0, 0, canvas.width, canvas.height); const dataUrl = canvas.toDataURL("image/png"); - // console.log("Successfully captured and converted frame to data URL"); + console.log("Captured frame at native resolution:", canvas.width, "x", canvas.height); return dataUrl; };