使用Opencv C ++跨图片 [英] Stride on image using Opencv C++

查看:120
本文介绍了使用Opencv C ++跨图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上,在C ++上使用opencv 2.4.2. 我用imread读取图像并将其放在Mat对象中. 之后,我使用Mat类的函数ptr获取原始数据的指针. 我想知道图像包含步幅时imread的工作方式. Mat的数据或仅像素的数据有跨步吗?

I am on windows and use opencv 2.4.2 on C++. I read an image with imread and put it in a Mat object. After that, i get a pointer on the raw data using the function ptr of the Mat class. I would like to know how works imread when the image contains stride. Is there stride in the data of the Mat or only data of pixels ?

其他信息:我需要原始数据,因为我使用的是用数组编写的代码,并且我不想为Mat类更改它.

Additional information: I need the raw data because I am using a code written with array and I don't want to change it for the Mat class.

推荐答案

大步是,cv :: Mat中的每个新像素行都不在最后一行的末尾开始. 这是因为如果内存以4字节的倍数开头,则内存速度更快-因此,只有当行中的字节数(像素数*颜色数)不是4的倍数时,才有意义.

The stride is that each new row of pixels in the cv::Mat doesn't start after the end of the last row. This is because the memory is faster if it starts on a multiple of 4bytes - so it only matters if the number of bytes in a row (number of pixels * number of colours) isn't a multiple of 4.

您可以检查.isContinuous()如果没有大步走就会返回true

You can check .isContinuous() will return true if there is no stride

访问图像的最安全方法是循环遍历所有行,并使用.ptr(row)获取指向行首的指针,然后对该行进行任何处理.

The safest way of accessing an image is to loop over all the rows and use .ptr(row) to get a pointer to the start of the row, then do any processing on that row.

如果您需要将opencv与其他库混合使用,则可以创建一个cv :: mat,它将使用您自己的内存来存储数据,并且您可以告诉opencv在这方面没有任何进展

If you need to mix opencv with other libs you can create a cv::mat that will use your own memory for the data and you can tell opencv that there is no stride on this

有关详细信息,请参见 http://opencv.willowgarage.com/documentation/cpp /core_basic_structures.html

For lots of details see http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html

这篇关于使用Opencv C ++跨图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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