Beispiel #1
0
    public async Task <IList <YoloBoundingBox> > AnalyzeImage(VideoFrame videoFrame)
    {
        // This appears to be the right way to handle background tasks.
        // We return to the main thread as fast as we can, and wait for the next call to the Update()
        // to advance our processing
#if SDK_1809
        TinyYoloV2O12Input input = new TinyYoloV2O12Input {
            image = ImageFeatureValue.CreateFromVideoFrame(videoFrame)
        };
#else
        TinyYoloV2O1ModelInput input = new TinyYoloV2O1ModelInput {
            image = videoFrame
        };
#endif
        var dims   = GetDimensionsFromVideoFrame(videoFrame);
        int width  = dims.Item1;
        int height = dims.Item2;

        var predictions = await model.EvaluateAsync(input).ConfigureAwait(false);

#if SDK_1809
        var boxes = parser.ParseOutputs(predictions.grid.GetAsVectorView().ToArray(), width, height, DetectionThreshold);
#else
        var boxes = parser.ParseOutputs(predictions.grid.ToArray(), width, height, DetectionThreshold);
#endif
        boxes = boxes.Where(b => b.Confidence >= DetectionThreshold).ToList();

        // normalize coordinates
        boxes = parser.NonMaxSuppress(boxes);
        return(boxes.ToList());
    }
Beispiel #2
0
    public async Task <TinyYoloV2O1ModelOutput> EvaluateAsync(TinyYoloV2O1ModelInput input)
    {
        TinyYoloV2O1ModelOutput     output  = new TinyYoloV2O1ModelOutput();
        LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel);

        binding.Bind("image", input.image);
        binding.Bind("grid", output.grid);
        LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty);

        return(output);
    }