private void Form1_Load(object sender, EventArgs e)
        {
            Capture capture = new Capture();

            capture.Start();
            capture.ImageGrabbed += (a, b) =>
            {
                var            image     = capture.RetrieveBgrFrame();
                var            grayimage = image.Convert <Gray, byte>();
                HaarCascade    haaryuz   = new HaarCascade("haarcascade_frontalface_alt2.xml");
                MCvAvgComp[][] Yuzler    = grayimage.DetectHaarCascade(haaryuz, 1.2, 5, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(15, 15));
                MCvFont        font      = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5);
                foreach (MCvAvgComp yuz in Yuzler[0])
                {
                    var sadeyuz = grayimage.Copy(yuz.rect).Convert <Gray, byte>().Resize(100, 100, INTER.CV_INTER_CUBIC);
                    //Resimler aynı boyutta olmalıdır. O yüzden Resize ile yeniden boyutlandırma yapılmıştır. Aksi taktirde Classifier_Train sınıfının 245. satırında hata alınacaktır.
                    pictureBox2.Image = sadeyuz.ToBitmap();
                    if (train != null)
                    {
                        if (train.IsTrained)
                        {
                            string name        = train.Recognise(sadeyuz);
                            int    match_value = (int)train.Get_Eigen_Distance;
                            image.Draw(name + " ", ref font, new Point(yuz.rect.X - 2, yuz.rect.Y - 2), new Bgr(Color.LightGreen));
                        }
                    }
                    image.Draw(yuz.rect, new Bgr(Color.Red), 2);
                }
                pictureBox1.Image = image.ToBitmap();
            };

            //Image<Gray, byte> img = new Image<Gray, byte>(new Bitmap("C:\\Users\\CurrentUser\\Desktop\\manzara-resimleri-56ce304610c7e.jpg"));
            //HaarCascade haaryuz = new HaarCascade("haarcascade_frontalface_alt2.xml");
            //MCvAvgComp[][] Yuzler = img.DetectHaarCascade(haaryuz, 1.2, 5, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(15, 15));

            //foreach (MCvAvgComp item in Yuzler[0])
            //{
            //    var yuz = img.Copy(item.rect).Convert<Gray, byte>().Resize(100, 100, INTER.CV_INTER_CUBIC);
            //    pictureBox1.Image = yuz.Bitmap;
            //    string name = train.Recognise(yuz);
            //}
        }
        //gelen resmi model ile kıyasla
        private void RecognisePicture(MemoryStream memoryStream)
        {
            Image <Gray, byte> img     = new Image <Gray, byte>(new Bitmap(Image.FromStream((Stream)memoryStream)));
            HaarCascade        haaryuz = new HaarCascade("haarcascade_frontalface_alt2.xml");

            MCvAvgComp[][] Yuzler = img.DetectHaarCascade(haaryuz, 1.2, 5, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(15, 15));

            foreach (MCvAvgComp item in Yuzler[0])
            {
                List <Classes.User> customerUsers = Classes.User.GetObjects().Where(x => x.CustomerId == GlobalSetting.CustomerId).ToList();
                var    yuz  = img.Copy(item.rect).Convert <Gray, byte>().Resize(100, 100, INTER.CV_INTER_CUBIC);
                string name = train.Recognise(yuz);
                if (string.IsNullOrEmpty(name) || name == "Tanımsız" || customerUsers.FirstOrDefault(x => x.Username == name) == null)
                {
                    AlarmSetting alarm = AlarmSetting.GetObjects().FirstOrDefault(x => x.AlarmSettingId == GlobalSetting.UserAlarmSettingId);
                    if (alarm.IsActive)
                    {
                        if (alarm.IsCallAlarmActive)
                        {
                            if (!string.IsNullOrEmpty(alarm.FirstPersonNumber))
                            {
                                if (alarm.FirstPersonNumber.Length == 10)
                                {
                                    alarm.FirstPersonNumber = "+90" + alarm.FirstPersonNumber;
                                }
                                else if (alarm.FirstPersonNumber.Length == 11)
                                {
                                    alarm.FirstPersonNumber = "+9" + alarm.FirstPersonNumber;
                                }
                                AlertRequest request = new AlertRequest();
                                request.AlarmNumber    = alarm.FirstPersonNumber;
                                request.AlarmParameter = string.Empty;
                                request.AlarmType      = "CallAlarm";
                                request.IsAlerted      = false;
                                request.Insert();
                            }

                            if (!string.IsNullOrEmpty(alarm.SecondPersonNumber))
                            {
                                if (alarm.SecondPersonNumber.Length == 10)
                                {
                                    alarm.SecondPersonNumber = "+90" + alarm.SecondPersonNumber;
                                }
                                else if (alarm.SecondPersonNumber.Length == 11)
                                {
                                    alarm.SecondPersonNumber = "+9" + alarm.SecondPersonNumber;
                                }
                                AlertRequest request = new AlertRequest();
                                request.AlarmNumber    = alarm.SecondPersonNumber;
                                request.AlarmParameter = string.Empty;
                                request.AlarmType      = "CallAlarm";
                                request.IsAlerted      = false;
                                request.Insert();
                            }
                        }
                        else if (alarm.IsPoliceAlarmActive)
                        {
                            if (alarm.SecondPersonNumber.Length == 10)
                            {
                                alarm.SecondPersonNumber = "+90" + alarm.SecondPersonNumber;
                            }
                            else if (alarm.SecondPersonNumber.Length == 11)
                            {
                                alarm.SecondPersonNumber = "+9" + alarm.SecondPersonNumber;
                            }
                            AlertRequest request = new AlertRequest();
                            request.AlarmNumber    = "911";
                            request.AlarmParameter = string.Empty;
                            request.AlarmType      = "CallAlarm";
                            request.IsAlerted      = false;
                            request.Insert();
                        }
                        else if (alarm.IsSmsAlarmActive)
                        {
                            if (alarm.SecondPersonNumber.Length == 10)
                            {
                                alarm.SecondPersonNumber = "+90" + alarm.SecondPersonNumber;
                            }
                            else if (alarm.SecondPersonNumber.Length == 11)
                            {
                                alarm.SecondPersonNumber = "+9" + alarm.SecondPersonNumber;
                            }
                            AlertRequest request = new AlertRequest();
                            request.AlarmNumber    = alarm.SecondPersonNumber;
                            request.AlarmParameter = string.Empty;
                            request.AlarmType      = "SmsAlarm";
                            request.IsAlerted      = false;
                            request.Insert();
                        }
                    }
                }
            }
        }