Created
March 27, 2015 07:31
-
-
Save 0V/e4a7da4faf13d4aa6b38 to your computer and use it in GitHub Desktop.
クロマキー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Mat ChromaKey(Mat srcMat, Mat backMat, int hueMin, int hueMax, int saturationMin, int saturationMax, int valueMin, int valueMax, int morphorogyIterations = 1) | |
{ | |
var mask = ColorExtractionMask(srcMat, ColorConversion.BgrToHsv, hueMin, hueMax, saturationMin, saturationMax, valueMin, valueMax); var element = new Mat(); | |
var back = new Mat(); | |
var face = new Mat(); | |
var result = new Mat(); | |
Cv2.MorphologyEx(mask, mask, MorphologyOperation.Close, element, null, morphorogyIterations); | |
Cv2.MorphologyEx(mask, mask, MorphologyOperation.Open, element, null, morphorogyIterations); | |
var reverseMask = ~mask; | |
srcMat.CopyTo(face, reverseMask); | |
backMat.CopyTo(back, mask); | |
Cv2.Add(back, face, result); | |
mask.Dispose(); | |
element.Dispose(); | |
back.Dispose(); | |
face.Dispose(); | |
reverseMask.Dispose(); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment