在做项目的过程中,标记数据是记录每个 bounding box 的左上角和右下角坐标。因为用到了数据增强,所以我有了一个疑虑:
将标记数据翻转后输入 cv2.rectangle
,此时输入格式已不再是 cv2.rectangle(image, 左上角坐标, 右下角坐标, color)
,而是变成了诸如 cv2.rectangle(image, 左下角坐标, 右上角坐标, color)
之类的,那么矩形框还能正常画么?cv2.rectangle
是通过 确定对角线 来画矩形的么?
no flip:
vertical flip:
horizontal flip:
h & v flip:
cv2.rectangle
确实是靠 确定对角线 来画矩形的。附上自己写的实验代码:
# 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)