报错only integer scalar arrays can be converted to a scalar index
color = colors[class_id]
修改为
color = np.array(colors)[class_id]
参考成功解决TypeError: only integer scalar arrays can be converted to a scalar index - 简书
报错Scalar value for argument 'color' is not numeric
颜色值不对
报错代码
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 3)
修改:在使用前转换一下,添加一句
color = tuple([int(x) for x in color]) # 设置为整数
参考Scalar value for argument ‘color‘ is not numeric错误处理_superdont的技术博客_51CTO博客
文章讲述了在使用OpenCV时遇到的两个错误:onlyintegerscalararrayscanbeconvertedtoascalarindex和Scalarvalueforargumentcolorisnotnumeric。解决方案分别是在引用颜色数组时用np.array转换,并在使用颜色值前将其转换为整数。
6835

被折叠的 条评论
为什么被折叠?



