Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.
ImageSearch
ImageSearch
- What's New
- Service Overview
- Getting Started
- API Reference
- SDK Reference
- FAQs
- General Reference
On this page
Show all
Copied.
Searching for Images
This section describes how to use an image to search for similar images using AK/SK authentication.
Replace the AK/SK in the sample code with the actual AK/SK. Set the Path parameter in the SearchPictureReq class to specify the URL of the image you want to use to search for similar images. After the configuration is complete, run the code.
- The sample code for image searching is as follows:
using System; using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.ImageSearch; using HuaweiCloud.SDK.ImageSearch.V1; using HuaweiCloud.SDK.ImageSearch.V1.Model; using Newtonsoft.Json; namespace RunSearchPictureSolution { class Program { static void Main(string[] args) { const string ak = "<YOUR AK>"; const string sk = "<YOUR SK>"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk); var client = ImageSearchClient.NewBuilder() .WithCredential(auth) .WithRegion(ImageSearchRegion.ValueOf("cn-north-4")) .WithHttpConfig(config) .Build(); var req = new RunSearchPictureRequest { InstanceName = "instance-name" }; req.Body = new SearchPictureReq() { Path = "https://bucketname.obs.cn-north-4.myhuaweicloud.com/imagesearch/test.jpg" }; try { var resp = client.RunSearchPicture(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody)); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } }
- Execute the sample code. If the image search result is displayed on the console, the code is successfully executed. For details, see Searching for Images.
200 { "result": [ { "path": "https://bucketname.obs.cn-north-4.myhuaweicloud.com/imagesearch/test.jpg", "sim": 1.0, "tags": {} } ], "count":1 }
Parent topic: Using the .NET SDK
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot