【发布时间】:2019-07-27 18:27:43
【问题描述】:
我正在尝试分割足球场。我正在关注一篇研究论文,该论文建议
- 转换为 HSV
- 抓住 Hue 通道
- 生成直方图
- 获取全局和局部最大值(全局最大值可以是
max(hist)) - 如果局部最大值是全局最大值的 20%,请考虑
问题是我不知道如何获得 Local Maximas。我正在尝试捕获直方图中的峰值列表。
我在 MatLab 上试过,效果很好,但我需要在 python 中做。我已经尝试过 peakutils 之类的库,但没有什么能给我想要的结果。
def field_area_mask(image):
# Convert to HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# Capture the Hue Channel
hue = hsv[:, :, 0]
# Generate Histogram
hist = cv2.calcHist([hue],[0],None,[256],[0,256])
# Capture range
hist_range = hist[:121] # 0-120
hist_range = hist_range.reshape(1, -1)[0]
Hmax = max(hist_range)
plt.plot(hist_range)
HiMax = [] # Need to populate the local maxima's list
【问题讨论】:
-
Finding local maxima/minima with Numpy in a 1D numpy array 可能会对您有所帮助。您还可以查看 sklearn 模块中的
argrelextrema函数。