didier

improvements on video, second way of detecting dices

arcs_module(
function(ARCS, tracking, POS, SVD) {
function(ARCS, _tracking, POS, SVD) {
var DiceDetector, DiceFace, recoverImageData;
var debugFeatures = function(context, corners) {
for (var i= 0; i < corners.length/2; i++) {
var color = '#' + Math.floor(Math.random()*16777215).toString(16);
context.fillStyle = color;
context.strokeStyle = color;
context.fillRect(corners[2*i], corners[2*i+1], 4, 4);
}
};
/**
* Dice face description
* @typedef {Object} DiceFaceDescription
......@@ -152,7 +164,7 @@ arcs_module(
//<--
var context = temporaryCanvas.getContext("2d");
context.putImageData(this.imageData, 0,0);
SURF.drawIPoints(context, this.keyPoints);
debugFeatures(context, this.corners);
//-->
};
......@@ -183,19 +195,18 @@ arcs_module(
this.imageData = {};
//<--
this.imageData = recoverImageData(descr.imageId);
var grayImage = tracking.Image.grayscale(
tracking.Image.blur(this.imageData.data,
this.imageData.width,
this.imageData.height),
this.imageData.height,blurRadius),
this.imageData.width, this.imageData.height);
this.corners = tracking.Fast.findCorners(grayImage,
this.imageData.width,
this.imageData.height);
this.descriptors = tracking.Brief.getDescriptors(grayImage, this.imageData.width, corners1);
/*var grayImage = SURF.grayImage(this.imageData);
this.keyPoints = SURF.surfDetDes(grayImage/*, 3,4,2,0.001*/);*/
this.descriptors = tracking.Brief.getDescriptors(grayImage, this.imageData.width, this. corners);
this.debugImage();
//-->
......@@ -250,7 +261,7 @@ arcs_module(
* @slot
*/
this.detect = function(image) {
var keyPoints = [];
//var keyPoints = [];
var globalMatches = [];
var points2D = [];
......@@ -266,27 +277,25 @@ arcs_module(
// will give hints about using surfDetDes(...)
//<--
/*grayImage = SURF.grayImage(image);
keyPoints = SURF.surfDetDes(grayImage/*, 3,4,2,0.001*/);*/
grayImage = tracking.Image.grayscale(tracking.Image.blur(image.data, image.width, image.height, blurRadius), image.width, image.height);
var corners = tracking.Fast.findCorners(grayImage, image.width, image.height));
var corners = tracking.Fast.findCorners(grayImage, image.width, image.height);
var descriptors = tracking.Brief.getDescriptors(grayImage, image.width, corners);
//-->
for (i =0; i< 6; i++) {
if (keyPoints.length > 0) {
if (corners.length > 0) {
// TODO #3: find matches between acquired image (img) and die faces.
// See documentation of global object SURF.
// It will give hints about using getMatches(...)
//<--
var matches = tracking.Brief.reciprocalMatch(corners, descriptors, diceFaces[i].corners, diceFaces[i].descriptors);
//console.log("matches length ", matches.length);
//-->
// if there are enough matches ...
if (matches.length >= 6) {
console.log("Found matches with image ", diceFaces[i].imageId);
//console.log("Found matches with image ", diceFaces[i].imageId);
for (j=0; j < matches.length; j++) {
// TODO #5
// insert, at the back of the point2D array,
......@@ -296,11 +305,8 @@ arcs_module(
// See also documentation of object of type Array in javascript
//<--
points2D.push(matches[j].keypoint1);
points3D.push(diceFaces[i].get3DCounterpart(matches[j].keypoint1));
/*points2D.push(matches[j][0]);
points3D.push(
diceFaces[i].get3DCounterpart(matches[j][1].x, matches[j][1].y));*/
points2D.push({ x: matches[j].keypoint1[0], y: matches[j].keypoint1[1]} );
points3D.push(diceFaces[i].get3DCounterpart(matches[j].keypoint2[0], matches[j].keypoint2[1] ));
//-->
}
......@@ -317,7 +323,7 @@ arcs_module(
//<--
if (debugCanvas) {
SURF.drawIPoints(debugCanvas.getContext("2d"), points2D);
debugFeatures(debugCanvas.getContext("2d"), corners);
}
//-->
......@@ -333,6 +339,7 @@ arcs_module(
//<--
pose = poseEstimator.pose(points2D, points3D);
//pose = {};
pose.rotation = pose.bestRotation;
pose.translation = pose.bestTranslation;
marker.id = currentId ;
......@@ -370,7 +377,6 @@ arcs_module(
},
[
"deps/tracking.js/tracking",
//{name:"deps/surf/surf", exports:"SURF"},
{name:"deps/pose/posit_gen",exports:"POS"},
{name:"deps/pose/svd",exports:"SVD"}
]
......
......@@ -15,6 +15,8 @@ arcs_module(function(ARCS) {
} else {
video.src = stream;
}
video.videoWidth=defaultWidth;
video.videoHeight=defaultHeight;
self.emit("onReady");
};
......@@ -40,7 +42,6 @@ arcs_module(function(ARCS) {
this.grabFrame = function () {
if ( context === undefined || canvas === undefined || video === undefined)
return;
if (video.readyState === video.HAVE_ENOUGH_DATA) {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
......