OpenCV 将仿射变换应用于单个点而不是整个图像 [英] OpenCV Applying Affine transform to single points rather than entire image
问题描述
我在 OpenCV 中从 KeypointBasedMotionEstimator 类获得了一个仿射变换矩阵.
I've got a Affine transform matrix in OpenCV from the KeypointBasedMotionEstimator class.
它的形式如下:
[1.0008478, -0.0017408683, -10.667297;
0.0011812132, 1.0009096, -3.3626099;
0, 0, 1]
我现在想将变换应用于向量
Pointf >,这样它就会变换每个点,就像它们在图像中一样.
I would now like to apply the transform to a vector< Pointf >, so that it will transform each point as it would be if they were in the image.
OpenCV 似乎不允许只转换点,函数:
The OpenCV does not seem to allow transforming points only, the function:
void cv::warpAffine ( InputArray src,
OutputArray dst,
InputArray M,
Size dsize,
int flags = INTER_LINEAR,
int borderMode = BORDER_CONSTANT,
const Scalar & borderValue = Scalar()
)
似乎只将图像作为输入和输出.
Only seems to take images as inputs and outputs.
有没有办法对 OpenCV 中的单点应用仿射变换?
Is there a way I can apply an affine transform to single points in OpenCV?
推荐答案
你可以使用
void cv::perspectiveTransform(InputArray src, OutputArray dst, InputArray m)
例如
cv::Mat yourAffineMatrix(3,3,CV_64FC1);
[...] // fill your transformation matrix
std::vector<cv::Point2f> yourPoints;
yourPoints.push_back(cv::Point2f(4,4));
yourPoints.push_back(cv::Point2f(0,0));
std::vector<cv::Point2f> transformedPoints;
cv::perspectiveTransform(yourPoints, transformedPoints, yourAffineMatrix);
不确定 Point 数据类型,但转换必须具有 double
类型,例如CV_64FC1
not sure about Point datatype, but the transformation must have double
type, e.g. CV_64FC1
参见 http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#perspectivetransform 也是
这篇关于OpenCV 将仿射变换应用于单个点而不是整个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!