Exemple #1
0
        public async Task Detect(byte[] imageData, YoloResult result)
        {
            try
            {
                state = State.Busy;
                DetectionRequest request = new DetectionRequest {
                    Image = ByteString.CopyFrom(imageData)
                };

                using (var call = client.Detect(request))
                {
                    var responseStream = call.ResponseStream;
                    while (await responseStream.MoveNext())
                    {
                        DetectionResponse response = responseStream.Current;
                        foreach (DetectionResult r in response.YoloItems)
                        {
                            result.Add(new YoloItem(r.Type, r.Confidence, r.X, r.Y, r.Width, r.Height));
                        }
                        result.ElapsedMilliseconds = response.ElapsedMilliseconds;
                        state = State.NewResponse;
                    }
                }
            }
            catch (RpcException e)
            {
                UnityEngine.Debug.LogError("RPC failed " + e);
                throw;
            }
        }
Exemple #2
0
        public override async Task Detect(DetectionRequest request,
                                          IServerStreamWriter <DetectionResponse> responseStream, ServerCallContext context)
        {
            Console.WriteLine("Image received...");
            Stopwatch timer = new Stopwatch();

            timer.Start();

            IEnumerable <YoloItem> items = yoloWrapper.Detect(request.Image.ToByteArray());

            DetectionResponse response = new DetectionResponse();

            foreach (YoloItem item in items)
            {
                response.YoloItems.Add(new DetectionResult
                {
                    Type       = item.Type,
                    Confidence = item.Confidence,
                    X          = item.X,
                    Y          = item.Y,
                    Width      = item.Width,
                    Height     = item.Height
                });
            }
            timer.Stop();
            response.ElapsedMilliseconds = timer.Elapsed.Milliseconds;
            Console.WriteLine("{0} objects detected in {1} ms", response.YoloItems.Count, timer.Elapsed.Milliseconds);

            await responseStream.WriteAsync(response);
        }