Search in sources :

Example 1 with LabelType

use of com.amplifyframework.predictions.models.LabelType in project amplify-android by aws-amplify.

the class AWSPredictionsService method detectLabels.

/**
 * Delegate to {@link AWSRekognitionService} to detect labels.
 * @param type the type of labels to detect
 * @param imageData the image data
 * @param onSuccess triggered upon successful result
 * @param onError triggered upon encountering error
 */
public void detectLabels(@NonNull IdentifyAction type, @NonNull ByteBuffer imageData, @NonNull Consumer<IdentifyResult> onSuccess, @NonNull Consumer<PredictionsException> onError) {
    final LabelType labelType;
    try {
        labelType = getLabelType(type);
    } catch (PredictionsException error) {
        onError.accept(error);
        return;
    }
    rekognitionService.detectLabels(labelType, imageData, onSuccess, onError);
}
Also used : LabelType(com.amplifyframework.predictions.models.LabelType) PredictionsException(com.amplifyframework.predictions.PredictionsException)

Example 2 with LabelType

use of com.amplifyframework.predictions.models.LabelType in project amplify-android by aws-amplify.

the class IdentifyLabelsConfiguration method fromJson.

/**
 * Construct an instance of {@link IdentifyLabelsConfiguration} from
 * plugin configuration JSON object.
 * @param configurationJson the plugin configuration
 * @return the configuration for label identification
 * @throws JSONException if identify configuration is malformed
 */
@Nullable
public static IdentifyLabelsConfiguration fromJson(@NonNull JSONObject configurationJson) throws JSONException {
    if (!configurationJson.has(CONFIG_NAME)) {
        return null;
    }
    JSONObject identifyLabelsJson = configurationJson.getJSONObject(CONFIG_NAME);
    String typeString = identifyLabelsJson.getString("type");
    String networkPolicyString = identifyLabelsJson.getString("defaultNetworkPolicy");
    final LabelType type = LabelType.valueOf(typeString);
    final NetworkPolicy networkPolicy = NetworkPolicy.fromKey(networkPolicyString);
    return new IdentifyLabelsConfiguration(type, networkPolicy);
}
Also used : JSONObject(org.json.JSONObject) NetworkPolicy(com.amplifyframework.predictions.aws.NetworkPolicy) LabelType(com.amplifyframework.predictions.models.LabelType) Nullable(androidx.annotation.Nullable)

Aggregations

LabelType (com.amplifyframework.predictions.models.LabelType)2 Nullable (androidx.annotation.Nullable)1 PredictionsException (com.amplifyframework.predictions.PredictionsException)1 NetworkPolicy (com.amplifyframework.predictions.aws.NetworkPolicy)1 JSONObject (org.json.JSONObject)1