I have a collection of cv::Mat objects of different sizes. I want to them all to have the same number of columns as the widest matrix in the collection. Matrices that have less columns should be padded to the right with a fixed color. Essentially I want the same functionality as Photoshop’s “Canvas Size…” operation. How should I do that in C++?
cv::resize doesn’t cut it, because it stretches content, instead of padding it. cv::Mat::resize also doesn’t fit the bill because it can only add rows, but not columns.
2
Answers
The trick is to create a new matrix with the desired dimensions and then copy data from the original image into a ROI representing the retained data:
You can also use
copyMakeBorder
:Usage: