Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

is there any efficient/fast/best way to remove/delete a given row/col from a cv::Mat?

Hi people, I was playing around with some code and I came into the demand of removing a specific given row/col from a cv::Mat. So, lets say we have the following cv::Mat:

Mat a = [1, 2, 3, 4, 5;
             7, 8, 9, 10, 11;
            12, 13, 14, 15, 16;
            17, 18, 19, 20, 21;
            22, 23, 24, 25, 26]

to transform it into:

[1, 2, 3, 4, 5;
 7, 8, 9, 10, 11;
 12, 13, 14, 15, 16;
 22, 23, 24, 25, 26]

or

[1, 2, 4, 5;
 7, 8, 10, 11;
 12, 13, 15, 16;
 17, 18, 20, 21;
 22, 23, 25, 26]

Searching around I found some approaches mainly in SO, e.g. here and here but none of them applies a direct way to do it. Therefore, I would like to ask if there is such a way or I will have to stick with one of these solutions?

I understand that it might be quite complicated for rows/cols in the middle of the cv::Mat, what about the case that I want to remove the first and last rows and cols respectively.

Thanks.