ImageDraw.rounded_rectangle(xy, radius=0, fill=None, outline=None, width=1) 该方法可以画一个圆角矩形 xy--> 在两个坐标点之间画一条直线,坐标点的传入方式是[(x, y), (x, y), ...]或者[x, y, x, y, ...] radius--> 角的半径 outline--> 轮廓的颜色 fill--> 填充的颜色 width-->...
draw.text(position, text, fill=text_color, font=font) # 绘制形状 shape_color = (255, 0, 0) # 红色 rectangle_coordinates = [100, 100, 200, 200] # xywh格式表示矩形位置及大小 draw.rectangle(rectangle_coordinates, outline=shape_color) # 保存图像到文件 output_path = "generated_image.png"...
使用Pillow的ImageDraw模块在图片上绘制矩形边界框: # 创建绘图对象 draw = ImageDraw.Draw(image) 定义边界框的左上角和右下角坐标 start_point = (50, 50) end_point = (200, 200) 定义边界框的颜色 color = (255, 0, 0) 在图片上绘制矩形边界框 draw.rectangle([start_point, end_point], outline...
draw.text((50, 250), "Hello, Pillow!", fill="blue", font=font) # 保存绘制后的图像 image.save("drawn.png") 在这个示例中,ImageDraw.Draw() 方法用于创建一个绘图对象,draw.rectangle() 方法用于绘制矩形,draw.text() 方法用于添加文本。 四、实际应用案例 批量处理图像 Pillow 可以用于批量处理图像...
1、安装Pillow库 首先,需要安装Pillow库。可以通过pip进行安装: pip install Pillow 2、读取图片 使用Image.open()函数读取图片: from PIL import Image, ImageDraw 读取图片 image = Image.open('path_to_your_image.jpg') 3、定义边界框 边界框用左上角和右下角的坐标来定义: ...
draw.rectangle([50, 50, 350, 250], outline='blue', width=2) draw.ellipse([100, 100, 300, 200], fill='red') # 添加文字 font = ImageFont.truetype('arial.ttf', 36) draw.text((150, 120), 'Hello Pillow!', font=font, fill='white') ...
最后,我们可以使用Pillow的ImageDraw模块来在图像上绘制各种形状,例如圆,矩形,多边形,以及文本: from PIL import ImageDraw # 创建一个ImageDraw对象 draw = ImageDraw.Draw(img) # 绘制一个矩形 draw.rectangle((100, 100, 200, 200), fill='red') ...
中文文档: https://www.osgeo.cn/pillow/ 1.2 安装 $ pip install --upgrade Pillow 1.3 常用子模块 Pillow模块中有很多子模块,常用的子模块有: Image: 该模块是Pillow中最重要的模块之一,用于处理图像文件。它提供了打开、保存、调整大小、旋转、裁剪、滤镜等功能,是图像处理的核心。 ImageDraw: 该模块提供了...
draw.text((x, y), char, font=font, fill=random.choice(rgb_list))# 添加随机粗点foriinrange(50): x = random.randint(0, width -1) y = random.randint(0, height -1) draw.rectangle([(x, y), (x +1, y +1)], fill=random.choice(rgb_list))# 添加随机线条foriinrange(5): ...
draw.rectangle((100, 100, 300, 300), outline="red", width=2) # 保存编辑后的截图 screenshot.save("edited_screenshot.png") 这段代码使用了Pillow的ImageDraw模块,在截图上绘制了一个红色的矩形框,并保存了编辑后的截图。 现在,我们已经实现了截图和简单编辑功能,接下来的问题是如何自动提交监控到的数据...