问题1

TypeError: function takes exactly 1 argument (3 given)

报错说PIL库中的函数只接收到一个参数,应该给三个,自己在这里记录下解决方法,出错的地方在yolo.py中,在yolo中在测试时需要对检测到的区域进行画出标记框和类别数字,因为作者测试的coco等图库都是RGB图像,会有三个参数输入给rectangle函数,不会发生报错,而在测试图像为灰度图时,就会出错。在解决错误是参考了参考文献[1]中的提示,很感谢!

对于这个错误原因,个人认为是这个函数在图像上绘制矩形框时,要求输入的图像的颜色空间维度要和矩形框颜色维度一致,比如:我们输入的灰度图(不做维度扩充),只能使用灰度进行画矩形框;输入的是RGB三色图,可以使用RGB颜色画矩形框。

解决方法:

1.对灰度图进行转换,

使用 image = image.convert('RGB')

比如部分yolo.py函数如下:

        for i, c in reversed(list(enumerate(out_classes))):
predicted_class = self.class_names[c]
box = out_boxes[i]
score = out_scores[i] label = '{} {:.2f}'.format(predicted_class, score)
# 对灰度图像进行RGB转换,输入的原图为(0)一维 转为(0,0,0)三维
image = image.convert('RGB')
draw = ImageDraw.Draw(image)
label_size = draw.textsize(label, font) top, left, bottom, right = box
top = max(0, np.floor(top + 0.5).astype('int32'))
left = max(0, np.floor(left + 0.5).astype('int32'))
bottom = min(image.size[1], np.floor(bottom + 0.5).astype('int32'))
right = min(image.size[0], np.floor(right + 0.5).astype('int32'))
print(label, (left, top), (right, bottom)) if top - label_size[1] >= 0:
text_origin = np.array([left, top - label_size[1]])
else:
text_origin = np.array([left, top + 1]) # My kingdom for a good redistributable image drawing library.
for i in range(thickness):
draw.rectangle(
[left + i, top + i, right - i, bottom - i],
outline=self.colors[c])
#outline=(255))
draw.rectangle(
[tuple(text_origin), tuple(text_origin + label_size)],
fill=self.colors[c])
#outline=(255))
#draw.text(text_origin, label, fill=(0, 0, 0), font=font)
draw.text(text_origin, label, fill=(0), font=font)
del draw

最新文章

  1. 【C-数据类型 常量 变量】
  2. 怎样设置Word下次打开时跳转到上次阅读的位置
  3. 12 factor 目录
  4. pandas 修改 DataFrame 列名
  5. Softmax 回归原理介绍
  6. KEIL4.12中添加ULINK2的支持
  7. jquery 项目所用
  8. 秒杀多线程第二篇 多线程第一次亲热接触 CreateThread与_beginthreadex本质差别
  9. DroidPlugin插件化开发
  10. 深入理解 React JS 中的 setState
  11. Python高级特性(一)
  12. hdu4064 三进制状态压缩 好题!
  13. aix 查看内存,CPU 配置信息
  14. 获取当前页面url并截取所需字段
  15. jformdesigner 开发
  16. ~Vue实现简单答题功能,主要包含单选框和复选框
  17. vue 移动端添加 时间日期选择器
  18. 保存csv时, 不保留index
  19. Visual Studio自动添加头部注释
  20. 焦作网络赛E-JiuYuanWantstoEat【树链剖分】【线段树】

热门文章

  1. canvas图片合成中的坑
  2. 求逆序对常用的两种算法 ----归并排 & 树状数组
  3. 阿里云各Linux发行版netcore兼容性评估报告---来自大石头的测试
  4. RedHat 6配置yum源为网易镜像(转)
  5. cmake教程
  6. 清除代码中的svn文件。
  7. vue-cli 构建的项目中 如何使用less
  8. git命令详解( 六 )
  9. 解决:coursera 视频总是缓冲或者无法观看
  10. dbconfig.properties