toyxyz / ComfyUI_toyxyz_test_nodes

Custom node and script for sending webcam to ComfyUI
GNU General Public License v3.0
460 stars 29 forks source link

ComfyUI_toyxyz_test_nodes

This node was created to send a webcam/screen to ComfyUI in real time.

This node is recommended for use with LCM/SDXL turbo

https://github.com/toyxyz/ComfyUI_toyxyz_test_nodes/assets/8006000/8536e96a-514a-48b2-b1aa-8eccbd3fa853

(This video is at 4x speed)

Update

2023/11/24 - AddSave image to path node. Add Render preview, Add export video, Add face detection (After the update, you will need to run CaptrueCam/setup.bat one more time.)

2023/11/29 - Add Region Capture. Made the Webcam app UI smaller.

2023/12/1 - Add Ai render overlay

Installation

  1. Git clone this repo to the ComfyUI/custom_nodes path.

    git clone https://github.com/toyxyz/ComfyUI_toyxyz_test_nodes

  2. Run setup.bat in ComfyUI/custom_nodes/ComfyUI_toyxyz_test_nodes/CaptureCam

Usage

Default workflow workflow (36) (Workflow embedded)

Render preview workflow workflow (38) (Workflow embedded)

Direct Webcam capture workflow (without webcam app) workflow (40) (Workflow embedded)

Load Webcam Image

Load an image from a path.

To use this node with webcam, you must first run run.bat in ComfyUI/custom_nodes/ComfyUI_toyxyz_test_nodes/CaptureCam.

And in the Webcam app, you'll need to select your webcam and run capture with start.

image

Capture Webcam

Captures an image directly from the webcam selected with 'select_webcam'. (Usually 0)

This is unstable compared to the Load Webcam Image node.

If you're using obs, I recommend using the Load Webcam Image node.

image

Save image to path

This node saves the generated images to a defined path.

If save_sequence is true, it saves the images in order without overwriting them.

image

LatentDelay

image

Set the delay between image generation.

ImageResize_Padding

Resizes the image while maintaining its proportions and painting the margins with the color you specify.

image

Webcam app

This script captures the selected webcam and saves it as an image file in real-time.

You can specify the resolution, format, and path of the image to be saved.

If you don't enter a path, it will be saved to the default path.

You can combine a sequence of saved images into a video using the Export button. Make sure to set save_sequence in Save Image to Path to true.

To use AI Render, you need a Save Image to Path node.

If you entered a location other than the default path in Save Image to Path, you must select a newly created render image in Select Rendered image.

Run_hide_cmd.vbs : Hide the cmd and run the app.

image

Webcam : List of camera devices connected to your computer

Width: Sets the width of the image.

Height: Sets the height of the image.

If either the width or height is zero, it will be automatically adjusted to fit the other values entered.

FPS : Set how often the capture occurs. If you enter 0, it is unlimited.

Webcam(Checkbox) : Preview the captured image.

Al Render: Preview the generated image in ComfyUi.

Always on top : Webcam, AI Render is always visible on top. To disable it, you need to close the preview window.

Face detect : Automatically recognize faces and generate masks. It is stored as face_mask.jpg. Use with inpainting.

Keep aspect ratio : Correct the aspect ratio of the image and the capture window.

Capture Path: The path where the captured image will be saved.

Render image: Path to the image generated by ComfyUI. Required to use AI Render.

If you don't enter a path, the default path is used.

Save format: Set the image format to be saved

Overlay alhpa : The alpha value of the overlay image displayed above the region capture window.

image

Padding: Set how to fill the margins of the image when using Keep aspect ratio.

Export video: Combines the image sequences located in the render image folder into a single video. Enter the desired FPS value.

Clear after export: Deletes the image sequence after the video is exported.

image

Add region window: Creates a window to specify the region to capture.

The name of the window is the same as entered in Save name. If you enter comma-separated text (e.g., A,B,C), you can use one Region window to capture three images, A, B, and C, alternating between them.

Save name: Set a name for the captured image.

Window list: Select the windows to capture. Other windows will not be captured. If set to Disable, it will be captured as it is displayed on the screen. Window capture is often unstable depending on the program. Be careful when using it.

Reload list: Refresh the list of webcams and windows.

The name of the currently captured and saved image file and the selected Region window are displayed in the Webcam/Ai Render preview window.

image

If you select 'Region Capture' from the Webcam list, it will capture the region of the window added with 'Add Region window'. If you select 'Window Capture', it will capture the entire window selected in the window list.

https://github.com/toyxyz/ComfyUI_toyxyz_test_nodes/assets/8006000/8723e014-caa5-4e16-8c8c-5c5edac6f141 image image image

Hotkeys :

S: Saves the image displayed in the current AI render to the render folder. Activate (click) the AI render window and then use it.

F : Toggles the Region widow (target window list selected) to full window mode. Select the target Region window and then click Use.

A : Select the Region window currently being captured. Enable the AI render or Webcam preview window, then use it.

C: Change the region window. Select the desired Region window and press the key to switch to that window. When used in the Ai Render or Webcam window, the Region windows are switched in the order they were created.

X: If the Region windows were created separated by commas, pressing the key while Ai Render or Webcam is active will switch the name of the captured image.

Q: Copy the image displayed in AI render to the clipboard. Activate AI render and then use.

M: Mask paint toggle. Allows you to paint the mask directly in the Webcam preview window. Paint with the left mouse and erase with the right. You can change the brush size with the mouse wheel. The mask is saved as the captured image name + '_mask'.

N: Erase all painted masks.

Z: Pause image capture. Use for Webcam or AI Render.

P: Displays the AI Render image as an overlay on the currently selected Region window. This is unstable and should be used with caution. It can only be enabled/disabled when capture is stopped and requires a target window to be set. Does not run even if there is no render image to load.

Render preview

Load the image file saved with the Save image to path node. Pressing 'Q' while the window is active will copy the preview image to the clipboard.

image

Face detection

Detect faces and create masks. Use it for inpainting with the Load Webcam Image node.

image

Note

The ControlNet preprocessor slows down the process, so I recommend using other tools to prepare the ControlNet image.

If you want ComfyUI to run continuously, use Auto Queue.

image

For maximum speed, set the VAE to taesd.

image