海康工业相机报80000102错误

海康工业相机的 ROI 参数(offset 和 width/height)必须满足对齐要求(通常是 4 或 8 的倍数),否则会报错 80000102。

py 复制代码
def align_roi_params(offset_x, offset_y, width, height, max_width, max_height, alignment=4):
    """
    对齐 ROI 参数以满足海康相机要求
    
    海康相机的 ROI 参数通常需要满足对齐要求(4或8的倍数)
    
    Args:
        offset_x, offset_y: ROI 偏移量
        width, height: ROI 尺寸
        max_width, max_height: 相机最大分辨率
        alignment: 对齐字节数(默认4)
    
    Returns:
        (aligned_offset_x, aligned_offset_y, aligned_width, aligned_height)
    """
    # 向下对齐到 alignment 的倍数
    def align_down(value, align):
        return (value // align) * align
    
    # offset 向下对齐(确保不会越界)
    aligned_offset_x = align_down(offset_x, alignment)
    aligned_offset_y = align_down(offset_y, alignment)
    
    # width/height 向下对齐(确保 offset + size 不超过最大值)
    # 先计算可用的最大尺寸
    max_available_width = max_width - aligned_offset_x
    max_available_height = max_height - aligned_offset_y
    
    # 将 width/height 对齐,但不超过可用空间
    aligned_width = min(align_down(width, alignment), align_down(max_available_width, alignment))
    aligned_height = min(align_down(height, alignment), align_down(max_available_height, alignment))
    
    # 确保最小尺寸(至少64像素)
    aligned_width = max(aligned_width, 64)
    aligned_height = max(aligned_height, 64)
    
    print(f"🔧 ROI参数对齐:")
    print(f"   原始: offset=({offset_x}, {offset_y}), size=({width}×{height})")
    print(f"   对齐后: offset=({aligned_offset_x}, {aligned_offset_y}), size=({aligned_width}×{aligned_height})")
    
    return aligned_offset_x, aligned_offset_y, aligned_width, aligned_height
相关推荐
cnbestec21 小时前
工业视觉开发实战:ZED 双目 + 单目相机组合如何解决料箱拣选与高速上下料难题
工业相机·工业自动化·视觉感知·zed相机·stereolabs·zed双目3d相机
weixin_4684668516 天前
工业相机成像原理新手入门指南
人工智能·自动化·机器视觉·工业相机·光学·光学系统·成像原理
weixin_4684668518 天前
基于OpenCV的工业相机标定技术实战
图像处理·人工智能·opencv·计算机视觉·相机标定·机器视觉·工业相机
kyle~20 天前
GigE Vision---GVCP( GigE Vision Control Protocol,GV控制协议)
linux·c++·机器人·工业相机·传感器
【ql君】qlexcel22 天前
工业相机和镜头参数和选型
分辨率·工业相机·镜头·靶面·聚焦·像元尺寸
未来超低端科技研究所1 个月前
大恒工业相机c#开发,NET8跨平台使用(armlinux和x86linux)
linux·c#·工业相机·net8·大恒图像·跨平台开发
51camera1 个月前
从传感器到主机:高分辨率、高吞吐成像的系统架构考量
工业相机
格林威1 个月前
3D相机视觉检测:环境光太强,结构光点云全是噪点怎么办?
开发语言·人工智能·数码相机·计算机视觉·3d·视觉检测·工业相机
格林威1 个月前
线阵工业相机:线阵图像出现“波浪纹”,是机械振动还是编码器问题?
开发语言·人工智能·数码相机·计算机视觉·视觉检测·工业相机·线阵相机
格林威1 个月前
工业视觉检测:单样本学习 vs 传统监督学习
人工智能·深度学习·数码相机·学习·计算机视觉·视觉检测·工业相机