# 图片中加入遮挡
def make_shelter_picture(photo_path,shelter_path,global_y0,global_x0,height=44,width=44): # 输入原图、遮挡图片路径,输出遮挡处理后的图片
global_x0 = random.randint(15,72) # 遮挡图片左上角定点坐标随机生成
global_y0 = random.randint(15,72)
src_photo = cv2.imread(photo_path)
main_photo_src = cv2.imread(photo_path) # 原图
main_photo = src_photo # 待操作的图
src_height = src_photo.shape[0] #将tuple中的元素取出,赋值给height,width,channels
src_width = src_photo.shape[1]
src_channels = src_photo.shape[2]
shelter_photo = cv2.imread(shelter_path) # 遮挡物
# height = 44 # 调整后遮挡图片的宽、高
# width = 44
shelter_photo = cv2.resize(shelter_photo,(height,width),interpolation=cv2.INTER_AREA) # 为图片重新指定尺寸
# global_x0 = 50 # 遮挡图片左上角的顶点坐标 0~100之间
# global_y0 = 50
if (global_y0+height<src_height) and (global_x0+width<src_width): # 遮挡图片位于原图内
main_photo[global_y0:height+global_y0, global_x0:width+global_x0] = shelter_photo
# 遍历像素 填补空白
for row in range
Python实现在图片中加入遮挡
最新推荐文章于 2023-08-11 16:07:03 发布