Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
111
rated 0 times [  118] [ 7]  / answers: 1 / hits: 17189  / 8 Years ago, tue, december 13, 2016, 12:00:00

enter


I am fairly new to JavaScript and I am working on a project the uses facial recognition to detect emotion. The facial recognition part is detecting emotion but I need to access the resulting emotion. There's constant feedback coming from the facial recognition API and the results constantly change under the "div" id= results tag


<div id="results" style="word-wrap:break-word;">
<span> Timestamp: 93.12 </span>
<br>
<span>Number of faces found: 1</span>
<br>
<span> Appearance: {"gender":"Male","glasses":"Yes","age":"25 - 34","ethnicity":"Black African"}</span><br><span>Emotions: {"joy":0,"sadness":0,"disgust":1,"contempt":0,"anger":0,"fear":0,"surprise":0,"valence":0,"engagement":0}
</span>
<br>
<span> Emoji:
<img class="chromoji" title="Neutral Face" alt=":neutral_face:" src="chrome-extension://cahedbegdkagmcjfolhdlechbkeaieki/images/apple/1f610.png"></span>
<br>
</div>

The title "Neutral Face" or alt is one of the attributes of the dominant emotion needed


I tried using solutions from


Extract property of a tag in HTML using Javascript
and
How to get title attribute from link within a class with javascript


in my actual code I have


<div id="results" style="word-wrap:break-word;">
<script>
//var images = document.querySelectorAll('img');
var emotion = document.getElementByTagName("img")[0].getAttributes("title");
console.log(emotion)
</script>
</div>

I tried to use the last two lines of code in this snippet in a JS file that produces the results:


detector.addEventListener("onImageResultsSuccess", function(faces, image, timestamp) {
$('#results').html("");
log('#results', "Timestamp: " + timestamp.toFixed(2));
log('#results', "Number of faces found: " + faces.length);
if (faces.length > 0) {
log('#results', "Appearance: " + JSON.stringify(faces[0].appearance));
log('#results', "Emotions: " + JSON.stringify(faces[0].emotions, function(key, val) {
return val.toFixed ? Number(val.toFixed(0)) : val;
}));
log('#results', "Emoji: " + faces[0].emojis.dominantEmoji);
drawFeaturePoints(image, faces[0].featurePoints);
var motion = faces[0].emojis.dominantEmoji;
log('#results', motion);
}
});

also on a separate time I added this to the JavaScript file that needs the feedback for the emotion recognition


var tag = document.getElementByTagName("img")
var emotion= tag.getAttribute("title");
console.log(emotion);

also on another separate trial I did this in the index html file


<script type="text/javascript">
var image = document.getElementsByTagName("img")[0];
var title = image.getAttribute("title");
console.log(title); // shows the value of title for the element "image"
</script>

The main idea of the project is to detect a users emotion and play music based on that emotion


More From » jquery

 Answers
22

You can try this:


<script type="text/javascript">
var image = document.getElementsByTagName("img")[0];
var title = image.getAttribute("title");

console.log(title); // shows the value of title for the element "image"
</script>

See demo here: http://codepen.io/anon/pen/vyVQBJ


[#59728] Saturday, December 10, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alyssiat

Total Points: 608
Total Questions: 102
Total Answers: 101

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;