Search in sources :

Example 36 with Entity

use of com.google.cloud.videointelligence.v1.Entity in project java-docs-samples by GoogleCloudPlatform.

the class Detect method analyzeLabelsFile.

/**
 * Performs label analysis on the video at the provided file path.
 *
 * @param filePath the path to the video file to analyze.
 */
public static void analyzeLabelsFile(String filePath) throws Exception {
    // Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
    try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
        // Read file and encode into Base64
        Path path = Paths.get(filePath);
        byte[] data = Files.readAllBytes(path);
        byte[] encodedBytes = Base64.encodeBase64(data);
        AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder().setInputContent(ByteString.copyFrom(encodedBytes)).addFeatures(Feature.LABEL_DETECTION).build();
        // Create an operation that will contain the response when the operation completes.
        OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response = client.annotateVideoAsync(request);
        System.out.println("Waiting for operation to complete...");
        for (VideoAnnotationResults results : response.get().getAnnotationResultsList()) {
            // process video / segment level label annotations
            System.out.println("Locations: ");
            for (LabelAnnotation labelAnnotation : results.getSegmentLabelAnnotationsList()) {
                System.out.println("Video label: " + labelAnnotation.getEntity().getDescription());
                // categories
                for (Entity categoryEntity : labelAnnotation.getCategoryEntitiesList()) {
                    System.out.println("Video label category: " + categoryEntity.getDescription());
                }
                // segments
                for (LabelSegment segment : labelAnnotation.getSegmentsList()) {
                    double startTime = segment.getSegment().getStartTimeOffset().getSeconds() + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                    double endTime = segment.getSegment().getEndTimeOffset().getSeconds() + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                    System.out.printf("Segment location: %.3f:%.2f\n", startTime, endTime);
                    System.out.println("Confidence: " + segment.getConfidence());
                }
            }
            // process shot label annotations
            for (LabelAnnotation labelAnnotation : results.getShotLabelAnnotationsList()) {
                System.out.println("Shot label: " + labelAnnotation.getEntity().getDescription());
                // categories
                for (Entity categoryEntity : labelAnnotation.getCategoryEntitiesList()) {
                    System.out.println("Shot label category: " + categoryEntity.getDescription());
                }
                // segments
                for (LabelSegment segment : labelAnnotation.getSegmentsList()) {
                    double startTime = segment.getSegment().getStartTimeOffset().getSeconds() + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                    double endTime = segment.getSegment().getEndTimeOffset().getSeconds() + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                    System.out.printf("Segment location: %.3f:%.2f\n", startTime, endTime);
                    System.out.println("Confidence: " + segment.getConfidence());
                }
            }
            // process frame label annotations
            for (LabelAnnotation labelAnnotation : results.getFrameLabelAnnotationsList()) {
                System.out.println("Frame label: " + labelAnnotation.getEntity().getDescription());
                // categories
                for (Entity categoryEntity : labelAnnotation.getCategoryEntitiesList()) {
                    System.out.println("Frame label category: " + categoryEntity.getDescription());
                }
                // segments
                for (LabelSegment segment : labelAnnotation.getSegmentsList()) {
                    double startTime = segment.getSegment().getStartTimeOffset().getSeconds() + segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
                    double endTime = segment.getSegment().getEndTimeOffset().getSeconds() + segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
                    System.out.printf("Segment location: %.3f:%.2f\n", startTime, endTime);
                    System.out.println("Confidence: " + segment.getConfidence());
                }
            }
        }
    }
// [END detect_labels_file]
}
Also used : VideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient) Path(java.nio.file.Path) AnnotateVideoProgress(com.google.cloud.videointelligence.v1.AnnotateVideoProgress) Entity(com.google.cloud.videointelligence.v1.Entity) LabelSegment(com.google.cloud.videointelligence.v1.LabelSegment) AnnotateVideoRequest(com.google.cloud.videointelligence.v1.AnnotateVideoRequest) VideoAnnotationResults(com.google.cloud.videointelligence.v1.VideoAnnotationResults) LabelAnnotation(com.google.cloud.videointelligence.v1.LabelAnnotation) AnnotateVideoResponse(com.google.cloud.videointelligence.v1.AnnotateVideoResponse)

Example 37 with Entity

use of com.google.cloud.videointelligence.v1.Entity in project openflowplugin by opendaylight.

the class ContextChainHolderImpl method ownershipChanged.

@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public void ownershipChanged(EntityOwnershipChange entityOwnershipChange) {
    if (entityOwnershipChange.getState().hasOwner()) {
        return;
    }
    // Findbugs flags a false violation for "Unchecked/unconfirmed cast" from GenericEntity to Entity hence the
    // suppression above. The suppression is temporary until EntityOwnershipChange is modified to eliminate the
    // violation.
    final String entityName = entityOwnershipChange.getEntity().getIdentifier().firstKeyOf(Entity.class).getName();
    if (Objects.nonNull(entityName)) {
        LOG.debug("Entity {} has no owner", entityName);
        try {
            // TODO:Remove notifications
            final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = DeviceStateUtil.createNodeInstanceIdentifier(new NodeId(entityName));
            deviceManager.sendNodeRemovedNotification(nodeInstanceIdentifier);
            LOG.info("Try to remove device {} from operational DS", entityName);
            deviceManager.removeDeviceFromOperationalDS(nodeInstanceIdentifier).get(REMOVE_DEVICE_FROM_DS_TIMEOUT, TimeUnit.MILLISECONDS);
            LOG.info("Removing device from operational DS {} was successful", entityName);
        } catch (TimeoutException | ExecutionException | NullPointerException | InterruptedException e) {
            LOG.warn("Not able to remove device {} from operational DS. ", entityName, e);
        }
    }
}
Also used : Entity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ExecutionException(java.util.concurrent.ExecutionException) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) TimeoutException(java.util.concurrent.TimeoutException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 38 with Entity

use of com.google.cloud.videointelligence.v1.Entity in project Village_Defense by Plajer.

the class RidableVillager method g.

@Override
public void g(float f, float f1) {
    EntityLiving entityliving = (EntityLiving) bt();
    if (entityliving == null) {
        for (final Entity e : passengers) {
            if (e instanceof EntityHuman) {
                entityliving = (EntityLiving) e;
                break;
            }
        }
        if (entityliving == null) {
            P = 0.5f;
            this.l((float) 0.12);
            super.g(f, f1);
            return;
        }
    }
    final float yaw = entityliving.yaw;
    this.yaw = yaw;
    lastYaw = yaw;
    pitch = entityliving.pitch * 0.5f;
    setYawPitch(this.yaw, pitch);
    final float yaw2 = this.yaw;
    aM = yaw2;
    aO = yaw2;
    f = entityliving.bd * 0.75F;
    f1 = entityliving.be;
    if (f1 <= 0.0f) {
        f1 *= 0.25F;
    }
    this.l((float) 0.12);
    super.g(f, f1);
    P = 1.0F;
}
Also used : Entity(net.minecraft.server.v1_9_R1.Entity) EntityHuman(net.minecraft.server.v1_9_R1.EntityHuman) EntityLiving(net.minecraft.server.v1_9_R1.EntityLiving)

Example 39 with Entity

use of com.google.cloud.videointelligence.v1.Entity in project Village_Defense by Plajer.

the class RidableVillager method a.

public void a(float f, float f1, float f2) {
    EntityLiving entityliving = null;
    for (final Entity e : passengers) {
        if (e instanceof EntityHuman) {
            entityliving = (EntityLiving) e;
            break;
        }
    }
    if (entityliving == null) {
        this.P = 0.5F;
        this.aR = 0.02F;
        this.k((float) 0.12);
        super.a(f, f1, f2);
        return;
    }
    this.lastYaw = this.yaw = entityliving.yaw;
    this.pitch = entityliving.pitch * 0.5F;
    this.setYawPitch(this.yaw, this.pitch);
    this.aO = this.aM = this.yaw;
    f = entityliving.be * 0.5F * 0.75F;
    f2 = entityliving.bg;
    if (f2 <= 0.0f) {
        f2 *= 0.25F;
    }
    k(0.12f);
    super.a(f, f1, f2);
    P = (float) 1.0;
}
Also used : Entity(net.minecraft.server.v1_12_R1.Entity) EntityHuman(net.minecraft.server.v1_12_R1.EntityHuman) EntityLiving(net.minecraft.server.v1_12_R1.EntityLiving)

Example 40 with Entity

use of com.google.cloud.videointelligence.v1.Entity in project Village_Defense by Plajer.

the class RidableVillager method g.

@Override
public void g(float f, float f1) {
    EntityLiving entityliving = (EntityLiving) bw();
    if (entityliving == null) {
        // search first human passenger
        for (final Entity e : passengers) {
            if (e instanceof EntityHuman) {
                entityliving = (EntityLiving) e;
                break;
            }
        }
        if (entityliving == null) {
            this.l((float) 0.12);
            super.g(f, f1);
            return;
        }
    }
    this.lastYaw = this.yaw = entityliving.yaw;
    this.pitch = entityliving.pitch * 0.5F;
    this.setYawPitch(this.yaw, this.pitch);
    this.aQ = this.aO = this.yaw;
    f = entityliving.be * 0.75F;
    f1 = entityliving.bf;
    if (f1 <= 0.0f) {
        f1 *= 0.25F;
    }
    this.l((float) 0.12);
    super.g(f, f1);
    P = (float) 1.0;
}
Also used : Entity(net.minecraft.server.v1_11_R1.Entity) EntityHuman(net.minecraft.server.v1_11_R1.EntityHuman) EntityLiving(net.minecraft.server.v1_11_R1.EntityLiving)

Aggregations

SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)41 LivingEntity (org.bukkit.entity.LivingEntity)39 net.minecraft.world.entity (net.minecraft.world.entity)16 org.bukkit.entity (org.bukkit.entity)16 Entity (net.minecraft.server.v1_12_R1.Entity)13 Entity (com.google.datastore.v1.Entity)12 Entity (net.minecraft.server.v1_11_R1.Entity)12 Entity (net.minecraft.server.v1_8_R3.Entity)11 PathEntity (net.minecraft.server.v1_11_R1.PathEntity)9 PathEntity (net.minecraft.server.v1_8_R3.PathEntity)9 CraftEntity (org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity)9 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)9 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)8 Entity (net.minecraft.server.v1_10_R1.Entity)8 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)8 Mob (net.minecraft.world.entity.Mob)8 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)8 org.bukkit.craftbukkit.v1_17_R1.entity (org.bukkit.craftbukkit.v1_17_R1.entity)8 Test (org.junit.Test)8 Key (com.google.datastore.v1.Key)7