Beispiel #1
0
            public FullStackFaceInfo[] Process(SpanBitmap srcImage)
            {
                var workingTensor = _Session.UseInputTensor <Byte>(0, srcImage.Height, srcImage.Width, 3)
                                    .AsSpanTensor3()
                                    .UpCast <Pixel.RGB24>();

                workingTensor.AsSpanBitmap().AsTypeless().SetPixels(0, 0, srcImage);

                _Session.Inference();

                var scores     = _Session.GetOutputTensor <float>(0).VerifyName(n => n == "scores").AsSpanTensor1();
                var bboxes     = _Session.GetOutputTensor <Int64>(1).VerifyName(n => n == "bboxes").AsSpanTensor2();
                var kpss       = _Session.GetOutputTensor <Int64>(2).VerifyName(n => n == "kpss").AsSpanTensor3();
                var align_imgs = _Session.GetOutputTensor <byte>(3).VerifyName(n => n == "align_imgs").AsSpanTensor4().UpCast <Pixel.BGR24>();
                var lmks       = _Session.GetOutputTensor <Int64>(4).VerifyName(n => n == "lmks").AsSpanTensor3();
                var M          = _Session.GetOutputTensor <float>(5).VerifyName(n => n == "M").AsSpanTensor3().UpCast <System.Numerics.Vector3>();

                return(FullStackFaceInfo.Parse(scores, bboxes, align_imgs, lmks));
            }
Beispiel #2
0
        // https://github.com/atksh/onnx-facial-lmk-detector

        public static                     FullStackFaceInfo[] Parse(SpanTensor1 <float> scores, SpanTensor2 <Int64> bboxes, SpanTensor3 <Pixel.BGR24> align_imgs, SpanTensor3 <Int64> lmks)
        {
            var result = new FullStackFaceInfo[scores.Dimensions[0]];

            for (int i = 0; i < scores.Dimensions[0]; ++i)
            {
                result[i].Score = scores[i];

                var bbox = bboxes[i];
                result[i].BoundingBox = new System.Drawing.Rectangle((int)bbox[0], (int)bbox[1], (int)bbox[2], (int)bbox[3]);

                MemoryBitmap <Pixel.BGR24> bmp = default;
                align_imgs[i].AsTensorBitmap(Tensors.Imaging.ColorEncoding.RGB).CopyTo(ref bmp);
                result[i].AlignedImage = bmp;

                var lmarks = lmks[i].ToArray();
            }

            return(result);
        }