图像翻转,BoundingBox翻转"/>
数据增强——图像翻转,BoundingBox翻转
数据增强——图像翻转,BoundingBox翻转
- 图像翻转很容易,边界框如何翻转呢?
- 找到一张没有标注的原图,用opecv在原图上把bbox画出来,利用QQ截图的功能,将坐标标出来
- 再把图片进行翻转得到下图
- 两张图进行对比
- 很明显可以观测到
图像翻转很容易,边界框如何翻转呢?
找到一张没有标注的原图,用opecv在原图上把bbox画出来,利用QQ截图的功能,将坐标标出来
代码如下:
import cv2 as cvimg_path = "./test_image/2007_000027.jpg"
img = cv.imread(img_path)
# 画框
cv.rectangle(img, (174, 101), (349, 351), color=(0, 255, 0),thickness=2)
cv.imshow("img", img)
cv.waitKey(0)
cv.destroyAllWindows()
再把图片进行翻转得到下图
代码如下:
import cv2 as cvimg_path = "./test_image/test.png" # qq截图标注后的图片
img = cv.imread(img_path)
# 翻转
flip_img = cv.flip(img, 1)
cv.imshow("flip_img", flip_img)
cv.imwrite("./test_image/flip_img.png", flip_img)
cv.waitKey(0)
cv.destroyAllWindows()
两张图进行对比
很明显可以观测到
新的xmin = 图像的width - 原来的xmax
新的xmax = 图像的width - 原来的xmin
ymin 和 ymax 不变
用代码计算:
# bbox: xmin, ymin, xmax, ymax
new_xmin = width - old_xmax
new_xmax = width - old_xmin
new_ymin = old_ymin
new_xmax = old_ymax
更多推荐
数据增强——图像翻转,BoundingBox翻转
发布评论