mirror of
https://github.com/euphy/polargraphcontroller
synced 2024-11-13 01:47:57 +01:00
Extracting captured image, tracing and isolation. Not completed writing to command queue yet, not decided how to scale it / place it quite yet.
This commit is contained in:
parent
3b7695fe50
commit
b37421b03b
@ -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<pointPaths.length; i++)
|
||||
{
|
||||
if (pointPaths[i] != null)
|
||||
{
|
||||
beginShape();
|
||||
for (int j = 0; j<pointPaths[i].length; j++)
|
||||
{
|
||||
PVector p = new PVector(pointPaths[i][j].x, pointPaths[i][j].y);
|
||||
p = PVector.mult(p, scaler);
|
||||
p = PVector.add(p, position);
|
||||
vertex(p.x, p.y);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void displayVectorImage()
|
||||
{
|
||||
displayVectorImage(color(0,0,0));
|
||||
displayVectorImage(getVectorShape(), color(0,0,0), true);
|
||||
}
|
||||
|
||||
public void displayVectorImage(int strokeColour)
|
||||
public void displayVectorImage(RShape vec, int strokeColour, boolean drawCentroid)
|
||||
{
|
||||
RPoint[][] pointPaths = getVectorShape().getPointsInPaths();
|
||||
RPoint[][] pointPaths = vec.getPointsInPaths();
|
||||
RG.ignoreStyles();
|
||||
strokeWeight(1);
|
||||
if (pointPaths != null)
|
||||
@ -452,14 +479,17 @@ class DisplayMachine extends Machine
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
// draw spot at centre
|
||||
PVector centroid = new PVector(getVectorShape().width/2, getVectorShape().height/2);
|
||||
centroid = PVector.mult(centroid, (vectorScaling/100));
|
||||
centroid = PVector.add(centroid, getVectorPosition());
|
||||
centroid = scaleToScreen(centroid);
|
||||
fill(255,0,0,128);
|
||||
ellipse(centroid.x, centroid.y, 20,20);
|
||||
noFill();
|
||||
if (drawCentroid)
|
||||
{
|
||||
// draw spot at centre
|
||||
PVector centroid = new PVector(vec.width/2, vec.height/2);
|
||||
centroid = PVector.mult(centroid, (vectorScaling/100));
|
||||
centroid = PVector.add(centroid, getVectorPosition());
|
||||
centroid = scaleToScreen(centroid);
|
||||
fill(255,0,0,128);
|
||||
ellipse(centroid.x, centroid.y, 20,20);
|
||||
noFill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,12 @@ void numberbox_mode_livePosteriseValue(int value)
|
||||
}
|
||||
void button_mode_liveCaptureFromLive()
|
||||
{
|
||||
addToCommandQueue(CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",END");
|
||||
webcam_captureCurrentImage();
|
||||
}
|
||||
|
||||
void button_mode_liveConfirmDraw()
|
||||
{
|
||||
sendVectorShapes(captureShape);
|
||||
}
|
||||
|
||||
|
||||
|
@ -703,6 +703,7 @@ List<String> 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<String, String> 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<String> 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;
|
||||
}
|
||||
|
17
drawing.pde
17
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;
|
||||
|
@ -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<Integer> colours = null;
|
||||
List<Integer> colourList = null;
|
||||
int posterizeValue = 8;
|
||||
int sepKeyColour = color(0, 0, 255);
|
||||
|
||||
Map<Integer, PImage> colourSeparations = null;
|
||||
RShape webcamShape = null;
|
||||
RShape captureShape = null;
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user