Skip to main content

图像选点与可缩放平移视图组件(PySide6),支持连线模式与撤销/重做;与 D05 lidar-manager 选点 API 配合。ZoomPanLabel、ImagePickerWindow、PickerSession,高内聚低耦合。

Project description

mini-image-picker

版本:v0.0.7

图像选点与可缩放平移视图组件(PySide6),高内聚低耦合。提供主窗口用 ZoomPanLabel、弹窗 ImagePickerWindowPickerSession 状态与结果封装;可与 D05 lidar-manager 的图像更新与颜色过滤配合使用。v0.0.7 新增:标记样式编辑器中文化、center_point.center_type 中心样式(空心/实心),以及 paint_img_marker(..., target_rect=...) 目标区域绘制。

安装

pip install mini-image-picker

依赖

  • Python >= 3.10
  • numpy, opencv-python, PySide6

功能

  • ZoomPanLabel:主窗口可缩放平移图像视图;set_pixmap(pixmap, keep_view_state=True) 更新图像并保留缩放/平移;map_to_image_coord(pos) 将 label 坐标转为图像像素坐标(选 3D 点、颜色过滤取像素等)。视图状态get_view_state() 返回 zoom_factorpan_offset_xpan_offset_yset_view_state(...) 恢复视图,便于保存/恢复而不依赖私有属性。多次选择只保留最后一次:仅维护一个活动点,点击即覆盖。配置 zoom_pan_label.draw_confirmed_while_active=False 时,有活动点只绘制活动点(只显示当前一个);可编程调用 set_active_point(coord) / set_active_point(None) 设置或清除活动点(如主窗口 3D 选点待确认十字)。
  • ImagePickerWindow:弹窗内图像选点(左键选点、微调、Enter 确认),仅维护一个待定点,再次点击/微调即覆盖,多次选择只保留最后一次;缩放/平移/十字准星/标记等由 config 配置。
  • PickerSession:持有 ImagePickerWindow,提供 get_state()get_result()get_summary() 及信号 points_changedsession_finished,避免与主程序状态冲突。v0.0.6:支持 undo()/redo()/can_undo()/can_redo() 透传;get_result() 在 line 模式下返回点对列表(List[LinePair])。
  • 连线模式(v0.0.6):config 中 mode: "line" 时,第一次点击为源点(src),第二次为目标点(dst),形成点对;绘制红 src、红虚线、绿 dst+编号。Esc 取消当前待定 src;Ctrl+Enter 最终确认。记号样式line_mode_marker_style 默认为 "default"(hujing 样式:纯红/纯绿、笔宽 3、drawPoint、编号偏移 5,5);可选 "classic"(十字+椭圆)。可通过 config 或运行时 set_line_marker_style("default"|"classic") 调整。
  • 撤销/重做(v0.0.6):Ctrl+Z 撤销、Ctrl+Y 或 Ctrl+Shift+Z 重做;session.undo()/session.redo() 或直接调用窗口的 undo()/redo()
  • 两种选点方式主窗口选点label.set_pick_mode(True) 后,在 ZoomPanLabel 上左键点击累计选点,通过 label.get_picked_points() 获取、label.clear_picked_points() 清空,并连接信号 point_picked(coord)弹窗选点:通过 PickerSession 打开 ImagePickerWindow,选点结束后用 session.get_result() 获取。两套点列表独立,可分别获取。
  • 光标样式:config 中 cursor_style 可配置十字、中心点、外轮廓、文字四组件(有/无、大小、颜色、粗细、线型等)。弹窗选点时会按该配置绘制跟随光标。CursorShowcaseWindow 提供 4×5 种预设样式展示;CursorStyleEditorDialog 为单独 UI,可自定义光标样式并实时预览。
  • 标记样式编辑器(v0.0.7):界面选项全部使用中文显示,包括交叉样式、外框样式、文字位置、中心样式、线条样式;内部 YAML 键名保持兼容。新增 center_point.center_type,支持 solid / hollowpaint_img_marker(..., target_rect=QRectF(...)) 可用同一套样式绘制选中区域:solidcenter_point.color 填充目标区域,hollow 只画外框,外框形状/线型/粗细由 outer_contour 控制。
  • Configget_default_config() 返回全部可配置项默认值;初始化时传入 config=my_config 覆盖部分项即可。
  • 坐标映射:包已导出 map_label_pos_to_image_coord(pos, pixmap, zoom, pan_offset, label_size),供无 label 实例时做坐标换算(如自定义控件、测试)。
  • 选点解析为最近 lidar 2D 点(v0.0.4):当传入 projection_mgr(D05 ProjectionManager,需已执行 project_points)时,左键选点会先查该像素是否有投影点;若无则用 find_nearest_point 在邻域内取最近的真实 lidar 投影 2D 点,再进入微调/确认。邻域半径由 config 中 lidar_pick.nearest_point_search_radius 控制(默认 15 像素)。弹窗 ImagePickerWindow 通过构造参数 projection_mgr 传入;主窗口 ZoomPanLabel 可通过构造参数 projection_mgrset_projection_mgr(proj_mgr) 传入。包已导出 resolve_click_to_lidar_2d(projection_mgr, px, py, search_radius) 供外部按像素解析。

与 D05 lidar-manager 的配合

  • 图像更新:主程序用 ProjectionManager 的 project_points + render_to_image 得到渲染图,转为 QPixmap 后调用 label.set_pixmap(pixmap, keep_view_state=True) 更新到 ZoomPanLabel;每次刷新均应使用 keep_view_state=True,避免视图跳动。
  • 颜色过滤:主程序在颜色过滤模式下临时接管 label 的点击(如替换 mousePressEvent),用 D07 的 map_to_image_coord(pos) 得到像素坐标再交给 lidar-manager;进入颜色过滤前若在 PnP 选点则 suspend_picking(),退出后 resume_picking(),保证互斥。

快速开始

from PySide6 import QtWidgets
from mini_image_picker import ZoomPanLabel, ImagePickerWindow, PickerSession, get_default_config, get_default_cursor_style, CursorShowcaseWindow, CursorStyleEditorDialog
import numpy as np

app = QtWidgets.QApplication([])

# 主窗口用视图(与 D05 渲染结果配合)
label = ZoomPanLabel(config=get_default_config())
label.set_pixmap(qt_pixmap, keep_view_state=True)
# 点击时取图像坐标: xy = label.map_to_image_coord(event.pos())

# 弹窗选点
image_bgr = np.zeros((1080, 1920, 3), dtype=np.uint8)
session = PickerSession(image_bgr, config=get_default_config())
session.points_changed.connect(lambda: print("points:", session.get_result()))
session.session_finished.connect(app.quit)
session.show()
app.exec()
print("result:", session.get_result())

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mini_image_picker-0.0.7.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mini_image_picker-0.0.7-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

Details for the file mini_image_picker-0.0.7.tar.gz.

File metadata

  • Download URL: mini_image_picker-0.0.7.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mini_image_picker-0.0.7.tar.gz
Algorithm Hash digest
SHA256 241df1033a6b378fa2987451e10031365434ffefd5051358c6d6808679594be5
MD5 f1412a10e8d8a74c20b89d233c14afa0
BLAKE2b-256 bd128c964473762597e9919ce4e8e404931cf96fea8199fab768f8e44f0fa406

See more details on using hashes here.

File details

Details for the file mini_image_picker-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for mini_image_picker-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 47863204ebbeb6018fd5be0b1be12b91b54f8b620a212592836d1c1213d20616
MD5 856d9b562cc8d5ac21d52050587eb376
BLAKE2b-256 fd650504749e50721d48d577950679d45ae092019abc21bf36c04c19a92c1736

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page