How can I apply a transformation matrix to a point in OpenCV?

后端 未结 1 1177
耶瑟儿~
耶瑟儿~ 2021-02-19 08:17

Suppose I have a transformation matrix Mat tr that I got from getAffineTransform() and a Point2d p. I want the p

相关标签:
1条回答
  • 2021-02-19 08:51

    cv::transform is used for transforming points with a transformation matrix.

    Every element of the N -channel array src is interpreted as N -element vector that is transformed using the M x N or M x (N+1) matrix m to M-element vector - the corresponding element of the output array dst .

    The function may be used for geometrical transformation of N -dimensional points, arbitrary linear color space transformation (such as various kinds of RGB to YUV transforms), shuffling the image channels, and so forth.

    There's a concise example in the InputArray documentation (otherwise not relevant):

    std::vector<Point2f> vec;
    // points or a circle
    for( int i = 0; i < 30; i++ )
        vec.push_back(Point2f((float)(100 + 30*cos(i*CV_PI*2/5)),
                              (float)(100 - 30*sin(i*CV_PI*2/5))));
    cv::transform(vec, vec, cv::Matx23f(0.707, -0.707, 10, 0.707, 0.707, 20));
    

    Or you can likely just convert the Point2f into a Mat and multiply by the matrix.

    0 讨论(0)
提交回复
热议问题