开发者

How to "crop" a matrix while keeping the byte alignment?

开发者 https://www.devze.com 2023-04-02 18:27 出处:网络
Let\'s say I have a 100x100 m开发者_高级运维atrix A, and I want to get another 100x50 matrix B containing only the 50 first columns of A.

Let's say I have a 100x100 m开发者_高级运维atrix A, and I want to get another 100x50 matrix B containing only the 50 first columns of A. The easiest method is to use cvGetSubRect, but this doesn't copy the values, it just gives me a header pointing to the data of A and "skips" the columns I don't need, while it is crucial for my application that the data in B can be read with continuously.

What is the most elegant way to do this in OpenCV? I don't mind actually copying the data from A to B but I am assuming there is a special function to do this?

thanks


Use Mat::copyTo() to do a full copy. If necessary (e.g., if the shape is wrong), this will reallocate data for the target matrix.

Since the question is actually tagged "c", I will mention for completeness that the C-API copy function is cvCopy() .

0

精彩评论

暂无评论...
验证码 换一张
取 消