Beispiel #1
0
        public async Task <SoftwareBitmap> SwapFacesAsync(SoftwareBitmap background, SoftwareBitmap foreground)
        {
            var backgroundPrep = await PrepBitmapAsync(background);

            if (backgroundPrep == null)
            {
                return(null);
            }
            var backgroundFaces  = backgroundPrep.Item1;
            var backgroundPoints = backgroundPrep.Item2;

            var foregroundPrep = await PrepBitmapAsync(foreground);

            if (foregroundPrep == null)
            {
                return(null);
            }
            var foregroundFaces  = foregroundPrep.Item1;
            var foregroundPoints = foregroundPrep.Item2;

            try
            {
                var resultingImage = default(Image <byte>);
                swapper.Swap3D(backgroundFaces, backgroundPoints, foregroundFaces, foregroundPoints, resultingImage);
                return(ConvertTo.SoftwareBitmap.FromImage(resultingImage));
            }
            catch (Exception ex)
            {
                Debugger.Break();
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Swap two faces and dump result.
        /// </summary>
        /// <param name="face1"></param>
        /// <param name="face2"></param>
        /// <param name="faceShape1"></param>
        /// <param name="faceShape2"></param>
        /// <param name="swapResult1">Swap result image, should be same as face1</param>
        private void FaceSwapInternal(
            Image <byte> face1,
            Image <byte> face2,
            IList <PointF> faceShape1,
            IList <PointF> faceShape2,
            Image <byte> swapResult1)
        {
            Stopwatch sw = Stopwatch.StartNew();

            // swap face 1 to face 2
            swapper.Swap3D(face1, faceShape1, face2, faceShape2, swapResult1);

            sw.Stop();
            long time1 = sw.ElapsedMilliseconds;

            sw.Restart();

            // swap face 2 to face 1
            //swapper.Swap3D(face2, faceShape2, face1, faceShape1, swapResult1);

            sw.Stop();
            long time2 = sw.ElapsedMilliseconds;
        }