luke_bowsher = './KnightbookScraping/Grade-12/Male/Luke Bowsher_male_Grade-12.png'
matt_phua = './KnightbookScraping/Grade-12/Male/Matthew Phua_male_Grade-12.png'
abby_doll = './KnightbookScraping/Grade-12/Female/Abigail Doll_female_Grade-12.png'
neha_tarkad = './KnightbookScraping/Grade-12/Female/Neha Tarakad Juneja_female_Grade-12.png'
max_dostart = './KnightbookScraping/Grade-12/Male/Max Dostart-Meers Dostart Meers_male_Grade-12.png'
paras_arora = './KnightbookScraping/Grade-12/Male/Paras Arora_male_Grade-12.png'
joseph_ma = './KnightbookScraping/Grade-12/Male/Joseph Ma Chou_male_Grade-12.png'


#此方法专用来打印api返回的信息
def print_result(hit, result):
    print(hit)
    print('\n'.join("  " + i for i in pformat(result, width=75).split('\n')))


def printFuctionTitle(title):
    return "\n" + "-" * 60 + title + "-" * 60


# 初始化对象,进行api的调用工作
api = API()

#人脸融合:https://console.faceplusplus.com.cn/documents/20813963
#template_rectangle参数中的数据要通过人脸检测api来获取
mergeFace_res = api.mergeface(template_file=File(matt_phua),
                              merge_file=File(santa))
print_result("mergeFace", mergeFace_res)

# Start Fusion
PythonSDK.ImagePro.ImageProCls.getMergeImg(mergeFace_res["result"])
Example #2
0
    right_nose_choose.append([right_nose.x, right_nose.y])
    right_face_choose.append([right_face.x, right_face.y])

cv2.imshow("points", dst_img)
# 抠图
left_choose = left_eye_up_choose + left_nose_choose + left_eyebrow_down_choose + left_face_choose
right_choose = right_eye_up_choose + right_nose_choose + right_eyebrow_down_choose + right_face_choose
# 创建一个掩码来抠图,需要扣的地方置为1,不扣的就使用 np.zeros 创建为 0
mask_array = np.zeros(origin_img.shape, dtype=np.uint8)
pts_left = np.array(left_choose)
pts_right = np.array(right_choose)
cv2.fillPoly(mask_array, [pts_left], color=(1, 1, 1))
cv2.fillPoly(mask_array, [pts_right], color=(1, 1, 1))
# 人脸融合:https://console.faceplusplus.com.cn/documents/20813963
# template_rectangle参数中的数据要通过人脸检测api来获取
mergeFace_res = api.mergeface(template_url=template_url, merge_url=merge_url)
# 从结果中把facepp返回的合成图base64拿到,然后转码成 string,提供给 cv2 使用
combine_img_data_str = base64.b64decode(mergeFace_res["result"])
# 装成 numpy 数组
combine_img_np_array = np.frombuffer(combine_img_data_str, np.uint8)
# 解码成 cv2 的图片格式
combine_img = cv2.imdecode(combine_img_np_array, cv2.IMREAD_COLOR)
# 结果图 = 原图 扣掉眼皮部分 + 合成图眼皮不服
# 原图眼皮部分扣掉 = 原图 - 原图*mask
# 合成图眼皮部分 = 合成图 * mask
res_res = origin_img - origin_img * mask_array + combine_img * mask_array
cv2.imshow('combine', combine_img)
cv2.imshow('combine_mask', combine_img * mask_array)
cv2.imshow('resres', res_res)
# # 等待按键输入
cv2.waitKey()
Example #3
0
# 人脸融合:https://console.faceplusplus.com.cn/documents/20813963
# template_rectangle参数中的数据要通过人脸检测api来获取

# template_url list:
# https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574980389347&di=a98287b30386b159d3be8067d5b8df00&imgtype=0&src=http%3A%2F%2Fgss0.baidu.com%2F7LsWdDW5_xN3otqbppnN2DJv%2Fzhidao%2Fpic%2Fitem%2F5d6034a85edf8db15af248710523dd54574e74c2.jpg
# http://i1.hdslb.com/bfs/archive/f391e3d633ca7fb2bcc1ac68cea380ec8b2c87f5.jpg
# https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574981285576&di=1cf524ef3fb08beea100ac79d917e752&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20170501%2F4274ec793fcf4b6098a67750892d900a_th.jpeg
# http://i2.hdslb.com/bfs/archive/48acf9efd46e9319c4dc05c5c60cdcc43d5985a7.jpg
# https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574981356999&di=1d4bd18dbce31f44604031b157fd26ef&imgtype=0&src=http%3A%2F%2Fwx3.sinaimg.cn%2Flarge%2F006byqyGly1fbp1ymowaqj30ji0shn0c.jpg
# https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=204522960,1226759988&fm=15&gp=0.jpg
# https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574981404543&di=dc51eb45956cd1ff86b2efbc5bfeee74&imgtype=0&src=http%3A%2F%2Fe0.ifengimg.com%2F03%2F2019%2F0414%2F5E4A8223AEDC57597EEC455E57EC6ECBBFE63678_size81_w750_h938.jpeg
# https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574981508096&di=ab20baafd546e408b84b02da1c769a4a&imgtype=0&src=http%3A%2F%2Fwww.jder.net%2Fwp-content%2Fuploads%2F2017%2F11%2F20171108130848-90.jpg
# https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574981557927&di=484eae05e3ed0c0f4d30914862a012a0&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20181110%2F2063daae7ad94d3294d21fda4d604a6b.jpeg
# https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=76125465,4026057848&fm=26&gp=0.jpg
mergeFace_res = api.mergeface(
    template_url='https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574981557927&di=484eae05e3ed0c0f4d30914862a012a0&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20181110%2F2063daae7ad94d3294d21fda4d604a6b.jpeg',
    merge_url='https://cdn.faceplusplus.com.cn/mc-official/scripts/demoScript/images/demo-pic114.jpg')
# mergeFace_res = api.mergeface(template_base64=template_base64, merge_base64=merge_base64)
# print_result("mergeFace", mergeFace_res)
#
# # 开始融合
print(type(mergeFace_res))
imgdata_str = base64.b64decode(mergeFace_res["result"])
import numpy as np
print(mergeFace_res)
nparr = np.fromstring(imgdata_str, np.uint8)
print(nparr)
imgdata = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
cv2.imshow("hebing", imgdata)
# 等待按键输入
cv2.waitKey()