Camel Components

Huawei Cloud Face Recognition Service (FRS)

Since Camel 3.15

Only producer is supported

Huawei Cloud Face Recognition Service component allows you to integrate with Face Recognition Service 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-frs</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

hwcloud-frs:operation[?options]

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, *.yaml files, 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 Face Recognition Service (FRS) component supports the following options which are listed below.

Name Description Default Type

lazyStartProducer (producer)

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

autowiredEnabled (advanced)

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 Face Recognition Service (FRS) endpoint is configured using URI syntax:

hwcloud-frs:operation

With the following path and query parameters:

Path Parameters

Name Description Default Type

operation (producer)

Required The operation that the producer performs: faceDetection to detect the faces in an image, faceVerification to compare the faces in two images and tell how similar they are, or faceLiveDetection to tell whether the person in a video is live, by comparing the actions in the video with the actions option.

String

Query Parameters

Name Description Default Type

accessKey (producer)

Required The access key ID (AK) of the Huawei Cloud account, which signs the requests to FRS. If not set, the accessKey of the serviceKeys option is used.

String

actions (producer)

The action list for faceLiveDetection: the codes of the actions that the person performs in the video, in order and separated by commas, for example 1,3,2. The codes are 1 (turn the face to the left), 2 (turn the face to the right), 3 (nod), 4 (mouth movement) and 5 (blink). The CamelHwCloudFrsVideoActions exchange property replaces this option. faceLiveDetection fails if neither is set.

String

actionTimes (producer)

The time of each action of the actions option in the video for faceLiveDetection: one start-end range per action, in the same order, in milliseconds from the start of the video and separated by commas, for example 1000-3000,4000-7000,9000-12000. The CamelHwCloudFrsVideoActionTimes exchange property replaces this option.

String

anotherImageBase64 (producer)

The second image for faceVerification, as a Base64 string: JPG, JPEG, BMP or PNG, at most 8 MB after Base64 encoding. The CamelHwCloudFrsAnotherImageBase64 exchange property replaces this option. The producer sends Base64 images only when both this and the first image (imageBase64) are set.

String

anotherImageFilePath (producer)

The path of the local file of the second image for faceVerification, which the producer uploads to FRS: at most 8 MB, and less than 1 MB is recommended. The CamelHwCloudFrsAnotherImageFilePath exchange property replaces this option. The producer uploads image files only when both this and the first image (imageFilePath) are set, and the two images are not both set as Base64 or as URLs.

String

anotherImageUrl (producer)

The URL of the second image for faceVerification: an object in an Object Storage Service (OBS) bucket of Huawei Cloud that FRS has permission to read. The CamelHwCloudFrsAnotherImageUrl exchange property replaces this option. The producer sends image URLs only when both this and the first image (imageUrl) are set, and the two images are not both set as Base64.

String

endpoint (producer)

The URL of FRS, for example https://face.cn-north-4.myhuaweicloud.com. If set, the region option is not used.

String

imageBase64 (producer)

The image for faceDetection, or the first image for faceVerification, as a Base64 string: JPG, JPEG, BMP or PNG, at most 8 MB after Base64 encoding. The CamelHwCloudFrsImageBase64 exchange property replaces this option. Set one of imageBase64, imageUrl and imageFilePath; if several are set, imageBase64 is used first, then imageUrl, then imageFilePath.

String

imageFilePath (producer)

The path of the local image file for faceDetection, or of the first image for faceVerification, which the producer uploads to FRS: at most 8 MB, and less than 1 MB is recommended. The CamelHwCloudFrsImageFilePath exchange property replaces this option. It is used only when no Base64 image and no image URL are set.

String

imageUrl (producer)

The URL of the image for faceDetection, or of the first image for faceVerification: an object in an Object Storage Service (OBS) bucket of Huawei Cloud that FRS has permission to read. The CamelHwCloudFrsImageUrl exchange property replaces this option. It is used only when no Base64 image is set.

String

projectId (producer)

Required The ID of the Huawei Cloud project that the requests to FRS are made in.

String

proxyHost (producer)

The host name or IP address of the proxy server for the requests to FRS. If not set, no proxy is used.

String

proxyPassword (producer)

The password for the authentication with the proxy server. It is used only when the proxyHost and proxyUser options are set.

String

proxyPort (producer)

The port of the proxy server. It is used only when the proxyHost option is set.

int

proxyUser (producer)

The user name for the authentication with the proxy server. It is used only when the proxyHost option is set.

String

region (producer)

Required The region ID of FRS, 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, which knows cn-north-1, cn-north-4, cn-south-1, cn-east-3, ap-southeast-1 and ap-southeast-2, and fails for any other region.

String

secretKey (producer)

Required The secret access key (SK) of the Huawei Cloud account, which signs the requests to FRS. If not set, the secretKey of the serviceKeys option is used.

String

serviceKeys (producer)

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

videoBase64 (producer)

The video for faceLiveDetection as a Base64 string: at most 8 MB after Base64 encoding (200 KB to 2 MB is recommended), 1 to 15 seconds long, in MP4, AVI, FLV, WEBM, ASF or MOV format. The CamelHwCloudFrsVideoBase64 exchange property replaces this option. Set one of videoBase64, videoUrl and videoFilePath; if several are set, videoBase64 is used first, then videoUrl, then videoFilePath.

String

videoFilePath (producer)

The path of the local video file for faceLiveDetection, which the producer uploads to FRS: at most 8 MB (200 KB to 2 MB is recommended), 1 to 15 seconds long, in MP4, AVI, FLV, WEBM, ASF or MOV format. The CamelHwCloudFrsVideoFilePath exchange property replaces this option. It is used only when no Base64 video and no video URL are set.

String

videoUrl (producer)

The URL of the video for faceLiveDetection: an object in an Object Storage Service (OBS) bucket of Huawei Cloud that FRS has permission to read. The video is 1 to 15 seconds long, in MP4, AVI, FLV, WEBM, ASF or MOV format. The CamelHwCloudFrsVideoUrl exchange property replaces this option. It is used only when no Base64 video is set.

String

lazyStartProducer (producer (advanced))

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

ignoreSslVerification (security)

Whether to skip the verification of the TLS certificate of FRS. This is unsafe, and meant for testing only.

false

boolean

Message Body

The message body at each side of the Huawei Cloud Face Recognition Service (FRS) 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

any

Not used, not even for the image: the image comes from the options or the exchange properties as base64 (CamelHwCloudFrsImageBase64), a URL (CamelHwCloudFrsImageUrl) or a local file path (CamelHwCloudFrsImageFilePath), the second image of faceVerification from the CamelHwCloudFrsAnotherImage properties, and the video of faceLiveDetection from the CamelHwCloudFrsVideo properties.

Producer output

pojo

The response of the Huawei Cloud SDK for the operation and the source of the image, such as the DetectFaceByBase64Response of faceDetection with base64, which holds the faces found.

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 imageBase64 or videoBase64 option, we suggest you use RAW(base64_value) to avoid encoding issue.

Usage

Message properties evaluated by the Face Recognition Service producer

Header Type Description

CamelHwCloudFrsImageBase64

String

The Base64 character string converted from an image. This property can be used when the operation is faceDetection or faceVerification.

CamelHwCloudFrsImageUrl

String

The URL of an image. This property can be used when the operation is faceDetection or faceVerification.

CamelHwCloudFrsImageFilePath

String

The local file path of an image. This property can be used when the operation is faceDetection or faceVerification.

CamelHwCloudFrsAnotherImageBase64

String

The Base64 character string converted from another image. This property can be used when the operation is faceVerification.

CamelHwCloudFrsAnotherImageUrl

String

The URL of another image. This property can be used when the operation is faceVerification.

CamelHwCloudFrsAnotherImageFilePath

String

The local file path of another image. This property can be used when the operation is faceVerification.

CamelHwCloudFrsVideoBase64

String

The Base64 character string converted from a video. This property can be used when the operation is faceLiveDetection.

CamelHwCloudFrsVideoUrl

String

The URL of a video. This property can be used when the operation is faceLiveDetection.

CamelHwCloudFrsVideoFilePath

String

The local file path of a video. This property can be used when the operation is faceLiveDetection.

CamelHwCloudFrsVideoActions

String

The action code sequence list. This property can be used when the operation is faceLiveDetection.

CamelHwCloudFrsVideoActionTimes

String

The action time array. This property is used when the operation is faceLiveDetection.

List of Supported Operations

  • faceDetection - detect, locate, and analyze the face in an input image, and output the key facial points and attributes.

  • faceVerification - compare two faces to verify whether they belong to the same person and return the confidence level

  • faceLiveDetection - determine whether a person in a video is alive by checking whether the person’s actions in the video are consistent with those in the input action list

Inline Configuration of route

faceDetection

  • Java

  • XML

  • YAML

from("direct:triggerRoute")
  .setProperty(FaceRecognitionProperties.FACE_IMAGE_URL, constant("https://xxxx"))
  .to("hwcloud-frs:faceDetection?accessKey=*********&secretKey=********&projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&region=cn-north-4")
<route>
  <from uri="direct:triggerRoute"/>
  <setProperty name="CamelHwCloudFrsImageUrl">
    <constant>https://xxxx</constant>
  </setProperty>
  <to uri="hwcloud-frs:faceDetection?accessKey=*********&amp;secretKey=********&amp;projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&amp;region=cn-north-4"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setProperty:
            name: CamelHwCloudFrsImageUrl
            expression:
              constant:
                expression: https://xxxx
        - to:
            uri: hwcloud-frs:faceDetection
            parameters:
              accessKey: "*********"
              secretKey: "********"
              projectId: 9071a38e7f6a4ba7b7bcbeb7d4ea6efc
              region: cn-north-4

faceVerification

  • Java

  • XML

  • YAML

from("direct:triggerRoute")
  .setProperty(FaceRecognitionProperties.FACE_IMAGE_BASE64, constant("/9j/4AAQSkZJRgABAQEASABIAAD/..."))
  .setProperty(FaceRecognitionProperties.ANOTHER_FACE_IMAGE_BASE64, constant("/9j/4AAQSkZJRgABAQAAAQABAAD/..."))
  .to("hwcloud-frs:faceVerification?accessKey=*********&secretKey=********&projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&region=cn-north-4")
<route>
  <from uri="direct:triggerRoute"/>
  <setProperty name="CamelHwCloudFrsImageBase64">
    <constant>/9j/4AAQSkZJRgABAQEASABIAAD/...</constant>
  </setProperty>
  <setProperty name="CamelHwCloudFrsAnotherImageBase64">
    <constant>/9j/4AAQSkZJRgABAQAAAQABAAD/...</constant>
  </setProperty>
  <to uri="hwcloud-frs:faceVerification?accessKey=*********&amp;secretKey=********&amp;projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&amp;region=cn-north-4"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setProperty:
            name: CamelHwCloudFrsImageBase64
            expression:
              constant:
                expression: "/9j/4AAQSkZJRgABAQEASABIAAD/..."
        - setProperty:
            name: CamelHwCloudFrsAnotherImageBase64
            expression:
              constant:
                expression: "/9j/4AAQSkZJRgABAQAAAQABAAD/..."
        - to:
            uri: hwcloud-frs:faceVerification
            parameters:
              accessKey: "*********"
              secretKey: "********"
              projectId: 9071a38e7f6a4ba7b7bcbeb7d4ea6efc
              region: cn-north-4

faceLiveDetection

  • Java

  • XML

  • YAML

from("direct:triggerRoute")
  .setProperty(FaceRecognitionProperties.FACE_VIDEO_FILE_PATH, constant("/tmp/video.mp4"))
  .setProperty(FaceRecognitionProperties.FACE_VIDEO_ACTIONS, constant("1,3,2"))
  .to("hwcloud-frs:faceLiveDetection?accessKey=*********&secretKey=********&projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&region=cn-north-4")
<route>
  <from uri="direct:triggerRoute"/>
  <setProperty name="CamelHwCloudFrsVideoFilePath">
    <constant>/tmp/video.mp4</constant>
  </setProperty>
  <setProperty name="CamelHwCloudFrsVideoActions">
    <constant>1,3,2</constant>
  </setProperty>
  <to uri="hwcloud-frs:faceLiveDetection?accessKey=*********&amp;secretKey=********&amp;projectId=9071a38e7f6a4ba7b7bcbeb7d4ea6efc&amp;region=cn-north-4"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setProperty:
            name: CamelHwCloudFrsVideoFilePath
            expression:
              constant:
                expression: /tmp/video.mp4
        - setProperty:
            name: CamelHwCloudFrsVideoActions
            expression:
              constant:
                expression: "1,3,2"
        - to:
            uri: hwcloud-frs:faceLiveDetection
            parameters:
              accessKey: "*********"
              secretKey: "********"
              projectId: 9071a38e7f6a4ba7b7bcbeb7d4ea6efc
              region: cn-north-4