OpenCV 使用 C++ 在循环中选择适当的子矩阵
我对 opencv 还很陌生。我正在尝试编写一个循环,对大(〜1000 x〜1000)矩阵的小(9x9)子矩阵进行一些处理。基于一些掩码矩阵,我决定是否在大矩阵中的特定点处处理 9x9。根据我阅读的文档,我试图将这行代码放在一个循环中:
Mat tempROI(*(data->cvData), Rect(i-4,j-4, i+5, j+5));
i和j是较大矩阵的行、列不等式。然后我有一个处理 tempROI 的函数。然而,我发现投资回报率的大小随着 i 和 j 的增加而增加。我将 a: 转储
printf("Size of ROI = %d, %d.\nFor IDX = %d, %d\n", tempROI.rows, tempROI.cols, i, j);
到循环中进行调试。我发现我的投资回报率正在显着增加。例如,这是一个随机转储:
ROI 的大小 = 191, 9。 对于 IDX = 4, 186
显然有些东西不能正常工作,我认为这是一个合理的假设,即谬误在于我对如何从较大的子矩阵中正确选择子矩阵的理解。有人可以建议解决这个问题的最佳方法是什么吗?
在相关说明中,我真的希望只使用指针,而不是在每次循环迭代时实际创建矩阵头。
简而言之 - 做我想做的事情的正确方法是什么?多谢。
I'm fairly new to opencv. I'm trying to write a loop that does some processing on a small (9x9) submatrix of a large (~1000 x ~1000) matrix. Based on some mask matrix I decided whether or not to process the 9x9 at a particular point in the large matrix. Based on the documentation I read I'm trying to put this line of code inside a loop:
Mat tempROI(*(data->cvData), Rect(i-4,j-4, i+5, j+5));
i and j are row,col indecies of the larger matrix. I then have a function that processes tempROI. I'm finding, however, that the size of my ROI is increasing with i and j. I dumped a:
printf("Size of ROI = %d, %d.\nFor IDX = %d, %d\n", tempROI.rows, tempROI.cols, i, j);
into the loop to debug. I see that my ROI is increasing significantly. For example here's a random dump:
Size of ROI = 191, 9.
For IDX = 4, 186
Clearly something's not working properly and I think it's a fair assumption that the fallacy lies in my understanding of how to properly select a submatrix from a larger one. Can someone advise as to what the best way to go about this is?
On a related note I was really hoping to just use a pointer as opposed to actually creating the matrix header every loop iteration.
In short - what's the right way to do what I'm trying to do? Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论