- Модуль: faceid
- Путь к файлу: ~/bitrix/modules/faceid/lib/photoidentifierfindface.php
- Класс: BitrixFaceIdPhotoIdentifierFindFace
- Вызов: PhotoIdentifierFindFace::identify
public function identify($imageContent, $galleryId = null)
{
$found = false;
$items = array();
$http = new BitrixMainWebHttpClient();
$resource = fopen($imageContent, 'r');
try
{
$http->setHeader('Authorization', 'Token '.$this->token);
$response = $http->post('https://api.findface.pro/v0/faces/gallery/'.$galleryId.'/identify/', array(
'photo' => $resource,
'threshold' => 'medium'
), true);
if ($http->getStatus() == 200)
{
$body = json_decode($response, true);
$bodyResults = array_values($body['results']);
if (!empty($bodyResults[0]))
{
$found = true;
$person = $bodyResults[0][0]; // just 0 for the old protocol
$items[] = array(
'face_id' => $person['face']['id'],
'meta' => $person['face']['meta'],
'confidence' => round($person['confidence'],4)*100,
'thumbnail' => $person['face']['thumbnail']
);
$msg = 'Found '.$person['face']['meta'].' ('.(round($person['confidence'],2)*100).'%)
'
.'
';
}
else
{
$msg = 'Unknown person';
}
}
else
{
$msg = $http->getStatus().': '.$response;
}
/*
//$res = $client->request('POST', 'https://api.findface.pro/identify/', array(
$res = $client->request('POST', 'https://api.findface.pro/v0/faces/gallery/'.$galleryId.'/identify/', array(
'multipart' => array(
array(
'name' => 'photo',
'contents' => $resource
)
),
'headers' => array(
'Authorization' => 'Token '.$this->token
)
));
if ($res->getStatusCode() == 200)
{
$body = json_decode($res->getBody(), true);
$bodyResults = array_values($body['results']);
if (!empty($bodyResults[0]))
{
$found = true;
$person = $bodyResults[0][0]; // just 0 for the old protocol
$msg = 'Found '.$person['face']['meta'].' ('.(round($person['confidence'],2)*100).'%)
'
.'
';
}
else
{
$msg = 'Unknown person';
}
}
else
{
$msg = $res->getStatusCode().': '.$res->getBody();
}
*/
}
catch (Exception $e)
{
$msg = $e->getMessage();
}
return array(
'found' => $found,
'items' => $items,
'msg' => $msg
);
}