コード例 #1
0
        // For Video Analysis
        public List <LabelDetection> GetDetectedLabelsVideo(string jobId, string target, out string message)
        {
            string outMessage = String.Empty;
            var    response   = _client.GetLabelDetectionAsync(new GetLabelDetectionRequest
            {
                JobId = jobId
            }).Result;


            if (response.JobStatus.Value.ToUpper() == "IN_PROGRESS")
            {
                while (response.JobStatus.Value.ToUpper() != "SUCCEEDED")
                {
                    Thread.Sleep(1000);
                    response = _client.GetLabelDetectionAsync(new GetLabelDetectionRequest
                    {
                        JobId = jobId
                    }).Result;
                }
                if (response.JobStatus.Value.ToUpper() == "SUCCEEDED")
                {
                    response = _client.GetLabelDetectionAsync(new GetLabelDetectionRequest
                    {
                        JobId = jobId
                    }).Result;
                }
            }

            foreach (var label in response.Labels)
            {
                //Console.WriteLine($"{label.Label.Name} at {label.Timestamp}        {label.Label.Confidence} %");
                if (label.Label.Name.Contains(target, StringComparison.InvariantCultureIgnoreCase))
                {
                    outMessage = outMessage = "The Object '" + target.ToUpper() + "' in your watchlist has been found in live stream with '" + Convert.ToInt32(label.Label.Confidence) + "%' confidence.";
                    break;
                }
            }

            message = (outMessage == "" || outMessage == null)? "The Object '" + target.ToUpper() + "' in your watchlist has not been found in live stream." : outMessage;

            LogResponse(GetIndentedJson(response), "GetDetectedLabelsVideo");
            return(response.Labels);
        }
コード例 #2
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var rekognitionClient = new AmazonRekognitionClient(Amazon.RegionEndpoint.USEast2);

            var tags = Table.LoadTable(client, "TagItAwayTags");
            var id   = request.QueryStringParameters["id"];

            var labelDetectionRequest = new GetLabelDetectionRequest
            {
                JobId = id
            };

            var result = await rekognitionClient.GetLabelDetectionAsync(labelDetectionRequest);

            return(new APIGatewayProxyResponse
            {
                StatusCode = 200,
                Body = JsonConvert.SerializeObject(result.Labels),
                Headers = new Dictionary <string, string> {
                    { "Access-Control-Allow-Origin", "*" }
                }
            });
        }
コード例 #3
0
ファイル: Function.cs プロジェクト: slarsen88/CloudComputing
        public async Task StartAnalyzingVideosAsync(string key, string bucketName)
        {
            string startJobID = string.Empty;
            StartLabelDetectionRequest startLabelDetectionRequest = new StartLabelDetectionRequest
            {
                Video = new Video
                {
                    S3Object = new S3Object
                    {
                        Bucket = bucketName,
                        Name   = key
                    }
                },
                MinConfidence = 50
            };

            var startLabelDetectionResponse = await client.StartLabelDetectionAsync(startLabelDetectionRequest);

            if (startLabelDetectionResponse != null)
            {
                startJobID = startLabelDetectionResponse.JobId;
            }

            Console.WriteLine("Analysis of {0} has started. Waiting 20 seconds to check status.", key);
            GetLabelDetectionRequest labelDetectionRequest = new GetLabelDetectionRequest()
            {
                JobId = startJobID
            };

            System.Threading.Thread.Sleep(20000);
            bool isPackage  = false;
            bool isComplete = false;

            // while job is not "successful"
            while (!isComplete)
            {
                GetLabelDetectionResponse labelDetectionResponse = await client.GetLabelDetectionAsync(labelDetectionRequest);

                if (labelDetectionResponse.JobStatus == VideoJobStatus.SUCCEEDED)
                {
                    isComplete = true;
                    Console.WriteLine("Job status is: " + labelDetectionResponse.JobStatus);
                    foreach (var label in labelDetectionResponse.Labels)
                    {
                        if (label.Label.Name.Equals("Package Delivery") || label.Label.Name.Equals("Carton") || label.Label.Name.Equals("Box"))
                        {
                            isPackage = true;
                            break;
                        }
                    }
                }

                if (isPackage)
                {
                    break;
                }
                Console.WriteLine("Still analyzing...");
                System.Threading.Thread.Sleep(20000);
            }

            AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.USEast1);

            if (isPackage)
            {
                string         ARN        = "arn:aws:sns:us-east-1:207457486405:PackageDelivery";
                PublishRequest pubRequest = new PublishRequest
                {
                    TopicArn = ARN,
                    Message  = "You have a delivery."
                };
                await snsClient.PublishAsync(pubRequest);

                Console.WriteLine("You have a delivery!");
            }
            else
            {
                Console.WriteLine("Someone's at your door but there is no delivery");
            }
        }