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();
// draw machine outline
liveImage = webcam_buildLiveImage();
processedLiveImage = webcam_processImageForTrace(liveImage);
// liveImage = webcam_buildLiveImage();
// draw actual image
if (displayingImage && imageIsReady() && webcamShape != null)
{
processedLiveImage = webcam_processImageForTrace(getImage());
colourSeparations = webcam_buildSeps(processedLiveImage, sepKeyColour);
webcamShape = webcam_traceImage(colourSeparations);
if (drawingLiveVideo)
{
displayLiveVideo();
}
// if (drawingLiveVideo)
// {
// displayLiveVideo();
// }
if (drawingWebcamShape && webcamShape != null)
{
displayWebcamShape();
}
else
{
}
}
public void displayLiveVideo()

View File

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

View File

@ -1,6 +1,6 @@
/**
Polargraph controller
Copyright Sandy Noble 2012.
Copyright Sandy Noble 2013.
This file is part of Polargraph Controller.
@ -27,7 +27,7 @@
http://code.google.com/p/polargraph/
*/
import processing.video.*;
//import processing.video.*;
import diewald_CV_kit.libraryinfo.*;
import diewald_CV_kit.utility.*;
import diewald_CV_kit.blobdetection.*;
@ -50,7 +50,7 @@ import controlP5.*;
import java.awt.event.*;
int majorVersionNo = 1;
int minorVersionNo = 5;
int minorVersionNo = 6;
int buildNo = 0;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
@ -461,10 +461,10 @@ public static Console console;
public boolean useWindowedConsole = false;
static boolean webcamEnabled = false;
static boolean drawingLiveVideo = true;
static boolean drawingLiveVideo = false;
static boolean drawingWebcamShape = true;
static boolean flipWebcamImage = true;
static boolean rotateWebcamImage = true;
static boolean flipWebcamImage = false;
static boolean rotateWebcamImage = false;
static boolean confirmedDraw = false;
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_MIN = 0;
Capture liveCamera;
//Capture liveCamera;
//JMyron liveCamera;
BlobDetector blob_detector;
int liveSimplification = 5;
@ -576,29 +576,7 @@ void setup()
addEventListeners();
//gamepad_init();
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;
}
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));
webcam_initCamera();
}
void addEventListeners()
{
@ -2777,7 +2755,16 @@ void loadFromPropertiesFile()
setVectorFilename(getStringProperty("controller.vector.filename", 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)
{
setVectorShape(shape);

View File

@ -1,42 +1,73 @@
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)
public void webcam_initCamera()
{
// dummy initCamera(), does nothing
webcamEnabled = true;
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);
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);
blob_detector.setBLOBable(new BLOBable_blueBlobs(liveImage));
}
// reverse the list
Collections.reverse(list);
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;
// }
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_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)
{
@ -171,8 +202,13 @@ public void webcam_captureCurrentImage(PImage inImage)
public void webcam_captureCurrentImage()
{
capturedImage = webcam_buildLiveImage();
webcam_captureCurrentImage(capturedImage);
// capturedImage = webcam_buildLiveImage();
// webcam_captureCurrentImage(capturedImage);
}
public void webcam_processLoadedImage()
{
webcam_captureCurrentImage(getDisplayMachine().getImage());
}
public void webcam_saveShape(RShape sh)
@ -183,8 +219,8 @@ public void webcam_saveShape(RShape sh)
RG.saveShape(filename, sh);
}
public void stop() {
liveCamera.stop();
super.stop();
}
//public void stop() {
// liveCamera.stop();
// super.stop();
//}