gpt4 book ai didi

opencv - OpenCV 中的 cvGetRows() 函数有什么用?

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:53 24 4
gpt4 key购买 nike

我什么时候应该使用这个功能。谁能举例说明一下?

最佳答案

根据 Documentation,返回数组行或行跨度。它返回您指定的行。

我将借助 Python 终端进行解释:

以灰度模式加载图像并检查其宽度和高度。

>>> import cv2.cv as cv
>>> img = cv.LoadImage('approx2.jpg',0)
>>> img
<iplimage(nChannels=1 width=300 height=300 widthStep=300 )>

看,图片尺寸为 300x300。下面是图片。

enter image description here

对所有像素求和,

>>> cv.Sum(img)
(1252271.0, 0.0, 0.0, 0.0)

现在我们应用我们的第一个函数,cv.GetRow()

>>> row = cv.GetRow(img,150)
>>> row
<cvmat(type=42424000 8UC1 rows=1 cols=300 step=300 )>

>>> cv.Sum(row)
(14279.0, 0.0, 0.0, 0.0)

我取了第 150 行并对该行中的所有元素求和。查看结果图像的高度 = 1。

现在获取函数 cv.GetRows()。

>>> rows = cv.GetRows(img,0,150)
>>> rows
<cvmat(type=42424000 8UC1 rows=150 cols=300 step=300 )>

>>> cv.Sum(rows)
(802501.0, 0.0, 0.0, 0.0)

我选取了从第 150 行开始的所有行。看到它的高度是 150。查看下图:

enter image description here

现在这个函数 delta_row 有第四个参数,可以用作增量。它将选择以上述步长为增量的行,跳过其间的所有内容。即,如果指定,该函数会提取从 start_row 到(但不包括)end_row 的每个 delta_row 第行。

>>> rows = cv.GetRows(img,0,300,5)
>>> rows
<cvmat(type=42420000 8UC1 rows=60 cols=300 step=1500 )>

看,现在高度只有 30,因为它每 5 行提取一次。

结果如下:

enter image description here

cv.GetCol() 和 cv.GetCols() 的情况类似。

关于opencv - OpenCV 中的 cvGetRows() 函数有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11372275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com