Skip to content

Commit

Permalink
adding polygon capture method
Browse files Browse the repository at this point in the history
  • Loading branch information
gvn committed Dec 23, 2013
1 parent aa09c7e commit f7a5e2d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _ui/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ video {
margin-right: 10px;
}

video:hover {
cursor: crosshair;
}

canvas, img {
width: 640px;
height: 480px;
Expand Down
25 changes: 25 additions & 0 deletions _ui/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ window.VIDEO = {

// Canvas Setup

self.ctx.imageSmoothingEnabled = true;
self.ctx.fillStyle = '#666';
self.ctx.fillRect(0, 0, self.options.width, self.options.height);

Expand Down Expand Up @@ -79,6 +80,30 @@ window.VIDEO = {
self.ctx.drawImage(self.elVideo, 0, 0, self.options.width, self.options.height);
self.ctx.restore();
},
/**
* Capture a polygonal shape from the video feed and render it onto the canvas
* @param {Array} points An array of arrays containing two Number values for x and y coords
*/
updatePolygon: function (points) {
var self = this;

if (points.length < 3) {
throw 'Polygons must have at least 3 points';
}

self.ctx.save();
self.ctx.beginPath();
self.ctx.moveTo(points[0][0], points[0][1]);

for (var i = 1; i < points.length; i++) {
self.ctx.lineTo(points[i][0], points[i][1]);
}

self.ctx.closePath();
self.ctx.clip();
self.ctx.drawImage(self.elVideo, 0, 0, self.options.width, self.options.height);
self.ctx.restore();
},
startRowGrab: function () {
var self = this,
x = 0,
Expand Down

0 comments on commit f7a5e2d

Please sign in to comment.