Baidu AI Application application , obtain APP_ID   API_KEY   SECRET_KEY.

Start drawing :
# -*- coding:utf-8 -*- import cv2 import base64 import numpy as np import os
from aip import AipBodyAnalysis import time import random APP_ID = '25365416'
API_KEY = 'pS5cVzzw2iBfLY6MKRhUE4cw' SECRET_KEY = '×××××××××××××××××××××××'
client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY) # Save the path after image segmentation path =
'./mask_img/' # Save binary path1 = './mask_front/' # Save original foreground # os.listdir Lists the names of pictures saved to pics
= os.listdir('./pictures') print(pics) for im in pics: # Construct picture paths in order img =
os.path.join("./pictures",im) img1 = cv2.imread(img) height, width, _ =
img1.shape # print(height, width) # Reading pictures in binary mode with open(img, 'rb') as fp:
img_info = fp.read() # Set to return only foreground That is, the split portrait res = client.bodySeg(img_info)
seg_res = client.bodySeg(img_info) labelmap =
base64.b64decode(seg_res['labelmap']) nparr = np.fromstring(labelmap, np.uint8)
labelimg = cv2.imdecode(nparr,1) labelimg = cv2.resize(labelimg,(width,height),
interpolation=cv2.INTER_NEAREST) new_img = np.where(labelimg==1, 255, labelimg)
cv2.imwrite(os.path.join(path,im), new_img) # Return to foreground result =
cv2.bitwise_and(img1, new_img) cv2.imwrite(os.path.join(path1,im), result)
print('======== Image segmentation completed ========')

 

 

Technology
©2019-2020 Toolsou All rights reserved,
( Super detail )Eclipse Using tutorials —— use Eclipse Create first HelloWorld! Database operation 5 code implementation mysql Addition, deletion, modification and query of database What can MCU do , Do you have any interesting works made by MCU or open source hardware Go to the interview after reading this , Steady over ~~ Single linked list of primary data structure (C Language implementation )SQL Comprehensive questions Employee unit comprehensive questions Python Implementation of Hanoi Tower code VHDL——JK trigger It's over , Starting salary 30k