图像拼图检测
更新时间:2026-07-29
简介
ImageCollageDetect 是拼贴 / 多子图检测算子,通过 OpenCV Canny 边缘 + HoughLinesP 直线检测判断图像是否为拼贴图。
算子参数
输入
| 输入 | 含义 |
|---|---|
| images | 待检测的图像列,取值由 image_src_type 决定(图像 URL / base64 / 二进制) |
输出
| 输出 | 含义 |
|---|---|
| result | bool,True 表示图像为拼贴 / 多子图 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| image_src_type | str | "image_url" | 图像输入类型,可选 image_url / image_binary / image_base64 |
| canny_low | int | 60 | Canny 边缘检测低阈值 |
| canny_high | int | 180 | Canny 边缘检测高阈值 |
| hough_threshold | int | 120 | HoughLinesP 累加器阈值 |
| line_len_ratio | float | 0.5 | 直线最小长度占图像最短边的比例阈值 |
| n_lines_threshold | int | 3 | 满足条件的横线 + 竖线总数阈值,达到该值判为拼贴 |
| fail_on_error | bool | False | 出错时是否抛异常;False 时对应行返回 False |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.image.image_collage_detect import ImageCollageDetect
10
11IMAGE = "bos://your-bucket/sample.jpg" # MOCK
12
13os.environ.setdefault("BOS_ENDPOINT", "http://bj.bcebos.com")
14os.environ.setdefault("BOS_REGION", "bj")
15
16if __name__ == "__main__":
17 if os.getenv("DAFT_RUNNER", "native") == "ray":
18 import ray
19
20 ray.init(ignore_reinit_error=True)
21 daft.set_runner_ray()
22 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
23
24 samples = {"image": [IMAGE]}
25 ds = daft.from_pydict(samples)
26 ds = ds.with_column(
27 "is_collage",
28 aihc_udf(
29 ImageCollageDetect,
30 construct_args={
31 "image_src_type": "image_url",
32 "canny_low": 60,
33 "canny_high": 180,
34 "hough_threshold": 120,
35 "line_len_ratio": 0.5,
36 "n_lines_threshold": 3,
37 },
38 num_cpus=1,
39 concurrency=1,
40 batch_size=1,
41 )(col("image")),
42 )
43 ds.show()
评价此篇文章
