Esempio n. 1
0
        public void ControlLoad(object sender, EventArgs e)
        {
            var environmentService = new EnvironmentService();
            var haarEyeFile = new FileInfo(environmentService.GetAbsolutePathFromAssemblyRelative("haarcascades/haarcascade_eye.xml"));
            var haarFaceFile = new FileInfo(environmentService.GetAbsolutePathFromAssemblyRelative("haarcascades/haarcascade_frontalface_default.xml"));

            _faceDetector = new FaceDetector(haarFaceFile.FullName, haarEyeFile.FullName);

            _sunglassOverlay2 = new AccessoryOverlay(environmentService.GetAbsolutePathFromAssemblyRelative("Resources/Images/sunglasses2.png"));
            _hatOverlay1 = new AccessoryOverlay(environmentService.GetAbsolutePathFromAssemblyRelative("Resources/Images/partyhat.png"));

            _classiferParams = new ClassifierParameters();
            classifierConfigControl.ConfigChanged += classifierConfigControl_ConfigChanged;
        }
Esempio n. 2
0
        public void ControlLoad(object sender, EventArgs e)
        {
            var environmentService = new EnvironmentService();
            var haarEyeFile        = new FileInfo(environmentService.GetAbsolutePathFromAssemblyRelative("haarcascades/haarcascade_eye.xml"));
            var haarFaceFile       = new FileInfo(environmentService.GetAbsolutePathFromAssemblyRelative("haarcascades/haarcascade_frontalface_default.xml"));

            _faceDetector = new FaceDetector(haarFaceFile.FullName, haarEyeFile.FullName);

            _sunglassOverlay2 = new AccessoryOverlay(environmentService.GetAbsolutePathFromAssemblyRelative("Resources/Images/sunglasses2.png"));
            _hatOverlay1      = new AccessoryOverlay(environmentService.GetAbsolutePathFromAssemblyRelative("Resources/Images/partyhat.png"));

            _classiferParams = new ClassifierParameters();
            classifierConfigControl.ConfigChanged += classifierConfigControl_ConfigChanged;
        }
Esempio n. 3
0
        /// <summary>
        /// If ROI goes beyond the image boundaries, things blow up
        /// </summary>
        private void ConformRoi(AccessoryOverlay accessory, Image <Bgra, byte> inputBgra)
        {
            var roiRect = accessory.CalculatedRectangle;

            var farRight = roiRect.X + roiRect.Width;

            if (farRight > inputBgra.Width)
            {
                roiRect.Width -= (farRight - inputBgra.Width);
            }

            if (roiRect.Y < 0)
            {
                roiRect.Height += roiRect.Y;
                roiRect.Y       = 0;
            }
            accessory.CalculatedRectangle = roiRect;
        }
Esempio n. 4
0
        public Image <Bgra, byte> WearObject(Image <Bgra, byte> inputBgra, AccessoryOverlay accessory)
        {
            var bgraBlack = new Bgra(0, 0, 0, 0);

            if (accessory.FinalRectangle == Rectangle.Empty)
            {
                return(inputBgra);
            }

            ConformRoi(accessory, inputBgra);

            var overlayRect       = accessory.FinalRectangle;
            var resizeOverlayBgra = accessory.Overlay.Resize(overlayRect.Width, overlayRect.Height, Inter.Linear);

            var overlayTargetBgra = new Image <Bgra, byte>(inputBgra.Width, inputBgra.Height, bgraBlack);

            Log.Info(m => m("Overlay rect {0}", overlayRect));
            overlayTargetBgra.ROI = overlayRect;
            resizeOverlayBgra.CopyTo(overlayTargetBgra);
            overlayTargetBgra.ROI = Rectangle.Empty;

            const bool useMask = true;

            if (useMask)
            {
                var overlayMask = new Image <Gray, Byte>(inputBgra.Width, inputBgra.Height);
                CvInvoke.CvtColor(overlayTargetBgra, overlayMask, ColorConversion.Bgr2Gray);
                overlayMask = overlayMask.ThresholdBinary(new Gray(1), new Gray(1));
                inputBgra.SetValue(bgraBlack, overlayMask);
            }

            var outputBgra = inputBgra.AddWeighted(overlayTargetBgra, 1, 1, 1);

            inputBgra.ROI  = Rectangle.Empty;
            outputBgra.ROI = Rectangle.Empty;

            return(outputBgra);
        }
Esempio n. 5
0
        /// <summary>
        /// If ROI goes beyond the image boundaries, things blow up
        /// </summary>
        private void ConformRoi(AccessoryOverlay accessory, Image<Bgra, byte> inputBgra)
        {
            var roiRect = accessory.CalculatedRectangle;

            var farRight = roiRect.X + roiRect.Width;
            if (farRight > inputBgra.Width)
            {
                roiRect.Width -= (farRight - inputBgra.Width);
            }

            if (roiRect.Y < 0)
            {
                roiRect.Height += roiRect.Y;
                roiRect.Y = 0;

            }
            accessory.CalculatedRectangle = roiRect;
        }
Esempio n. 6
0
        public Image<Bgra, byte> WearObject(Image<Bgra, byte> inputBgra, AccessoryOverlay accessory)
        {
            var bgraBlack = new Bgra(0, 0, 0, 0);

            if (accessory.FinalRectangle == Rectangle.Empty)
            {
                return inputBgra;
            }

            ConformRoi(accessory, inputBgra);

            var overlayRect = accessory.FinalRectangle;
            var resizeOverlayBgra = accessory.Overlay.Resize(overlayRect.Width, overlayRect.Height, Inter.Linear);

            var overlayTargetBgra = new Image<Bgra, byte>(inputBgra.Width, inputBgra.Height, bgraBlack);
            Log.Info(m => m("Overlay rect {0}", overlayRect));
            overlayTargetBgra.ROI = overlayRect;
            resizeOverlayBgra.CopyTo(overlayTargetBgra);
            overlayTargetBgra.ROI = Rectangle.Empty;

            const bool useMask = true;
            if (useMask)
            {
                var overlayMask = new Image<Gray, Byte>(inputBgra.Width, inputBgra.Height);
                CvInvoke.CvtColor(overlayTargetBgra, overlayMask, ColorConversion.Bgr2Gray);
                overlayMask = overlayMask.ThresholdBinary(new Gray(1), new Gray(1));
                inputBgra.SetValue(bgraBlack, overlayMask);
            }

            var outputBgra = inputBgra.AddWeighted(overlayTargetBgra, 1, 1, 1);

            inputBgra.ROI = Rectangle.Empty;
            outputBgra.ROI = Rectangle.Empty;

            return outputBgra;
        }