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 ], "video_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, "banner" => "Have a nice day!" ], "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" ] ]; $ip = "192.168.0.42"; $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true); if ($tempConfig['status']) { $t = json_decode($tempConfig['data'], true); $temp = explode("/", $t['url']); $servermqtt = $t['servermqtt']; } return $this->render('index', [ "servermqtt" => $servermqtt, "url" => $temp[2] ]); } 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" => "http://" . $post['url'] . "/api/box/getConfig" ]), ] ]; json_decode(file_get_contents("http://localhost:4004/SaveAPIConfig", false, stream_context_create($options)), true); return Url::to(['check-engine']); } } 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); if (count($engineConfig['data']['engines']) == 0) return $this->redirect(['/config']); $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); if (!$checkConfig['status']) return $this->redirect(['/config']); $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 ]); } } public function actionReset() { if (Yii::$app->request->isAjax) { $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); if (count($engineConfig['data']['engines']) == 0) { $path = ""; } else { $path = $engineConfig['data']['engines'][0]['path']; } file_get_contents("http://localhost:4004/Reset", false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", 'method' => "POST", 'content' => json_encode([ 'path' => $path ]) ] ])); return Url::to(['/config']); } } public function actionCheckEngine() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = "json"; $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 ['status' => false]; $engineConfig = json_decode($tempConfig['data'], true); if (count($engineConfig['data']['engines']) == 0) return ['status' => false]; $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); if (!$checkConfig['status']) { return ['status' => false]; } else { return ['status' => true, 'url' => Url::to(['cau-hinh-nhan-dien'])]; } } } }