首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >opencv: cv2.rectangle 通过确定对角线 画矩形

opencv: cv2.rectangle 通过确定对角线 画矩形

作者头像
JNingWei
发布2018-09-27 16:05:57
2.4K0
发布2018-09-27 16:05:57
举报

疑问

在做项目的过程中,标记数据是记录每个 bounding box 的左上角和右下角坐标。因为用到了数据增强,所以我有了一个疑虑:

将标记数据翻转后输入 cv2.rectangle ,此时输入格式已不再是 cv2.rectangle(image, 左上角坐标, 右下角坐标, color) ,而是变成了诸如 cv2.rectangle(image, 左下角坐标, 右上角坐标, color) 之类的,那么矩形框还能正常画么?cv2.rectangle 是通过 确定对角线 来画矩形的么?

Demo

no flip:

这里写图片描述
这里写图片描述

vertical flip:

这里写图片描述
这里写图片描述

horizontal flip:

这里写图片描述
这里写图片描述

h & v flip:

这里写图片描述
这里写图片描述

经验证:

  • cv2.rectangle 确实是靠 确定对角线 来画矩形的。

Code

附上自己写的实验代码:

# encoding:utf-8

import cv2
image = cv2.imread("girl.jpg")
h, w = image.shape[:2]
h, w = map(int, [h/4, w/4])

# no flip
draw_0 = cv2.rectangle(image, (2*w, 2*h), (3*w, 3*h), (255, 0, 0), 2)
# vertical flip
draw_1 = cv2.rectangle(image, (2*w, 3*h), (3*w, 2*h), (255, 0, 0), 2)
# horizontal flip
draw_2 = cv2.rectangle(image, (3*w, 2*h), (2*w, 3*h), (255, 0, 0), 2)
# h & v flip
draw_3 = cv2.rectangle(image, (3*w, 3*h), (2*w, 2*h), (255, 0, 0), 2)

cv2.imwrite("origin.jpg", draw_0)
cv2.imwrite("vertical_flip.jpg", draw_1)
cv2.imwrite("horizontal_flip.jpg", draw_2)
cv2.imwrite("hv_flip.jpg", draw_3)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年12月09日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 疑问
  • Demo
    • 经验证:
    • Code
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档