From 2e6e53bc1060e388f65c9a4a137d69e8c5053104 Mon Sep 17 00:00:00 2001 From: dongpd Date: Fri, 22 May 2020 14:49:20 +0700 Subject: [PATCH] BiFace config --- .gitignore | 4 +- assets/ConfigAsset.php | 23 + config/web.php | 4 +- controllers/ConfigController.php | 240 +++++++ controllers/SiteController.php | 2 +- .../yiisoft/yii2-app/layouts/header.php | 22 +- views/config/cau-hinh-nhan-dien.tpl | 627 ++++++++++++++++++ views/config/index.tpl | 63 ++ web/css/site.css | 403 +++++++++++ web/js/config.js | 151 +++++ 10 files changed, 1524 insertions(+), 15 deletions(-) create mode 100644 assets/ConfigAsset.php create mode 100644 controllers/ConfigController.php create mode 100644 views/config/cau-hinh-nhan-dien.tpl create mode 100644 views/config/index.tpl create mode 100644 web/js/config.js diff --git a/.gitignore b/.gitignore index 7f9ce2a2..f9a7c2d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /runtime /web/assets -/web/data \ No newline at end of file +/web/data +/vendor/ +/nbproject/private/ \ No newline at end of file diff --git a/assets/ConfigAsset.php b/assets/ConfigAsset.php new file mode 100644 index 00000000..326c6127 --- /dev/null +++ b/assets/ConfigAsset.php @@ -0,0 +1,23 @@ + 'basic', - 'homeUrl' => ['/dashboard'], + 'homeUrl' => ['/config'], 'name' => 'AIParking Server', - 'defaultRoute' => 'dashboard', + 'defaultRoute' => 'config', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'timeZone' => 'Asia/Ho_Chi_Minh', diff --git a/controllers/ConfigController.php b/controllers/ConfigController.php new file mode 100644 index 00000000..d72b1cb5 --- /dev/null +++ b/controllers/ConfigController.php @@ -0,0 +1,240 @@ +user->isGuest) { + return $this->redirect(['/site/login']); + } + } + + /** + * {@inheritdoc} + */ + public function behaviors() { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + public $config_json = [ + "camera" => [ + "auto_check" => 1, + "num_cam" => 2, + "rgb" => [ + "url" => "/dev/video3", + "type" => "usb", + "rotate" => -1, + "config" => [ + "enable" => 0, + "brightness" => 9999, + "gain" => 9999, + "saturation" => 9999, + "sharpness" => 9999 + ] + ], + "ir" => [ + "url" => "/dev/video1", + "type" => "usb", + "rotate" => -1, + "translate_x" => 0, + "translate_y" => 70, + "ir_scale" => 1.0, + "config" => [ + "enable" => 0 + ] + ], + "max_queue_size" => 6, + "count_frame_to_skip" => 0, + "fps" => 14, + "merge_queue_pause" => 10, + "raw_resolution" => [ + "width" => 1280, + "height" => 720 + ], + "cam_resize" => [ + "width" => 640, + "height" => 360 + ], + "crop_frame" => [ + "x" => 120, + "y" => 40, + "width" => 400, + "height" => 280 + ] + ], + "face_verify" => [ + "show_fake_label" => 0, + "debug" => 0, + "max_fake_time" => 4, + "min_real_time" => 1, + "saturation" => [ + "enable" => 1, + "min_std_thresh" => 13, + "min_mean_thresh" => 20 + ], + "mtcnn" => [ + "enable" => 1, + "size" => 96, + "num_thread" => 1 + ], + "ir_face_verify" => [ + "enable" => 1, + "ir_scale" => 1.05, + "ir_neighbor" => 1 + ] + ], + "haarcascade" => [ + "enable" => 1, + "show_time_detect" => 0, + "min_size" => 60, + "max_size" => 120, + "scale" => 1.1, + "neighbor" => 5 + ], + "engine" => [ + "max_fps" => 40, + "cam_id" => 311, + "server_authen" => "http://api.cloudv2.beetai.com/api/aibox/authentication" + ], + "recognition" => [ + "enable" => 1, + "accuracy" => 1.1, + "server_recog" => "http://api.biface.beetai.com/api/face_recognition_auth?token=", + "request_timeout" => 20, + "num_face_recog" => 100, + "first_time_recog" => 5, + "next_time_recog" => 5 + ], + "screen" => [ + "show_video" => 1, + "full_screen" => 1, + "width" => 1920, + "height" => 1080 + ], + "id_city" => 1581130, + "open_door" => [ + "enable" => 0, + "port_name" => "/dev/ttyUSB0" + ], + "log" => [ + "path" => "log.txt", + "limit" => 3000, + "clear_line" => 500 + ] + ]; + + /** + * Lists all Script models. + * @return mixed + */ + public function actionIndex() { + $this->view->title = "Cấu hình thiết bị"; + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ]; + $apiConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true); + return $this->render('index', [ + "apiConfig" => $apiConfig + ]); + } + + public function actionCauHinhMayChu() { + if (Yii::$app->request->post()) { + $post = Yii::$app->request->post(); + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + "servermqtt" => $post['servermqtt'], + "url" => $post['url'] + ]), + ] + ]; + json_decode(file_get_contents("http://localhost:4004/SaveAPIConfig", false, stream_context_create($options)), true); + return Url::to(['cau-hinh-nhan-dien']); + } + } + + public function actionCauHinhNhanDien() { + if (Yii::$app->request->post()) { + $post = Yii::$app->request->post(); + Yii::$app->response->format = "json"; + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ]; + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create($options)), true); + + if (!$tempConfig['status']) + return false; + + $engineConfig = json_decode($tempConfig['data'], true); + $engineConfig['data']['engines'][0]['isConfig'] = "1"; + + file_get_contents("http://localhost:4004/SaveEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $engineConfig['data']['engines'][0]['path'], + 'config' => $engineConfig, + 'configEngine' => $post['config'] + ]) + ] + ])); + return true; + } else { + $this->view->title = "Cấu hình nhận diện"; + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ])), true); + if (!$tempConfig['status']) + return $this->redirect(['/config']); + + $engineConfig = json_decode($tempConfig['data'], true); + $checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $engineConfig['data']['engines'][0]['path'] + ]) + ] + ])), true); + $config_json = $this->config_json; + if ($checkConfig['status']) + $config_json = json_decode($checkConfig['data'], true); + + return $this->render('cau-hinh-nhan-dien', [ + "config_json" => $config_json + ]); + } + } + +} diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 7715fe1f..2b91dae3 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -73,7 +73,7 @@ class SiteController extends Controller { $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { - return $this->redirect(["/dashboard"]); + return $this->redirect(["/config"]); } $model->password = ''; diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php index ab178948..342bdef5 100644 --- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php +++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php @@ -25,7 +25,7 @@ use yii\widgets\ActiveForm;