c++ - Convert a point on an inclined image to a non-inclined point -
i have image of image, inner image inclined , has own coordinate table (visible on edges):
now need convert point of actual image (x cm, y cm)
point on inclined image. say, want know (x cm, y cm)
coordinates bottom left corner ((0, img.height())
) of actual image has. is, if inner image's coordinate table extrapolated.
i know:
- the angle
a
of inclined image - two points
p1
,p2
selected manually inclined image - the cm coordinates
p1cm
,p2cm
these 2 points
i can scale of image comparing 2 points , getting ratio between cm distance , actual distance:
double dcmx = p1cm.x() - p2cm.x(); double dcmy = p1cm.y() - p2cm.y(); double dcm = sqrt(pow(dcmx, 2) + pow(dcmy, 2)) double dpointx = p1.x() - p2.x(); double dpointy = p1.y() - p2.y(); double dpoint = sqrt(pow(dpointx, 2) + pow(dpointy, 2)) double scale = dpoint / dcm;
but have no idea how coordinates of left bottom corner in cm coordinates.
this kind of transformation (using scale , tilt angle) called affine transformation. might want use opencv
libraries simplicity. code simple:
double scale = dpoint / dcm; point center = point( img.cols/2, img.rows/2); mat warpmat = getrotationmatrix2d( center, angle, scale ); point2f src[1]; point2f dst[1]; src[0] = point2f(src_x, src_y); transform(src, dst, warpmat);
then have result inside dst
. can of course make src
array larger , give transform
method more points @ once.
see this more information opencv , affine transformation.
if don't want use opencv
can still take @ documentation pages of getrotationmatrix2d
, warpaffine
, implement yourself, quite simple:
build matrix (warpmat
):
and then, each point (x,y)
build vector [x,y,1]
, matrix multiplication between warpmat
, [x,y,1]
:
Comments
Post a Comment