简体   繁体   中英

Combine matrices using Mat opencv

I have 2 matrices as follows

    R = [1,0,0,0
         0,1,0,0
         0,0,1,0
         0,0,0,1]

and

   T = [1,0,0]

Can I make a 4X4 Matrix from the above 2 in this format?

    [    R | T
     0 0 0   1]

This is basically obtaining the transformation matrix from the rotation and translation. I am trying using for loops and combining them into one matrix. But is there an easy way or a function that can help me do this in a shorter way?

Here is a way to approach this. You can create an output matrix first and then operate on a rectangular sub-regions of the output (ROI – “Region of Interest”):

  1. Allocate a matrix that will keep the result. Fill in the matrix with desired initial values (optional). Make sure the matrix has the correct dimension and data type. For example:

     // create output matrix // rows and cols specify the disired size for the output matrix // CV_32F is data type for matrix elements Mat out(rows, cols, CV_32F, Scalar(0)); 
  2. Set regions of interest (ROI) in your output matrix to desired sub-matrices. For example

     // your input matrices Mat R, T; // set ROI for R cv::Rect rect_R(0, 0, R.rows, R.cols); cv::Mat out_R = out(rect_R); // this assignment does not copy data // out and out_R now share data // assign out_R to R out_R = R; // similarly you can set another area of out to matrix T, etc. 
  3. out is set. you are done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM