python - 如何检测图中的峰值数量?
问题描述
我有一个代码可以识别绘图左侧 40% 侧(蓝线左侧)的边缘(峰值和底部)并将它们的幅度相加。问题:我希望代码也分别计算峰值和底部的数量。有什么帮助吗?
我的代码:
# now we will get the sum of the peaks in the given image
# To do this we use opencv's cornerHarris function.
# this function gives the corners in an image which in our case is peaks.
# we get the coordinates of these peaks through the cornerHarris function,
# and we subtract it from the coordinates of mid line in order to find the
# height of the peak. Then we add all these heights to get the sum of the
# heights which is our feature for classifying the image.
def give_peak_sum(file):
image = cv2.imread(file) # opencv's image read function
image_copy = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# converts image from
# BGR color space to RGB color space
image_dims = image.shape
x_dim = image_dims[1]
# converting to gray scale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
# detect corners
dst = cv2.cornerHarris(gray, 2, 3, 0.04)
# dilate corner image to enhance corner points
dst = cv2.dilate(dst, None)
thresh = 0.02*dst.max()
peak_sum = 0
mid_line = get_mid_line(image_copy) # using previously defined function
for j in range(0, dst.shape[0]):
for i in range(0, dst.shape[1]):
if (dst[j, i] > thresh and i < 0.4*x_dim):
peak_sum += abs(j-mid_line)
return (peak_sum)
解决方案
推荐阅读
- python - .start() 不会导致启动线程
- python - python list_iterator 类未定义
- python - 基于列的每周图的 Pandas Dataframe 线图
- delphi - Rapidapi & 401 未经授权的响应
- php - Laravel 的初学者 - 急切的加载似乎不起作用?
- verilog - 验证 2 位 BCD 加法器
- javascript - 使用 Javascript 给定值编辑表格内容
- flutter - Flutter webrtc 无法设置远程应答 sdp
- javascript - 使用浏览器通知时如何处理错误?
- database - 从 EC2 连接时的 Amazon Lightsail 数据库数据传输成本