X_Trust
X_Trust

Reputation: 817

Transposing a Mat image into a larger Mat image, Opencv

I have written a function to take a Mat image in and transpose it onto the center of a blank image three times the size. I have written function to do so but I feel it can be improved in terms of efficiency.

void transposeFrame( cv::Mat &frame){

   Mat new_frame( frame.rows * 3, frame.cols * 3, CV_8UC3, Scalar(0,0,255));

   Rect dim = Rect( frame.rows, frame.cols, frame.rows * 2, frame.cols * 2);

   Mat subview = new_frame(dim);

   frame.copyTo(subview);
   frame = subview;
}

Is there a better to preform this operation?

Upvotes: 0

Views: 1668

Answers (2)

The Nomadic Coder
The Nomadic Coder

Reputation: 650

I'd use something like :-

Mat frame_tpsed;
cv::Mat::transpose(frame, frame_tpsed);
new_frame(Rect(frame.rows, frame.cols, frame.rows*2, frame.cols*2))  = frame_tpsed

Transpose on opencvDocs : http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#void transpose(InputArray src, OutputArray dst)

Didn't try it out. Forgot to mention it.

Upvotes: 1

Sergei Nosov
Sergei Nosov

Reputation: 1675

You can use the copyMakeBorder function. However, I don't think it will work considerably faster.

Upvotes: 0

Related Questions