如何在OpenCV中裁剪CvMat? [英] How to crop a CvMat in OpenCV?

查看:965
本文介绍了如何在OpenCV中裁剪CvMat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像转换为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆