Как определить количество пиков на участке? - PullRequest
0 голосов
/ 24 апреля 2019

У меня есть код, который распознает края (пики и основания) на левой 40% стороне графика (слева от синей линии) и суммирует их амплитуду.Проблема: я хочу, чтобы код также подсчитывал количество пиков и впадин отдельно.любая помощь?

(например, изображение, для которого работает код) image that the code works for

Мой код:

 # 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)
...