提取单个像素数据的最快方法?
我必须使用 OpenCV 获取有关灰度图像上许多像素的标量值的信息。它将遍历数十万个像素,因此我需要尽可能最快的方法。我在网上找到的所有其他来源都非常神秘且难以理解。是否有一行简单的代码应该只传递一个简单的整数值,表示图像的第一个通道(亮度)的标量值?
I have to get information about the scalar value of a lot of pixels on a gray-scale image using OpenCV. It will be traversing hundreds of thousands of pixels so I need the fastest possible method. Every other source I've found online has been very cryptic and hard to understand. Is there a simple line of code that should just hand a simple integer value representing the scalar value of the first channel (brightness) of the image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要获取每个新行上的数据指针,因为 opencv 会将数据填充到每行开头的 32 位边界
You need to get the data pointer on each new row because opencv will pad the data to 32bit boundary at the start of each row
关于Martin的帖子,您实际上可以使用OpenCV的Mat对象中的isContinously()方法来检查内存是否连续分配。以下是确保外循环仅循环一次(如果可能)的常见习惯用法:
With regards to Martin's post, you can actually check if the memory is allocated continuously using the isContinuous() method in OpenCV's Mat object. The following is a common idiom for ensuring the outer loop only loops once if possible: