我试图用FrameDetector处理现有的MP4文件。 我已经把视频文件和HTML / JavaScript的下方的node.js服务器内,并在本地主机上运行,所以不应该有奥比CORS问题。
该探测器正常启动,但是当我的图像数据发送给它,同样的两件事情,每次:
- 第一请求返回一个空
faces
阵列 - 所述第二请求返回错误(每次用一个独特的,尾随数):
worker code reported an exception14920304
。
我真的不知道该怎么与MESSAGE-做没有任何人有什么建议?
//- FrameDetector.pug
html
head
title FrameDetector Demo
script(src='https://download.affectiva.com/js/3.2/affdex.js')
body
canvas#canvas
video#video-to-analyze(preload="auto" controls="true")
source(type="video/mp4" src="video/my-video.mp4")
script(src='js/FrameDetector.js')
和
// FrameDetector.js
var heartbeat, startTimestamp;
document.addEventListener('DOMContentLoaded', function(){
var v = document.getElementById('video-to-analyze');
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var cw = Math.floor(canvas.clientWidth / 100);
var ch = Math.floor(canvas.clientHeight / 100);
canvas.width = cw;
canvas.height = ch;
v.addEventListener('play', function(){
draw(this,context,cw,ch);
},false);
},false);
function draw(v,c,w,h) {
if(v.paused || v.ended) return false;
c.drawImage(v,0,0,w,h);
setTimeout(draw,20,v,c,w,h);
}
function analyzeVideoFrame() {
//Get a canvas element from DOM
var aCanvas = document.getElementById("canvas");
var context = aCanvas.getContext('2d');
//Get imageData object.
var imageData = context.getImageData(0, 0, 640, 360);
console.log("Captured imageData.", imageData);
//Get current time in seconds
var now = (new Date()).getTime() / 1000;
//Get delta time between the first frame and the current frame.
var deltaTime = now - startTimestamp;
//Process the frame
detector.process(imageData, deltaTime);
}
function onImageResultsSuccess(faces, image, timestamp) {
console.log("onImageResultsSuccess:", timestamp, faces.length, faces[0]);
}
function onImageResultsFailure(image, timestamp, err_detail) {
console.error("onImageResultsFailure:", timestamp, err_detail);
clearInterval(heartbeat);
}
if (typeof(affdex)=="undefined") {
console.log("The affdex global variable has not been loaded.");
}
var detector = new affdex.FrameDetector(affdex.FaceDetectorMode.LARGE_FACES);
detector.detectAllExpressions();
detector.detectAllEmotions();
detector.detectAllAppearance();
detector.addEventListener("onInitializeSuccess", function() {
document.getElementById('video-to-analyze').play();
startTimestamp = (new Date()).getTime() / 1000;
heartbeat = setInterval(analyzeVideoFrame, 1000);
});
detector.addEventListener("onInitializeFailure", function() {
console.error("Affectiva failed to initialize.");
});
detector.addEventListener("onImageResultsSuccess", onImageResultsSuccess);
detector.addEventListener("onImageResultsFailure", onImageResultsFailure);
detector.start();
输出在控制台:
Captured imageData. ImageData {data: Uint8ClampedArray(921600), width: 640, height: 360}
onImageResultsSuccess: 0.005000114440917969 0 undefined
Captured imageData. ImageData {data: Uint8ClampedArray(921600), width: 640, height: 360}
onImageResultsFailure: 0.0009999275207519531 worker code reported an exception14920304