wangzhibo
2022-03-24 a01eb79d5bd40decaaa4693534de77efdf330bb8
bug fix   w > image_w /4
1个文件已修改
7 ■■■■■ 已修改文件
extract_voltage_task.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
extract_voltage_task.py
@@ -64,8 +64,6 @@
        return "@"
def extrct_digits_from_frame(frame, col_start, col_end, rows_start, rows_end):
    image = frame[col_start:col_end, rows_start:rows_end]
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
@@ -73,7 +71,8 @@
                           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)
    contours, hierarchy = cv2.findContours(counter, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    contours, hierarchy = cv2.findContours(
        counter, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    return_numbers = []
    contours_count = 0
    image_h = image.shape[0]
@@ -82,7 +81,7 @@
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3:
            if w>w/4:
            if w > image_w/4:
                half_width = int(w/2)
                one_number = get_most_simmilar_digit(cv2.threshold(cv2.resize(
                gray[y:y+h, x:x+half_width], (20, 30)), 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1])