Search in sources :

Example 41 with Entity

use of com.google.cloud.videointelligence.v1p3beta1.Entity in project entity-service by hypertrace.

the class EdsCacheClientTest method testGetByTypeAndIdentifyingAttributes.

@Test
public void testGetByTypeAndIdentifyingAttributes() {
    String tenantId = "tenant";
    String entityId = "entity-12345";
    Map<String, AttributeValue> identifyingAttributesMap = new HashMap<>();
    identifyingAttributesMap.put("entity_name", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("GET /products").build()).build());
    identifyingAttributesMap.put("is_active", AttributeValue.newBuilder().setValue(Value.newBuilder().setBoolean(true).build()).build());
    Entity entity = Entity.newBuilder().setTenantId(tenantId).setEntityId(entityId).setEntityType("API").setEntityName("GET /products").putAllIdentifyingAttributes(identifyingAttributesMap).build();
    when(entityDataServiceClient.getById(anyString(), anyString())).thenReturn(entity);
    when(entityDataServiceClient.getByTypeAndIdentifyingAttributes(anyString(), any())).thenReturn(entity);
    ByTypeAndIdentifyingAttributes attributes = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType("API").putAllIdentifyingAttributes(identifyingAttributesMap).build();
    edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
    edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
    verify(entityDataServiceClient, times(1)).getByTypeAndIdentifyingAttributes("tenant", attributes);
    verify(entityDataServiceClient, never()).getById("tenant", "entity-12345");
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 42 with Entity

use of com.google.cloud.videointelligence.v1p3beta1.Entity in project entity-service by hypertrace.

the class EntityDataServiceClientRetriesTest method testRetryForInternalError.

@Test
public void testRetryForInternalError() {
    doAnswer(invocation -> {
        StreamObserver<Entity> observer = invocation.getArgument(1, StreamObserver.class);
        observer.onError(new RuntimeException(new StatusRuntimeException(Status.INTERNAL)));
        return null;
    }).when(this.mockDataService).getById(any(), any());
    StatusRuntimeException exception = assertThrows(StatusRuntimeException.class, () -> edsClient.getById("__default", "id1"));
    assertEquals(Status.INTERNAL, exception.getStatus());
    verify(this.mockDataService, times(3)).getById(any(), any());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) StatusRuntimeException(io.grpc.StatusRuntimeException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.jupiter.api.Test)

Example 43 with Entity

use of com.google.cloud.videointelligence.v1p3beta1.Entity in project java-video-intelligence by googleapis.

the class TrackObjects method trackObjects.

// [START video_object_tracking_beta]
/**
 * Track objects in a video.
 *
 * @param filePath the path to the video file to analyze.
 */
public static VideoAnnotationResults trackObjects(String filePath) throws Exception {
    try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
        // Read file
        Path path = Paths.get(filePath);
        byte[] data = Files.readAllBytes(path);
        // Create the request
        AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder().setInputContent(ByteString.copyFrom(data)).addFeatures(Feature.OBJECT_TRACKING).setLocationId("us-east1").build();
        // asynchronously perform object tracking on videos
        OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> future = client.annotateVideoAsync(request);
        System.out.println("Waiting for operation to complete...");
        // The first result is retrieved because a single video was processed.
        AnnotateVideoResponse response = future.get(600, TimeUnit.SECONDS);
        VideoAnnotationResults results = response.getAnnotationResults(0);
        // Get only the first annotation for demo purposes.
        ObjectTrackingAnnotation annotation = results.getObjectAnnotations(0);
        System.out.println("Confidence: " + annotation.getConfidence());
        if (annotation.hasEntity()) {
            Entity entity = annotation.getEntity();
            System.out.println("Entity description: " + entity.getDescription());
            System.out.println("Entity id:: " + entity.getEntityId());
        }
        if (annotation.hasSegment()) {
            VideoSegment videoSegment = annotation.getSegment();
            Duration startTimeOffset = videoSegment.getStartTimeOffset();
            Duration endTimeOffset = videoSegment.getEndTimeOffset();
            // Display the segment time in seconds, 1e9 converts nanos to seconds
            System.out.println(String.format("Segment: %.2fs to %.2fs", startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9, endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
        }
        // Here we print only the bounding box of the first frame in this segment.
        ObjectTrackingFrame frame = annotation.getFrames(0);
        // Display the offset time in seconds, 1e9 converts nanos to seconds
        Duration timeOffset = frame.getTimeOffset();
        System.out.println(String.format("Time offset of the first frame: %.2fs", timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
        // Display the bounding box of the detected object
        NormalizedBoundingBox normalizedBoundingBox = frame.getNormalizedBoundingBox();
        System.out.println("Bounding box position:");
        System.out.println("\tleft: " + normalizedBoundingBox.getLeft());
        System.out.println("\ttop: " + normalizedBoundingBox.getTop());
        System.out.println("\tright: " + normalizedBoundingBox.getRight());
        System.out.println("\tbottom: " + normalizedBoundingBox.getBottom());
        return results;
    }
}
Also used : Path(java.nio.file.Path) Entity(com.google.cloud.videointelligence.v1p2beta1.Entity) ObjectTrackingAnnotation(com.google.cloud.videointelligence.v1p2beta1.ObjectTrackingAnnotation) AnnotateVideoRequest(com.google.cloud.videointelligence.v1p2beta1.AnnotateVideoRequest) Duration(com.google.protobuf.Duration) VideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1p2beta1.VideoIntelligenceServiceClient) ObjectTrackingFrame(com.google.cloud.videointelligence.v1p2beta1.ObjectTrackingFrame) AnnotateVideoProgress(com.google.cloud.videointelligence.v1p2beta1.AnnotateVideoProgress) NormalizedBoundingBox(com.google.cloud.videointelligence.v1p2beta1.NormalizedBoundingBox) VideoSegment(com.google.cloud.videointelligence.v1p2beta1.VideoSegment) VideoAnnotationResults(com.google.cloud.videointelligence.v1p2beta1.VideoAnnotationResults) AnnotateVideoResponse(com.google.cloud.videointelligence.v1p2beta1.AnnotateVideoResponse)

Example 44 with Entity

use of com.google.cloud.videointelligence.v1p3beta1.Entity in project java-video-intelligence by googleapis.

the class Detect method analyzeLabels.

/**
 * Performs label analysis on the video at the provided Cloud Storage path.
 *
 * @param gcsUri the path to the video file to analyze.
 */
public static void analyzeLabels(String gcsUri) throws Exception {
    // Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
    try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
        // Provide path to file hosted on GCS as "gs://bucket-name/..."
        AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder().setInputUri(gcsUri).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:%.3f\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:%.3f\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 video_analyze_labels_gcs]
}
Also used : VideoIntelligenceServiceClient(com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient) 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 45 with Entity

use of com.google.cloud.videointelligence.v1p3beta1.Entity in project java-video-intelligence by googleapis.

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);
        AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder().setInputContent(ByteString.copyFrom(data)).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 video_analyze_labels]
}
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)

Aggregations

Entity (org.hypertrace.entity.data.service.v1.Entity)110 LivingEntity (org.bukkit.entity.LivingEntity)95 Test (org.junit.jupiter.api.Test)95 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 net.minecraft.world.entity (net.minecraft.world.entity)40 org.bukkit.entity (org.bukkit.entity)40 Entity (com.google.datastore.v1.Entity)33 ArrayList (java.util.ArrayList)33 Location (org.bukkit.Location)33 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)32 Event (org.hypertrace.core.datamodel.Event)27 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)21 Mob (net.minecraft.world.entity.Mob)20 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 Entity (net.minecraft.server.v1_8_R3.Entity)18 AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)17 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)17 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)17 Entity (com.google.cloud.videointelligence.v1.Entity)17