Skip to content

Instantly share code, notes, and snippets.

@n1ckfg
Forked from atduskgreg/interactive_inpainting.pde
Last active August 18, 2017 18:22
Show Gist options
  • Save n1ckfg/f0860012f7d2e67220a59ec5764508f0 to your computer and use it in GitHub Desktop.
Save n1ckfg/f0860012f7d2e67220a59ec5764508f0 to your computer and use it in GitHub Desktop.
Interactive in-painting with OpenCV for Processing
// updated for Processing 3
import gab.opencv.*;
import org.opencv.photo.Photo;
import org.opencv.imgproc.Imgproc;
import processing.opengl.PGraphics2D;
PImage src;
PGraphics2D canvas;
OpenCV opencv, mask;
int strokeSize = 30;
void setup(){
size(50, 50, P2D);
src = loadImage("test.png");
opencv = new OpenCV(this, src, true);
canvas = (PGraphics2D) createGraphics(src.width, src.height, P2D);
mask = new OpenCV(this, canvas.width, canvas.height);
canvas.beginDraw();
canvas.background(0);
canvas.endDraw();
surface.setSize(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