Find homography in D?
Jordan Wilson
wilsonjord at gmail.com
Tue Apr 30 20:53:00 UTC 2024
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);
}
```
More information about the Digitalmars-d-learn
mailing list