如何从打开的cv中的图像访问第一个5 * 5块? [英] How to access first 5*5 block from an image in open cv?

查看:125
本文介绍了如何从打开的cv中的图像访问第一个5 * 5块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我访问第一个5 * 5块从一个图像?我是新的打开CV,我正在编码的C ++。我搜索net.If任何人都可以回答这将使我的工作更容易。

Can anyone please help me to access first 5*5 block from an image?I am new to open CV,I am doing the coding in c++.i searched over net.If anyone could answer this it would make my work easier.

推荐答案

您可以使用 cv :: Mat :: operator code>。

You can access image ROI using the cv::Mat::operator().

例如,要获取图像的第一个5x5块,您可以执行以下操作:

e.g, to get the first 5x5 block of the image, you can do the following:

int roi_origin_x = 0;
int roi_origin_y = 0;
int block_width = 5;
int block_height = 5;

cv::Rect roi(roi_origin_x, roi_origin_y, block_width, block_height);

cv::Mat region = image(roi);

要访问特定块号,例如(i,j),只需更改块的原点this:

To access a specific block number e.g (i,j), just change the origin of the block like this:

int block_width = 5;
int block_height = 5;
int roi_origin_x =  i * block_width;
int roi_origin_y = j * block_height;

cv::Rect roi(roi_origin_x, roi_origin_y, block_width, block_height);

roi可能会超出图像范围,因此请确保应用检查将其保留在图像边界,

The roi may go out of image bounds, so make sure you apply the checks to keep it inside the image boundary,

这篇关于如何从打开的cv中的图像访问第一个5 * 5块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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