东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 3737|回复: 1

[学习笔记] 036、imgaug图像增强之Bounding Boxes变换

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14429
QQ
发表于 2020-1-13 17:33:50 | 显示全部楼层 |阅读模式
036、imgaug图像增强之Bounding Boxes变换


  1. import imgaug as ia
  2. import imgaug.augmenters as iaa
  3. import numpy as np
  4. import imageio

  5. print(ia.__version__)

  6. img_path = 'dfy_imgs/ai111.jpg'
  7. image = imageio.imread(img_path)
  8. print(type(image), image.shape)
  9. ia.seed(666)


  10. # 定义2个bounding box
  11. bbs = ia.BoundingBoxesOnImage([
  12.     ia.BoundingBox(x1=65, y1=100, x2=200, y2=150),
  13.     ia.BoundingBox(x1=150, y1=80, x2=200, y2=130)
  14. ], shape=image.shape)

  15. seq = iaa.Sequential([
  16.     iaa.Multiply((1.2, 1.5)),   # 改变亮度, 不影响bounding box
  17.     iaa.Affine(translate_px={"x": 40, "y": 60}, scale=0.8)   # 平移后缩放,会影响bounding box
  18. ])

  19. # 固定变换
  20. seq_det = seq.to_deterministic()

  21. # 变换图像和bounding box
  22. image_aug = seq_det.augment_images([image])[0]
  23. bbs_aug = seq_det.augment_bounding_boxes([bbs])[0]

  24. # 打印坐标
  25. # use .x1_int, .y_int, ... to get integer coordinates
  26. for i in range(len(bbs.bounding_boxes)):
  27.     before = bbs.bounding_boxes[i]
  28.     after = bbs_aug.bounding_boxes[i]
  29.     print("BB %d: (%.4f, %.4f, %.4f, %.4f) -> (%.4f, %.4f, %.4f, %.4f)" % (
  30.         i,
  31.         before.x1, before.y1, before.x2, before.y2,
  32.         after.x1, after.y1, after.x2, after.y2)
  33.     )

  34. # image with BBs before/after augmentation (shown below)
  35. image_before = bbs.draw_on_image(image, size=2)
  36. image_after = bbs_aug.draw_on_image(image_aug, size=2, color=[0, 0, 255])

  37. ia.imshow(np.hstack([image_before, image_after]))

复制代码


Bounding Boxes变换.jpg
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

0

主题

117

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
QQ
发表于 2020-2-3 15:21:03 | 显示全部楼层
谢谢老师答疑解惑
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-4-19 07:29 , Processed in 0.179233 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表