云AI平台实战

制作微信名片


初始环境,配置网络,能 PING 通外网

配置 YUM 源

1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# mkdir /dvd
[root@localhost ~]# mount /dev/sr0 /dvd/
[root@localhost ~]# vim /etc/yum.repos.d/local.repo
[local]
name = This is local repo
baseurl = file:///dvd
enabled = 1
gpgcheck = 0
[root@localhost ~]# yum clean all
[root@localhost ~]# yum repolist

安装软件包

1
2
3
4
5
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install python36 python36u-pip python36u-redis python36-numpy
[root@localhost ~]# yum -y install python36-devel
[root@localhost ~]# yum -y install zlib-devel
[root@localhost ~]# yum -y install libjpeg-turbo-devel

配置 pip

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# mkdir .pip
[root@localhost ~]# cd .pip/
[root@localhost .pip]# vim pip.conf
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host=pypi.tuna.tsinghua.edu.cn

安装gcc,以免安装MyQR报错
[root@localhost .pip]# yum -y install gcc*
安装MyQR
[root@localhost .pip]# pip3 install MyQR

安装 zbar、pyzbar、pillow

1
2
3
[root@localhost .pip]# cd
[root@localhost ~]# yum -y install zbar
[root@localhost ~]# pip3 install pyzbar pillow

编写微信名片图像解码程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
'文件名'无所谓,以.py结尾
[root@localhost ~]# vim decode.py
from pyzbar.pyzbar import decode
from PIL import Image

image="wx.jpg" # 这里图片路径在当前目录 /root/ 目录下,注意文件名和格式要一致;物理机的话建议scp
img = Image.open(image)
barcodes = decode(img)
for barcode in barcodes:
url = barcode.data.decode("utf-8")
print(url)

[root@localhost ~]# python3 decode.py
https://u.wechat.com/MFSMySpvW2Ec2mJUjK7cn0M # 获得输出链接,复制

编写微信代码

动态图片背景(gif)

1
2
3
4
5
6
7
8
9
10
11
12
13
'文件名'无所谓,以.py结尾					
# 原图片路径(picture)在/root/Desktop/222.gif
[root@localhost ~]# vim myqr_wx2.py
from MyQR import myqr
myqr.run(words="https://u.wechat.com/MFSMySpvW2Ec2mJUjK7cn0M",version=3,picture="/root/Desktop/222.gif",colorized=True,
save_name="233.gif", 注意这里的后缀只能是'.jpg', '.png', '.bmp', '.gif',建议'.gif'
save_dir="/root/Desktop") 输出路径

这里直接执行py文件可能由于numpy版本过高报错,需要安装低版本
[root@localhost ~]# pip3 install imageio==2.13.5
再次执行py文件
[root@localhost ~]# python3 myqr_wx2.py
line 16: mode: byte

标识人脸特征


安装环境

在Python官网下载 python-3.6.6-amd64.exe,如果有其它版本记得先卸载

image-20220711220012434

以下命令在cmd操作 👇

1
2
3
4
5
6
7
8
9
10
检验 python
C:\Users\Lai>python --version
Python 3.6.6 👈 版本

在当前目录新建pip文件夹,写一个'pip.ini'文件
# 内容如下,注意扩展名是ini
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
2

安装人脸检测相关的包

1
2
3
4
5
6
7
8
9
10
11
下载 Pillow
C:\Users\Lai>pip install Pillow==7.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/

安装 CMake
C:\Users\Lai>pip install CMake

安装 dlib
C:\Users\Lai>pip install dlib==19.8.1

安装 face_recognition
C:\Users\Lai>pip install face_recognition

编写人脸识别特征程序

写一个face_1.py文件,内容如下 👇

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import face_recognition

from PIL import Image,ImageDraw

image = face_recognition.load_image_file("G312xixi.jpg")

face_landmarks_list = face_recognition.face_landmarks(image)

print("I found {} face(s) in this photograph.".format(len(face_landmarks_list)))

pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image)

for face_landmarks in face_landmarks_list:
for facial_feature in face_landmarks.keys():
print("The {} in this face has the following points:{}".format(facial_feature,face_landmarks[facial_feature]))
for facial_feature in face_landmarks.keys():
d.line(face_landmarks[facial_feature],width=5)

pil_image.show()

运行程序即可

1
C:\Users\Lai>python face_1.py
image-20220711230350855