image-pixel-data-crop.js

total 0
used 0
limit 0
/* title: Image Data Boundry Edge Detection categories: imagedata raw files: head pointlist point stage stroke ../point_src/random.js ../point_src/image.js ../point_src/image-edge-detection.js ../point_src/recttools.js ../point_src/offscreen.js --- */ class MainStage extends Stage { canvas='playspace' mounted(){ // this.dragging.add() this.point = new Point(100, 100, 50) this.points = PointList.generate.random(3, [100, 200], [50, 50, 10, 0]) } firstDraw(ctx) { // this.clear(ctx) this.drawAll(ctx) } detectEdges(ctx) { const imageData = ctx.getImageData(0, 0, 400, 400) const data = imageData.data; let place = detectEdges(imageData.data, imageData.width) return place; } drawAll(ctx=this.ctx){ this.clear(ctx) this.points.pen.fill(ctx, '#999') this.points.pen.indicator(ctx, {width:1}) // this.point.pen.indicator(ctx) const imageData = ctx.getImageData(0, 0, 400, 400) const data = imageData.data; // sepia(data) // ctx.putImageData(imageData, 200, 10); // invert(data) // ctx.putImageData(imageData, 400, 30); // grayscale(data) // ctx.putImageData(imageData, 600, 30); // const reImageData = ctx.getImageData(0, 0, 800, 600) let place = detectEdges(imageData.data, imageData.width) ctx.putImageData(imageData, 0, 300); this.place = place this.plotEdgePoints(place) this.drawPins(ctx) } plotEdgePoints(place){ this.boxPoints = new PointList( [place.left, place.top] , [place.left, place.bottom] // , [place.right, place.bottom] // , [place.right, place.top] // , [place.left, place.top] ).cast() this.boxPoints2 = new PointList( // [place.left, place.top] // , [place.left, place.bottom] [place.right, place.bottom] , [place.right, place.top] // , [place.left, place.top] ).cast() } drawPins(ctx){ this.boxPoints.pen.indicator(ctx, {color: 'red'}) this.boxPoints2.pen.indicator(ctx, {color: 'yellow'}) } onResize(ev) { console.log('Resize', this) /* Resize may occur before mounted(). As such - easy back-out... */ if(this.points) { this.drawAll() } } createImage(){ /* grab the placement, and create a new download image with cropping.*/ let edges = this.place let offscreen = this.offscreen.create(edges) let ctx = this.ctx const imageData = ctx.getImageData( edges.left, //x edges.top, //y edges.width, edges.height ) // const data = imageData.data; let offCtx = offscreen.getContext('2d') offCtx.putImageData(imageData, 0, 0); setTimeout(()=>{ let cb = (blob) => { const anchor = document.createElement('a'); anchor.download = name anchor.href = URL.createObjectURL(blob); anchor.click(); // ✨ magic! // URL.revokeObjectURL(anchor.href); // remove it from memory and save on memory! 😎 setTimeout(()=> URL.revokeObjectURL(anchor.href), 1000) } offscreen.convertToBlob().then(cb); },1) } draw(ctx){ this.drawPins(ctx) } } ;stage = MainStage.go({ loop: false});
Run
Meta Data
title Image Data Boundry Edge Detection
imports ()
files ('head', 'pointlist', 'point', 'stage', 'stroke', '../point_src/random.js', '../point_src/image.js', '../point_src/image-edge-detection.js', '../point_src/recttools.js', '../point_src/offscreen.js')
unused_keys ()
unknown_keys ('categories',)
categories ['imagedata', 'raw']
filepath_exists True
path image-pixel-data-crop.js
filepath image-pixel-data-crop.js
clean_files ('../point_src/core/head.js', '../point_src/pointlistdraw.js', '../point_src/pointlistgradient.js', '../point_src/pointlistshape.js', '../point_src/pointlistgenerator.js', '../point_src/unpack.js', '../point_src/pointlist.js', '../point_src/pointlistpen.js', '../point_src/pointpen.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.js', '../point_src/pointdraw.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/random.js', '../point_src/image.js', '../point_src/image-edge-detection.js', '../point_src/recttools.js', '../point_src/offscreen.js')
markdown {'html': '', 'content': 'title: Image Data Boundry Edge Detection\ncategories: imagedata\n raw\nfiles:\n head\n pointlist\n point\n stage\n stroke\n ../point_src/random.js\n ../point_src/image.js\n ../point_src/image-edge-detection.js\n ../point_src/recttools.js\n ../point_src/offscreen.js\n---'}