We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm attempting to use the keystone library for corner pin warps to correct a given trapezium to a square. Though I can do a pretty close job with my mouse in calibration mode I need a more precise and quicker option to occur automatically (given the parameters of the trapezium).
You should be able to see the intention there ^^
Someone was helping me before the forum updated and they were talking about a linear equation solution but I was struggling to implement it. My code so far:
import deadpixel.keystone.*;
Keystone ks;
CornerPinSurface surface;
PGraphics offscreen;
void setup() {
size(1280, 720, P3D);
smooth();
ks = new Keystone(this);
surface = ks.createCornerPinSurface(400, 400, 20);
offscreen = createGraphics(400, 400, P3D);
}
void draw() {
offscreen.beginDraw();
offscreen.background(255);
offscreen.fill(#67cd47);
offscreen.strokeWeight(2);
offscreen.beginShape();
offscreen.vertex(0, 50);
offscreen.vertex(400, 0);
offscreen.vertex(400, 400);
offscreen.vertex(0, 250);
offscreen.endShape(CLOSE);
offscreen.endDraw();
background(80);
surface.render(offscreen);
}
void keyPressed() {
switch (key) {
case 'c':
ks.toggleCalibration();
break;
case 't':
surface.moveMeshPointBy(surface.BL, 0, 100); //The amout '100' needs to be replaced by the amount to move down.
surface.moveMeshPointBy(surface.TL, 0, -100);
break;
}
}
Answers
that someone was me. hello.
do you have the coords of the vertices of the green quad on the left?
http://forum.processing.org/one/topic/keystone-warp-issue.html
Should we continue on the old post or here?
I do have them: offscreen.vertex(0, 50); offscreen.vertex(400, 0); offscreen.vertex(400, 400); offscreen.vertex(0, 250);)
old forum is locked...
texture is a 400x400 image with the green bit drawn (crudely) on it as per coords given above. press any key and it'll redraw the shape with new coords so that the green bit of the texture fills the original square. press another and it'll pop back.
thinking about it, i may have just re-written lerp().
Any idea when this little bit is sticking out? Works perfectly well using the keystone corner pin warp but for me when I use textures I get this.
Otherwise absolutely perfect: thank you so much!!
i think this is the usual texture problem that shows up from time to time, something to do with the shape being two triangles rather than one quad. see how the tip of the lump is in line with a line from bottom right and top left?
the usual way around this is to split the shapes and textures up into smaller pieces, but that's a pain in this case.
not sure why i didn't see that. maybe i wasn't looking hard enough? i'm using P2D and version 1.5.1...