Added rotate function to webcam. Primarily so folk with webcams on laptops can use it. Huzzah!

This commit is contained in:
Sandy Noble 2013-04-23 23:59:05 +01:00
parent e3a6cea6cd
commit aa92a55359
5 changed files with 103 additions and 29 deletions

View File

@ -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();

View File

@ -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)

View File

@ -274,7 +274,7 @@ Map<String, Controller> buildAllControls()
}
}
initialiseMiniToggleValues(map);
initialiseToggleValues(map);
initialiseNumberboxValues(map);
return map;
}
@ -506,7 +506,7 @@ Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
}
Map<String, Controller> initialiseMiniToggleValues(Map<String, Controller> map)
Map<String, Controller> initialiseToggleValues(Map<String, Controller> map)
{
for (String key : map.keySet())
{
@ -515,26 +515,42 @@ Map<String, Controller> initialiseMiniToggleValues(Map<String, Controller> 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<String> 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<String> 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<String, String> 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<String> 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;
}

View File

@ -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;

View File

@ -107,10 +107,13 @@ public RShape webcam_traceImage(Map<Integer, PImage> 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;
}