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:
Sandy Noble 2013-03-30 14:10:12 +00:00
parent 3b7695fe50
commit b37421b03b
5 changed files with 102 additions and 59 deletions

View File

@ -351,38 +351,28 @@ class DisplayMachine extends Machine
// work out the scaling factor. // work out the scaling factor.
noStroke(); noStroke();
// draw machine outline // draw machine outline
liveImage = webcam_buildLiveImage();
processedLiveImage = webcam_processImageForTrace(liveImage);
colourSeparations = webcam_buildSeps(processedLiveImage, sepKeyColour);
webcamShape = webcam_traceImage(colourSeparations);
if (drawingLiveVideo) if (drawingLiveVideo)
{ {
displayLiveVideo(); displayLiveVideo();
} }
if (displayingVector && getVectorShape() != null) if (drawingWebcamShape && webcamShape != null)
{ {
displayVectorImage(color(200)); displayWebcamShape();
}
if (displayingGuides
&& getOutline().surrounds(getMouseVector())
&& currentMode != MODE_MOVE_IMAGE
&& mouseOverControls().isEmpty()
)
{
cursor(CROSS);
}
else
{
cursor(ARROW);
} }
} }
public void displayLiveVideo() public void displayLiveVideo()
{ {
buildLiveImage(); // draw actual image, maximum size
// draw actual image, full size in centre of page if (processedLiveImage != null)
if (liveImage != null)
{ {
float ox = getPanel(PANEL_NAME_WEBCAM).getOutline().getRight()+7; float ox = getPanel(PANEL_NAME_WEBCAM).getOutline().getRight()+7;
float oy = getPanel(PANEL_NAME_GENERAL).getOutline().getTop(); float oy = getPanel(PANEL_NAME_GENERAL).getOutline().getTop();
@ -398,7 +388,8 @@ class DisplayMachine extends Machine
tint(255, getImageTransparency()); tint(255, getImageTransparency());
translate(ox, oy+h); translate(ox, oy+h);
rotate(radians(270)); 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)); rotate(radians(-270));
translate(-ox, -(oy+h)); translate(-ox, -(oy+h));
noTint(); noTint();
@ -406,27 +397,63 @@ class DisplayMachine extends Machine
} }
} }
public void buildLiveImage() public void displayWebcamShape()
{ {
liveCamera.update(); strokeWeight(1);
liveImage = createImage(640,480, RGB);
liveImage.loadPixels(); if (captureShape != null)
// rotate it {
liveImage.pixels = liveCamera.image(); stroke(150);
liveImage.filter(BLUR, blurValue); displayWebcamShapeAtFullSize(webcamShape);
liveImage.filter(GRAY); stroke(255);
liveImage.filter(POSTERIZE, posterizeValue); displayWebcamShapeAtFullSize(captureShape);
liveImage.updatePixels(); }
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() 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(); RG.ignoreStyles();
strokeWeight(1); strokeWeight(1);
if (pointPaths != null) if (pointPaths != null)
@ -452,14 +479,17 @@ class DisplayMachine extends Machine
endShape(); endShape();
} }
} }
// draw spot at centre if (drawCentroid)
PVector centroid = new PVector(getVectorShape().width/2, getVectorShape().height/2); {
centroid = PVector.mult(centroid, (vectorScaling/100)); // draw spot at centre
centroid = PVector.add(centroid, getVectorPosition()); PVector centroid = new PVector(vec.width/2, vec.height/2);
centroid = scaleToScreen(centroid); centroid = PVector.mult(centroid, (vectorScaling/100));
fill(255,0,0,128); centroid = PVector.add(centroid, getVectorPosition());
ellipse(centroid.x, centroid.y, 20,20); centroid = scaleToScreen(centroid);
noFill(); fill(255,0,0,128);
ellipse(centroid.x, centroid.y, 20,20);
noFill();
}
} }
} }

View File

@ -122,7 +122,12 @@ void numberbox_mode_livePosteriseValue(int value)
} }
void button_mode_liveCaptureFromLive() void button_mode_liveCaptureFromLive()
{ {
addToCommandQueue(CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",END"); webcam_captureCurrentImage();
}
void button_mode_liveConfirmDraw()
{
sendVectorShapes(captureShape);
} }

View File

@ -703,6 +703,7 @@ List<String> getControlNamesForWebcamPanel()
controlNames.add(MODE_LIVE_SIMPLIFICATION_VALUE); controlNames.add(MODE_LIVE_SIMPLIFICATION_VALUE);
controlNames.add(MODE_LIVE_POSTERISE_VALUE); controlNames.add(MODE_LIVE_POSTERISE_VALUE);
controlNames.add(MODE_LIVE_CAPTURE_FROM_LIVE); controlNames.add(MODE_LIVE_CAPTURE_FROM_LIVE);
controlNames.add(MODE_LIVE_CONFIRM_DRAW);
return controlNames; return controlNames;
} }
@ -904,6 +905,7 @@ Map<String, String> buildControlLabels()
result.put(MODE_LIVE_SIMPLIFICATION_VALUE, "Simplify"); result.put(MODE_LIVE_SIMPLIFICATION_VALUE, "Simplify");
result.put(MODE_LIVE_POSTERISE_VALUE, "Posterise"); result.put(MODE_LIVE_POSTERISE_VALUE, "Posterise");
result.put(MODE_LIVE_CAPTURE_FROM_LIVE, "Capture"); result.put(MODE_LIVE_CAPTURE_FROM_LIVE, "Capture");
result.put(MODE_LIVE_CONFIRM_DRAW, "Draw capture");
return result; return result;
@ -1034,6 +1036,7 @@ Set<String> buildControlNames()
result.add(MODE_LIVE_SIMPLIFICATION_VALUE); result.add(MODE_LIVE_SIMPLIFICATION_VALUE);
result.add(MODE_LIVE_POSTERISE_VALUE); result.add(MODE_LIVE_POSTERISE_VALUE);
result.add(MODE_LIVE_CAPTURE_FROM_LIVE); result.add(MODE_LIVE_CAPTURE_FROM_LIVE);
result.add(MODE_LIVE_CONFIRM_DRAW);
return result; return result;
} }

View File

@ -638,11 +638,15 @@ void sendOutlineOfBox()
} }
void sendVectorShapes() void sendVectorShapes()
{
sendVectorShapes(getVectorShape());
}
void sendVectorShapes(RShape vec)
{ {
println("Send vector shapes."); println("Send vector shapes.");
RPoint[][] pointPaths = getVectorShape().getPointsInPaths(); RPoint[][] pointPaths = vec.getPointsInPaths();
String command = ""; String command = "";
PVector lastPoint = new PVector(); PVector lastPoint = new PVector();
@ -661,14 +665,7 @@ void sendVectorShapes()
{ {
// draw the first one with a pen up and down to get to it // draw the first one with a pen up and down to get to it
PVector p = filteredPoints.get(0); PVector p = filteredPoints.get(0);
if ( if ( p.x == lastPoint.x && p.y == lastPoint.y )
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
)
liftToGetToNewPoint = false; liftToGetToNewPoint = false;
else else
liftToGetToNewPoint = true; liftToGetToNewPoint = true;

View File

@ -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_SIMPLIFICATION_VALUE = "numberbox_mode_liveSimplificationValue";
static final String MODE_LIVE_POSTERISE_VALUE = "numberbox_mode_livePosteriseValue"; 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_CAPTURE_FROM_LIVE = "button_mode_liveCaptureFromLive";
static final String MODE_LIVE_CONFIRM_DRAW = "button_mode_liveConfirmDraw";
PVector statusTextPosition = new PVector(300.0, 12.0); PVector statusTextPosition = new PVector(300.0, 12.0);
@ -448,17 +449,24 @@ boolean overwriteExistingStoreFile = true;
public static Console console; public static Console console;
public boolean useWindowedConsole = false; public boolean useWindowedConsole = false;
static boolean drawingLiveVideo = true; static boolean drawingLiveVideo = false;
static boolean drawingWebcamShape = true;
static PImage liveImage = null; static PImage liveImage = null;
static PImage processedLiveImage = null;
static PImage capturedImage = null;
static PImage processedCapturedImage = null;
JMyron liveCamera; JMyron liveCamera;
BlobDetector blob_detector; BlobDetector blob_detector;
int liveSimplification = 0; int liveSimplification = 2;
int blurValue = 1; int blurValue = 1;
int posterizeValue = 6; int posterizeValue = 8;
Set<Integer> colours = null; int sepKeyColour = color(0, 0, 255);
List<Integer> colourList = null;
Map<Integer, PImage> colourSeparations = null;
RShape webcamShape = null;
RShape captureShape = null;
void setup() void setup()
{ {