From b37421b03b0c8f5571c6fb074a2e2c8e76be6d52 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Sat, 30 Mar 2013 14:10:12 +0000 Subject: [PATCH] Extracting captured image, tracing and isolation. Not completed writing to command queue yet, not decided how to scale it / place it quite yet. --- DisplayMachine.pde | 116 ++++++++++++++++++++------------ controlsActions.pde | 7 +- controlsSetup.pde | 3 + drawing.pde | 17 ++--- polargraphcontroller_webcam.pde | 18 +++-- 5 files changed, 102 insertions(+), 59 deletions(-) diff --git a/DisplayMachine.pde b/DisplayMachine.pde index 0dc135c..bd9ec52 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -351,38 +351,28 @@ class DisplayMachine extends Machine // work out the scaling factor. noStroke(); // draw machine outline + + liveImage = webcam_buildLiveImage(); + processedLiveImage = webcam_processImageForTrace(liveImage); + + colourSeparations = webcam_buildSeps(processedLiveImage, sepKeyColour); + webcamShape = webcam_traceImage(colourSeparations); if (drawingLiveVideo) { displayLiveVideo(); } - - if (displayingVector && getVectorShape() != null) + + if (drawingWebcamShape && webcamShape != null) { - displayVectorImage(color(200)); - } - - if (displayingGuides - && getOutline().surrounds(getMouseVector()) - && currentMode != MODE_MOVE_IMAGE - && mouseOverControls().isEmpty() - ) - { - cursor(CROSS); - } - else - { - cursor(ARROW); + displayWebcamShape(); } } public void displayLiveVideo() { - buildLiveImage(); - // draw actual image, full size in centre of page - - - if (liveImage != null) + // draw actual image, maximum size + if (processedLiveImage != null) { float ox = getPanel(PANEL_NAME_WEBCAM).getOutline().getRight()+7; float oy = getPanel(PANEL_NAME_GENERAL).getOutline().getTop(); @@ -398,7 +388,8 @@ class DisplayMachine extends Machine tint(255, getImageTransparency()); translate(ox, oy+h); rotate(radians(270)); - image(liveImage, 0, 0, h, w); + image(processedLiveImage, 0, 0, h, w); + image(liveImage, h-(h/4), w+10, h/4, w/4); rotate(radians(-270)); translate(-ox, -(oy+h)); noTint(); @@ -406,27 +397,63 @@ class DisplayMachine extends Machine } } - public void buildLiveImage() + public void displayWebcamShape() { - liveCamera.update(); - liveImage = createImage(640,480, RGB); - liveImage.loadPixels(); - // rotate it - liveImage.pixels = liveCamera.image(); - liveImage.filter(BLUR, blurValue); - liveImage.filter(GRAY); - liveImage.filter(POSTERIZE, posterizeValue); - liveImage.updatePixels(); + strokeWeight(1); + + if (captureShape != null) + { + stroke(150); + displayWebcamShapeAtFullSize(webcamShape); + stroke(255); + displayWebcamShapeAtFullSize(captureShape); + } + else + { + stroke(255); + displayWebcamShapeAtFullSize(webcamShape); + } + } + + public void displayWebcamShapeAtFullSize(RShape vec) + { + RG.ignoreStyles(); + // work out scaling to make it full size on the screen + float aspectRatio = vec.getWidth()/vec.getHeight(); // rotated, remember + float h = height - getPanel(PANEL_NAME_GENERAL).getOutline().getTop() -10; + float w = h * aspectRatio; + float scaler = h / vec.getHeight(); + PVector position = new PVector(getPanel(PANEL_NAME_WEBCAM).getOutline().getRight()+7, height -10); + + RPoint[][] pointPaths = vec.getPointsInPaths(); + if (pointPaths != null) + { + for(int i = 0; i getControlNamesForWebcamPanel() controlNames.add(MODE_LIVE_SIMPLIFICATION_VALUE); controlNames.add(MODE_LIVE_POSTERISE_VALUE); controlNames.add(MODE_LIVE_CAPTURE_FROM_LIVE); + controlNames.add(MODE_LIVE_CONFIRM_DRAW); return controlNames; } @@ -904,6 +905,7 @@ Map buildControlLabels() result.put(MODE_LIVE_SIMPLIFICATION_VALUE, "Simplify"); result.put(MODE_LIVE_POSTERISE_VALUE, "Posterise"); result.put(MODE_LIVE_CAPTURE_FROM_LIVE, "Capture"); + result.put(MODE_LIVE_CONFIRM_DRAW, "Draw capture"); return result; @@ -1034,6 +1036,7 @@ Set buildControlNames() result.add(MODE_LIVE_SIMPLIFICATION_VALUE); result.add(MODE_LIVE_POSTERISE_VALUE); result.add(MODE_LIVE_CAPTURE_FROM_LIVE); + result.add(MODE_LIVE_CONFIRM_DRAW); return result; } diff --git a/drawing.pde b/drawing.pde index 97f80fe..57fe89b 100644 --- a/drawing.pde +++ b/drawing.pde @@ -638,11 +638,15 @@ void sendOutlineOfBox() } - void sendVectorShapes() +{ + sendVectorShapes(getVectorShape()); +} + +void sendVectorShapes(RShape vec) { println("Send vector shapes."); - RPoint[][] pointPaths = getVectorShape().getPointsInPaths(); + RPoint[][] pointPaths = vec.getPointsInPaths(); String command = ""; PVector lastPoint = new PVector(); @@ -661,14 +665,7 @@ void sendVectorShapes() { // draw the first one with a pen up and down to get to it PVector p = filteredPoints.get(0); - if ( - p.x == lastPoint.x - && p.y == lastPoint.y -// p.x <= lastPoint.x+2 -// && p.x >= lastPoint.x-2 -// && p.y <= lastPoint.y+2 -// && p.y >= lastPoint.y-2 - ) + if ( p.x == lastPoint.x && p.y == lastPoint.y ) liftToGetToNewPoint = false; else liftToGetToNewPoint = true; diff --git a/polargraphcontroller_webcam.pde b/polargraphcontroller_webcam.pde index 4f9d8c8..295ad82 100644 --- a/polargraphcontroller_webcam.pde +++ b/polargraphcontroller_webcam.pde @@ -310,6 +310,7 @@ static final String MODE_LIVE_BLUR_VALUE = "numberbox_mode_liveBlurValue"; static final String MODE_LIVE_SIMPLIFICATION_VALUE = "numberbox_mode_liveSimplificationValue"; static final String MODE_LIVE_POSTERISE_VALUE = "numberbox_mode_livePosteriseValue"; static final String MODE_LIVE_CAPTURE_FROM_LIVE = "button_mode_liveCaptureFromLive"; +static final String MODE_LIVE_CONFIRM_DRAW = "button_mode_liveConfirmDraw"; PVector statusTextPosition = new PVector(300.0, 12.0); @@ -448,17 +449,24 @@ boolean overwriteExistingStoreFile = true; public static Console console; public boolean useWindowedConsole = false; -static boolean drawingLiveVideo = true; +static boolean drawingLiveVideo = false; +static boolean drawingWebcamShape = true; static PImage liveImage = null; +static PImage processedLiveImage = null; +static PImage capturedImage = null; +static PImage processedCapturedImage = null; + JMyron liveCamera; BlobDetector blob_detector; -int liveSimplification = 0; +int liveSimplification = 2; int blurValue = 1; -int posterizeValue = 6; -Set colours = null; -List colourList = null; +int posterizeValue = 8; +int sepKeyColour = color(0, 0, 255); +Map colourSeparations = null; +RShape webcamShape = null; +RShape captureShape = null; void setup() {