python 代码:
from aip import AipBodyAnalysis
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()
file = sys.argv[1]
real = cv2.imread(file)
height, width, channels = real.shape
maskfile = 'mask.'+file
resfile = 'res.'+file
yuantu = get_file_content(file)
res = client.bodySeg(yuantu);
labelmap = base64.b64decode(res['labelmap'])
nparr = np.fromstring(labelmap,np.uint8)
labelimg = cv2.imdecode(nparr,1)
#labelimg = cv2.resize(labelimg,(402,402),interpolation=cv2.INTER_NEAREST)
labelimg = cv2.resize(labelimg,(width,height),interpolation=cv2.INTER_NEAREST)
im_new = np.where(labelimg==1, 255, labelimg)
cv2.imwrite(maskfile, im_new)
#add merge
result = cv2.bitwise_and(real, im_new)
cv2.imwrite(resfile, result)
原图:
二值图:
最终图:
说好的人像呢
问一下怎么样才能把结果输出成图片呢??
这个。。。。大猩猩表示很无辜啊