海康 GigE Vision 网口工业相机 Python 控制库
使用 Pythonic 风格封装海康网口工业相机 Python SDK, 灵活易用, 方便集成.
▮ 特性 Features
with
语法来调用:
with HikCamera() as cam:
cam["ExposureTime"]=100000
,
print(cam["ExposureTime"])
cams.robust_get_frame()
.dng
格式
diyer22/hik_camera
)
▮ 安装 Install
docker run --net=host -v /tmp:/tmp -it diyer22/hik_camera
pip install hik_camera
$ python -m hik_camera.hik_camera
All camera IP adresses: ['10.101.68.102', '10.101.68.103']
Saveing image to: /tmp/10.101.68.102.jpg
"cam.get_frame" spend time: 0.072249
----------------------------------------
imgs = cams.robust_get_frame()
└── /: dict 2
├── 10.101.68.102: (3036, 4024, 3)uint8
└── 10.101.68.103: (3036, 4024, 3)uint8
"cams.get_frame" spend time: 0.700901
▮ 用法 Usage
图像采集 Demo
python -m hik_camera.collect_img
"空格"
键拍照,
Q
键退出
Python 接口
from hik_camera import HikCamera
ips = HikCamera.get_all_ips()
print("All camera IP adresses:", ips)
ip = ips[0]
cam = HikCamera(ip)
with cam: # 用 with 的上下文的方式来 OpenDevice
cam["ExposureAuto"] = "Off" # 配置参数和海康官方 API 一致
cam["ExposureTime"] = 50000 # 单位 ns
rgb = cam.robust_get_frame() # rgb's shape is np.uint8(h, w, 3)
print("Saveing image to:", cam.save(rgb, ip + ".jpg"))
HikCamera.setting()
的注释
HikCamera
类, 并 override setting 函数来配置相机参数, 例子:
hik_camera/collect_img.py