From aa92a55359c0b79149871e31d18790a356d0cc5b Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Tue, 23 Apr 2013 23:59:05 +0100 Subject: [PATCH] Added rotate function to webcam. Primarily so folk with webcams on laptops can use it. Huzzah! --- DisplayMachine.pde | 50 ++++++++++++++++++++++++++++++---------- controlsActions.pde | 14 ++++++++++- controlsSetup.pde | 47 +++++++++++++++++++++++++++++-------- polargraphcontroller.pde | 10 +++++--- webcam.pde | 11 +++++---- 5 files changed, 103 insertions(+), 29 deletions(-) diff --git a/DisplayMachine.pde b/DisplayMachine.pde index bcfe711..0bf60a2 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -374,24 +374,48 @@ class DisplayMachine extends Machine // draw actual image, maximum size if (processedLiveImage != null) { + // origin - top left of the corner float ox = getPanel(PANEL_NAME_WEBCAM).getOutline().getRight()+7; float oy = getPanel(PANEL_NAME_GENERAL).getOutline().getTop(); - // calculate height. 640 pixels stretched to - float aspectRatio = 480.0/640.0; // rotated, remember + // calculate size to display at. + float aspectRatio = (rotateWebcamImage) ? 480.0/640.0 : 640.0/480.0; // rotated, remember float h = height - getPanel(PANEL_NAME_GENERAL).getOutline().getTop() -10; - float w = h * aspectRatio; + float w = h * (480.0/640.0); + println("height: " + h + ", width: " + w); + println("origin x: " + ox + ", y: " + oy); - stroke(255); + if (rotateWebcamImage) + { + float t = h; + h = w; + w = t; + } + + //stroke(255); rect(ox,oy,w,h); tint(255, getImageTransparency()); - translate(ox, oy+h); - rotate(radians(270)); - image(processedLiveImage, 0, 0, h, w); - image(liveImage, h-(h/4), w+10, h/4, w/4); - rotate(radians(-270)); - translate(-ox, -(oy+h)); + if (rotateWebcamImage) + { + translate(ox, oy); + rotate(radians(270)); + image(processedLiveImage, -w, 0, w, h); + image(liveImage, -w, (w-(w/4))+10, w/4, h/4); +// stroke(0,255,0); +// ellipse(0,0,80,40); +// stroke(0,0,255); +// ellipse(-w,0,80,40); + rotate(radians(-270)); + translate(-ox, -oy); + } + else + { + translate(ox, oy); + image(processedLiveImage, 0, 0, h, w); + image(liveImage, h-(h/4), w+10, h/4, w/4); + translate(-ox, -oy); + } noTint(); noFill(); } @@ -419,8 +443,10 @@ class DisplayMachine extends Machine 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, getPanel(PANEL_NAME_GENERAL).getOutline().getTop() -10); + float scaler = h / vec.getWidth(); + if (rotateWebcamImage) + scaler = h / vec.getHeight(); + PVector position = new PVector(getPanel(PANEL_NAME_WEBCAM).getOutline().getRight()+7, getPanel(PANEL_NAME_GENERAL).getOutline().getTop()); noFill(); RPoint[][] pointPaths = vec.getPointsInPaths(); diff --git a/controlsActions.pde b/controlsActions.pde index 6a1ba25..200c6a6 100644 --- a/controlsActions.pde +++ b/controlsActions.pde @@ -158,7 +158,19 @@ void button_mode_liveConfirmDraw() // save shape as SVG webcam_saveShape(captureShape); } -} +} +void toggle_mode_showWebcamRawVideo(boolean flag) +{ + drawingLiveVideo = flag; +} +void toggle_mode_flipWebcam(boolean flag) +{ + flipWebcamImage = flag; +} +void toggle_mode_rotateWebcam(boolean flag) +{ + rotateWebcamImage = flag; +} void toggle_mode_inputBoxTopLeft(boolean flag) diff --git a/controlsSetup.pde b/controlsSetup.pde index 311e2f1..06cf76a 100644 --- a/controlsSetup.pde +++ b/controlsSetup.pde @@ -274,7 +274,7 @@ Map buildAllControls() } } - initialiseMiniToggleValues(map); + initialiseToggleValues(map); initialiseNumberboxValues(map); return map; } @@ -506,7 +506,7 @@ Map initialiseNumberboxValues(Map map) } -Map initialiseMiniToggleValues(Map map) +Map initialiseToggleValues(Map map) { for (String key : map.keySet()) { @@ -515,26 +515,42 @@ Map initialiseMiniToggleValues(Map map) Toggle t = (Toggle) map.get(key); t.setValue((displayingDensityPreview) ? 1 : 0); } - if (MODE_SHOW_QUEUE_PREVIEW.equals(key)) + else if (MODE_SHOW_QUEUE_PREVIEW.equals(key)) { Toggle t = (Toggle) map.get(key); t.setValue((displayingQueuePreview) ? 1 : 0); } - if (MODE_SHOW_IMAGE.equals(key)) + else if (MODE_SHOW_IMAGE.equals(key)) { Toggle t = (Toggle) map.get(key); t.setValue((displayingImage) ? 1 : 0); } - if (MODE_SHOW_VECTOR.equals(key)) + else if (MODE_SHOW_VECTOR.equals(key)) { Toggle t = (Toggle) map.get(key); t.setValue((displayingVector) ? 1 : 0); } - if (MODE_SHOW_GUIDES.equals(key)) + else if (MODE_SHOW_GUIDES.equals(key)) { Toggle t = (Toggle) map.get(key); t.setValue((displayingGuides) ? 1 : 0); } + else if (MODE_SHOW_WEBCAM_RAW_VIDEO.equals(key)) + { + Toggle t = (Toggle) map.get(key); + t.setValue((drawingLiveVideo) ? 1 : 0); + } + else if (MODE_FLIP_WEBCAM_INPUT.equals(key)) + { + Toggle t = (Toggle) map.get(key); + t.setValue((flipWebcamImage) ? 1 : 0); + } + else if (MODE_ROTATE_WEBCAM_INPUT.equals(key)) + { + Toggle t = (Toggle) map.get(key); + t.setValue((rotateWebcamImage) ? 1 : 0); + } + } return map; } @@ -670,7 +686,7 @@ List getControlNamesForInputPanel() controlNames.add(MODE_RESIZE_VECTOR); controlNames.add(MODE_MOVE_VECTOR); controlNames.add(MODE_CHANGE_MIN_VECTOR_LINE_LENGTH); - controlNames.add(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF); + //controlNames.add(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF); controlNames.add(MODE_RENDER_VECTORS); controlNames.add(MODE_SHOW_IMAGE); @@ -712,9 +728,13 @@ List getControlNamesForWebcamPanel() controlNames.add(MODE_LIVE_POSTERISE_VALUE); controlNames.add(MODE_LIVE_CAPTURE_FROM_LIVE); controlNames.add(MODE_LIVE_CANCEL_CAPTURE); - controlNames.add(MODE_LIVE_ADD_CAPTION); +// controlNames.add(MODE_LIVE_ADD_CAPTION); controlNames.add(MODE_LIVE_CONFIRM_DRAW); - controlNames.add(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF); +// controlNames.add(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF); + + controlNames.add(MODE_SHOW_WEBCAM_RAW_VIDEO); + controlNames.add(MODE_FLIP_WEBCAM_INPUT); + controlNames.add(MODE_ROTATE_WEBCAM_INPUT); return controlNames; } @@ -923,6 +943,10 @@ Map buildControlLabels() result.put(MODE_LIVE_ADD_CAPTION, "Add caption"); result.put(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF, "Path length cutoff"); + result.put(MODE_SHOW_WEBCAM_RAW_VIDEO, "Show video"); + result.put(MODE_FLIP_WEBCAM_INPUT, "Flip video"); + result.put(MODE_ROTATE_WEBCAM_INPUT, "Rotate webcam"); + return result; @@ -1057,6 +1081,11 @@ Set buildControlNames() result.add(MODE_LIVE_ADD_CAPTION); result.add(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF); + result.add(MODE_SHOW_WEBCAM_RAW_VIDEO); + result.add(MODE_FLIP_WEBCAM_INPUT); + result.add(MODE_ROTATE_WEBCAM_INPUT); + + return result; } diff --git a/polargraphcontroller.pde b/polargraphcontroller.pde index 600a9fd..e9a2f23 100644 --- a/polargraphcontroller.pde +++ b/polargraphcontroller.pde @@ -50,8 +50,8 @@ import controlP5.*; import java.awt.event.*; int majorVersionNo = 1; -int minorVersionNo = 4; -int buildNo = 2; +int minorVersionNo = 5; +int buildNo = 0; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; ControlP5 cp5; @@ -316,6 +316,9 @@ static final String MODE_LIVE_ADD_CAPTION = "button_mode_liveAddCaption"; static final String MODE_LIVE_CONFIRM_DRAW = "button_mode_liveConfirmDraw"; static final String MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF = "numberbox_mode_vectorPathLengthHighPassCutoff"; +static final String MODE_SHOW_WEBCAM_RAW_VIDEO = "toggle_mode_showWebcamRawVideo"; +static final String MODE_FLIP_WEBCAM_INPUT = "toggle_mode_flipWebcam"; +static final String MODE_ROTATE_WEBCAM_INPUT = "toggle_mode_rotateWebcam"; PVector statusTextPosition = new PVector(300.0, 12.0); @@ -455,9 +458,10 @@ public static Console console; public boolean useWindowedConsole = false; static boolean webcamEnabled = false; -static boolean drawingLiveVideo = false; +static boolean drawingLiveVideo = true; static boolean drawingWebcamShape = true; static boolean flipWebcamImage = true; +static boolean rotateWebcamImage = true; static boolean confirmedDraw = false; static PImage liveImage = null; diff --git a/webcam.pde b/webcam.pde index 99af50a..8d3b13e 100644 --- a/webcam.pde +++ b/webcam.pde @@ -107,10 +107,13 @@ public RShape webcam_traceImage(Map seps) } } // rotate image - allShapes.rotate(radians(-90)); - // transform it so that top left is at 0,0. - RPoint topLeft = allShapes.getTopLeft(); - allShapes.translate(-topLeft.x, -topLeft.y); + if (rotateWebcamImage) + { + allShapes.rotate(radians(-90)); + // transform it so that top left is at 0,0. + RPoint topLeft = allShapes.getTopLeft(); + allShapes.translate(-topLeft.x, -topLeft.y); + } return allShapes; }