update lấy features từ ảnh upload
This commit is contained in:
@@ -10,6 +10,7 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use app\models\CaptureLogs;
|
||||
use app\models\common;
|
||||
use yii\helpers\FileHelper;
|
||||
|
||||
/**
|
||||
* ListMamagementController implements the CRUD actions for ListMamagement model.
|
||||
@@ -33,14 +34,14 @@ class ListManagementController extends Controller {
|
||||
public function actionIndex($from = "", $to = "", $name = "", $type = "all", $gender = "all") {
|
||||
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
|
||||
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
|
||||
if ($from !== "" && $to !== "") {
|
||||
$f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U');
|
||||
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
|
||||
}
|
||||
$this->view->title = "List management";
|
||||
$searchModel = new ListManagementSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]);
|
||||
if ($from !== "" && $to !== "") {
|
||||
$f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U');
|
||||
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
|
||||
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]);
|
||||
}
|
||||
if ($name !== "")
|
||||
$dataProvider->query->andWhere(["LIKE", "name", $name]);
|
||||
if ($type !== "all")
|
||||
@@ -58,10 +59,23 @@ class ListManagementController extends Controller {
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionView($id) {
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
public function actionAdd() {
|
||||
$model = new ListManagement();
|
||||
Yii::$app->response->format = "json";
|
||||
if (Yii::$app->request->post()) {
|
||||
$data = Yii::$app->request->post();
|
||||
$features = json_decode(common::requestToEngine("/get-feature", [
|
||||
"image_paths" => [
|
||||
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $data['image'], "type" => "raw"]
|
||||
]
|
||||
]), true);
|
||||
$data['image'] = json_encode([
|
||||
["url" => $data['image'], "features" => $features['results'][0]['feature']]
|
||||
]);
|
||||
$model->create($data);
|
||||
file_get_contents("http://localhost:2305/update-feature");
|
||||
return ["status" => true];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionCreate() {
|
||||
@@ -129,6 +143,16 @@ class ListManagementController extends Controller {
|
||||
if (Yii::$app->request->post()) {
|
||||
$data = Yii::$app->request->post();
|
||||
$model = $this->findModel($data['id']);
|
||||
if ($data['image'] !== "") {
|
||||
$features = json_decode(common::requestToEngine("/get-feature", [
|
||||
"image_paths" => [
|
||||
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $data['image'], "type" => "raw"]
|
||||
]
|
||||
]), true);
|
||||
$images = json_decode($model->image, true);
|
||||
$images[] = ["url" => $data['image'], "features" => $features['results'][0]['feature']];
|
||||
$model->image = json_encode($images);
|
||||
}
|
||||
$model->type = $data['type'];
|
||||
$model->name = $data['name'];
|
||||
$model->gender = $data['gender'];
|
||||
@@ -188,10 +212,24 @@ class ListManagementController extends Controller {
|
||||
if (Yii::$app->request->post()) {
|
||||
$model = new common();
|
||||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"dataPath" => "BiFace/",
|
||||
"url" => $model->UploadFile("AnhNhanVien", ["PNG", "JPG", "JPEG", "GIF"], "temp")
|
||||
];
|
||||
$url = $model->UploadFile("AnhNhanVien", ["PNG", "JPG", "JPEG", "GIF"], "temp");
|
||||
$features = json_decode(common::requestToEngine("/get-feature", [
|
||||
"image_paths" => [
|
||||
["url" => "/var/www/html/BiFace_Server_Lite/web/" . $url, "type" => "crop"]
|
||||
]
|
||||
]), true);
|
||||
unlink("/var/www/html/BiFace_Server_Lite/web/" . $url);
|
||||
if ($features['results'][0]['crop'] === "") {
|
||||
return ["status" => false];
|
||||
} else {
|
||||
$key = common::generateRandomString();
|
||||
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
|
||||
$targetPath = $RootFolder . "/face";
|
||||
$fileName = "face_" . $key . "_" . time() . ".png";
|
||||
FileHelper::createDirectory($targetPath, 0777);
|
||||
file_put_contents($targetPath . "/" . $fileName, base64_decode($features['results'][0]['crop']));
|
||||
return ["status" => true, "url" => $fileName, "dataPath" => "data/uploads/face/"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user