CornerPinTOP Perspective transform

Could the CornerpinTOP please include a “Perspective Correct” mode for mapping purposes? Would be an excellent, lightweight alternative to the stoner for simple mapping.
See this post for reference.
viewtopic.php?f=12&t=5856&p=22078&hilit=stoner+perspective#p22078

1 Like

This would be great!

I’m bringing this post back from 2015!
Perspective corner pinning was added, however…

It would be great if this was also added to the extraction method. It appears to still be bilinear.

I was able to figure it out with a homography in OpenCV:

Am I doing something wrong?
The drop-down menu is in the “Pin” tab and has no effect on the extraction, however, the “grid refinement” in the “Pin” tab works for both methods.

1 Like

+1, I found myself wishing corner pin extract supported perspective mapping just recently. Here’s some shader code to compute the perspective mapping and produce an UV LUT for use with the Remap TOP:

uniform vec2 uTopLeft;
uniform vec2 uTopRight;
uniform vec2 uBottomLeft;
uniform vec2 uBottomRight;

mat3 perspective_matrix(vec2 bl, vec2 br, vec2 tl, vec2 tr) {
	float disc = tr.x * (br.y - tl.y) + br.x * (tl.y - tr.y) + tl.x * (-br.y + tr.y);
	return mat3((bl.x * (tr.x * (-br.y + tl.y) + tl.x * (br.y - tr.y)) + br.x * (tr.x * (bl.y - tl.y) + tl.x * (-bl.y + tr.y))) / disc, (tr.x * (bl.y - br.y) * tl.y + bl.x * br.y * tl.y - tl.x * bl.y * tr.y - bl.x * br.y * tr.y + tl.x * br.y * tr.y + br.x * bl.y * (-tl.y + tr.y)) / disc, (-((tl.x - tr.x) * (bl.y - br.y)) + (bl.x - br.x) * (tl.y - tr.y)) / disc, (tr.x * (tl.x * (-bl.y + br.y) + bl.x * (-br.y + tl.y)) + br.x * (tl.x * (bl.y - tr.y) + bl.x * (-tl.y + tr.y))) / disc, (-(bl.x * br.y * tl.y) + tr.x * br.y * (-bl.y + tl.y) + tl.x * bl.y * (br.y - tr.y) + br.x * bl.y * tr.y + bl.x * tl.y * tr.y - br.x * tl.y * tr.y) / disc, ((br.x - tr.x) * (bl.y - tl.y) - (bl.x - tl.x) * (br.y - tr.y)) / disc, bl.x, bl.y, 1.0);
}

vec2 perpective_transform(mat3 m, vec3 v) {
	vec3 t = m * v;
	t /= t.z;
	return t.st;
}

out vec4 fragColor;
void main() {
	mat3 m = perspective_matrix(uBottomLeft, uBottomRight, uTopLeft, uTopRight);
	vec2 uv = perpective_transform(m, vec3(vUV.st, 1.0));
	vec4 color = vec4(uv, 0, 0);
	fragColor = TDOutputSwizzle(color);
}

Hi @harveymoon and @r-ssek,

added as an RFE.

Cheers
Markus

1 Like