コード例 #1
0
        public static Image <Gray, byte> DetectAndTrimFace(int[] pixels, Size initialSize, Size outputSize, String haarcascadePath)
        {
            var inBitmap = ConvertToBitmap(pixels, initialSize.Width, initialSize.Width);

            //for testing purposes I can the picture to a folder
            //inBitmap.Save(@"E:\data\phototest\received.bmp");

            var grayframe = new Image <Gray, byte>(inBitmap);

            var haar  = new HaarCascade(haarcascadePath);
            var faces = haar.Detect(grayframe,
                                    1.2,
                                    3,
                                    HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                    new Size(30, 30));


            if (faces.Count() != 1)
            {
                return(null);
            }
            var face = faces[0];

            var returnImage = grayframe.Copy(face.rect).Resize(outputSize.Width, outputSize.Height, INTER.CV_INTER_CUBIC);

            //cleanup managed resources
            haar.Dispose();
            grayframe.Dispose();

            return(returnImage);
        }
コード例 #2
0
ファイル: Face.cs プロジェクト: dtfirewind/UnityOpenCV
 public void Dispose()
 {
     _faceCascade.Dispose();
 }