首页 版块 访问AI主站 注册 发帖
爱罗堂
10
积分 积分商城
0
获赞
python 人像分割问题 foreground
Ta的回复 :顶上去同步,二值图 和 灰度度 都没有问题,可前景透明图就是出不来 from aip import AipBodyAnalysis import cv2 import numpy as np import base64 import os import json """ 你的 APPID AK SK """ APP_ID = '' API_KEY = '' SECRET_KEY = '' client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY) """ 读取图片 """ def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() image = get_file_content('test.png') """ 调用人像分割 """ #client.bodySeg(image); res = client.bodySeg(image) foreground = base64.b64decode(res['foreground']) labelmap = base64.b64decode(res['labelmap']) scoremap = base64.b64decode(res['scoremap']) nparr_foreground = np.fromstring(foreground,np.uint8) foregroundimg = cv2.imdecode(nparr_foreground,1) foregroundimg = cv2.resize(foregroundimg,(512,512),interpolation=cv2.INTER_NEAREST) im_new_foreground = np.where(foregroundimg==1, 10, foregroundimg) cv2.imwrite('foreground.png', im_new_foreground) nparr_labelmap = np.fromstring(labelmap,np.uint8) labelmapimg = cv2.imdecode(nparr_labelmap,1) labelmapimg = cv2.resize(labelmapimg,(512,512),interpolation=cv2.INTER_NEAREST) im_new_labelmapimg = np.where(labelmapimg==1, 255, labelmapimg) cv2.imwrite('labelmap.png', im_new_labelmapimg) nparr_scoremap = np.fromstring(scoremap,np.uint8) scoremapimg = cv2.imdecode(nparr_scoremap,1) scoremapimg = cv2.resize(scoremapimg,(512,512),interpolation=cv2.INTER_NEAREST) im_new_scoremapimg = np.where(scoremapimg==1, 255, scoremapimg) cv2.imwrite('scoremap.png', im_new_scoremapimg)   问题出在哪????python的代码
3
切换版块
智能客服