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

查看:55
本文介绍了如何在 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天全站免登陆