content
FaceRect
  Last updated: 22/3/2018
  • Installs:
  • Today: 0
  • All Time: 73944
Developer:userapicloud
Discussions
1 Answer
Follow conversation
getting response issue
The code below enables to detect the facial features. I'm having an issue with getting the response when the request is sent. Please help troubleshoot such issue.

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Facerect</title>
</head>

<body>

<script>

//chnage this url

url += "url=" + encodeURI(image_location);
url += "&features=true";

alert(url);

var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader("X-Mashape-Authorization", "zVNNYMfznlE1LpqFTWDjx7Ddt3yD51oy");


xmlhttp.onreadystatechange=function(){

alert(xmlhttp.readyState + "," + xmlhttp.status);
alert(xmlhttp.statusText);
alert(xmlhttp.responseText);


if(xmlhttp.readyState==4) {
alert ("response text = " + xmlhttp.responseText);

var response=JSON.parse(xmlhttp.responseText);
//alert (xmlhttp.responseText);
alert (response.faces[0].features.nose.x);

//var response=JSON.parse(xmlhttp.responseText);
//alert (xmlhttp.responseText);
alert (response.faces[0].features.nose.y);

//var response=JSON.parse(xmlhttp.responseText);
//alert (xmlhttp.responseText);
alert (response.faces[0].features.mouth.x);

//var response=JSON.parse(xmlhttp.responseText);
//alert (xmlhttp.responseText);
alert (response.faces[0].features.mouth.y);

alert (response.faces[0].features.eyes[0].x);
alert (response.faces[0].features.eyes[0].y);
alert (response.faces[0].features.eyes[1].x);
alert (response.faces[0].features.eyes[1].y);

var x1 = response.faces[0].features.eyes[0].x;
var y1 = response.faces[0].features.eyes[0].y;
var x2 = response.faces[0].features.eyes[1].x;
var y2 = response.faces[0].features.eyes[1].y;

var dist = Math.sqrt(((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)));

alert(dist);
}
}

xmlhttp.send(null);


</script>
</body>
</html>
user
apicloudresponded with an answer
Hi there!
Seems like you are trying to perform a cross-domain HTTP request which is blocked by most browsers. Please see the following StackOverflow question:

A possible solution would be to perform server-side calls to the API instead of using JS and XMLHttpRequest. Hope that helps!

Best regards,
Andy
userHello developer, Please Sign in to post an answer
x
circle
FaceRect
$ / m
We will charge your card every month for the plan amount, as well as any overages incurred in the previous month.
?

Oops, we are missing some details

Looks like there are a few missing details that you haven't filled in yet.
These details are important and will help us protect you and let you know about anything new.

x

Login to RapidAPI

Create endpoints based on popular APIs and share with others.
Follow popular APIs and get updated. Stand out in the community of developers.

LOG INSIGN UP
Login with Github
Login with Facebook
Login with Google
Or
Remember Me

  • We're not going to post anything on your wall.
  • We're not planning to spam you.
  • esccloses this view
    x

    Why sign up to RapidAPI?

    • integrate
      Integrate APIs into your app
      Ruby, Java, Elixir, Node.js, Phyton, Objective C, Swift, PHP and MORE
    • keys
      Save all API keys in one place
    • notifications
      Get notifications about API changes
    • stats
      Get stats and monitor API connections
    Sign up with Github
    Sign up with Facebook
    Sign up with Google
  • We're not going to post anything on your wall.
  • We're not planning to spam you.
  • esccloses this view
    x

    Authentication

    Authenticate
    esccloses this view