Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV. How do I multiply point and matrix (CvMat)

Tags:

c

opencv

I have matrix that is used for rotation:

CvMat* rot_mat = cvCreateMat(2, 3, CV_32FC1);
cv2DRotationMatrix(center, angle, scale, rot_mat);
...

This matrix is used for image operations.

cvWarpAffine(..., ..., rot_mat, ..., ...);

I have to know, how this matrix should affect exact pixel - location it should be transfered.

How can I multiply 2D point (pixel location) and my matrix to find out where pixel should be transferred?

like image 513
user149691 Avatar asked Sep 17 '25 09:09

user149691


1 Answers

I found an answer to this in this forum. Just in case the link fails here is the solution:

cv::Point2f operator*(cv::Mat M, const cv::Point2f& p)
{ 
    cv::Mat_<double> src(3/*rows*/,1 /* cols */); 

    src(0,0)=p.x; 
    src(1,0)=p.y; 
    src(2,0)=1.0; 

    cv::Mat_<double> dst = M*src; //USE MATRIX ALGEBRA 
    return cv::Point2f(dst(0,0),dst(1,0)); 
} 
like image 154
Yonatan Simson Avatar answered Sep 19 '25 03:09

Yonatan Simson