warpPerspective with more than 4 points

Perspective Transform in node.js introduces a way to warp an image with 4 given coordinates, but is there a way to warp an image with more than 4 points?

Perhaps a relocation of pixels to the corresponding coordinates.

please, please, no useless screenshots of code, here, please. remove & replace with TEXT, thank you.

there’s OpenCV: cv::ThinPlateSplineShapeTransformer Class Reference

related thread: Thin plate spline warpImage produces only zeros

more related on stack overflow

I’m sorry @berak I meant to relate it to the official document example here

let src = cv.imread('canvasInput');
let dst = new cv.Mat();
let dsize = new cv.Size(src.rows, src.cols);
// (data32F[0], data32F[1]) is the first point
// (data32F[2], data32F[3]) is the sescond point
// (data32F[4], data32F[5]) is the third point
// (data32F[6], data32F[7]) is the fourth point
let srcTri = cv.matFromArray(4, 1, cv.CV_32FC2, [56, 65, 368, 52, 28, 387, 389, 390]);
let dstTri = cv.matFromArray(4, 1, cv.CV_32FC2, [0, 0, 300, 0, 0, 300, 300, 300]);
let M = cv.getPerspectiveTransform(srcTri, dstTri);
// You can try more different parameters
cv.warpPerspective(src, dst, M, dsize, cv.INTER_LINEAR, cv.BORDER_CONSTANT, new cv.Scalar());
cv.imshow('canvasOutput', dst);
src.delete(); dst.delete(); M.delete(); srcTri.delete(); dstTri.delete();

@crackwitz Yes! I just found it too! :smiley: but I guess it’s not supported in node.js :frowning:

Thanks for the help!

the “not supported” part may be easy to fix. AFAIK it requires whitelisting so that transpilation is even attempted. perhaps nobody has needed/tried it yet. perhaps you’ll get a better answer yet, or you could browse previous opencv.js questions, where I’m sure some of the plumbing is explained.

ThinPlateSplineShapeTransformer uses cv::remap() function. Focus on if you solve your problem with cv::remap()

see the reference code: