Skip to content

Commit b7f2066

Browse files
committed
dev: add vision exam to alpha
1 parent b57aed3 commit b7f2066

File tree

18 files changed

+486
-1
lines changed

18 files changed

+486
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

examples/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 关于 Examples
2+
3+
本目录用来存放各种 Alpha 版本的测试用例. 用来展示不同的基线功能.
4+
每个子目录内都有 README.md 提示如何使用.
5+
6+
> 建议使用 mac, 基线都是在 mac 上测试的. windows 可能兼容存在问题.
7+
8+
使用 examples 的步骤:
9+
10+
## 1. clone 仓库
11+
12+
```bash
13+
git clone https://github.com/GhostInShells/MOSShell MOSShell
14+
cd MOSShell
15+
```
16+
17+
## 2. 创建环境
18+
19+
* 使用 `uv` 创建环境, 运行 `uv venv` . 由于依赖 live2d, 所以默认的 python 版本是 3.12
20+
* 进入 uv 的环境: `source .venv/bin/activate`
21+
* 安装所有依赖:
22+
23+
```bash
24+
uv sync --active --all-extras
25+
```
26+
27+
## 3. 配置环境变量
28+
29+
todo
30+
31+
## 4. 运行个别例子或全部
32+
33+
todo

examples/vision_exam/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ZMQ Transport
2+
3+
用来验证 Channel 通过 provider->broker 范式进行跨进程通讯, 并且能同步上下文.
4+
5+
测试方式:
6+
7+
1. 确保已经运行 `uv sync --active --all-extras` 完成依赖同步.
8+
2. 确认 python 在 uv 的 venv 环境: `which python`
9+
3. 直接运行 vision_provider: `python ./examples/vision_exam/vision_provider.py`
10+
* 这会启动 vision channel 的 provider 进程, 监听 5557 端口允许被访问.
11+
* 会打开一个 opencv 的端口, 可以看到视觉信息.
12+
4. 运行 vision_proxy: `python ./examples/vision_exam/vision_proxy.py`
13+
* 会与 vision provider 建立双工通讯, 可以控制对方.
14+
* 打开一个 pyqt6 的 simple viewer, 周期性同步 vision channel 的信息.
15+
16+
当 vision provider 的视觉消息同步给了 vision proxy, 能正确展示图片, 则测试成功.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from ghoshell_moss_contrib.channels.opencv_vision import OpenCVVision
2+
from ghoshell_moss import get_container
3+
from ghoshell_moss.transports.zmq_channel import ZMQChannelProvider
4+
5+
if __name__ == "__main__":
6+
# 初始化容器
7+
_container = get_container()
8+
9+
# 创建视觉模块
10+
vision = OpenCVVision(_container)
11+
12+
# 创建ZMQ Channel Provider
13+
provider = ZMQChannelProvider(
14+
address="tcp://localhost:5557",
15+
container=_container,
16+
)
17+
18+
try:
19+
# 将视觉模块包装为Channel并运行
20+
channel = vision.as_channel()
21+
provider.run_in_thread(channel)
22+
23+
# 启动视觉捕获循环(会阻塞)
24+
vision.run_opencv_loop()
25+
26+
finally:
27+
# 确保清理顺序正确
28+
vision.close()
29+
provider.close()
30+
provider.wait_closed_sync()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import asyncio
2+
3+
from ghoshell_moss.transports.zmq_channel.zmq_channel import ZMQChannelProxy
4+
from ghoshell_moss_contrib.gui.image_viewer import SimpleImageViewer, run_img_viewer
5+
from ghoshell_moss.message.contents import Base64Image
6+
7+
if __name__ == '__main__':
8+
# 测试专用.
9+
proxy = ZMQChannelProxy(
10+
name="vision",
11+
address="tcp://127.0.0.1:5557",
12+
)
13+
14+
15+
def callback(viewer: SimpleImageViewer):
16+
17+
async def main():
18+
async with proxy.bootstrap() as broker:
19+
await broker.wait_connected()
20+
while True:
21+
await asyncio.sleep(2)
22+
if not proxy.is_running():
23+
continue
24+
await proxy.broker.refresh_meta()
25+
meta = proxy.broker.meta()
26+
for msg in meta.context:
27+
for ct in msg.contents:
28+
if i := Base64Image.from_content(ct):
29+
viewer.set_pil_image(i.to_pil_image())
30+
31+
asyncio.run(main())
32+
33+
34+
run_img_viewer(callback)

examples/zmq_transport/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ contrib = [
3232
"python-mpv-jsonipc>=1.2.1",
3333
"rich>=14.2.0",
3434
"javascript>=1!1.2.6",
35+
"opencv-python>=4.13.0.92",
3536
]
3637

3738
[tool.setuptools]
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)