Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ ImageSearch/ API Reference/ APIs/ Searching for Images

Searching for Images

Updated on 2023-12-13 GMT+08:00

Function

You can use the API to search for similar images from the image library.

URI

POST /v1/{project_id}/{instance_name}/image/search

Table 1 Path parameters

Name

Mandatory

Type

Description

instance_name

Yes

String

Instance name

project_id

Yes

String

Project ID. See Obtaining a Project ID and Name.

Request Message

Table 2 Request header parameters

Name

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token

Used to obtain the permission to call APIs. For details about how to obtain the token, see Authentication. The value of X-Subject-Token in the response header is the token.

Table 3 Request body parameters

Name

Mandatory

Type

Description

file

No

String

Base64 character string converted from the image. Only the JPEG, JPG, PNG, and BMP formats are supported. The image resolution of the narrow sides of an image must be greater than or equal to 100 pixels, and that of the wide sides cannot exceed 2048 pixels. Configure either this parameter or path. If both parameters are set, file is used.

path

No

String

Image URL, which is the index ID of an image in the image library. Configure either this parameter or file. If both parameters are set, file is used.

limit

No

Integer

Number of retrieved images. The value is an integer ranging from 1 to 100.

Minimum value: 1

Maximum value: 100

Default value: 10

offset

No

Integer

Offset used to specify the start position of the search result. The value is an integer greater than or equal to 0. The default value is 0.

Minimum value: 0

tags

No

Object

Custom image tag. A maximum of 10 tags can be customized. The tags are key-value pairs. To add a tag name (key), do as follows:

  • Log in to the ImageSearch management console, click Create Instance, and configure Customize Tag.
  • Log in to the Image Search management console. Go to the Instance Management page, and click an instance name. On the Instance Details page that is displayed, configure Customize Tag. This parameter is mandatory when the image tag is used for search.

is_crop

No

Boolean

Indicates whether to specify an area (parameter box) in an image for search. This parameter is valid only for certain models. The value can be true or false.

  • true: Specify an area (parameter box) in an image for search.
  • false: Use the entire image to search.

The default value is false.

box

No

SearchBoxDetail object

Area specified in the image.

Table 4 SearchBoxDetail

Parameter

Mandatory

Type

Description

x

No

Integer

Minimum value of the horizontal (x) coordinate in an area, in pixels

y

No

Integer

Minimum value of the vertical (y) coordinate in an area, in pixels

width

No

Integer

Width of the specified area, in pixels

height

No

Integer

Height of the specified area, in pixels

Response Parameters

Status code: 200

Table 5 Response body parameter

Name

Type

Description

count

Integer

Total number of search records

result

Array of SearchPictureItem objects

Search result details

Table 6 SearchPictureItem

Name

Type

Description

path

String

Path of the searched image

sim

Float

Similarity between the original image and the searched image. The closer the value reaches 1, the more similar the images are.

tags

Object

Custom tag name and content

Status code: 400

Table 7 Response body parameter

Name

Type

Description

error_code

String

Error code of a failed API call. For details, see Error Codes.

This parameter is not included when the API is successfully called.

error_msg

String

Error message when the API call fails.

This parameter is not included when the API is successfully called.

Example Requests

  • Method 1: Use the Base64 code of an image to search for similar images in the image index library. The number of returned images is 10.
    POST https://{endpoint}/v1/{project_id}/{instance_name}/image/search
    
    {
      "limit" : 10,
      "offset" : 0,
      "file" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA..."
    }
  • Method 2: Use the image URL to search for similar images in the image index library. The number of returned images is 10.
    POST https://{endpoint}/v1/{project_id}/{instance_name}/image/search
    
    {
      "limit" : 10,
      "offset" : 0,
      "path" : "https://BucketName.obs.myhuaweicloud.com/image/test1.jpg"
    }
  • Method 3: Use tags to search for similar images in the image index library. The number of returned images is 10.
    POST https://{endpoint}/v1/{project_id}/{instance_name}/image/search
    
    {
      "limit" : 10,
      "offset" : 0,
      "tags" : {
        "test-tags" : "test-image"
      }
    }
  • Method 4: Use the Base64 code and tags of an image to search for similar images in the image index library. The number of returned images is 10.
    POST https://{endpoint}/v1/{project_id}/{instance_name}/image/search
    
    {
      "limit" : 10,
      "offset" : 0,
      "file" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA...",
      "tags" : {
        "test-tags" : "test-image"
      }
    }
  • Method 5: Use the image URL and tags to search for similar images in the image index library. The number of returned images is 10.
    POST https://{endpoint}/v1/{project_id}/{instance_name}/image/search
    
    {
      "limit" : 10,
      "offset" : 0,
      "path" : "https://BucketName.obs.myhuaweicloud.com/image/test1.jpg",
      "tags" : {
        "test-tags" : "test-image"
      }
    }
  • Method 6: Use a specified area to search for similar images in the image index library. The number of returned images is 10.
    POST https://{endpoint}/v1/{project_id}/{instance_name}/image/search
    
    {
      "limit" : 10,
      "offset" : 0,
      "path" : "https://BucketName.obs.myhuaweicloud.com/image/test1.jpg",
      "box" : {
        "x" : 100,
        "y" : 200,
        "height" : 50,
        "width" : 20
      }
    }

Example Response

Status code: 200

Example of a successful response

{
  "count" : 2,
  "result" : [ {
    "path" : "https://BucketName.obs.myhuaweicloud.com/CBL025106G/CBL025106G_2.JPG",
    "sim" : 0.51263,
    "tags" : {
      "test-tags" : "test-image"
    }
  } ]
}

Status code: 400

Example of a failed response

{
  "error_code" : "IS.0003",
  "error_msg" : "Arguments of path can not be null."
}

Status Code

Status Code

Description

200

Successful response

400

Failed response

Error Code

For details, see Error Codes.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback