Deprecating the webcam stuff, but trying to keep the line tracing.

This commit is contained in:
Sandy Noble 2013-05-07 09:09:52 +01:00
parent fb23a40fc5
commit 256f2b8a05
4 changed files with 124 additions and 84 deletions

View File

@ -352,21 +352,29 @@ class DisplayMachine extends Machine
noStroke(); noStroke();
// draw machine outline // draw machine outline
liveImage = webcam_buildLiveImage(); // liveImage = webcam_buildLiveImage();
processedLiveImage = webcam_processImageForTrace(liveImage); // draw actual image
if (displayingImage && imageIsReady() && webcamShape != null)
colourSeparations = webcam_buildSeps(processedLiveImage, sepKeyColour);
webcamShape = webcam_traceImage(colourSeparations);
if (drawingLiveVideo)
{ {
displayLiveVideo(); processedLiveImage = webcam_processImageForTrace(getImage());
colourSeparations = webcam_buildSeps(processedLiveImage, sepKeyColour);
webcamShape = webcam_traceImage(colourSeparations);
} }
// if (drawingLiveVideo)
// {
// displayLiveVideo();
// }
if (drawingWebcamShape && webcamShape != null) if (drawingWebcamShape && webcamShape != null)
{ {
displayWebcamShape(); displayWebcamShape();
} }
else
{
}
} }
public void displayLiveVideo() public void displayLiveVideo()

View File

@ -521,8 +521,17 @@ class Machine
{ {
// check for format etc here // check for format etc here
println("loading from filename: " + filename); println("loading from filename: " + filename);
this.imageBitmap = loadImage(filename); try
this.imageFilename = filename; {
this.imageBitmap = loadImage(filename);
this.imageFilename = filename;
}
catch (Exception e)
{
println("Image failed to load: " + e.getMessage());
this.imageBitmap = null;
}
} }
else else
{ {

View File

@ -1,6 +1,6 @@
/** /**
Polargraph controller Polargraph controller
Copyright Sandy Noble 2012. Copyright Sandy Noble 2013.
This file is part of Polargraph Controller. This file is part of Polargraph Controller.
@ -27,7 +27,7 @@
http://code.google.com/p/polargraph/ http://code.google.com/p/polargraph/
*/ */
import processing.video.*; //import processing.video.*;
import diewald_CV_kit.libraryinfo.*; import diewald_CV_kit.libraryinfo.*;
import diewald_CV_kit.utility.*; import diewald_CV_kit.utility.*;
import diewald_CV_kit.blobdetection.*; import diewald_CV_kit.blobdetection.*;
@ -50,7 +50,7 @@ import controlP5.*;
import java.awt.event.*; import java.awt.event.*;
int majorVersionNo = 1; int majorVersionNo = 1;
int minorVersionNo = 5; int minorVersionNo = 6;
int buildNo = 0; int buildNo = 0;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
@ -461,10 +461,10 @@ public static Console console;
public boolean useWindowedConsole = false; public boolean useWindowedConsole = false;
static boolean webcamEnabled = false; static boolean webcamEnabled = false;
static boolean drawingLiveVideo = true; static boolean drawingLiveVideo = false;
static boolean drawingWebcamShape = true; static boolean drawingWebcamShape = true;
static boolean flipWebcamImage = true; static boolean flipWebcamImage = false;
static boolean rotateWebcamImage = true; static boolean rotateWebcamImage = false;
static boolean confirmedDraw = false; static boolean confirmedDraw = false;
static PImage liveImage = null; static PImage liveImage = null;
@ -479,7 +479,7 @@ static int pathLengthHighPassCutoff = 0;
static final Integer PATH_LENGTH_HIGHPASS_CUTOFF_MAX = 10000; static final Integer PATH_LENGTH_HIGHPASS_CUTOFF_MAX = 10000;
static final Integer PATH_LENGTH_HIGHPASS_CUTOFF_MIN = 0; static final Integer PATH_LENGTH_HIGHPASS_CUTOFF_MIN = 0;
Capture liveCamera; //Capture liveCamera;
//JMyron liveCamera; //JMyron liveCamera;
BlobDetector blob_detector; BlobDetector blob_detector;
int liveSimplification = 5; int liveSimplification = 5;
@ -576,29 +576,7 @@ void setup()
addEventListeners(); addEventListeners();
//gamepad_init(); //gamepad_init();
try webcam_initCamera();
{
String[] cameras = Capture.list();
if (cameras.length > 0) {
liveCamera = new Capture(this, 640, 480, cameras[0]);
//liveCamera.start();
webcamEnabled = true;
}
}
catch (Exception e)
{
println("Exception occurred trying to look for attached webcams. Webcam will not be used. " + e.getMessage());
webcamEnabled = false;
}
blob_detector = new BlobDetector( 640, 480);
blob_detector.setResolution(1);
blob_detector.computeContours(true);
blob_detector.computeBlobPixels(true);
blob_detector.setMinMaxPixels(10*10, 640*480);
blob_detector.setBLOBable(new BLOBable_blueBlobs(liveImage));
} }
void addEventListeners() void addEventListeners()
{ {
@ -2777,7 +2755,16 @@ void loadFromPropertiesFile()
setVectorFilename(getStringProperty("controller.vector.filename", null)); setVectorFilename(getStringProperty("controller.vector.filename", null));
if (getVectorFilename() != null) if (getVectorFilename() != null)
{ {
RShape shape = RG.loadShape(getVectorFilename()); RShape shape = null;
try
{
shape = RG.loadShape(getVectorFilename());
}
catch (Exception e)
{
shape = null;
}
if (shape != null) if (shape != null)
{ {
setVectorShape(shape); setVectorShape(shape);

View File

@ -1,43 +1,74 @@
public PImage webcam_buildLiveImage() public void webcam_initCamera()
{ {
//liveCamera.start(); // dummy initCamera(), does nothing
PImage pimg = createImage(640, 480, RGB); webcamEnabled = true;
pimg.loadPixels(); blob_detector = new BlobDetector( 640, 480);
if (liveCamera.available()) { blob_detector.setResolution(1);
liveCamera.read(); blob_detector.computeContours(true);
} blob_detector.computeBlobPixels(true);
pimg.pixels = liveCamera.pixels; blob_detector.setMinMaxPixels(10*10, 640*480);
// flip the image left to right
if (flipWebcamImage) blob_detector.setBLOBable(new BLOBable_blueBlobs(liveImage));
{
List<int[]> list = new ArrayList<int[]>(480);
for (int r=0; r<pimg.pixels.length; r+=640)
{
int[] temp = new int[640];
for (int c=0; c<640; c++)
{
temp[c] = pimg.pixels[r+c];
}
list.add(temp);
}
// reverse the list
Collections.reverse(list);
for (int r=0; r<list.size(); r++)
{
for (int c=0; c<640; c++)
{
pimg.pixels[(r*640)+c] = list.get(r)[c];
}
}
}
pimg.updatePixels();
return pimg;
} }
public void webcam_initCameraProcCam()
{
// try
// {
// String[] cameras = Capture.list();
// if (cameras.length > 0) {
// liveCamera = new Capture(this, 640, 480, cameras[0]);
// //liveCamera.start();
// webcamEnabled = true;
// }
// }
// catch (Exception e)
// {
// println("Exception occurred trying to look for attached webcams. Webcam will not be used. " + e.getMessage());
// webcamEnabled = false;
// }
}
//public PImage webcam_buildLiveImage()
//{
// //liveCamera.start();
// PImage pimg = createImage(640, 480, RGB);
// pimg.loadPixels();
// if (liveCamera.available()) {
// liveCamera.read();
// }
// pimg.pixels = liveCamera.pixels;
// // flip the image left to right
// if (flipWebcamImage)
// {
//
// List<int[]> list = new ArrayList<int[]>(480);
//
// for (int r=0; r<pimg.pixels.length; r+=640)
// {
// int[] temp = new int[640];
// for (int c=0; c<640; c++)
// {
// temp[c] = pimg.pixels[r+c];
// }
// list.add(temp);
// }
//
// // reverse the list
// Collections.reverse(list);
//
// for (int r=0; r<list.size(); r++)
// {
// for (int c=0; c<640; c++)
// {
// pimg.pixels[(r*640)+c] = list.get(r)[c];
// }
// }
// }
// pimg.updatePixels();
// return pimg;
//}
public PImage webcam_processImageForTrace(PImage in) public PImage webcam_processImageForTrace(PImage in)
{ {
PImage out = createImage(in.width, in.height, RGB); PImage out = createImage(in.width, in.height, RGB);
@ -171,8 +202,13 @@ public void webcam_captureCurrentImage(PImage inImage)
public void webcam_captureCurrentImage() public void webcam_captureCurrentImage()
{ {
capturedImage = webcam_buildLiveImage(); // capturedImage = webcam_buildLiveImage();
webcam_captureCurrentImage(capturedImage); // webcam_captureCurrentImage(capturedImage);
}
public void webcam_processLoadedImage()
{
webcam_captureCurrentImage(getDisplayMachine().getImage());
} }
public void webcam_saveShape(RShape sh) public void webcam_saveShape(RShape sh)
@ -183,8 +219,8 @@ public void webcam_saveShape(RShape sh)
RG.saveShape(filename, sh); RG.saveShape(filename, sh);
} }
public void stop() { //public void stop() {
liveCamera.stop(); // liveCamera.stop();
super.stop(); // super.stop();
} //}