Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
712 changes: 712 additions & 0 deletions unilabos/devices/cameraSII/cameraDriver.py

Large diffs are not rendered by default.

401 changes: 401 additions & 0 deletions unilabos/devices/cameraSII/cameraUSB.py

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions unilabos/devices/cameraSII/cameraUSB_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
import time
import json

from cameraUSB import CameraController


def main():
# 按你的实际情况改
cfg = dict(
host_id="demo-host",
signal_backend_url="wss://sciol.ac.cn/api/realtime/signal/host",
rtmp_url="rtmp://srs.sciol.ac.cn:4499/live/camera-01",
webrtc_api="https://srs.sciol.ac.cn/rtc/v1/play/",
webrtc_stream_url="webrtc://srs.sciol.ac.cn:4500/live/camera-01",
video_device="/dev/video7",
width=1280,
height=720,
fps=30,
video_bitrate="1500k",
audio_device=None,
)

c = CameraController(**cfg)

# 可选:如果你不想依赖 __init__ 自动 start,可以这样显式调用:
# c = CameraController(host_id=cfg["host_id"])
# c.start(cfg)

run_seconds = 30 # 测试运行时长
t0 = time.time()

try:
while True:
st = c.get_status()
print(json.dumps(st, ensure_ascii=False, indent=2))

if time.time() - t0 >= run_seconds:
break

time.sleep(2)
except KeyboardInterrupt:
print("Interrupted, stopping...")
finally:
print("Stopping controller...")
c.stop()
print("Done.")


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions unilabos/devices/cameraSII/demo_camera_pic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import cv2

# 推荐把 @ 进行 URL 编码:@ -> %40
RTSP_URL = "rtsp://admin:admin123@192.168.31.164:554/stream1"
OUTPUT_IMAGE = "rtsp_test_frame.jpg"

def main():
print(f"尝试连接 RTSP 流: {RTSP_URL}")
cap = cv2.VideoCapture(RTSP_URL)

if not cap.isOpened():
print("错误:无法打开 RTSP 流,请检查:")
print(" 1. IP/端口是否正确")
print(" 2. 账号密码(尤其是 @ 是否已转成 %40)是否正确")
print(" 3. 摄像头是否允许当前主机访问(同一网段、防火墙等)")
return

print("连接成功,开始读取一帧...")
ret, frame = cap.read()

if not ret or frame is None:
print("错误:已连接但未能读取到帧数据(可能是码流未开启或网络抖动)")
cap.release()
return

# 保存当前帧
success = cv2.imwrite(OUTPUT_IMAGE, frame)
cap.release()

if success:
print(f"成功截取一帧并保存为: {OUTPUT_IMAGE}")
else:
print("错误:写入图片失败,请检查磁盘权限/路径")

if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions unilabos/devices/cameraSII/demo_camera_push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# run_camera_push.py
import time
from cameraDriver import CameraController # 这里根据你的文件名调整

if __name__ == "__main__":
controller = CameraController(
host_id="demo-host",
signal_backend_url="wss://sciol.ac.cn/api/realtime/signal/host",
rtmp_url="rtmp://srs.sciol.ac.cn:4499/live/camera-01",
webrtc_api="https://srs.sciol.ac.cn/rtc/v1/play/",
webrtc_stream_url="webrtc://srs.sciol.ac.cn:4500/live/camera-01",
camera_rtsp_url="rtsp://admin:admin123@192.168.31.164:554/stream1",
)

try:
while True:
status = controller.get_status()
print(status)
time.sleep(5)
except KeyboardInterrupt:
controller.stop()
78 changes: 78 additions & 0 deletions unilabos/devices/cameraSII/ptz_cameracontroller_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
使用 CameraController 来测试 PTZ:
让摄像头按顺序向下、向上、向左、向右运动几次。
"""

import time
import sys

# 根据你的工程结构修改导入路径:
# 假设 CameraController 定义在 cameraController.py 里
from cameraDriver import CameraController


def main():
# === 根据你的实际情况填 IP、端口、账号密码 ===
ptz_host = "192.168.31.164"
ptz_port = 2020 # 注意要和你单独测试 PTZController 时保持一致
ptz_user = "admin"
ptz_password = "admin123"

# 1. 创建 CameraController 实例
cam = CameraController(
# 其他摄像机相关参数按你类的 __init__ 来补充
ptz_host=ptz_host,
ptz_port=ptz_port,
ptz_user=ptz_user,
ptz_password=ptz_password,
)

# 2. 启动 / 初始化(如果你的 CameraController 有 start(config) 之类的接口)
# 这里给一个最小的 config,重点是 PTZ 相关字段
config = {
"ptz_host": ptz_host,
"ptz_port": ptz_port,
"ptz_user": ptz_user,
"ptz_password": ptz_password,
}

try:
cam.start(config)
except Exception as e:
print(f"[TEST] CameraController start() 失败: {e}", file=sys.stderr)
return

# 这里可以判断一下内部 _ptz 是否初始化成功(如果你对 CameraController 做了封装)
if getattr(cam, "_ptz", None) is None:
print("[TEST] CameraController 内部 PTZ 未初始化成功,请检查 ptz_host/port/user/password 配置。", file=sys.stderr)
return

# 3. 依次调用 CameraController 的 PTZ 方法
# 这里假设你在 CameraController 中提供了这几个对外方法:
# ptz_move_down / ptz_move_up / ptz_move_left / ptz_move_right
# 如果你命名不一样,把下面调用名改成你的即可。

print("向下移动(通过 CameraController)...")
cam.ptz_move_down(speed=0.5, duration=1.0)
time.sleep(1)

print("向上移动(通过 CameraController)...")
cam.ptz_move_up(speed=0.5, duration=1.0)
time.sleep(1)

print("向左移动(通过 CameraController)...")
cam.ptz_move_left(speed=0.5, duration=1.0)
time.sleep(1)

print("向右移动(通过 CameraController)...")
cam.ptz_move_right(speed=0.5, duration=1.0)
time.sleep(1)

print("测试结束。")


if __name__ == "__main__":
main()
50 changes: 50 additions & 0 deletions unilabos/devices/cameraSII/ptz_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
测试 cameraDriver.py中的 PTZController 类,让摄像头按顺序运动几次
"""

import time

from cameraDriver import PTZController


def main():
# 根据你的实际情况填 IP、端口、账号密码
host = "192.168.31.164"
port = 80
user = "admin"
password = "admin123"

ptz = PTZController(host=host, port=port, user=user, password=password)

# 1. 连接摄像头
if not ptz.connect():
print("连接 PTZ 失败,检查 IP/用户名/密码/端口。")
return

# 2. 依次测试几个动作
# 每个动作之间 sleep 一下方便观察

print("向下移动...")
ptz.move_down(speed=0.5, duration=1.0)
time.sleep(1)

print("向上移动...")
ptz.move_up(speed=0.5, duration=1.0)
time.sleep(1)

print("向左移动...")
ptz.move_left(speed=0.5, duration=1.0)
time.sleep(1)

print("向右移动...")
ptz.move_right(speed=0.5, duration=1.0)
time.sleep(1)

print("测试结束。")


if __name__ == "__main__":
main()
105 changes: 105 additions & 0 deletions unilabos/registry/devices/cameraSII.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
cameracontroller_device:
category:
- cameraSII
class:
action_value_mappings:
auto-start:
feedback: {}
goal: {}
goal_default:
config: null
handles: {}
result: {}
schema:
description: ''
properties:
feedback: {}
goal:
properties:
config:
type: string
required: []
type: object
result: {}
required:
- goal
title: start参数
type: object
type: UniLabJsonCommand
auto-stop:
feedback: {}
goal: {}
goal_default: {}
handles: {}
result: {}
schema:
description: ''
properties:
feedback: {}
goal:
properties: {}
required: []
type: object
result: {}
required:
- goal
title: stop参数
type: object
type: UniLabJsonCommand
module: unilabos.devices.cameraSII.cameraUSB:CameraController
status_types:
status: dict
type: python
config_info: []
description: Uni-Lab-OS 摄像头驱动(Linux USB 摄像头版,无 PTZ)
handles: []
icon: ''
init_param_schema:
config:
properties:
audio_bitrate:
default: 64k
type: string
audio_device:
type: string
fps:
default: 30
type: integer
height:
default: 720
type: integer
host_id:
default: demo-host
type: string
rtmp_url:
default: rtmp://srs.sciol.ac.cn:4499/live/camera-01
type: string
signal_backend_url:
default: wss://sciol.ac.cn/api/realtime/signal/host
type: string
video_bitrate:
default: 1500k
type: string
video_device:
default: /dev/video0
type: string
webrtc_api:
default: https://srs.sciol.ac.cn/rtc/v1/play/
type: string
webrtc_stream_url:
default: webrtc://srs.sciol.ac.cn:4500/live/camera-01
type: string
width:
default: 1280
type: integer
required: []
type: object
data:
properties:
status:
type: object
required:
- status
type: object
registry_type: device
version: 1.0.0
Loading