# humanseg_example **Repository Path**: vax52/humanseg_example ## Basic Information - **Project Name**: humanseg_example - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-07-23 - **Last Updated**: 2024-08-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 基于paddlehub的人像分割背景替换实例 ##原始图片 ![avatar](origin/meditation.jpg) ## 替换后的图片 ![replace](humanseg_output/result_deeplab.jpg) # 参考资料 https://aistudio.baidu.com/aistudio/projectdetail/2213056 # serving example hub serving start -m pyramidbox_lite_mobile ```python import requests import json import cv2 import base64 def cv2_to_base64(image): data = cv2.imencode('.jpg', image)[1] return base64.b64encode(data.tostring()).decode('utf8') # 发送HTTP请求 data = {'images':[cv2_to_base64(cv2.imread("/PATH/TO/IMAGE"))]} headers = {"Content-type": "application/json"} url = "http://127.0.0.1:8866/predict/pyramidbox_lite_mobile" r = requests.post(url=url, headers=headers, data=json.dumps(data)) # 打印预测结果 print(r.json()["results"]) ```