www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Find homography in D?

reply Paolo Invernizzi <paolo.invernizzi gmail.com> writes:
Hi,

Someone can point me to a D implementation of the classical 
OpenCV find homography matrix?

Thank you,
Paolo
Apr 21
next sibling parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote:
 Hi,

 Someone can point me to a D implementation of the classical 
 OpenCV find homography matrix?

 Thank you,
 Paolo
Kinda some work but it should be doable using DCV and mir.lubeck in theory DCV can compute, not sift or surf b, but similar features https://github.com/libmir/dcv/blob/master/examples/features/source/app.d Lubeck computes singular value decomposition https://github.com/kaleidicassociates/lubeck And this method but with mir ndslices https://medium.com/all-things-about-robotics-and-computer-vision/homography-and-how-to-calculate-it-8abf3a13ddc5
Apr 21
prev sibling next sibling parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote:
 Hi,

 Someone can point me to a D implementation of the classical 
 OpenCV find homography matrix?

 Thank you,
 Paolo
Just for future records in the forum. // https://math.stackexchange.com/questions/3509039/calculate-homography-with-and-without-svd /+dub.sdl: dependency "lubeck" version="~>1.5.4" +/ import std; import mir.ndslice; import kaleidic.lubeck; void main() { double[2] x_1 = [93,-7]; double[2] y_1 = [63,0]; double[2] x_2 = [293,3]; double[2] y_2 = [868,-6]; double[2] x_3 = [1207,7]; double[2] y_3 = [998,-4]; double[2] x_4 = [1218,3]; double[2] y_4 = [309,2]; auto A = [ -x_1[0], -y_1[0], -1, 0, 0, 0, x_1[0]*x_1[1], y_1[0]*x_1[1], x_1[1], 0, 0, 0, -x_1[0], -y_1[0], -1, x_1[0]*y_1[1], y_1[0]*y_1[1], y_1[1], -x_2[0], -y_2[0], -1, 0, 0, 0, x_2[0]*x_2[1], y_2[0]*x_2[1], x_2[1], 0, 0, 0, -x_2[0], -y_2[0], -1, x_2[0]*y_2[1], y_2[0]*y_2[1], y_2[1], -x_3[0], -y_3[0], -1, 0, 0, 0, x_3[0]*x_3[1], y_3[0]*x_3[1], x_3[1], 0, 0, 0, -x_3[0], -y_3[0], -1, x_3[0]*y_3[1], y_3[0]*y_3[1], y_3[1], -x_4[0], -y_4[0], -1, 0, 0, 0, x_4[0]*x_4[1], y_4[0]*x_4[1], x_4[1], 0, 0, 0, -x_4[0], -y_4[0], -1, x_4[0]*y_4[1], y_4[0]*y_4[1], y_4[1] ].sliced(8, 9); auto svdResult = svd(A); auto homography = svdResult.vt[$-1].sliced(3, 3); auto transformedPoint = homography.mtimes([1679, 128, 1].sliced.as!double.slice); transformedPoint[] /= transformedPoint[2]; writeln(transformedPoint); //[4, 7, 1] }
Apr 30
prev sibling next sibling parent Jordan Wilson <wilsonjord gmail.com> writes:
On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote:
 Hi,

 Someone can point me to a D implementation of the classical 
 OpenCV find homography matrix?

 Thank you,
 Paolo
Something I wrote awhile ago... ``` import kaleidic.lubeck : svd; import gfm.math; import mir.ndslice : sliced; auto generateTransformationArray(int[] p) { return generateTransformationArray(p[0],p[1],p[2],p[3]); } auto generateTransformationArray(int x, int y, int x_, int y_) { return [-x, -y, -1, 0, 0, 0, x*x_, y*x_, x_, 0, 0, 0, -x, -y, -1, x*y_, y*y_, y_]; } auto transformCoor (mat3d mat, vec3d vec) { auto res = mat * vec; return res / res[2]; } auto findHomography (int[][] correspondances) { auto a = correspondances .map!(a => a.generateTransformationArray) .joiner .array .sliced(8,9); auto r = a.svd; auto homog = r.vt.back; return mat3d(homog.map!(a => a/homog.back).array); } ```
Apr 30
prev sibling parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote:
 Hi,

 Someone can point me to a D implementation of the classical 
 OpenCV find homography matrix?

 Thank you,
 Paolo
Now, we can do image stitching using DCV. It needs improvements though. https://github.com/libmir/dcv/tree/master/examples/imagestitchinghomography
May 13