Skip to main content

图像选点与可缩放平移视图组件(PySide6),与 D05 lidar-manager 选点 API 配合;选点时可优先解析为最近真实 lidar 投影 2D 点(find_nearest_point)。ZoomPanLabel、ImagePickerWindow、PickerSession,高内聚低耦合。

Project description

mini-image-picker

版本:v0.0.4

图像选点与可缩放平移视图组件(PySide6),高内聚低耦合。提供主窗口用 ZoomPanLabel、弹窗 ImagePickerWindowPickerSession 状态与结果封装;可与 D05 lidar-manager 的图像更新与颜色过滤配合使用。v0.0.4 新增:选点时若未刚好点中 lidar 投影点,会优先用 find_nearest_point 解析为最近的真实 lidar 投影 2D 点。

安装

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,避免与主程序状态冲突。
  • 两种选点方式主窗口选点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,可自定义光标样式并实时预览。
  • 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.4.tar.gz (29.5 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.4-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_image_picker-0.0.4.tar.gz
  • Upload date:
  • Size: 29.5 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.4.tar.gz
Algorithm Hash digest
SHA256 74eea000883281d7c94a1db02c9d11eb16816a14ac3270a9edd0f78e45a49a8b
MD5 07dd9c88eb7bb80e0e2552b2ef8a386d
BLAKE2b-256 a310732a2790074e95b3c3bee2e8baa929281a8b5ce2f44c4484ec9d3f238733

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mini_image_picker-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fb2e8ccf848a3b8216504780fc8dd2ea75669b252688238b10838d5c6afb2d20
MD5 277102abb2cf9425000513190625b3c8
BLAKE2b-256 6fa268ef7fc4a6a0fd37cba601d260829f2c2d3b5875117e03a6a1c52c952a6d

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