Apply postprocessing filters in KC test endpoint
The KC test was showing the raw captured image instead of the processed one. Now resolves the filter chain from postprocessing templates and applies them before color extraction, matching live KC processing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ from wled_controller.api.dependencies import (
|
|||||||
get_pattern_template_store,
|
get_pattern_template_store,
|
||||||
get_picture_source_store,
|
get_picture_source_store,
|
||||||
get_picture_target_store,
|
get_picture_target_store,
|
||||||
|
get_pp_template_store,
|
||||||
get_processor_manager,
|
get_processor_manager,
|
||||||
get_template_store,
|
get_template_store,
|
||||||
)
|
)
|
||||||
@@ -34,6 +35,7 @@ from wled_controller.api.schemas.picture_targets import (
|
|||||||
)
|
)
|
||||||
from wled_controller.config import config
|
from wled_controller.config import config
|
||||||
from wled_controller.core.capture_engines import EngineRegistry
|
from wled_controller.core.capture_engines import EngineRegistry
|
||||||
|
from wled_controller.core.filters import FilterRegistry, ImagePool
|
||||||
from wled_controller.core.processor_manager import ProcessorManager, ProcessingSettings
|
from wled_controller.core.processor_manager import ProcessorManager, ProcessingSettings
|
||||||
from wled_controller.core.screen_capture import (
|
from wled_controller.core.screen_capture import (
|
||||||
calculate_average_color,
|
calculate_average_color,
|
||||||
@@ -564,6 +566,7 @@ async def test_kc_target(
|
|||||||
pattern_store: PatternTemplateStore = Depends(get_pattern_template_store),
|
pattern_store: PatternTemplateStore = Depends(get_pattern_template_store),
|
||||||
processor_manager: ProcessorManager = Depends(get_processor_manager),
|
processor_manager: ProcessorManager = Depends(get_processor_manager),
|
||||||
device_store: DeviceStore = Depends(get_device_store),
|
device_store: DeviceStore = Depends(get_device_store),
|
||||||
|
pp_template_store=Depends(get_pp_template_store),
|
||||||
):
|
):
|
||||||
"""Test a key-colors target: capture a frame, extract colors from each rectangle."""
|
"""Test a key-colors target: capture a frame, extract colors from each rectangle."""
|
||||||
import httpx
|
import httpx
|
||||||
@@ -665,6 +668,27 @@ async def test_kc_target(
|
|||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=400, detail="Unsupported picture source type")
|
raise HTTPException(status_code=400, detail="Unsupported picture source type")
|
||||||
|
|
||||||
|
# 3b. Apply postprocessing filters (if the picture source has a filter chain)
|
||||||
|
pp_template_ids = chain.get("postprocessing_template_ids", [])
|
||||||
|
if pp_template_ids and pp_template_store:
|
||||||
|
img_array = np.array(pil_image)
|
||||||
|
image_pool = ImagePool()
|
||||||
|
for pp_id in pp_template_ids:
|
||||||
|
try:
|
||||||
|
pp_template = pp_template_store.get_template(pp_id)
|
||||||
|
except ValueError:
|
||||||
|
logger.warning(f"KC test: PP template {pp_id} not found, skipping")
|
||||||
|
continue
|
||||||
|
for fi in pp_template.filters:
|
||||||
|
try:
|
||||||
|
f = FilterRegistry.create_instance(fi.filter_id, fi.options)
|
||||||
|
result = f.process_image(img_array, image_pool)
|
||||||
|
if result is not None:
|
||||||
|
img_array = result
|
||||||
|
except ValueError:
|
||||||
|
logger.warning(f"KC test: unknown filter '{fi.filter_id}', skipping")
|
||||||
|
pil_image = Image.fromarray(img_array)
|
||||||
|
|
||||||
# 4. Extract colors from each rectangle
|
# 4. Extract colors from each rectangle
|
||||||
img_array = np.array(pil_image)
|
img_array = np.array(pil_image)
|
||||||
h, w = img_array.shape[:2]
|
h, w = img_array.shape[:2]
|
||||||
|
|||||||
Reference in New Issue
Block a user