private void FaceSwapInTwoImages( Image <byte> argbImage1, Image <byte> argbImage2, Image <byte> facepointSource, out Image <byte> swapResult1) { if (argbImage1 == null || argbImage1.Channels < Color.RgbChannels) { throw new ArgumentException("Input image 1 should be a valid color image."); } if (argbImage2 == null || argbImage2.Channels < Color.RgbChannels) { throw new ArgumentException("Input image 2 should be a valid color image."); } // face detection Image <byte> imgGray1 = new ImageGray(facepointSource); //argbImage1 Stopwatch sw = Stopwatch.StartNew(); Stopwatch sw2 = Stopwatch.StartNew(); var faces1 = detector.Detect(imgGray1); if (faces1.Length < 1) { throw new InvalidOperationException("Fail to detect face in image 1."); } // pick two largest faces var face1 = faces1.OrderByDescending(y => y.Rect.Area).First(); Image <byte> imgGray2 = new ImageGray(argbImage2); sw.Restart(); var faces2 = detector.Detect(imgGray2); if (faces2.Length < 1) { throw new InvalidOperationException("Fail to detect face in image 2."); } var face2 = faces2.OrderByDescending(y => y.Rect.Area).First(); sw.Restart(); var alignmentShape1 = alignmentor.Align(imgGray1, face1.Rect); sw.Restart(); var alignmentShape2 = alignmentor.Align(imgGray2, face2.Rect); // create the face point file FaceSwapper.SaveTestData("points-Source", argbImage1, alignmentShape1); FaceSwapper.SaveTestData("facepoints-Source", facepointSource, alignmentShape1); FaceSwapper.SaveTestData("points-target", argbImage2, alignmentShape2); swapResult1 = argbImage2.Clone(); sw.Restart(); FaceSwapInternal(argbImage1, argbImage2, alignmentShape1, alignmentShape2, swapResult1); }
public void Awake() { instance = this; sp = faces.normal; }