diff --git a/v_dl/sdk/www/lib/visageRendering.js b/v_dl/sdk/www/lib/visageRendering.js index e49e004..ce6119c 100644 --- a/v_dl/sdk/www/lib/visageRendering.js +++ b/v_dl/sdk/www/lib/visageRendering.js @@ -14,7 +14,7 @@ var IRIS_COLOR = "rgba(200,80,0,255)", FEMALE_GENDER = "rgba(255,0,0,0.8)", GRAY_COLOR = "rgba(128,128,128,1)", GREEN_COLOR = "rgba(0,255,0,1)"; - + var CHIN_POINTS = "#8080FF", INNER_LIP_POINTS = "#EC0000", OUTER_LIP_POINTS = "#EC0000", @@ -26,11 +26,11 @@ var CHIN_POINTS = "#8080FF", EYEBROWS_COLOR = "#E3FE49", HAIR_COLOR = "#646464", GAZE_COLOR = "#00FF00"; - + var CALIB_COLOR = "#1d97e9", ESTIM_COLOR = "#37fd82"; - - + + var styles = {'LINE' : 0, 'LINELOOP' : 1, 'POINT' : 2, 'SPLINE' : 3} var splineResolution = 5; @@ -87,7 +87,7 @@ function drawPoints2D(points, pointsNum, style, featurePoints2D, color, radius, canCon.beginPath(); canCon.closePath(); - + var n = 0; for (var i = 0; i < pointsNum*2; i+=2){ if (featurePoints2D.FPIsDefined(points[i],points[i+1]) === true){ @@ -157,7 +157,7 @@ function drawPoints2D(points, pointsNum, style, featurePoints2D, color, radius, } } } - + n++; } } @@ -181,9 +181,9 @@ function drawPoints2D(points, pointsNum, style, featurePoints2D, color, radius, } } } - - - + + + if (style == styles.LINELOOP){ var x = featurePoints2D.getFPPos(points[0],points[1])[0]*canvas.width; var y = (1 - featurePoints2D.getFPPos(points[0],points[1])[1])*canvas.height; @@ -195,19 +195,19 @@ function drawPoints2D(points, pointsNum, style, featurePoints2D, color, radius, } /* -* Draw irises +* Draw irises */ function drawIrises(faceData, width, height) { var irisRadius = faceData.getIrisRadius(); - + if (irisRadius[0] > 0 || irisRadius[1] > 0) { var featurePoints2D = faceData.getFeaturePoints2D(); - + var fpGroup = 3; var fpIndex = [5,6]; - + for (var irisIndex = 0; irisIndex < 2; irisIndex+=1) { if (irisRadius[irisIndex] > 0) @@ -235,7 +235,7 @@ function drawIrises(faceData, width, height) * Draw facial features *

* @param {FaceDataVector} faceData - Array of {@link FaceData|FaceData} objects containing the tracking results -* @param {bool} drawQuality +* @param {bool} drawQuality * Extracts location of feature points from faceData. Calls drawPoints2D() function for drawing feature points and lines between points on canvas. */ function drawFaceFeatures(faceData, drawQuality) @@ -243,14 +243,14 @@ function drawFaceFeatures(faceData, drawQuality) if (typeof drawQuality === 'undefined') drawQuality = false; var radius = (faceData.faceScale / mWidth) * 10; - + var chinPoints = [ 2, 1, ] drawPoints2D(chinPoints, 1, styles.POINT, faceData.getFeaturePoints2D(),POINTS_COLOR, radius, drawQuality); - + var innerLipPoints = [ 2, 2, 17, 18, @@ -389,7 +389,7 @@ function drawFaceFeatures(faceData, drawQuality) ] drawPoints2D(irisPoints, 1,styles.POINT, faceData.getFeaturePoints2D(),IRIS_COLOR,radius); } - + if(faceData.getEyeClosure()[1]) { //if eye is open, draw the iris @@ -605,7 +605,7 @@ function drawFaceFeatures(faceData, drawQuality) 15, 4, 15, 2 ] - + drawPoints2D(contourPointsPhysical, 17, styles.SPLINE, faceData.getFeaturePoints2D(), SPLINES_COLOR, true); drawPoints2D(contourPointsPhysical, 17, styles.POINT, faceData.getFeaturePoints2D(), POINTS_COLOR, radius, drawQuality, true); } @@ -613,7 +613,7 @@ function drawFaceFeatures(faceData, drawQuality) /** * Draw tracking quality bar on canvas *

-* @param {float} quality - Estimated tracking quality level for the current frame. The value is between 0 and 1. +* @param {float} quality - Estimated tracking quality level for the current frame. The value is between 0 and 1. */ function drawTrackingQualityBar(quality) { @@ -626,7 +626,7 @@ function drawTrackingQualityBar(quality) var barPosY = mHeight*0.9; var barColor = "rgba("+ (255 - quality*255).toFixed(0) + "," + (quality*255).toFixed(0) + ",0,1.0)"; - var barColor + var barColor //background rectangle canCon.beginPath(); canCon.rect(barPosX, barPosY, barWidth, barHeight); @@ -664,7 +664,7 @@ function drawName(x,y,name) canCon.fillText(""+ name, x+6, y+6); canCon.closePath(); canCon.translate(mWidth, 0); - canCon.scale(-1, 1); + canCon.scale(-1, 1); } /** @@ -682,54 +682,54 @@ function draw3DModel() faceModelGeometry.dispose(); var texCoordsStatic = TfaceDataArray.get(0).getFaceModelTextureCoordsStatic(); - + tempUV = [[]]; var triangles = TfaceDataArray.get(0).getFaceModelTriangles(); for(var i = 0; i < triangles.length; i += 3) - { + { face = [ new THREE.Vector2( texCoordsStatic[ triangles[i] * 2 - ], + ], texCoordsStatic[ triangles[i] * 2 + 1 ] ), - + new THREE.Vector2( texCoordsStatic[ triangles[i + 1] * 2 - ], + ], texCoordsStatic[ triangles[i + 1] * 2 + 1 ] ), - + new THREE.Vector2( texCoordsStatic[ triangles[i + 2] * 2 - ], + ], texCoordsStatic[ triangles[i + 2] * 2 + 1 ] ) - ]; - + ]; + tempUV[0].push(face); } faceModelGeometry = new THREE.Geometry(); //faceModelTriangleCount - + var triangles = TfaceData.getFaceModelTriangles(); for(i=0;i
@@ -1020,7 +1046,7 @@ function drawGaze(faceData){ * @param {int} mode - used to determine the operating mode */ function drawGenderAgeEmotions(emotion_values,gender,age,index,mode) -{ +{ if (mode === MODE_TRACK) { fd = TfaceDataArray.get(index); @@ -1029,19 +1055,19 @@ function drawGenderAgeEmotions(emotion_values,gender,age,index,mode) { fd = DfaceDataArray.get(index); } - + calculateBackgroundSize(); var x; var y; var xOffset = 5; var yOffset = 15 - + var down = fd.getFeaturePoints2D().getFPPos(2,1); var left = fd.getFeaturePoints2D().getFPPos(4,5); var right = fd.getFeaturePoints2D().getFPPos(4,6); var up = fd.getFeaturePoints2D().getFPPos(11,1); - + if (up[1] * canvas.height - backgroundHeight < canvas.height) { x = (1 - up[0])*canvas.width; @@ -1070,10 +1096,10 @@ function drawGenderAgeEmotions(emotion_values,gender,age,index,mode) var emotions = ["Anger", "Disgust", "Fear", "Happiness", "Sadness", "Surprise", "Neutral"]; canCon.fillStyle="rgba(255,255,255,0.5)"; - + canCon.fillRect(x,y,backgroundWidth,backgroundHeight); - - if(withinConstraints()) + + if(withinConstraints()) { if(drawGender && drawAge) { @@ -1123,9 +1149,9 @@ function drawGenderAgeEmotions(emotion_values,gender,age,index,mode) else canCon.fillText("Age: -- ",x+xOffset,y+yOffset); canCon.closePath(); - + } - + if(drawEmotions && (drawAge || drawGender)) { canCon.beginPath(); @@ -1141,7 +1167,9 @@ function drawGenderAgeEmotions(emotion_values,gender,age,index,mode) { for(var j = 0; j < numberOfEmotions; ++j) { - var length = emotion_values[j] * (backgroundWidth-emotionsBarOffset-xOffset*3); + console.log(emotion_values[j]); + beep(100, 500 + 500 * emotion_values[j], 1, "sine", () => {}); + var length = emotion_values[j] * (backgroundWidth-emotionsBarOffset-xOffset*3); canCon.beginPath(); canCon.fillStyle="black"; canCon.font = fontSize.toString() + "px Arial"; @@ -1165,7 +1193,7 @@ function drawGenderAgeEmotions(emotion_values,gender,age,index,mode) canCon.fillText("only in frontal pose",x+xOffset,y+yOffset*backgroundHeight/backgroundHeightMax*3); canCon.fillText("and if face is fairly",x+xOffset,y+yOffset*backgroundHeight/backgroundHeightMax*4); canCon.fillText("close to the camera.",x+xOffset,y+yOffset*backgroundHeight/backgroundHeightMax*5); - + canCon.closePath(); } } @@ -1176,7 +1204,7 @@ function drawGenderAgeEmotions(emotion_values,gender,age,index,mode) * Parameters: */ function calculateBackgroundSize() -{ +{ backgroundWidthMax = 180; backgroundHeightMax = 120; @@ -1184,8 +1212,8 @@ function calculateBackgroundSize() { if(drawEmotions) { - fontSizePerc = 15/backgroundWidthMax; - + fontSizePerc = 15/backgroundWidthMax; + } else { @@ -1199,25 +1227,25 @@ function calculateBackgroundSize() backgroundWidthMax = 180; backgroundHeightMax = 80; fontSizePerc = 15/backgroundWidthMax; - + } - + backgroundPercW = backgroundWidthMax/canvas.width; - backgroundPercH = backgroundHeightMax/canvas.height; + backgroundPercH = backgroundHeightMax/canvas.height; backgroundWidth = canvas.width * backgroundPercW; backgroundHeight = canvas.height * backgroundPercH; - + verticalStepMax = 12; verticalStepPerc = verticalStepMax/backgroundHeightMax; - verticalStep = backgroundHeight * verticalStepPerc; - + verticalStep = backgroundHeight * verticalStepPerc; + emotionsBarOffsetMax = 70; emotionsBarOffsetPerc = emotionsBarOffsetMax/backgroundWidthMax; emotionsBarOffset = backgroundWidth * emotionsBarOffsetPerc + 1; backgroundLine = backgroundWidth * 0.9; - - fontSize = backgroundWidth*fontSizePerc; + + fontSize = backgroundWidth*fontSizePerc; } /** @@ -1238,9 +1266,9 @@ function withinConstraints() // var CONSTRAINT_ANGLE = 40; // - if (Math.abs(head_pitch_compensated_deg) > CONSTRAINT_ANGLE || - Math.abs(head_yaw_compensated_deg) > CONSTRAINT_ANGLE || - Math.abs(head_roll_deg) > CONSTRAINT_ANGLE || + if (Math.abs(head_pitch_compensated_deg) > CONSTRAINT_ANGLE || + Math.abs(head_yaw_compensated_deg) > CONSTRAINT_ANGLE || + Math.abs(head_roll_deg) > CONSTRAINT_ANGLE || fd.faceScale < 40) { return false; @@ -1254,7 +1282,7 @@ function withinConstraints() * Parameters: * @param {float} x x coordinate of the point in normalized screen coordinates * @param {float} y y coordinate of the point in normalized screen coordinates -* @param {int} inState - state of gaze estimator:
+* @param {int} inState - state of gaze estimator:
* - Estimator is off, inState is equal to 0.
* - Estimator is calibrating, inState is equal to 1.
* - Estimator is estimating, inState is equal to 2. @@ -1267,7 +1295,7 @@ function drawScreenSpaceGaze(gazeCanCon, x, y, inState) { gazeCanCon.closePath(); gazeCanCon.fill(); } - + if (inState == 1 || inState == 2) { gazeCanCon.beginPath(); gazeCanCon.fillStyle = '#070a0f'; @@ -1275,7 +1303,7 @@ function drawScreenSpaceGaze(gazeCanCon, x, y, inState) { gazeCanCon.closePath(); gazeCanCon.fill(); } - + if (inState == 1) { gazeCanCon.beginPath(); gazeCanCon.fillStyle = CALIB_COLOR; @@ -1283,7 +1311,7 @@ function drawScreenSpaceGaze(gazeCanCon, x, y, inState) { gazeCanCon.closePath(); gazeCanCon.fill(); } - + if (inState == 2) { gazeCanCon.beginPath(); gazeCanCon.fillStyle = ESTIM_COLOR; @@ -1298,7 +1326,7 @@ function drawScreenSpaceGaze(gazeCanCon, x, y, inState) { *

*/ function multiplyMatrix(m1, m2, M, N, P) { - + var res = []; for(var i = 0; i < M; ++i) { @@ -1312,6 +1340,6 @@ function multiplyMatrix(m1, m2, M, N, P) { res[i*P+j] = sum; } } - + return res; }