图片上画线条

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:WindowsFonts拷贝一份字体文件 当前脚本路径下

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模块在图片画线写字就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持云海天教程。

原文链接:https://blog.csdn.net/qq_37550440/article/details/89923524

python中怎样在图片上画线段_python 实现PIL模块在图片画线写字相关推荐

  1. python怎么在图片上写字的软件_python 实现PIL模块在图片画线写字

    图片上画线条 import sys from PIL import Image,ImageDraw im = Image.open("th.png") draw = ImageDr ...

  2. python写字_python 实现PIL模块在图片画线写字

    图片上画线条 import sys from PIL import Image,ImageDraw im = Image.open("th.png") draw = ImageDr ...

  3. python画波浪线_python 实现PIL模块在图片画线写字

    图片上画线条 import sys from PIL import Image,ImageDraw im = Image.open("th.png") draw = ImageDr ...

  4. python识别图片上的文字_python如何一行代码实现图片文字识别

    编写代码如下: from PIL import Imageimport pytesseract text = pytesseract.image_to_string(Image.open('C:\\U ...

  5. php网页中不能上传图片,为什么我的PHP图片上传代码可以实现插入数据库但图片不能插入文件夹中?...

    为什么我的PHP图片上传代码可以实现插入数据库但图片不能插入文件夹中? 关注:167  答案:4  mip版 解决时间 2021-01-19 00:58 提问者慢慢学会遗忘 2021-01-18 00 ...

  6. PIL篇---python 实现PIL模块在图片画线写字

    python 实现PIL模块在图片画线写字 from PIL import Image, ImageDraw, ImageFont# get an image base = Image.open('2 ...

  7. kindeditor扩展粘贴截图功能修改图片上传路径并通过webapi上传图片到图片服务器...

    2019独角兽企业重金招聘Python工程师标准>>> kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. ...

  8. html结构转图片上传服务器并实现点击复制图片到剪贴板

    html结构转图片上传服务器并实现点击复制图片到剪贴板 总结 主要实现了将前端页面上某区域的页面html结构通过html2canvas插件转换成canvas对象,通过canvas对象的toDataUR ...

  9. 【python小课堂专栏】python小课堂15 - 史上最详细的包和模块import讲解篇

    python小课堂15 - 史上最详细的包和模块import讲解篇 前言 在大量的代码设计中,我们不可能将所有代码都写在一个.py文件,所以有了包.模块,而为了代码可以重复利用(复用性),就有了类.函 ...

最新文章

  1. 深度学习中7种最优化算法的可视化与理解
  2. 深度揭秘Windows 7
  3. 【转】C# 中文URL编码
  4. 今晚直播 | 从编码器与解码器端改进生成式句子摘要
  5. hdu 4150 Powerful Incantation
  6. xilinx FPGA的远程更新(动态加载)详解(Using a Microprocessor to Configure 7 Series FPGAs)
  7. 设计模式1——设计模式的原则
  8. Criteria和DetachedCriteria区别应用
  9. 直播丨抢鲜体验-openGauss入门
  10. Soap、Http、TCP/IP 三个基本的通讯协议有什么区别?
  11. 【实用工具】远程桌面工具
  12. NLTK简单入门和数据清洗
  13. 如何使用STM32F4的BootLoader和APP程序
  14. Fancybox丰富的弹出层效果
  15. Linux之RedHat7如何更换yum源
  16. c语言生成exe文件的作用,c语言怎么生成exe文件
  17. 计算机教室云教学反思,《观察云》教学反思
  18. Notepad++软件安装教程
  19. 女人要男人真心还是现金?
  20. python 艺术照片滤镜_[宜配屋]听图阁 - Python实现PS滤镜Fish lens图像扭曲效果示例...

热门文章

  1. 【系统分析师之路】2016年系统分析师下午案例分析真题
  2. KAL 推出 Kalignite Hypervisor 解决方案—引领 ATM 硬件更新创新模式
  3. 虚拟试戴用时尚拉近了粉丝和剧中人的距离
  4. vue+elementUI+vue-i18n 实现国际化
  5. Vue使用快速使用Echarts图标以及使用水滴图
  6. 个人总结 高阶PLSQL 数据库编程
  7. DolphinPHP 框架wangeditor编辑器图片路径改为绝对链接
  8. android放微信短视频文件,参考微信实现的短视频录像
  9. 基于FPGA 的TF卡 UHS-I 方式存储
  10. 一对一直播怎么开发?一对一直播app开发关键点