mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2026-01-23 12:24:29 +08:00
simplify webcam node
This commit is contained in:
parent
8df4ea78cb
commit
bc4890f798
@ -87,7 +87,7 @@ NODE_CONFIG = {
|
||||
"CustomSigmas": {"class": CustomSigmas, "name": "Custom Sigmas"},
|
||||
#utility
|
||||
"WidgetToString": {"class": WidgetToString, "name": "Widget To String"},
|
||||
"DummyLatentOut": {"class": DummyLatentOut, "name": "Dummy Latent Out"},
|
||||
"DummyOut": {"class": DummyOut, "name": "Dummy Out"},
|
||||
"GetLatentsFromBatchIndexed": {"class": GetLatentsFromBatchIndexed, "name": "Get Latents From Batch Indexed"},
|
||||
"ScaleBatchPromptSchedule": {"class": ScaleBatchPromptSchedule, "name": "Scale Batch Prompt Schedule"},
|
||||
"CameraPoseVisualizer": {"class": CameraPoseVisualizer, "name": "Camera Pose Visualizer"},
|
||||
|
||||
@ -472,7 +472,7 @@ class WebcamCaptureCV2:
|
||||
FUNCTION = "capture"
|
||||
CATEGORY = "KJNodes/experimental"
|
||||
DESCRIPTION = """
|
||||
Captures an area specified by screen coordinates.
|
||||
Captures a frame from a webcam using CV2.
|
||||
Can be used for realtime diffusion with autoqueue.
|
||||
"""
|
||||
|
||||
@ -482,41 +482,33 @@ Can be used for realtime diffusion with autoqueue.
|
||||
"required": {
|
||||
"x": ("INT", {"default": 0,"min": 0, "max": 4096, "step": 1}),
|
||||
"y": ("INT", {"default": 0,"min": 0, "max": 4096, "step": 1}),
|
||||
"cam_index": ("INT", {"default": 0,"min": 0, "max": 255, "step": 1}),
|
||||
"width": ("INT", {"default": 512,"min": 0, "max": 4096, "step": 1}),
|
||||
"height": ("INT", {"default": 512,"min": 0, "max": 4096, "step": 1}),
|
||||
"num_frames": ("INT", {"default": 1,"min": 1, "max": 255, "step": 1}),
|
||||
"delay": ("FLOAT", {"default": 0.1,"min": 0.0, "max": 10.0, "step": 0.01}),
|
||||
"cam_index": ("INT", {"default": 0,"min": 0, "max": 255, "step": 1}),
|
||||
"release": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
def capture(self, x, y, cam_index, width, height, num_frames, delay, release):
|
||||
def capture(self, x, y, cam_index, width, height, release):
|
||||
|
||||
captures = []
|
||||
|
||||
if not hasattr(self, "cap") or self.cap is None:
|
||||
self.cap = cv2.VideoCapture(cam_index) # Open the first webcam (0)
|
||||
self.cap = cv2.VideoCapture(cam_index)
|
||||
if not self.cap.isOpened():
|
||||
raise Exception("Could not open webcam")
|
||||
|
||||
for _ in range(num_frames):
|
||||
ret, frame = self.cap.read()
|
||||
if not ret:
|
||||
raise Exception("Failed to capture image from webcam")
|
||||
ret, frame = self.cap.read()
|
||||
if not ret:
|
||||
raise Exception("Failed to capture image from webcam")
|
||||
|
||||
# Crop the frame to the specified bbox
|
||||
frame = frame[y:y+height, x:x+width]
|
||||
img_torch = torch.from_numpy(frame[..., [2, 1, 0]]).float() / 255.0
|
||||
captures.append(img_torch)
|
||||
# Crop the frame to the specified bbox
|
||||
frame = frame[y:y+height, x:x+width]
|
||||
img_torch = torch.from_numpy(frame[..., [2, 1, 0]]).float() / 255.0
|
||||
|
||||
if num_frames > 1:
|
||||
time.sleep(delay)
|
||||
if release:
|
||||
self.cap.release()
|
||||
self.cap = None
|
||||
|
||||
return (torch.stack(captures, 0),)
|
||||
return (img_torch.unsqueeze(0),)
|
||||
|
||||
class AddLabel:
|
||||
@classmethod
|
||||
|
||||
@ -750,17 +750,17 @@ To see node id's, enable node id display from Manager badge menu.
|
||||
raise NameError(f"Node not found: {id}")
|
||||
return (', '.join(results).strip(', '), )
|
||||
|
||||
class DummyLatentOut:
|
||||
class DummyOut:
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"latent": ("LATENT",),
|
||||
"any_input": (any, {}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("LATENT",)
|
||||
RETURN_TYPES = (any,)
|
||||
FUNCTION = "dummy"
|
||||
CATEGORY = "KJNodes/misc"
|
||||
OUTPUT_NODE = True
|
||||
@ -769,8 +769,8 @@ Does nothing, used to trigger generic workflow output.
|
||||
A way to get previews in the UI without saving anything to disk.
|
||||
"""
|
||||
|
||||
def dummy(self, latent):
|
||||
return (latent,)
|
||||
def dummy(self, any_input):
|
||||
return (any_input,)
|
||||
|
||||
class FlipSigmasAdjusted:
|
||||
@classmethod
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user