Created
December 3, 2015 20:30
-
-
Save atduskgreg/3b771c5e9724caf84c35 to your computer and use it in GitHub Desktop.
Interactive in-painting with OpenCV for Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gab.opencv.*; | |
import org.opencv.photo.Photo; | |
import org.opencv.imgproc.Imgproc; | |
PImage src; | |
PGraphics canvas; | |
OpenCV opencv, mask; | |
int strokeSize = 30; | |
void setup(){ | |
src = loadImage("test.png"); | |
opencv = new OpenCV(this, src, true); | |
canvas = createGraphics(src.width, src.height); | |
mask = new OpenCV(this, canvas.width, canvas.height); | |
canvas.beginDraw(); | |
canvas.background(0); | |
canvas.endDraw(); | |
size(src.width, src.height/2); | |
} | |
void draw(){ | |
pushMatrix(); | |
scale(0.5); | |
image(opencv.getOutput(), 0, 0); | |
noTint(); | |
image(canvas, src.width , 0); | |
popMatrix(); | |
noFill(); | |
stroke(255,0,0); | |
ellipse(mouseX, mouseY, strokeSize, strokeSize); | |
} | |
void mouseDragged(){ | |
canvas.beginDraw(); | |
canvas.fill(255); | |
canvas.noStroke(); | |
canvas.ellipse(mouseX*2, mouseY*2, strokeSize,strokeSize); | |
canvas.endDraw(); | |
} | |
void mouseReleased(){ | |
mask.loadImage(canvas); | |
Imgproc.cvtColor(opencv.getColor(), opencv.getColor(), Imgproc.COLOR_BGRA2BGR); | |
Photo.inpaint(opencv.getColor(), mask.getGray(), opencv.getColor(), 5.0, Photo.INPAINT_NS); | |
Imgproc.cvtColor(opencv.getColor(), opencv.getColor(), Imgproc.COLOR_BGR2BGRA); | |
} | |
void keyPressed(){ | |
if(key == '-'){ | |
strokeSize -= 5; | |
} | |
if(key == '='){ | |
strokeSize += 5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment