You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中使用OpenCV 4.7生成Charuco板报错求助

解决OpenCV 4.7生成Charuco板的错误问题

你的核心问题是字典初始化方式错误,OpenCV 4.5+版本对ArUco模块的API做了调整,旧版直接通过aruco.Dictionary()构造预定义字典的方法已不再适用,导致你创建的字典bytesList全为0,触发后续断言错误。

正确代码示例

import cv2
from cv2 import aruco

# 用新版API获取预定义字典
dictionary = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)

# 定义Charuco板的内部角点尺寸(示例为7列5行)
chkbrd_width = 7
chkbrd_height = 5

# 创建Charuco板:参数依次为(内部角点尺寸, 方格边长, 标记边长, 字典)
board = aruco.CharucoBoard((chkbrd_width, chkbrd_height), squareLength=6, markerLength=4, dictionary=dictionary)

# 生成Charuco板图像
image = board.generateImage(outSize=(1000, 1000), marginSize=10, borderBits=1)

# 验证结果
cv2.imwrite('charuco_board.png', image)
cv2.imshow('Charuco Board', image)
cv2.waitKey(0)
cv2.destroyAllWindows()

关键说明

  • 必须使用aruco.getPredefinedDictionary()获取官方预定义的字典,直接调用aruco.Dictionary()构造函数仅适用于自定义字典场景。
  • CharucoBoard的参数需注意顺序:squareLength是棋盘方格的边长,markerLength是ArUco标记的边长,两者单位需统一(像素或物理单位均可)。
  • chkbrd_width和chkbrd_height指的是Charuco板内部的角点数量,而非方格数量,需根据实际需求调整。

内容的提问来源于stack exchange,提问作者baca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 19:54:55