python写字_python 实现PIL模块在图片画线写字
图片上画线条
import sys
from PIL import Image,ImageDraw
im = Image.open("th.png")
draw = ImageDraw.Draw(im) #实例化一个对象
draw.line((0, 0) + im.size, fill=128, width=5) #线的起点和终点,线宽
draw.line((0, im.size[1], im.size[0], 0), fill=128)
draw.line((0,im.size[1]/2)+(im.size[0]/2,im.size[1]), fill=128, width=5)
im.show()
图片上写字
from PIL import Image, ImageDraw, ImageFont
# get an image
base = Image.open('th.jpg').convert('RGBA')
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font 需要在C:\Windows\Fonts拷贝一份字体文件 当前脚本路径下
fnt = ImageFont.truetype('cambriai.ttf', 40)
# get a drawing context
d = ImageDraw.Draw(txt)
# draw text, half opacity
d.text((10,10), "Hello", font=fnt, fill=(255,255,255,128))
# draw text, full opacity
d.text((10,60), "World", font=fnt, fill=(255,255,255,255))
fillcolor = "#ff0000" #字体颜色
d.text((base.size[0]-20,10), "4", font=fnt, fill=fillcolor)
out = Image.alpha_composite(base, txt)
out.show()
参考官方文档 https://pillow.readthedocs.io/en/stable/reference/Image.html
补充知识:python对图像中的人脸进行画框(人脸的位置数据记录在记事本文件中)
我就废话不多说了,大家还是直接看代码吧!
import numpy as py
import os
import cv2 as cv
with open('labelFaceData.txt','r')as fp:#打开记录了数据的记事本文件
pictureNumber = 0#用来记录照片的数量
while 1:
count = 1
line = fp.readline()#读取文件中每一行的数据
if not line:#如果读取失败则退出
break
pictureNumber+=1#图片数加1
str1 = line.split()#用一个数组以字符串的形式储存文件中的数据
img = cv.inread(str[0])#str[0]中存放的是要读取的图片地址,用cv.inread读取它
faceNumber = (len(str1)-1)/16#用来记录人脸的总数
for i in reage(faceNumber):#用for循环对人脸进行画框
x = int(str1[count+1])#x,y,w,h为画框需要的点
y = int(str1[count+2])
w = int(str1[count+3])
h = int(str1[count+4])
cv.rectangle(img,(x,y),(x+w,y+h),(255,0,0),3,4,0)#用rectangle对图像进行画框
count+=16
#cv.namedWindow(str[0],0)
#cv.imshow(str[0],img);
#cv.waitKey(0)
cv.imwrite("./result/image1_"+str(pictureNumber)+".jpg",img)#保存图片
fp.close()
以上这篇python 实现PIL模块在图片画线写字就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。
本文标题: python 实现PIL模块在图片画线写字
本文地址: http://www.cppcns.com/jiaoben/python/313544.html
python写字_python 实现PIL模块在图片画线写字相关推荐
- python中怎样在图片上画线段_python 实现PIL模块在图片画线写字
图片上画线条 import sys from PIL import Image,ImageDraw im = Image.open("th.png") draw = ImageDr ...
- python怎么在图片上写字的软件_python 实现PIL模块在图片画线写字
图片上画线条 import sys from PIL import Image,ImageDraw im = Image.open("th.png") draw = ImageDr ...
- python画波浪线_python 实现PIL模块在图片画线写字
图片上画线条 import sys from PIL import Image,ImageDraw im = Image.open("th.png") draw = ImageDr ...
- PIL篇---python 实现PIL模块在图片画线写字
python 实现PIL模块在图片画线写字 from PIL import Image, ImageDraw, ImageFont# get an image base = Image.open('2 ...
- python PIL模块在图片画线写字
图片上画线条 import sys from PIL import Image,ImageDrawim = Image.open("th.png") draw = ImageDra ...
- pil显示图片_Python之PIL模块使用
PIL/Pillow 是 Python强大的图像处理库,功能包括:基本图像操作(创建缩略图.几何变换.图像裁剪.图像分离与合并.粘贴图片)图像存储.图像显示.格式转换.截屏操作.图像绘制功能.图像滤镜 ...
- python自带的PIL库扩展图片大小给图片加上文字描述
利用python自带的PIL库扩展图片大小给图片加上文字描述.大多都是库函数调用,只是给定图片宽度后计算文字所需行数的代码需要写. 代码比较丑,but it works. #!/usr/bin/env ...
- Android在图片画线(放大,旋转,平移后可继续正确画线,限制画线区域)
最近因为公司业务需求,需要给学校的老师们做一个在手机和电脑上同步进行图片上画线批注的效果.刚开始在github上看了几天, 但跟我们要求吻合的开源项目几乎没有.最后只能自己来实现一个相应的功能,经过一 ...
- Python实战案例,PIL模块,Python实现自动化生成倒计时图片
前言 利用Python实现自动化生成倒计时图片.废话不多说. 让我们愉快地开始吧~ 开发工具 Python版本: 3.6.4 相关模块: PIL模块: os模块: 以及一些Python自带的模块. 环 ...
最新文章
- TCP三次握手,四次分手
- 在3D世界中创建不同的相机模式——检查对象是否可见
- 基于分类任务的信号(EEG)处理--代码分步解析
- ASP.NET分页存储过程自定义用户控件
- 当别人不听我们的话的时候
- Spark on Yarn 模式编写workcount实例
- qmediaplayer获取流类型_Java 流API
- Spring RabbitMQ教程
- python实践项目(九)
- 关于python中字典描述正确的是_python总结七
- 《C++ AMP:用Visual C++加速大规模并行计算》——3.6 parallel_for_each
- 解决@media screen (自适应)IE浏览器不兼容问题
- 预防 Android Dex 64k Method Size Limit
- Coffice协同办公管理系统(C#)(
- 《Android源码设计模式》之策略模式
- 词根词缀 (一):前缀篇
- 可视化搭建平台的参考网格线设计
- sigmoid的通俗理解
- 关于微功率短距离无线电发射设备,无需做SRRC认证
- WIN8应用商店闪退
热门文章
- Service xxx does not have a SELinux domain defined.amp;amp;avc denied权限问题
- Manifold 安装无线网卡Intel7260
- 动词的使役+授受辅助动词
- PMI-PMP®模考一(180题附答案及解析)
- smoke.js是一款基于HTML5 Canvas的逼真烟雾特效js插件。通过该js插件,可以非常轻松的在页面中制作出各种烟雾效果。...
- 电商“三国杀”:消失的子弹
- python编辑游戏脚本_用PYTHON做一个简单的游戏脚本(基础,详细)
- Google Earth Engine ——利用where来合理划分NDVI阈值
- 简介oracle oerr工具使用
- oerr 工具使用汇总