/*
Code by lingib
Last update 12 Feb 2017
This software uses the openCV library and Canny edge detection
to trace the outlines within an image. These outlines are then
converted to gcode for use with an Inkscape compatible plotter
which assumes that the (0,0) co-ordinate is at the lower left).
To run this software you first need to import the openCV
(open computer vision) library by clicking the following pull-down
menu options within Processing 3:
"Sketch|Import Library|Add Library|Open CV for processing"
Each photo requires a lower and upper threshold. A simple
method for determining each threshold is to move the
"find edges" & "display edges" code from the "setup" section
into the "draw" section and uncomment the lines containing
mouseX & mouseY. Move your mouse over the image window and
note the two readings when the outline is optimum then
restore the code to its original state.
This code is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License. If
not, see .
*/
import gab.opencv.*; //openCV library
OpenCV opencv; //instantiate opencv
PrintWriter output; //instantiate output
PImage src, canny; //image work areas
boolean recursionFlag;
boolean lastCommandG00 = false;
int lastX = 0;
int lastY = 0;
// -------------------------------------
// setup
// -------------------------------------
void setup() {
// ----- match screen size to image
size(500, 664);
// ----- get image
src = loadImage("image.jpg"); //get image
loadPixels(); //load image into pixel[] array
// ----- find edges
opencv = new OpenCV(this, src);
opencv.findCannyEdges(99, 122);
//opencv.findCannyEdges(mouseX, mouseY);
//println(mouseX);
//println(mouseY);
canny = opencv.getSnapshot();
// ----- display edges
pushMatrix();
image(canny, 0, 0); //white outline
filter(INVERT); //black outline
popMatrix();
// Create a new file in the sketch directory
output = createWriter("outline.ngc");
noLoop(); //draw() only runs once
}
// -------------------------------------
// main loop
// -------------------------------------
void draw() {
// ----- refresh pixels[] array
loadPixels();
// ----- move 3x3 matrix center over the image
for (int y=1; y