fix filters multi people

This commit is contained in:
dongpd 2021-06-07 13:55:54 +07:00
parent 821cf9463d
commit 1e3f0bef13
3 changed files with 157 additions and 5 deletions

View File

@ -503,4 +503,156 @@ class ApiController extends Controller {
return ["data" => "reset updating flag"];
}
public function actionCheckLogs() {
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
$id_camera = intval($device_id->data);
$datas = json_decode(file_get_contents($ip . "/api/model/get_log_model", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"idCamera" => $id_camera
])
]
])), true);
if ($datas['status'] == 10000) {
$logs = $datas['data'];
foreach ($logs as $key => $value) {
$response = json_decode(file_get_contents($ip . "/api/oem/get_all_image", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"id_camera" => $id_camera,
"ids_staff" => [],
"objs_staff" => [$value['obj_Staff']]
])
]
])), true);
if ($response['status'] == 10000) {
$personInfo = $response['data'][0];
$model = ListManagement::findOne(['staff_id' => $personInfo['id']]);
$ft = [];
if ($model) {
if (isset($personInfo['images'])) {
$extractFeature = $this->extractFeature($personInfo['images'], $personInfo['files_name'], $personInfo['id'], json_decode($model->image, true));
$ft = $extractFeature['features'];
}
$model->abbreviated_name = $personInfo['abbreviated_name'];
$model->code = $personInfo['code'];
$model->name = $personInfo['name'];
$model->address = $personInfo['department'];
$model->image = json_encode($ft);
$model->last_modified = time();
$model->save();
} else {
if (isset($personInfo['images'])) {
$extractFeature = $this->extractFeature($personInfo['images'], $personInfo['files_name'], $personInfo['id']);
$ft = $extractFeature['features'];
}
$model = new ListManagement();
$model->create([
'code' => strval($personInfo['code']),
'type' => "wl",
'name' => $personInfo['name'],
'abbreviated_name' => $personInfo['abbreviated_name'],
'staff_id' => $personInfo['id'],
'image' => json_encode($ft),
'gender' => "Male",
'birthday' => "",
'telephone' => "",
'address' => $personInfo['department']
]);
}
file_get_contents($ip . "/api/model/set_log_model", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"infomation" => [
["obj_Log" => $value['obj_Log']]
]
])
]
]));
file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
}
}
}
Yii::$app->response->format = "json";
return ["data" => "check logs"];
}
public function extractFeature($images, $files_name, $staff_id, $currentImg = false) {
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
$ft = [];
$currentArr = [];
if ($currentImg) {
foreach ($currentImg as $key => $value) {
if (isset($value['serverKey']))
$currentArr[] = $value['serverKey'];
}
$ft = $currentImg;
}
foreach ($images as $key => $value) {
if ($key < Yii::$app->params['maxPicture'] && !in_array($files_name[$key], $currentArr)) {
$fileName = "face_" . $staff_id . "_" . common::generateRandomString() . "_" . time() . ".png";
$img = false;
try {
$img = file_get_contents(str_replace("&amp;", "&", $value));
} catch (\Exception $e) {
}
if ($img && $img !== "null") {
$fileTarget = $targetPath . "/" . $fileName;
if (!$this->resizeImg($img, $fileTarget)) {
file_put_contents($fileTarget, $img);
}
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
],
"type" => "128"
]), true);
$ft[] = [
"serverKey" => $files_name[$key],
"url" => $fileName,
"urlOld" => $fileName,
"features" => $features['results'][0]['feature'],
"features512" => []
];
}
}
}
return [
"features" => $ft
];
}
public function resizeImg($img, $fileTarget) {
$im = imagecreatefromstring($img);
$width = imagesx($im);
$height = imagesy($im);
$newwidth = 224;
$newheight = 224;
if ($width > $newwidth && $height > $newheight) {
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $fileTarget);
imagedestroy($thumb);
imagedestroy($im);
return true;
}
return false;
}
}

View File

@ -424,7 +424,7 @@ class ListManagementController extends Controller {
])), true);
$filters = [];
foreach ($datas['data'] as $key => $value) {
$filters[$value['code']] = $value['code'] . " - " . $value['name'] . " - " . $value['department'];
$filters[$value['id']] = $value['code'] . " - " . $value['name'] . " - " . $value['department'];
}
Yii::$app->response->format = "json";
return [
@ -680,7 +680,7 @@ class ListManagementController extends Controller {
$datas = ListManagement::find()->orderBy(["code" => SORT_ASC])->all();
$filters = [];
foreach ($datas as $key => $value) {
$filters[$value->code] = $value->code . " - " . $value->name . " - " . $value->address;
$filters[$value->staff_id] = $value->code . " - " . $value->name . " - " . $value->address;
}
return [
"title" => "<i class='fa fa-upload'></i> Đồng bộ lên máy chủ",

View File

@ -593,12 +593,12 @@ function filters(e) {
if (id === "") {
$(".filters").removeClass("hidden");
$(".btn-select").removeClass("hidden");
checkAllSync(false);
// checkAllSync(false);
} else {
$(".filters").addClass("hidden");
$("#filters-" + id).removeClass("hidden");
$(".btn-select").addClass("hidden");
checkAllSync(false);
// checkAllSync(false);
choooseToSync($("#filters-" + id));
}
}
@ -607,7 +607,7 @@ function removeFilters() {
$(".filters").removeClass("hidden");
$(".btn-select").removeClass("hidden");
$("#filter-from-server").val('').trigger('change');
checkAllSync(false);
// checkAllSync(false);
}
function getTotalFeature() {