Remove Image Background 是非常火爆的人像照片(其实也可以去除其他物体,比如沙发…)背景去除工具,只需要上传一张带有人像的照片,它就会帮你自动抠掉背景,整个过程全自动、5秒内完成,而且完全免费,甚至还支持多种语言的 Background Removal API 调用。
效果如下图所示
,不到5秒瞬间完成…(该图为本人真实、亲测旅游卫视图片处理效果)
另外,再推荐一个国内在线的抠图工具 —— 搞定抠图,功能相比 Remove Bg 稍微逊色,主要不够 AI,很多需要人工确定抠图范围,在访问 Remove Bg 遇到困难的时候(remove.bg 使用了 reCAPTCHA 预防滥用,而 re 的服务器位于 Google,所以你懂得 ..),也可以作为备选使用:
搞定抠图 传送门懂开发的攻城狮同学,也可以根据下面实现好的,直接拿来改装,不用自己造重复轮子。
ImageURL
方式,上传图片文件方式请参见官网。
$ curl -H 'X-API-Key: INSERT_YOUR_API_KEY_HERE' \ -F 'image_url=https://commandnotfound.cn/example.jpg' \ -F 'size=auto' \ -f https://api.remove.bg/v1.0/removebg -o no-bg.png
// Requires "request" to be installed (see https://www.npmjs.com/package/request) var request = require('request'); var fs = require('fs'); request.post({ url: 'https://api.remove.bg/v1.0/removebg', formData: { image_url: 'https://commandnotfound.cn/example.jpg', size: 'auto', }, headers: { 'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE' }, encoding: null }, function(error, response, body) { if(error) return console.error('Request failed:', error); if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8')); fs.writeFileSync("no-bg.png", body); });
# Requires "requests" to be installed (see python-requests.org) import requests response = requests.post( 'https://api.remove.bg/v1.0/removebg', data={ 'image_url': 'https://commandnotfound.cn/example.jpg', 'size': 'auto' }, headers={'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'}, ) if response.status_code == requests.codes.ok: with open('no-bg.png', 'wb') as out: out.write(response.content) else: print("Error:", response.status_code, response.text)
# Install "remove_bg" first (https://github.com/remove-bg/ruby) require "remove_bg" RemoveBg.from_url("https://commandnotfound.cn/example.jpg", api_key: "INSERT_YOUR_API_KEY_HERE" ).save("no-bg.png")
// Requires "guzzle" to be installed (see guzzlephp.org) $client = new GuzzleHttp\Client(); $res = $client->post('https://api.remove.bg/v1.0/removebg', [ 'multipart' => [ [ 'name' => 'image_url', 'contents' => 'https://commandnotfound.cn/example.jpg' ], [ 'name' => 'size', 'contents' => 'auto' ] ], 'headers' => [ 'X-Api-Key' => 'INSERT_YOUR_API_KEY_HERE' ] ]); $fp = fopen("no-bg.png", "wb"); fwrite($fp, $res->getBody()); fclose($fp);
// Requires "Apache HttpComponents" to be installed (see hc.apache.org) Response response = Request.Post("https://api.remove.bg/v1.0/removebg") .addHeader("X-Api-Key", "INSERT_YOUR_API_KEY_HERE") .body( MultipartEntityBuilder.create() .addTextBody("image_url", "https://commandnotfound.cn/example.jpg") .addTextBody("size", "auto") .build() ).execute(); response.saveContent(new File("no-bg.png"));
using (var client = new HttpClient()) using (var formData = new MultipartFormDataContent()) { formData.Headers.Add("X-Api-Key", "INSERT_YOUR_API_KEY_HERE"); formData.Add(new StringContent("https://commandnotfound.cn/example.jpg"), "image_url"); formData.Add(new StringContent("auto"), "size"); var response = client.PostAsync("https://api.remove.bg/v1.0/removebg", formData).Result; if(response.IsSuccessStatusCode) { FileStream fileStream = new FileStream("no-bg.png", FileMode.Create, FileAccess.Write, FileShare.None); response.Content.CopyToAsync(fileStream).ContinueWith((copyTask) =>{ fileStream.Close(); }); } else { Console.WriteLine("Error: " + response.Content.ReadAsStringAsync().Result); } }
// Requires Alamofire to be installed (see https://github.com/Alamofire/Alamofire) Alamofire .request( URL(string: "https://api.remove.bg/v1.0/removebg")!, method: .post, parameters: ["image_url": "https://commandnotfound.cn/example.jpg"], encoding: URLEncoding(), headers: [ "X-Api-Key": "INSERT_YOUR_API_KEY_HERE" ] ) .responseData { imageResponse in guard let imageData = imageResponse.data, let image = UIImage(data: imageData) else { return } self.imageView.image = image }
// Requires AFNetworking to be installed (see https://github.com/AFNetworking/AFNetworking) AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration: NSURLSessionConfiguration.defaultSessionConfiguration]; manager.responseSerializer = [AFImageResponseSerializer serializer]; [manager.requestSerializer setValue:@"INSERT_YOUR_API_KEY_HERE" forHTTPHeaderField:@"X-Api-Key"]; NSURLSessionDataTask *dataTask = [manager POST:@"https://api.remove.bg/v1.0/removebg" parameters:@{@"image_url": @"https://commandnotfound.cn/example.jpg"} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { if ([responseObject isKindOfClass:UIImage.class] == false) { return; } self.imageView.image = responseObject; } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"ERROR"); }]; [dataTask resume];