代码说明:
将jpg或者gif动态图,转变为数字或者英文(看你所需要)的图片或动态图
效果如下:
代码如下:
import imageio as igo
import cv2
#pip install opencv-python 安装命令
#OpenCV计算机视觉库
import numpy as np
#1.读取图片GIF图,建立多维数组
#2.对GIF每一帧进行处理
#3.组成新的GIFt图
pics = igo.mimread("xx.gif") #修改图片名称,建立多维数组
print(np.array(pics).shape) #读取长度,进行打印
A = []
string = """01""" #其实输入啥都行
count = len(string)
for img in pics:
u,v,_ = img.shape
c = img * 0 + 255
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
for i in range(0,u,6):
for j in range(0,v,6):
pix = gray[i,j]
b,g,r, _ = img[i,j]
zifu = string[int(((count-1)*pix) / 256)]
cv2.putText(c,zifu,(j,i),cv2.FONT_HERSHEY_COMPLEX,0.2,(int(b),int(g),int(r),1))
A.append(c)
igo.mimsave("xxx.gif",A,"GIF",duration=0.1)