如何在OpenCV中裁剪CvMat? [英] How to crop a CvMat in OpenCV?
问题描述
我将图像转换为CvMat
矩阵,例如CVMat source
.从source
获得感兴趣的区域后,我希望将算法的其余部分仅应用于该感兴趣的区域.为此,我认为我必须以某种方式裁剪无法执行的source
矩阵.是否存在可以裁剪CvMat
矩阵并返回另一个裁剪的CvMat
矩阵的方法或函数?谢谢.
I have an image converted in a CvMat
Matrix say CVMat source
. Once I get a region of interest from source
I want the rest of the algorithm to be applied to that region of interest only. For that I think I will have to somehow crop the source
matrix which I am unable to do so. Is there a method or a function that could crop a CvMat
Matrix and return another cropped CvMat
matrix? thanks.
推荐答案
OpenCV具有感兴趣的区域功能,您可能会发现它很有用.如果您使用的是cv::Mat
,则可以使用以下内容.
OpenCV has region of interest functions which you may find useful. If you are using the cv::Mat
then you could use something like the following.
// You mention that you start with a CVMat* imagesource
CVMat * imagesource;
// Transform it into the C++ cv::Mat format
cv::Mat image(imagesource);
// Setup a rectangle to define your region of interest
cv::Rect myROI(10, 10, 100, 100);
// Crop the full image to that image contained by the rectangle myROI
// Note that this doesn't copy the data
cv::Mat croppedImage = image(myROI);
这篇关于如何在OpenCV中裁剪CvMat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!