tencent cloud

masukan

Search by Image

Terakhir diperbarui:2024-02-02 16:51:03

    Overview

    This document provides an overview of APIs and SDK code samples for search by image.
    API
    Description
    Enables the search by image feature for a bucket
    Adds an image to the image library
    Searches for an image in the image library
    Removes an image from the image library

    Enabling Search by Image

    Feature description

    This API is used to enable the search by image feature for a bucket.

    Method prototype

    boolean openImageSearch(OpenImageSearchRequest imageSearchRequest);

    Sample request

    //1. Create a job request object
    OpenImageSearchRequest request = new OpenImageSearchRequest();
    //2. Add request parameters as detailed in the API documentation
    request.setBucketName("demobucket-123456789");
    request.setMaxCapacity("100");
    request.setMaxQps("10");
    //3. Call the API to get the job response object
    boolean response = client.openImageSearch(request);

    Parameter description

    Request has the following sub-nodes:
    Node Name (Keyword)
    Parent Node
    Description
    Type
    Required
    bucketName
    Request
    Bucket name in the format of BucketName-APPID. For more information, see Bucket Overview.
    String
    Yes
    maxCapacity
    Request
    Maximum capacity of the image library
    String
    Yes
    MaxQps
    Request
    Maximum QPS of the image library
    String
    No

    Response description

    Success: true is returned upon success.
    Failure: An error (such as the bucket does not exist) occurs, reporting the CosClientException or CosServiceException exception. For more information, see Troubleshooting.

    Adding Image to Image Library

    Feature description

    This API is used to add an image to the image library.

    Method prototype

    boolean addGalleryImages(ImageSearchRequest imageSearchRequest);

    Sample request

    //1. Create a job request object
    ImageSearchRequest request = new ImageSearchRequest();
    //2. Add request parameters as detailed in the API documentation
    request.setBucketName("demobucket-123456789");
    request.setObjectKey("1.png");
    request.setEntityId("mark1");
    //3. Call the API to get the job response object
    boolean response = client.addGalleryImages(request);

    Parameter description

    Request has the following sub-nodes:
    Node Name (Keyword)
    Parent Node
    Description
    Type
    Required
    bucketName
    Request
    Bucket name in the format of BucketName-APPID. For more information, see Bucket Overview.
    String
    Yes
    objectKey
    Request
    Location of the image in the bucket
    String
    Yes
    entityId
    Request
    Entity ID, which can contain up to 64 characters. If EntityId already exists, this request will add the image to it.
    String
    Yes
    customContent
    Request
    Custom content, which can contain up to 4,096 characters. The content set will be returned when the image is queried.
    String
    No
    tags
    Request
    Custom image tags. The value is a JSON string containing up to 10 key:value pairs.
    String
    No

    Response description

    Success: true is returned upon success.
    Failure: An error (such as the bucket does not exist) occurs, reporting the CosClientException or CosServiceException exception. For more information, see Troubleshooting.

    Searching for Image

    Feature description

    This API is used to search for an image in the image library.

    Method prototype

    ImageSearchResponse searchGalleryImages(ImageSearchRequest imageSearchRequest);

    Sample request

    //1. Create a job request object
    ImageSearchRequest request = new ImageSearchRequest();
    //2. Add request parameters as detailed in the API documentation
    request.setBucketName("demobucket-123456789");
    request.setObjectKey("1.png");
    //3. Call the API to get the job response object
    ImageSearchResponse response = client.searchGalleryImages(request);

    Parameter description

    Request has the following sub-nodes:
    Node Name (Keyword)
    Parent Node
    Description
    Type
    Required
    bucketName
    Request
    Bucket name in the format of BucketName-APPID. For more information, see Bucket Overview.
    String
    Yes
    objectKey
    Request
    Location of the image in the bucket
    String
    Yes
    matchThreshold
    Request
    Only images scoring higher than the value of MatchThreshold will be returned. Default value: 0.
    String
    No
    Offset
    Request
    Starting number. Default value: 0.
    String
    No
    limit
    Request
    Number of results to be returned. Default value: 10. Maximum value: 100.
    String
    No
    filter
    Request
    Uses image tags to filter images. You can use AND and OR to set multiple conditions (>, >=, <, <=, =, !=).
    String
    No

    Response description

    Success: The ImageSearchResponse response object is returned upon success.
    Failure: An error (such as the bucket does not exist) occurs, reporting the CosClientException or CosServiceException exception. For more information, see Troubleshooting.

    Removing Image from Image Library

    Feature description

    This API is used to remove an image from the image library.

    Method prototype

    boolean deleteGalleryImages(ImageSearchRequest imageSearchRequest);

    Sample request

    //1. Create a job request object
    ImageSearchRequest request = new ImageSearchRequest();
    //2. Add request parameters as detailed in the API documentation
    request.setBucketName("demobucket-123456789");
    request.setObjectKey("1.png");
    request.setEntityId("mark");
    //3. Call the API to get the job response object
    boolean response = client.deleteGalleryImages(request);

    Parameter description

    Request has the following sub-nodes:
    Node Name (Keyword)
    Parent Node
    Description
    Type
    Required
    bucketName
    Request
    Bucket name in the format of BucketName-APPID. For more information, see Bucket Overview.
    String
    Yes
    objectKey
    Request
    Location of the image in the bucket
    String
    Yes
    entityId
    Request
    Entity ID
    String
    Yes

    Response description

    Success: true is returned upon success.
    Failure: An error (such as the bucket does not exist) occurs, reporting the CosClientException or CosServiceException exception. For more information, see Troubleshooting.
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24