Esempio n. 1
0
        private void LayBienSoXe()
        {
            Utilities.frmMain.lbThongBao.Text = "";

            Utilities.Cam1 = camTruoc.TakeSnapshot();
            Utilities.Cam2 = camSau.TakeSnapshot();
            Utilities.Cam3 = camToanCanh.TakeSnapshot();

            // nhan dien cam truoc
            Recognizer   recognizer = Recognizer.Instance;
            AlprPlateNet plate      = recognizer.Recognize(Utilities.Cam1);

            if (plate != null)
            {
                // hien thi len phieu can
                _frmPhieuCan.TxtBSX.Text = FormatBXS(plate.Characters);
            }
            else
            {
                // nhan dien cam sau - neu cam truoc ko dc
                plate = recognizer.Recognize(Utilities.Cam2);
                _frmPhieuCan.TxtBSX.Text = (plate == null) ? "Lấy biển số lỗi" : FormatBXS(plate.Characters);
            }

            // load cac thong tin liên quan nếu nhận diện được
            if (plate != null)
            {
                XeCtrl xeCtrl = new XeCtrl();
                XeInfo xeInfo = xeCtrl.LayThongTinXe(FormatBXS(plate.Characters));
                if (xeInfo != null)
                {
                    _frmPhieuCan.TxtKhachHang.Text = xeInfo.Khachhang;
                    _frmPhieuCan.TxtTenLaiXe.Text  = xeInfo.TaiXe;
                    _frmPhieuCan.TxtKLCanLan2.Text = xeInfo.TrongLuong.ToString();
                    _frmPhieuCan.TxtKLHang.Text    = (int.Parse(blKLCan.Text) - xeInfo.TrongLuong).ToString();
                    Utilities.XeDaCoTrongCSDL      = true;
                    Utilities.klXe = xeInfo.TrongLuong;
                }
                else
                {
                    frmMain.lbThongBao.Text = "Xe này chưa có trong cơ sở dữ liệu";
                }
            }
        }
            private void ExitExaminer()
            {
                AlprNet alpr = new AlprNet("us", "openalpr.conf", "runtime_dir");

                alpr.TopN = 1;
                HashSet <string> recognized = new HashSet <string>();
                Stopwatch        bar        = null;

                while (true)
                {
                    Bitmap bitmap;
                    lock (_lock)
                    {
                        if (_kill)
                        {
                            break;
                        }
                    }
                    if (bar != null && bar.IsRunning)
                    {
                        if (bar.ElapsedMilliseconds < 10000)
                        {
                            continue;
                        }
                        else
                        {
                            bar.Stop();
                            _framesQueue.TryDequeue(out bitmap);
                            _WriteLog("Bar closed", _name);
                        }
                    }
                    if (_framesQueue.TryDequeue(out bitmap))
                    {
                        bool           left    = false;
                        AlprResultsNet results = alpr.Recognize(bitmap);
                        if (results.Plates.Count != 0)
                        {
                            AlprPlateNet plate = results.Plates[0].BestPlate;
                            if (recognized.Add(plate.Characters))
                            {
                                _WriteLog(plate.Characters, _name);
                                try
                                {
                                    Api <HistoryLast> data = ("http://api.ipark.altervista.org/history/" + plate.Characters + "/last").SetQueryParams(new { token = _token }).GetJsonAsync <Api <HistoryLast> >().Result;
                                    if (data.meta.code == 200)
                                    {
                                        if (data.response.payment == null)
                                        {
                                            _WriteLog(plate.Characters + " has not paid yet", _name, LogType.WARNING);
                                            recognized.Remove(recognized.Last());
                                        }
                                        else
                                        {
                                            Api <Registered> internalData = ("http://api.ipark.altervista.org/history/register/exit/" + data.response.plate).SetQueryParams(new { token = _token }).PutJsonAsync(null).ReceiveJson <Api <Registered> >().Result;
                                            if (internalData.meta.code == 200)
                                            {
                                                _UpdatePie(UpdateType.SUB);
                                                _LogResult(internalData.response, _name);
                                                left = true;
                                            }
                                        }
                                    }
                                }
                                catch (Exception exception)
                                {
                                    _WriteLog(exception.ToString(), _name, LogType.ERROR);
                                }
                            }
                        }
                        if (left)
                        {
                            recognized.Clear();
                            bar = new Stopwatch();
                            bar.Start();
                            _WriteLog("Bar raised", _name);
                        }
                    }
                }
            }
        private async Task LayBienSo()
        {
            resetUI();

            // reset bien so
            Utilities.BienSoXe = null;

            Utilities.Cam1 = camTruoc.TakeSnapshot();
            Utilities.Cam2 = camTruoc01.TakeSnapshot();
            Utilities.Cam3 = camSau.TakeSnapshot();
            Utilities.Cam4 = camToanCanh.TakeSnapshot();

            // nhan dien cam truoc - nhan dien bien so chu nhat
            log.Info("Nhan dien bien so ngang");
            Recognizer   recognizer = Recognizer.Instance;
            AlprPlateNet plate      = recognizer.Recognize(Utilities.Cam1);

            if (plate != null)
            {
                // hien thi len phieu can
                txtBienSoXe.Text = FormatBXS(plate.Characters);
            }
            else
            {
                // nhan dien cam truoc 01
                plate = recognizer.Recognize(Utilities.Cam2);
                if (plate != null)
                {
                    txtBienSoXe.Text = FormatBXS(plate.Characters);
                }
                else
                {
                    // nhan dien cam sau
                    plate = recognizer.Recognize(Utilities.Cam3);
                    if (plate != null)
                    {
                        txtBienSoXe.Text = FormatBXS(plate.Characters);
                    }
                    //txtBienSoXe.Text = (plate == null) ? "Lấy biển số lỗi" : FormatBXS(plate.Characters);
                }
            }

            // nhan dien bien so vuong neu bien so hinh chu nhat khong nhan dien dc
            if (plate == null)
            {
                log.Info("Nhan dien bien so vuong");
                string plateNumber = await recognizer.RegconizeTwoLinePlate(Utilities.Cam1);

                if (plateNumber != null)
                {
                    txtBienSoXe.Text = FormatBXS(plateNumber);
                }
                else  // nhan dien cam2, neu cam1 NOT ok
                {
                    plateNumber = await recognizer.RegconizeTwoLinePlate(Utilities.Cam3);

                    if (plateNumber != null)
                    {
                        txtBienSoXe.Text = FormatBXS(plateNumber);
                    }
                    else
                    {
                        txtBienSoXe.Text = "Lấy biển số lỗi";
                    }
                }
            }

            // show bien so image
            pictureBoxBSXVao.Image = Utilities.BienSoXe;
        }