python人像精细分割_python 人像分割问题 foreground

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-29 23:40   16   0

顶上去同步,二值图 和 灰度度 都没有问题,可前景透明图就是出不来

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的代码

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP