private void timerPlateIn_Tick(object sender, EventArgs e)
        {
            Image <Bgr, byte> capPrImageIn = null;

            if (isDemo)
            {
                if (_currentFramePlateIn < _totalFramePlateIn)
                {
                    capPrImageIn = _capturePlateIn.QueryFrame().ToImage <Bgr, byte>();
                    _currentFramePlateIn++;
                    Image_Xe_Vao_Truoc.Update();
                }
                //await Task.Delay(1000 / _fpsFaceIn / 4);
            }
            else
            {
                capPrImageIn = _capturePlateIn.QueryFrame().ToImage <Bgr, byte>();
                //Image_Xe_Vao_Truoc.Update();
                //Image_Xe_Vao_Sau.Update();
            }

            if (capPrImageIn != null && isFinishFaceIn)
            {
                try
                {
                    List <Rectangle>  listRect = new List <Rectangle>();
                    List <Mat>        listMat  = new List <Mat>();
                    Bitmap            imagePlate;
                    Image             Plate_Draw;
                    Image <Bgr, byte> Plate_Draw_Resize;

                    _currentPRDT = DateTime.Now;
                    //if (_currentPRDT.Subtract(_startPRDT).TotalMilliseconds > DELAY_PR_DT)
                    //{
                    //    _startPRDT = DateTime.Now;
                    _lpr.ProcessImage(capPrImageIn.Bitmap, out Plate_Draw, out Plate_Draw_Resize, null);
                    if (Plate_Draw_Resize != null)
                    {
                        isFinishPlateIn   = true;
                        Image_Plate.Image = Plate_Draw;
                    }
                    //if (_lpr.DetectRectangleLPR(capPrImageIn.Bitmap, out imagePlate, out listRect, out listMat))
                    //{

                    //}
                    //}
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Beispiel #2
0
        private void timerPlateOut_Tick(object sender, EventArgs e)

        {
            Image <Bgr, byte> capPrImageOut = null;

            if (_isDemo)
            {
                if (_currentFramePlateOut < _totalFramePlateOut)
                {
                    capPrImageOut = _capturePlateOut.QueryFrame().ToImage <Bgr, byte>();
                    _currentFramePlateOut++;
                    Image_Xe_Ra_Truoc.Image = capPrImageOut.Resize(Image_Xe_Ra_Truoc.Width, Image_Xe_Ra_Truoc.Height, Inter.Cubic).Bitmap;
                    Image_Xe_Ra_Truoc.Update();
                }
                //await Task.Delay(1000 / _fpsFaceIn / 4);
            }
            else if (_capturePlateOut.IsOpened)
            {
                capPrImageOut           = _capturePlateOut.QueryFrame().ToImage <Bgr, byte>();
                Image_Xe_Ra_Truoc.Image = capPrImageOut.Resize(Image_Xe_Ra_Truoc.Width, Image_Xe_Ra_Truoc.Height, Inter.Cubic).Bitmap;
            }

            if (capPrImageOut != null && _isFinishFaceOut && !_isFinishOut)
            {
                lbNotify.Text = Global.TEXT_DETECT_PLATE;
                try
                {
                    Image             Plate_Draw;
                    Image <Bgr, byte> PlateResize;
                    _lprPlateOut.ProcessImage(capPrImageOut.Bitmap, out Plate_Draw, out PlateResize, _plate);
                    if (_lprPlateOut.PlateImagesList.Count != 0)
                    {
                        _isFinishPlateOut = true;
                        Bitmap imagePlate = null;
                        string biensoxe   = _lprPlateOut.GetRecoginatinon(_lprPlateOut.PlateImagesList, out imagePlate);
                        Image_Plate.Image = (new Image <Bgr, byte>(imagePlate).Resize(Image_Plate.Width, Image_Plate.Height, Inter.Cubic)).Bitmap;
                        #region Xử lý khi đã nhận diện biển số thành công (Lưu ảnh và lưu vào cơ sở dữ liệu
                        if (imagePlate != null)
                        {
                            DateTime currentDT = DateTime.Now;
                            string   stringDT  = currentDT.Year.ToString() + currentDT.Month.ToString()
                                                 + currentDT.Day.ToString() + currentDT.Hour.ToString()
                                                 + currentDT.Minute.ToString() + currentDT.Second.ToString();
                            string pathface  = Global.PATH_FACE_IMAGE + stringDT + ".jpg";
                            string pathPlate = Global.PATH_PLATE_IMAGE + stringDT + ".jpg";;
                            string pathFull  = Global.PATH_FULL_IMAGE + stringDT + ".jpg";;
                            if (biensoxe.Length > 7)
                            {
                                if (_checkOCRPlateOut != biensoxe)
                                {
                                    _isCheckPlateOut  = false;
                                    _checkOCRPlateOut = biensoxe;
                                }
                                else
                                {
                                    //lbNotify.Text = Global.TEXT_SAVE;
                                    _isCheckPlateOut = true;
                                }
                                lbPlate.Text = biensoxe;
                                if (_isCheckPlateOut)
                                {
                                    if (_IsExistFaceOut)
                                    {
                                        LeaveError resultDB = _dataContext.CheckGoLeave(Int32.Parse(lbID.Text), biensoxe, pathface, pathPlate, pathFull);
                                        if (resultDB == LeaveError.SUCCESSS)
                                        {
                                            _captureFaceOut.QueryFrame().ToImage <Bgr, byte>().Save(pathFull);
                                            imagePlate.Save(pathPlate);
                                            _image_Store_FaceOut.Save(pathface);
                                            string OCR = biensoxe;
                                            lbPlate.Text  = OCR;
                                            lbNotify.Text = Global.TEXT_SUCCESS;
                                            MessageBox.Show("Xe ra thành công");
                                            _isFinishFaceOut        = false;
                                            _isFinishOut            = true;
                                            _startWatingTimeFaceOut = DateTime.Now;
                                            _isLeave         = false;
                                            _countErrorPlate = 0;
                                        }
                                        else if (resultDB == LeaveError.NOTFOUND)
                                        {
                                            if (_isLeave)
                                            {
                                                lbNotify.Text = Global.TEXT_SUCCESS;
                                                MessageBox.Show("Xe ra thất bại, có thể khuôn mặt không đúng hoặc là xe mới. Vui lòng kiểm tra lại ");

                                                _isLeave = false;
                                            }
                                        }
                                        else if (resultDB == LeaveError.WRONGOCG && _countErrorPlate <= 5)
                                        {
                                            _countErrorPlate++;
                                        }
                                        else if (resultDB == LeaveError.WRONGOCG && _countErrorPlate > 5)
                                        {
                                            ReasonForm reasonForm = new ReasonForm(null, biensoxe,
                                                                                   null, _captureFaceOut.QueryFrame().ToImage <Bgr, byte>(),
                                                                                   null, _image_Store_FaceOut,
                                                                                   null, new Image <Bgr, byte>(imagePlate));
                                            reasonForm.ShowDialog();
                                            // _dataContext.CreateMember(biensoxe, pathface, pathPlate, pathFull);
                                            string OCR = biensoxe;
                                            lbPlate.Text            = OCR;
                                            _isFinishFaceOut        = false;
                                            _isFinishOut            = true;
                                            _startWatingTimeFaceOut = DateTime.Now;
                                        }
                                    }
                                    else
                                    {
                                        if (_isStopFinish)
                                        {
                                            ReasonForm reasonForm = new ReasonForm(null, biensoxe,
                                                                                   null, _captureFaceOut.QueryFrame().ToImage <Bgr, byte>(),
                                                                                   null, _image_Store_FaceOut,
                                                                                   null, new Image <Bgr, byte>(imagePlate));
                                            reasonForm.Show();
                                            // _dataContext.CreateMember(biensoxe, pathface, pathPlate, pathFull);
                                            string OCR = biensoxe;
                                            lbPlate.Text            = OCR;
                                            _isFinishFaceOut        = false;
                                            _isFinishOut            = true;
                                            _startWatingTimeFaceOut = DateTime.Now;
                                        }
                                    }
                                    lbDirector.Text = Global.TEXT_DIRECTOR_OUT;

                                    _dataContext.LoadTraningFace(out _listFace, out _listLabel);
                                    _recognition.Update(_listFace, _listLabel);
                                }
                            }
                        }
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Beispiel #3
0
        private void timerPlateIn_Tick(object sender, EventArgs e)
        {
            Image <Bgr, byte> capPrImageIn = null;

            if (_isDemo)
            {
                if (_currentFramePlateIn < _totalFramePlateIn)
                {
                    capPrImageIn = _capturePlateIn.QueryFrame().ToImage <Bgr, byte>();
                    _currentFramePlateIn++;
                    Image_Xe_Vao_Truoc.Image = capPrImageIn.Resize(Image_Xe_Vao_Truoc.Width, Image_Xe_Ra_Truoc.Height, Inter.Cubic).Bitmap;
                    Image_Xe_Vao_Truoc.Update();
                }
                //await Task.Delay(1000 / _fpsFaceIn / 4);
            }
            else if (_capturePlateIn.IsOpened)
            {
                capPrImageIn             = _capturePlateIn.QueryFrame().ToImage <Bgr, byte>();
                Image_Xe_Vao_Truoc.Image = capPrImageIn.Resize(Image_Xe_Vao_Truoc.Width, Image_Xe_Ra_Truoc.Height, Inter.Cubic).Bitmap;
            }

            if (capPrImageIn != null && _isFinishFaceIn && !_isFinishIn)
            {
                lbNotify.Text = Global.TEXT_DETECT_PLATE;
                try
                {
                    Image             Plate_Draw;
                    Image <Bgr, byte> PlateResize;
                    _lprPlateIn.ProcessImage(capPrImageIn.Bitmap, out Plate_Draw, out PlateResize, _plate);
                    if (_lprPlateIn.PlateImagesList.Count != 0)
                    {
                        _isFinishPlateIn = true;
                        Bitmap imagePlate = null;
                        string biensoxe   = _lprPlateIn.GetRecoginatinon(_lprPlateIn.PlateImagesList, out imagePlate);
                        Image_Plate.Image = (new Image <Bgr, byte>(imagePlate).Resize(Image_Plate.Width, Image_Plate.Height, Inter.Cubic)).Bitmap;
                        #region Xử lý khi đã nhận diện biển số thành công (Lưu ảnh và lưu vào cơ sở dữ liệu
                        if (imagePlate != null)
                        {
                            DateTime currentDT = DateTime.Now;
                            string   stringDT  = currentDT.Year.ToString() + currentDT.Month.ToString()
                                                 + currentDT.Day.ToString() + currentDT.Hour.ToString()
                                                 + currentDT.Minute.ToString() + currentDT.Second.ToString();
                            string pathface  = Global.PATH_FACE_IMAGE + stringDT + ".jpg";
                            string pathPlate = Global.PATH_PLATE_IMAGE + stringDT + ".jpg";;
                            string pathFull  = Global.PATH_FULL_IMAGE + stringDT + ".jpg";;
                            if (biensoxe.Length > 7)
                            {
                                if (_checkOCRPlateIn != biensoxe)
                                {
                                    _isCheckPlateIn  = false;
                                    _checkOCRPlateIn = biensoxe;
                                }
                                else
                                {
                                    lbNotify.Text   = Global.TEXT_SAVE;
                                    _isCheckPlateIn = true;
                                }
                                lbPlate.Text = biensoxe;
                                if (_isCheckPlateIn)
                                {
                                    if (_IsExistFaceIn)
                                    {
                                        _dataContext.CreateGoLeave(Int32.Parse(lbID.Text), biensoxe, pathface, pathPlate, pathFull);
                                        _captureFaceIn.QueryFrame().ToImage <Bgr, byte>().Save(pathFull);
                                        imagePlate.Save(pathPlate);
                                        _image_Store_FaceIn.Save(pathface);
                                        string OCR = biensoxe;
                                        lbPlate.Text    = OCR;
                                        lbNotify.Text   = Global.TEXT_SUCCESS;
                                        _isFinishFaceIn = false;
                                        _isFinishIn     = true;
                                        MessageBox.Show("Xe vào thành công");
                                        _startWatingTimeFaceIn = DateTime.Now;
                                    }
                                    else
                                    {
                                        _dataContext.CreateMember(biensoxe, pathface, pathPlate, pathFull);
                                        _captureFaceIn.QueryFrame().ToImage <Bgr, byte>().Save(pathFull);
                                        imagePlate.Save(pathPlate);
                                        _image_Store_FaceIn.Save(pathface);
                                        string OCR = biensoxe;
                                        lbPlate.Text    = OCR;
                                        lbNotify.Text   = Global.TEXT_SUCCESS;
                                        _isFinishFaceIn = false;
                                        _isFinishIn     = true;
                                        MessageBox.Show("Xe vào thành công");
                                        _startWatingTimeFaceIn = DateTime.Now;
                                    }
                                    lbDirector.Text = Global.TEXT_DIRECTOR_GO;
                                    _dataContext.LoadTraningFace(out _listFace, out _listLabel);
                                    _recognition.Update(_listFace, _listLabel);
                                }

                                _isFinishPlateIn = true;
                            }
                        }
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }