diff --git a/images/hart.png b/images/hart.png new file mode 100644 index 0000000..4fb7a4d Binary files /dev/null and b/images/hart.png differ diff --git a/images/hartje2.jpg b/images/hartje2.jpg new file mode 100644 index 0000000..e2cf3ae Binary files /dev/null and b/images/hartje2.jpg differ diff --git a/index5.html b/index5.html index 36e0d7c..63103c9 100644 --- a/index5.html +++ b/index5.html @@ -18,6 +18,8 @@ //var threshold = 120; //circus var contourFinder = new ContourFinder(); var startTime = 0; + var currentContour = 0; + $( document ).ready(function() { console.log( "ready!" ); image = document.getElementById('image'); @@ -34,7 +36,17 @@ // ToDo: preprocess: threshold contourFinder.findContours(image,foregroudColor,backgroundColor,threshold); - alert(Date.now()-startTime); + console.log("contourFinder.allpoints.length): " + contourFinder.allpoints.length); + //alert(Date.now()-startTime); + + imageCtx.clearRect(0,0,1000,1000); + + for (var i=0; i diff --git a/js/ContourFinder.js b/js/ContourFinder.js index 3157d4b..85b4b9f 100644 --- a/js/ContourFinder.js +++ b/js/ContourFinder.js @@ -6,7 +6,9 @@ function ContourFinder() { this.fColor; // foreground color this.bColor; // background color this.threshold; - this.maxContourPoints = 500*4; + this.maxContourPoints = 500*10; //was 500*4 + this.allpoints = []; + this.findContours = function(image,foregroundColor,backgroundColor,threshold) { var w = this.pixelsWidth = image.width; var h = this.pixelsHeight = image.height; @@ -51,6 +53,8 @@ function ContourFinder() { //imageCtx.putImageData(imageData, 0, 0); // at coords 0,0 //return; + var counter = 0; + for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var index = y*w*4+x*4; @@ -64,7 +68,9 @@ function ContourFinder() { value = (value > threshold)? 255 : 0; // if we enter a foreGround color and red isn't 0 (already stored as contour) if(prevValue == backgroundColor && value == foregroundColor && r != 0) { - this.followContour([x,y]); + var points = this.followContour([x,y]); + this.allpoints.push(points); + counter++; } //r = 255; @@ -75,6 +81,12 @@ function ContourFinder() { prevValue = value; } } + + // console.log("counter: " +counter); + + // console.log(this.getPoints(points)); + // console.log("======================================"); + /*for (var i = 0, n = pixels.length; i < n; i += 4) { var grayscale = pixels[i ] * .3 + pixels[i+1] * .59 + pixels[i+2] * .11; @@ -187,7 +199,10 @@ function ContourFinder() { //console.log(point[0],startPoint[0]," ",point[1],startPoint[1]); } while(!(point[0] == startPoint[0] && point[1] == startPoint[1]) && numPoints < this.maxContourPoints); + this.closeContour(points); + + return points; } this.closeContour = function(points) { //console.log("pixels: ",this.pixels);