海康工业相机报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
相关推荐
A_nanda6 天前
学习工业相机的大纲
学习·工业相机
格林威9 天前
C# 图像使用AVX2指令集:使用OpenCvSharp实现字节图像解压缩速度和map_image算子速度提升
开发语言·图像处理·人工智能·计算机视觉·c#·视觉检测·工业相机
成都佳洋光电科技有限公司11 天前
【综述】主要红外探测器材料综合特性对比及未来发展趋势
工业相机·工业镜头·短波红外·红外热像仪·红外探测器
成都佳洋光电科技有限公司11 天前
【综述】如何选择不同波段的红外相机以及它们的区别?
工业相机·工业镜头·短波红外·红外热像仪
格林威12 天前
C# 相机图像阴影校正:使用OpenCvSharp实现工业相机阴影平场校正功能
人工智能·数码相机·opencv·计算机视觉·c#·机器视觉·工业相机
成都佳洋光电科技有限公司15 天前
一文了解机器视觉检测精度分析
视觉检测·工业相机·短波红外·红外热像仪
成都佳洋光电科技有限公司15 天前
短波红外相机在穿透烟、雾、霾中的应用
人工智能·工业相机·工业镜头·短波红外·红外热像仪
成都佳洋光电科技有限公司15 天前
【干货】机器视觉光学基础—放大率 ,视场角
工业相机·工业镜头·短波红外·红外热像仪·放大率和视场角
格林威18 天前
C# 相机Burst模式图像采集:使用相机内存配合OpenCvSharp和Halcon实现短时间的高速采集的方法
开发语言·人工智能·数码相机·计算机视觉·c#·视觉检测·工业相机
成都佳洋光电科技有限公司19 天前
一文了解位移传感器
工业相机·工业镜头·短波红外·位移传感器·光电知识