mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2026-05-25 01:42:14 +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"},
|
"CustomSigmas": {"class": CustomSigmas, "name": "Custom Sigmas"},
|
||||||
#utility
|
#utility
|
||||||
"WidgetToString": {"class": WidgetToString, "name": "Widget To String"},
|
"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"},
|
"GetLatentsFromBatchIndexed": {"class": GetLatentsFromBatchIndexed, "name": "Get Latents From Batch Indexed"},
|
||||||
"ScaleBatchPromptSchedule": {"class": ScaleBatchPromptSchedule, "name": "Scale Batch Prompt Schedule"},
|
"ScaleBatchPromptSchedule": {"class": ScaleBatchPromptSchedule, "name": "Scale Batch Prompt Schedule"},
|
||||||
"CameraPoseVisualizer": {"class": CameraPoseVisualizer, "name": "Camera Pose Visualizer"},
|
"CameraPoseVisualizer": {"class": CameraPoseVisualizer, "name": "Camera Pose Visualizer"},
|
||||||
|
|||||||
@ -472,7 +472,7 @@ class WebcamCaptureCV2:
|
|||||||
FUNCTION = "capture"
|
FUNCTION = "capture"
|
||||||
CATEGORY = "KJNodes/experimental"
|
CATEGORY = "KJNodes/experimental"
|
||||||
DESCRIPTION = """
|
DESCRIPTION = """
|
||||||
Captures an area specified by screen coordinates.
|
Captures a frame from a webcam using CV2.
|
||||||
Can be used for realtime diffusion with autoqueue.
|
Can be used for realtime diffusion with autoqueue.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -482,41 +482,33 @@ Can be used for realtime diffusion with autoqueue.
|
|||||||
"required": {
|
"required": {
|
||||||
"x": ("INT", {"default": 0,"min": 0, "max": 4096, "step": 1}),
|
"x": ("INT", {"default": 0,"min": 0, "max": 4096, "step": 1}),
|
||||||
"y": ("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}),
|
"width": ("INT", {"default": 512,"min": 0, "max": 4096, "step": 1}),
|
||||||
"height": ("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}),
|
"cam_index": ("INT", {"default": 0,"min": 0, "max": 255, "step": 1}),
|
||||||
"delay": ("FLOAT", {"default": 0.1,"min": 0.0, "max": 10.0, "step": 0.01}),
|
|
||||||
"release": ("BOOLEAN", {"default": False}),
|
"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:
|
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():
|
if not self.cap.isOpened():
|
||||||
raise Exception("Could not open webcam")
|
raise Exception("Could not open webcam")
|
||||||
|
|
||||||
for _ in range(num_frames):
|
ret, frame = self.cap.read()
|
||||||
ret, frame = self.cap.read()
|
if not ret:
|
||||||
if not ret:
|
raise Exception("Failed to capture image from webcam")
|
||||||
raise Exception("Failed to capture image from webcam")
|
|
||||||
|
|
||||||
# Crop the frame to the specified bbox
|
# Crop the frame to the specified bbox
|
||||||
frame = frame[y:y+height, x:x+width]
|
frame = frame[y:y+height, x:x+width]
|
||||||
img_torch = torch.from_numpy(frame[..., [2, 1, 0]]).float() / 255.0
|
img_torch = torch.from_numpy(frame[..., [2, 1, 0]]).float() / 255.0
|
||||||
captures.append(img_torch)
|
|
||||||
|
|
||||||
if num_frames > 1:
|
|
||||||
time.sleep(delay)
|
|
||||||
if release:
|
if release:
|
||||||
self.cap.release()
|
self.cap.release()
|
||||||
self.cap = None
|
self.cap = None
|
||||||
|
|
||||||
return (torch.stack(captures, 0),)
|
return (img_torch.unsqueeze(0),)
|
||||||
|
|
||||||
class AddLabel:
|
class AddLabel:
|
||||||
@classmethod
|
@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}")
|
raise NameError(f"Node not found: {id}")
|
||||||
return (', '.join(results).strip(', '), )
|
return (', '.join(results).strip(', '), )
|
||||||
|
|
||||||
class DummyLatentOut:
|
class DummyOut:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls):
|
def INPUT_TYPES(cls):
|
||||||
return {
|
return {
|
||||||
"required": {
|
"required": {
|
||||||
"latent": ("LATENT",),
|
"any_input": (any, {}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_TYPES = ("LATENT",)
|
RETURN_TYPES = (any,)
|
||||||
FUNCTION = "dummy"
|
FUNCTION = "dummy"
|
||||||
CATEGORY = "KJNodes/misc"
|
CATEGORY = "KJNodes/misc"
|
||||||
OUTPUT_NODE = True
|
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.
|
A way to get previews in the UI without saving anything to disk.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def dummy(self, latent):
|
def dummy(self, any_input):
|
||||||
return (latent,)
|
return (any_input,)
|
||||||
|
|
||||||
class FlipSigmasAdjusted:
|
class FlipSigmasAdjusted:
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user