在训练口罩模型时直接使用鼻子以上的图片进行训练,对数据进行裁剪
import cv2
import tensorflow as tf
import matplotlib.pyplot as plt
import os
os.chdir(r'E:\centernet_data\COCO_dataset\val2017')
bear = cv2.imread('000000000285.jpg')
# 根据小图像的大小,在大图像上创建感兴趣区域roi(放置位置任意取)
height, width = bear.shape[:2] #获取bear的高度、宽度
print(height, width)
cv2.imshow('img0',bear)
cv2.waitKey (0)
#plt.imshow(bear)
sess = tf.Session()
bear1 = sess.run(tf.image.crop_to_bounding_box(
bear,
0,
0,
320,
586
))
#bear1 = tf.cast(bear1, tf.float32)
height, width = bear1.shape[:2]
print(height, width)
cv2.imshow('img',bear1)
cv2.waitKey (0)
cv2.destroyAllWindows()
效果: