OpenCV图像扫描技术与效率优化
1. 连续图像的高效扫描
在图像处理中,为了提高效率,图像每行末尾可能会填充额外像素。不过,未填充的图像可以看作一个长度为WxH像素的一维数组。 cv::Mat 类提供了 isContinuous 方法来判断图像是否有填充像素,若返回 true 则表示无填充。也可以通过以下代码检查矩阵的连续性:
// check if size of a line (in bytes)
// equals the number of columns times pixel size in bytes
image.step == image.cols*image.elemSize();
但建议始终使用 isContinuous 方法进行连续性检查。在某些特定处理算法中,可利用图像的连续性,通过一个更长的单循环处理图像。以下是颜色缩减函数的实现:
void colorReduce(cv::Mat image, int div=64) {
int nl= image.rows; // number of lines
// total number of elements per line
int nc= image.cols * image.channels();
if (image.isContinuous()) {
// then no padded
超级会员免费看
订阅专栏 解锁全文
2万+

被折叠的 条评论
为什么被折叠?



