示例#1
0
 public TensorBitmap(SpanTensor3 <T> tensor, ColorEncoding encoding)
 {
     _ChannelX = tensor.Dimensions[0] > 0 ? tensor[0].Span : default;
     _ChannelY = tensor.Dimensions[0] > 1 ? tensor[1].Span : default;
     _ChannelZ = tensor.Dimensions[0] > 2 ? tensor[2].Span : default;
     _ChannelW = tensor.Dimensions[0] > 3 ? tensor[3].Span : default;
     _Channels = tensor.Dimensions[0];
     _Width    = tensor.Dimensions[2];
     _Height   = tensor.Dimensions[1];
     _Encoding = encoding;
 }
示例#2
0
        public void CopyImage(SpanBitmap src, SpanTensor3 <float> dst)
        {
            switch (src.PixelFormat.Code)
            {
            case Pixel.BGR24.Code: CopyImage(src.OfType <Pixel.BGR24>(), dst); return;

            case Pixel.RGB24.Code: CopyImage(src.OfType <Pixel.RGB24>(), dst); return;

            case Pixel.BGRA32.Code: CopyImage(src.OfType <Pixel.BGRA32>(), dst); return;

            case Pixel.RGBA32.Code: CopyImage(src.OfType <Pixel.RGBA32>(), dst); return;

            case Pixel.Undefined24.Code: CopyImage(src.OfType <Pixel.Undefined24>(), dst); return;
            }

            throw new NotImplementedException($"{src.PixelFormat}");
        }
示例#3
0
        public void CopyImage <TSrcPixel>(SpanBitmap <TSrcPixel> src, SpanTensor3 <float> dst)
            where TSrcPixel : unmanaged, Pixel.IReflection
        {
            var dstEncoding = _TensorsExtensions.GetColorEncoding <TPixel>();

            var cmad = ColorTransform;

            if (default(TSrcPixel).IsQuantized)
            {
                cmad = cmad.ConcatMul(1f / 255f);
            }

            var sampler = src.AsBitmapSampler();

            if (dst.Dimensions[2] == 3) // dst[h][w][3]
            {
                var tmpTensor = dst.UpCast <System.Numerics.Vector3>();
                tmpTensor.AsTensorBitmap(dstEncoding).FitPixels(sampler, cmad);
                return;
            }

            if (dst.Dimensions[2] == 4) // dst[h][w][4]
            {
                var tmpTensor = dst.UpCast <System.Numerics.Vector4>();
                tmpTensor.AsTensorBitmap(dstEncoding).FitPixels(sampler, cmad);
                return;
            }

            if (dst.Dimensions[0] == 3) // dst[3][h][w]
            {
                dst.AsBitmapSampler(dstEncoding).FitPixels(sampler, cmad);
                return;
            }

            throw new NotImplementedException();
        }
示例#4
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);
        }
示例#5
0
 void ITensorImageProcessor <float> .CopyImage(SpanTensor3 <float> src, SpanBitmap dst)
 {
     throw new NotImplementedException();
 }
 public static SpanTensor3 <float> SetImage(this SpanTensor3 <float> dst, SpanBitmap src, ITensorImageProcessor <float> options)
 {
     options.CopyImage(src, dst);
     return(dst);
 }