Animetrics Face Recognition

GRATIS CON POSSIBILITÀ DI UPGRADE
Da animetrics | Aggiornamento a month ago | Media
Health Check

N/A

Torna a tutte le discussioni

Keeps on returning: "message":"Missing Mashape application key. Go to https:\/\/www.mashape.com to get your key.".

Rapid account: Baggio Wong
BaggioWong
9 лет назад

Here’s my code block:

	//	set up picture
	$animetrics_api_key ='be1cfaea79d6160e1571bd56e24fcb97';
	// $animetrics_api_key = "66a6ffce3f6c402ff2e9e69dbc522722";	//	fudan mail API
	$photo_url = "http://api.animetrics.com/img/test/sc.jpg";

	//	features extraction
	$data = array('api_key'=>$animetrics_api_key, 'url'=> $photo_url); //'image'=>'@'.$path_to_local_file);
	// $data = array(
 //    "selector" => "FACE, EYES, FULL",
 //    "url" => "http://api.animetrics.com/img/test/sc.jpg"
 //  );
	$headers = array(
"X-Mashape-Key" => "75DpeDVzr9mshQ0bnpmZDNfiTNhcp1Z1SmJjsnUYhb5Ngif2Ea"//,
// "Content-Type" => "application/x-www-form-urlencoded",
// "Accept" => "application/json"

// “X-Mashape-Key: 75DpeDVzr9mshQ0bnpmZDNfiTNhcp1Z1SmJjsnUYhb5Ngif2Ea”,
// “Content-Type: application/x-www-form-urlencoded”,
// “Accept: application/json”

);
ch=curlinit();//curlsetopt(ch = curl_init(); // curl_setopt(ch, CURLOPT_URL, ‘http://api.animetrics.com/v1/detect’);
curl_setopt(ch,CURLOPTURL,https://animetrics.p.mashape.com/detect?apikey=be1cfaea79d6160e1571bd56e24fcb97);curlsetopt(ch, CURLOPT_URL, 'https://animetrics.p.mashape.com/detect?api_key=be1cfaea79d6160e1571bd56e24fcb97'); curl_setopt(ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(ch,CURLOPTFOLLOWLOCATION,TRUE);curlsetopt(ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt(ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, headers);curlsetopt(headers); curl_setopt(ch, CURLOPT_POSTFIELDS, $data);
response=curlexec(response = curl_exec(ch);

	echo $response;

But it always return the error message that it can’t detect my Mashape application key. Would appreciate some help, thanks.

Rapid account: Animetrics
animetrics Commented 9 лет назад

Glad you got it working!

Rapid account: Baggio Wong
BaggioWong Commented 9 лет назад

Whoops, forgot to close.

Rapid account: Baggio Wong
BaggioWong Commented 9 лет назад

Hey there I change two things and it’s now working:

First I changed the ‘image’ field to ‘url’ in the data array,
Second, I added an element in the data array - ‘selector’=> “FULL”, so it returns with the full array of all coordinates of the face in the photo.

Here’s the entire working code block:

try
{
    $mashape_key ='mashape_key';
    $animetrics_api_key ='animetrics_api_key';
    $selector = "FULL";
    $url = 'http://api.animetrics.com/img/test/sc.jpg';

$data = array('api_key'=>$animetrics_api_key,'selector'=>$selector, 'url'=>$url);//'@'.$path_to_local_file);
$headers = array('X-Mashape-Key: ' . $mashape_key);
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://animetrics.p.mashape.com/detect');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);

//echo $response;

$json = json_decode($response);

var_dump($json);

if (empty($json) || sizeof($json->images) < 1 || sizeof($json->images[0]->faces) < 1)
    throw new Exception('No faces found in response!');

$image_id = $json->images[0]->image_id;

// {...} store $image_id locally

$topLeftX = $json->images[0]->faces[0]->topLeftX;
$topLeftY = $json->images[0]->faces[0]->topLeftY;
$width    = $json->images[0]->faces[0]->width;
$height   = $json->images[0]->faces[0]->height;

echo "Face found with imageid $image_id at ($topLeftX, $topLeftY, $width, $height)" . PHP_EOL;
}
catch(Exception $e)
{
    echo $e->getMessage() . PHP_EOL;
}

Thanks for all your help and super rapid response! 😃

Have a nice one.

Rapid account: Baggio Wong
BaggioWong Commented 9 лет назад

Hi there - thanks for the quick response. And sorry about the code block - I must have forgotten to preview.

In any case, I’ve tried running this code block, and the request is sent, however, the response body is empty. All I did was to modify the $mashape_key, $animetrics_api_key, $path_to_local_file fields - I tried two variations of the $path_to_local_file variable - an online photo’s URL and a local photo’s URL, to no avail.

To be more precise, I commented the three conditions that threw a “no faces found in response”, and tried each condition in turn - and it was the last condition in the if statement that threw this error:

if (sizeof($json->images[0]->faces) < 1)
        throw new Exception('No faces found in response!');

Also, for the online photo, the URL I tried was this: http://api.animetrics.com/img/test/sc.jpg.

Would appreciate your advice on this, thanks!

Rapid account: Animetrics
animetrics Commented 9 лет назад

Please do not post your api and mashape keys publicly. Difficult to read your code because the formatting got messed up but the following modification of our example works.

<?php
try
{
	$mashape_key ='YOUR_MASHAPE_KEY_HERE';
	$animetrics_api_key ='YOUR_API_KEY_HERE';
	$path_to_local_file = '/Users/someone/image.jpg';

	$data = array('api_key'=>$animetrics_api_key,'image'=>'@'.$path_to_local_file);
	$headers = array('X-Mashape-Key: ' . $mashape_key);
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, 'https://animetrics.p.mashape.com/detect');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	$response = curl_exec($ch);

	//echo $response;

	$json = json_decode($response);

	if (empty($json) || sizeof($json->images) < 1 || sizeof($json->images[0]->faces) < 1)
		throw new Exception('No faces found in response!');

	$image_id = $json->images[0]->image_id;

	// {...} store $image_id locally

	$topLeftX = $json->images[0]->faces[0]->topLeftX;
	$topLeftY = $json->images[0]->faces[0]->topLeftY;
	$width    = $json->images[0]->faces[0]->width;
	$height   = $json->images[0]->faces[0]->height;

	echo "Face found with imageid $image_id at ($topLeftX, $topLeftY, $width, $height)" . PHP_EOL;
}
catch(Exception $e)
{
	echo $e->getMessage() . PHP_EOL;
}

?>

Partecipa alla discussione - aggiungi un commento di seguito:

Accedi/Iscriviti per pubblicare nuovi commenti