Smart Crop

1. Smart cropping with photo URL input

API:

MethodURL
GEThttps://cloud.computervision.com.vn/api/v2/smartcrop/crop_image

Params:

KeyValueDescription
urlhttps://example.com/image.pngImage URL
width400Width of output image
height600Height of output image

Demo Python:

import requests
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
img_url = 'link_url_img'
width = 400
height = 600
response = requests.get(
"https://cloud.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:

MethodURLcontent-type
POSThttps://cloud.computervision.com.vn/api/v2/smartcrop/crop_imagemultipart/form-data

Params:

KeyValueDescription
width400Width of output image
height600Height of output image

Body:

KeyTypeValueDescription
imgfileexample.jpgImage file

Demo Python:

import requests
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
img_path = '/path/to/your/image.jpg'
width = 400
height = 600
response = requests.post(
"https://cloud.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:

MethodURL
GEThttps://cloud.computervision.com.vn/api/v2/smartcrop/crop_person

Params:

KeyValueDescription
urlhttps://example.com/image.pngImage URL
width400Width of output image
height600Height of output image

Demo Python:

import requests
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
img_url = 'link_url_img'
width = 400
height = 600
response = requests.get(
"https://cloud.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:

MethodURLcontent-type
POSThttps://cloud.computervision.com.vn/api/v2/smartcrop/crop_personmultipart/form-data

Params:

KeyValueDescription
width400Width of output image
height600Height of output image

Body:

KeyTypeValueDescription
imgfileexample.jpgImage file

Demo Python:

import requests
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
img_path = '/path/to/your/image.jpg'
width = 400
height = 600
response = requests.post(
"https://cloud.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:

CodeMessage
0Success
1Incorrect image format
2Url is unavailable
3Incorrect image format
4Incorrect api_key or api_secret
5Out of requests
6Error when processing the request

Warning error code table:

CodeMessage
0Successful
1The photo does not contain face
2Photo contains more than one face
3Wearing sun glasses
4Wearing a hat
5Wearing a mask
6Tilt more than 15 degrees
7Photo taken from picture, screen
8The face in the picture is too small