wangzhibo
2022-03-23 8afe7455067996bf8bca087418425c2bb7d6d492
add height check
1个文件已修改
6 ■■■■■ 已修改文件
extract_voltage_task.py 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
extract_voltage_task.py
@@ -56,7 +56,7 @@
        max_val = cv2.minMaxLoc(res)[1]
        source.append(max_val)
    # print(max(source))
    if max(source) > 0.5:
    if max(source) > 0.3:
        return digits[source.index(max(source))][1]
    else:
        return "@"
@@ -69,14 +69,14 @@
                           cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (6, 6))
    counter = cv2.morphologyEx(thresh.copy(), cv2.MORPH_OPEN, kernel)
    #image_h = image.shape[0]
    contours, hierarchy = cv2.findContours(counter, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    return_numbers = []
    contours_count = 0
    image_h = image.shape[0]
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        #if image_h*0.98 > h > image_h * 0.3:
        if hierarchy[0][contours_count][3] ==0 :
        if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3:
            #print((x, y, w, h))
            #cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
            one_number = get_most_simmilar_digit(cv2.threshold(cv2.resize(