该内容介绍了基于PaddleHub人脸关键点检测的脸颊物品粘贴项目。先说明相关参数,接着阐述实现步骤:安装并导入PaddleHub及PaddleGAN,定义物品粘贴函数,进行图像动漫化处理,最后根据单侧或双侧需求实现物品粘贴并展示。还提及报错原因及解决方案。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜


声明:以上均为展示,请不要上升到国家/球队/个人层面
| 内容 | 范围 | 说明 |
|---|---|---|
| genre | 0,1,2 | 0:左边单侧 1:右边单侧 2:双侧 |
| flagimg | 地址 | 贴图地址 |
| faceimg | 地址 | 人物正脸地址(脸要尽可能明显) |
| toflagimg | 地址 | 另外一侧贴图地址(右侧) |
genre = 2 # 0:左边单侧 1:右边单侧 2:双侧flagimg = './agt.png' # 贴图地址faceimg = './p2c_photo.png' # 人物地址toflagimg = './bx.png' # 另外一侧贴图地址(右侧)
!pip install -U paddlehub !hub install face_landmark_localization==1.0.2# 安装PaddleGAN的pip包,即可使用api预测方式!pip install --upgrade ppgan !pip install dlib==19.22.0 -i https://pypi.douban.com/simple
import paddlehub as hubimport cv2import os face_landmark = hub.Module(name="face_landmark_localization") result = face_landmark.keypoint_detection(images=[cv2.imread(faceimg)])
import numpy as npfrom PIL import Imageimport cv2import numpy as npfrom math import sqrtdef sjb_hand(result1, flagimg, faceimg, select):
result1 = result[0]['data'][0]
pts = []
def around(select):
order = [[2, 30, 3, 31], [30, 31, 16, 15]]
order = order[select] for o in order:
tx = int(result1[o-1][0])
ty = int(result1[o-1][1])
pts.append([tx, ty])
x = []
y = [] for pt in pts:
x.append(pt[0])
y.append(pt[1]) # x = tuple(x)
# y = tuple(y)
x1 = min(x)
y1 = min(y)
x2 = max(x)
y2 = max(y) # print(x1, x2, y1, y2)
return x1, x2, y1, y2
x1, x2, y1, y2 = around(select)
img = Image.open(flagimg) # print(((x2 - x1) // 2), int((y2 - y1) * 1.2))
reim=img.resize((((x2 - x1) // 2), int((y2 - y1) * 1.2))) # 宽*高
reim.save('newflagimg.png')
im = cv2.imread(faceimg)
obj = cv2.imread('newflagimg.png')
mask = 255 * np.ones(obj.shape, obj.dtype) # print(im.shape, obj.shape)
center = (int(x1+(x2-x1)//2), y1+(y2-y1)//2)
mixed_clone = cv2.seamlessClone(obj, im, mask, center, cv2. NORMAL_CLONE)
cv2.imwrite("inputimg.jpg", mixed_clone)#生成动画头像from ppgan.apps import Photo2CartoonPredictor %cd /home/aistudio p2c = Photo2CartoonPredictor(output_path='/home/aistudio/result/') p2c.run(faceimg)
if genre == 0:
sjb_hand(result, flagimg, './result/p2c_photo.png', 0)
os.rename("./inputimg.jpg", './newphoto.jpg')
sjb_hand(result, flagimg, './result/p2c_cartoon.png', 0)
os.rename("./inputimg.jpg", './newcartoon.jpg')elif genre == 1:
sjb_hand(result, flagimg, './result/p2c_photo.png', 1)
os.rename("./inputimg.jpg", './newphoto.jpg')
sjb_hand(result, flagimg, './result/p2c_cartoon.png', 1)
os.rename("./inputimg.jpg", './newcartoon.jpg')elif genre == 2:
tofaceimg = "inputimg.jpg"
sjb_hand(result, flagimg, './result/p2c_photo.png', 0)
sjb_hand(result, toflagimg, tofaceimg, 1)
os.rename("./inputimg.jpg", './newphoto.jpg')
sjb_hand(result, flagimg, './result/p2c_cartoon.png', 0)
sjb_hand(result, toflagimg, tofaceimg, 1)
os.rename("./inputimg.jpg", './newcartoon.jpg')from PIL import Image
Image.open('newcartoon.jpg')<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=256x256 at 0x7F4CFC1D4DD0>
from PIL import Image
Image.open('newphoto.jpg')<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=256x256 at 0x7F4CFC25CAD0>
以上就是世界杯谁家球队人气旺?一键为自家球队打call!的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号