Skip to content

Instantly share code, notes, and snippets.

@n1ckfg
Created October 27, 2018 00:59
Show Gist options
  • Save n1ckfg/57da5435257d9b1f71097e4ca5998d78 to your computer and use it in GitHub Desktop.
Save n1ckfg/57da5435257d9b1f71097e4ca5998d78 to your computer and use it in GitHub Desktop.
import gab.opencv.*;
OpenCV opencv;
PImage src, canny;
int lowThreshold = 20;
int highThreshold = 75;
void setup() {
src = loadImage("test.jpg");
size(1080, 720, P2D);
doCanny();
}
void doCanny() {
opencv = new OpenCV(this, src);
opencv.findCannyEdges(lowThreshold, highThreshold);
canny = opencv.getSnapshot();
}
void draw() {
if (keyPressed) {
if (key == 'w') {
lowThreshold++;
} else if (key == 's') {
lowThreshold--;
}
if (key == 'i') {
highThreshold++;
} else if (key == 'k') {
highThreshold--;
}
if (key == 'w' || key == 's' || key == 'i' || key == 'k') {
lowThreshold = constrain(lowThreshold, 0, 255);
highThreshold = constrain(highThreshold, 0, 255);
doCanny();
println(lowThreshold + " " + highThreshold);
}
}
image(canny, 0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment