Smart Crop
1. Smart cropping with photo URL input
API:
| Method | URL | 
|---|---|
| GET | https://demo.computervision.com.vn/api/v2/smartcrop/crop_image | 
Params:
| Key | Value | Description | 
|---|---|---|
| url | https://example.com/image.png | Image URL | 
| width | 400 | Width of output image | 
| height | 600 | Height of output image | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"img_url = 'link_url_img'width = 400height = 600response = requests.get("https://demo.computervision.com.vn/api/v2/smartcrop/crop_image?url=%s&width=%s&height=%s"% (img_url, width, height),auth = (api_key, api_secret))print(response.json())
2. Smart cropping with image file input
API:
| Method | URL | content-type | 
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/smartcrop/crop_image | multipart/form-data | 
Params:
| Key | Value | Description | 
|---|---|---|
| width | 400 | Width of output image | 
| height | 600 | Height of output image | 
Body:
| Key | Type | Value | Description | 
|---|---|---|---|
| img | file | example.jpg | Image file | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"img_path = '/path/to/your/image.jpg'width = 400height = 600response = requests.post("https://demo.computervision.com.vn/api/v2/smartcrop/crop_image?width=%s&height=%s"% (width, height),auth=(api_key, api_secret),files={'img': open(img_path, 'rb')})print(response.json())
3. Smart crop optimized for photos with one or more people, using photo URL input
API:
| Method | URL | 
|---|---|
| GET | https://demo.computervision.com.vn/api/v2/smartcrop/crop_person | 
Params:
| Key | Value | Description | 
|---|---|---|
| url | https://example.com/image.png | Image URL | 
| width | 400 | Width of output image | 
| height | 600 | Height of output image | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"img_url = 'link_url_img'width = 400height = 600response = requests.get("https://demo.computervision.com.vn/api/v2/smartcrop/crop_person?url=%s&width=%s&height=%s"% (img_url, width, height),auth = (api_key, api_secret))print(response.json())
4. Smart crop optimized for photos with one or more people, using image file input
API:
| Method | URL | content-type | 
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/smartcrop/crop_person | multipart/form-data | 
Params:
| Key | Value | Description | 
|---|---|---|
| width | 400 | Width of output image | 
| height | 600 | Height of output image | 
Body:
| Key | Type | Value | Description | 
|---|---|---|---|
| img | file | example.jpg | Image file | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"img_path = '/path/to/your/image.jpg'width = 400height = 600response = requests.post("https://demo.computervision.com.vn/api/v2/smartcrop/crop_person?width=%s&height=%s"% (width, height),auth=(api_key, api_secret),files={'img': open(img_path, 'rb')})print(response.json())
5. Response
The response will be a JSON with the following format:
{"url": [xxxx], // Result image URL"errorCode": int,"errorMessage": string,"invalidCode": int, // Only for crop_person"invalidMessage": string // Only for crop_person}
Error code table:
| Code | Message | 
|---|---|
| 0 | Success | 
| 1 | Incorrect image format | 
| 2 | Url is unavailable | 
| 3 | Incorrect image format | 
| 4 | Incorrect api_key or api_secret | 
| 5 | Out of requests | 
| 6 | Error when processing the request | 
Warning error code table:
| Code | Message | 
|---|---|
| 0 | Successful | 
| 1 | The photo does not contain face | 
| 2 | Photo contains more than one face | 
| 3 | Wearing sun glasses | 
| 4 | Wearing a hat | 
| 5 | Wearing a mask | 
| 6 | Tilt more than 15 degrees | 
| 7 | Photo taken from picture, screen | 
| 8 | The face in the picture is too small |