MCPcopy Create free account
hub / github.com/creatale/node-dv / getPerspectiveTransform

Method getPerspectiveTransform

deps/opencv/modules/imgproc/src/imgwarp.cpp:3946–3971  ·  view source on GitHub ↗

Calculates coefficients of perspective transformation * which maps (xi,yi) to (ui,vi), (i=1,2,3,4): * * c00*xi + c01*yi + c02 * ui = --------------------- * c20*xi + c21*yi + c22 * * c10*xi + c11*yi + c12 * vi = --------------------- * c20*xi + c21*yi + c22 * * Coefficients are calculated by solving linear system: * / x0 y0 1 0 0 0 -x0*u0 -y0*u0 \ /c00\ /u0\ *

Source from the content-addressed store, hash-verified

3944 * cij - matrix coefficients, c22 = 1
3945 */
3946cv::Mat cv::getPerspectiveTransform( const Point2f src[], const Point2f dst[] )
3947{
3948 Mat M(3, 3, CV_64F), X(8, 1, CV_64F, M.data);
3949 double a[8][8], b[8];
3950 Mat A(8, 8, CV_64F, a), B(8, 1, CV_64F, b);
3951
3952 for( int i = 0; i < 4; ++i )
3953 {
3954 a[i][0] = a[i+4][3] = src[i].x;
3955 a[i][1] = a[i+4][4] = src[i].y;
3956 a[i][2] = a[i+4][5] = 1;
3957 a[i][3] = a[i][4] = a[i][5] =
3958 a[i+4][0] = a[i+4][1] = a[i+4][2] = 0;
3959 a[i][6] = -src[i].x*dst[i].x;
3960 a[i][7] = -src[i].y*dst[i].x;
3961 a[i+4][6] = -src[i].x*dst[i].y;
3962 a[i+4][7] = -src[i].y*dst[i].y;
3963 b[i] = dst[i].x;
3964 b[i+4] = dst[i].y;
3965 }
3966
3967 solve( A, B, X, DECOMP_SVD );
3968 ((double*)M.data)[8] = 1.;
3969
3970 return M;
3971}
3972
3973/* Calculates coefficients of affine transformation
3974 * which maps (xi,yi) to (ui,vi), (i=1,2,3):

Callers

nothing calls this directly

Calls 2

checkVectorMethod · 0.80
getMatMethod · 0.45

Tested by

no test coverage detected