Huawei Cloud Image Recognition
Since Camel 3.12
Only producer is supported
Huawei Cloud Image Recognition component allows you to integrate with Image Recognition provided by Huawei Cloud.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-huaweicloud-imagerecognition</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Huawei Cloud Image Recognition component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Huawei Cloud Image Recognition endpoint is configured using URI syntax:
hwcloud-imagerecognition:operation
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The access key ID (AK) of the Huawei Cloud account, which signs the requests to Image Recognition. If not set, the accessKey of the serviceKeys option is used. | String | ||
The URL of Image Recognition, for example https://image.cn-north-4.myhuaweicloud.com. If set, the region option is not used. | String | ||
The image as a Base64 string, in JPG, PNG or BMP format and at most 10 MB. The CamelHwCloudImageContent exchange property replaces this option. Set this option or imageUrl; if both are set, the producer sends both to Image Recognition. | String | ||
The URL of the image: a public HTTP or HTTPS URL, or the URL of an object in Object Storage Service (OBS) that Image Recognition is authorized to read. The CamelHwCloudImageUrl exchange property replaces this option. Set this option or imageContent; if both are set, the producer sends both to Image Recognition. | String | ||
Required The ID of the Huawei Cloud project that the requests to Image Recognition are made in. | String | ||
The host name or IP address of the proxy server for the requests to Image Recognition. If not set, no proxy is used. | String | ||
The password for the authentication with the proxy server. It is used only when the proxyHost and proxyUser options are set. | String | ||
The port of the proxy server. It is used only when the proxyHost option is set. | int | ||
The user name for the authentication with the proxy server. It is used only when the proxyHost option is set. | String | ||
Required The region ID of Image Recognition, for example cn-north-4. If the endpoint option is not set, the producer looks up the endpoint of this region in the Huawei Cloud SDK, and fails for a region that the SDK does not know. | String | ||
Required The secret access key (SK) of the Huawei Cloud account, which signs the requests to Image Recognition. If not set, the secretKey of the serviceKeys option is used. | String | ||
The access key and secret key as an org.apache.camel.component.huaweicloud.common.models.ServiceKeys. Its accessKey and its secretKey are each used when the option of the same name is not set. | ServiceKeys | ||
The language of the tags that tagRecognition returns: zh for Chinese or en for English. The CamelHwCloudImageTagLanguage exchange property replaces this option. The producer rejects any other value. | zh | String | |
The maximum number of tags that tagRecognition returns. The CamelHwCloudImageTagLimit exchange property replaces this option. | 50 | int | |
The minimum confidence score of a returned result: from 0 to 100 for tagRecognition (60 if not set), and from 0 to 1 for celebrityRecognition (0.48 if not set). The CamelHwCloudImageThreshold exchange property replaces this option. The producer rejects a value outside the range of the operation. | float | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether to skip the verification of the TLS certificate of Image Recognition. This is unsafe, and meant for testing only. | false | boolean |
Message Body
The message body at each side of the Huawei Cloud Image Recognition component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| Not used, not even for the image: the image comes from the imageContent option or the CamelHwCloudImageContent exchange property as base64, or from the imageUrl option or the CamelHwCloudImageUrl exchange property as a URL. |
Producer output |
| The result of the Huawei Cloud SDK: for celebrityRecognition a List with a CelebrityRecognitionResultBody per celebrity found, and for tagRecognition an ImageTaggingResponseResult with the tags.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
| When using imageContent option, we suggest you use RAW(image_base64_value) to avoid encoding issue. |
Usage
Message properties evaluated by the Image Recognition producer
| Header | Type | Description |
|---|---|---|
|
| The Base64 character string converted from the image |
|
| The URL of an image |
|
| The maximum number of the returned tags when the operation is tagRecognition |
|
| The language of the returned tags when the operation is tagRecognition |
|
| The threshold of confidence. |
List of Supported Image Recognition Operations
-
celebrityRecognition - to analyze and identify the political figures, stars and online celebrities contained in the picture, and return the person information and face coordinates
-
tagRecognition - to recognize hundreds of scenes and thousands of objects and their properties in natural images
Inline Configuration of route
celebrityRecognition
-
Java
-
XML
-
YAML
from("direct:triggerRoute")
.setProperty(ImageRecognitionProperties.IMAGE_URL, constant("https://xxxx"))
.setProperty(ImageRecognitionProperties.THRESHOLD, constant(0.5))
.to("hwcloud-imagerecognition:celebrityRecognition?accessKey=*********&secretKey=********&projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc®ion=cn-north-4") <route>
<from uri="direct:triggerRoute"/>
<setProperty name="CamelHwCloudImageUrl">
<constant>https://xxxx</constant>
</setProperty>
<setProperty name="CamelHwCloudImageThreshold">
<constant>0.5</constant>
</setProperty>
<to uri="hwcloud-imagerecognition:celebrityRecognition?accessKey=*********&secretKey=********&projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&region=cn-north-4"/>
</route> - route:
from:
uri: direct:triggerRoute
steps:
- setProperty:
name: CamelHwCloudImageUrl
expression:
constant:
expression: https://xxxx
- setProperty:
name: CamelHwCloudImageThreshold
expression:
constant:
expression: "0.5"
- to:
uri: hwcloud-imagerecognition:celebrityRecognition
parameters:
accessKey: "*********"
secretKey: "********"
projectId: 9071a38e7f6a4ba7b7bcbeb7d4ea6efc
region: cn-north-4 tagRecognition
-
Java
-
XML
-
YAML
from("direct:triggerRoute")
.setProperty(ImageRecognitionProperties.IMAGE_CONTENT, constant("/9j/4AAQSkZJRgABAQEASABIAAD/..."))
.setProperty(ImageRecognitionProperties.THRESHOLD, constant(60))
.setProperty(ImageRecognitionProperties.TAG_LANGUAGE, constant("en"))
.setProperty(ImageRecognitionProperties.TAG_LIMIT, constant(50))
.to("hwcloud-imagerecognition:tagRecognition?accessKey=*********&secretKey=********&projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc®ion=cn-north-4") <route>
<from uri="direct:triggerRoute"/>
<setProperty name="CamelHwCloudImageContent">
<constant>/9j/4AAQSkZJRgABAQEASABIAAD/...</constant>
</setProperty>
<setProperty name="CamelHwCloudImageThreshold">
<constant>60</constant>
</setProperty>
<setProperty name="CamelHwCloudImageTagLanguage">
<constant>en</constant>
</setProperty>
<setProperty name="CamelHwCloudImageTagLimit">
<constant>50</constant>
</setProperty>
<to uri="hwcloud-imagerecognition:tagRecognition?accessKey=*********&secretKey=********&projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&region=cn-north-4"/>
</route> - route:
from:
uri: direct:triggerRoute
steps:
- setProperty:
name: CamelHwCloudImageContent
expression:
constant:
expression: "/9j/4AAQSkZJRgABAQEASABIAAD/..."
- setProperty:
name: CamelHwCloudImageThreshold
expression:
constant:
expression: "60"
- setProperty:
name: CamelHwCloudImageTagLanguage
expression:
constant:
expression: en
- setProperty:
name: CamelHwCloudImageTagLimit
expression:
constant:
expression: "50"
- to:
uri: hwcloud-imagerecognition:tagRecognition
parameters:
accessKey: "*********"
secretKey: "********"
projectId: 9071a38e7f6a4ba7b7bcbeb7d4ea6efc
region: cn-north-4