wangzhibo
2022-03-23 69b8cbd754284a2071d06149f0c92d9fe50a744e
add height check
9个文件已修改
2个文件已删除
1个文件已添加
45 ■■■■■ 已修改文件
debug/0_get_frame.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/1_check_frame_boundary.py 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/1_check_video_boundary.py 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/2022-03-14-15-40-32.jpg 补丁 | 查看 | 原始文档 | blame | 历史
debug/2022-03-14-15-40-32_clip.jpg 补丁 | 查看 | 原始文档 | blame | 历史
debug/2_check_frame_digits.py 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/2_check_video_digits.py 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/2_split_digit_from_video.py 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/3_using_template.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/__pycache__/_image_clip_setting.cpython-36.pyc 补丁 | 查看 | 原始文档 | blame | 历史
debug/_image_clip_setting.py 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
debug/new.mp4 补丁 | 查看 | 原始文档 | blame | 历史
debug/0_get_frame.py
@@ -7,7 +7,7 @@
time_now = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
#cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture("7122.mp4")
cap = cv2.VideoCapture("new.mp4")
ret, frame = cap.read()
cv2.imwrite(time_now+".jpg", frame)
print('手动设置 唯一的参数: 数字仪表盘的位置: 要稍微留些余量。')
debug/1_check_frame_boundary.py
@@ -14,12 +14,12 @@
                       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)
    contours_count = 0
    image_h = image.shape[0]
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        if hierarchy[0][contours_count][3] ==0 :
        if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3:
        #if image_h*0.98 > h > image_h * 0.6:
            print((x, y, w, h))
            cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
debug/1_check_video_boundary.py
@@ -17,9 +17,10 @@
    counter = cv2.morphologyEx(thresh.copy(), cv2.MORPH_OPEN, kernel)
    contours, hierarchy = cv2.findContours(counter,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    contours_count = 0
    image_h = image.shape[0]
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        if hierarchy[0][contours_count][3] ==0 :
        if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3:
        #if image_h*0.98 > h > image_h * 0.6:
            print((x, y, w, h))
            cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
@@ -28,7 +29,7 @@
    if cv2.waitKey(100) & 0xFF == ord('q'): #按q退出
        cv2.waitKey(0)
        
cap = cv2.VideoCapture("video.mp4")  # for testing
cap = cv2.VideoCapture("new.mp4")  # for testing
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
debug/2022-03-14-15-40-32.jpg
Binary files differ
debug/2022-03-14-15-40-32_clip.jpg
Binary files differ
debug/2_check_frame_digits.py
@@ -73,9 +73,10 @@
    contours, hierarchy = cv2.findContours(counter,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    contours_count = 0
    return_numbers = []
    image_h = image.shape[0]
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        if hierarchy[0][contours_count][3] ==0 :
        if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3:
        #if image_h*0.98 > h > image_h * 0.6:
            print((x, y, w, h))
            cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
debug/2_check_video_digits.py
@@ -56,8 +56,8 @@
        res = cv2.matchTemplate(target_img, digitROI[0], cv2.TM_CCOEFF_NORMED)
        max_val = cv2.minMaxLoc(res)[1]
        source.append(max_val)
    # print(max(source))
    if max(source) > 0.5:
    print(max(source))
    if max(source) > 0.3:
        return digits[source.index(max(source))][1]
    else:
        return "@"
@@ -77,7 +77,7 @@
    return_numbers = []
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        if hierarchy[0][contours_count][3] ==0 :
        if hierarchy[0][contours_count][3] ==0 and h > image_h * 0.3:
        #if image_h*0.98 > h > image_h * 0.3:
            #print((x, y, w, h))
            #cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
@@ -127,7 +127,7 @@
        cv2.waitKey(0)
cap = cv2.VideoCapture("7122.mp4")  # for testing
cap = cv2.VideoCapture("new.mp4")  # for testing
total_frame = 0 
while(cap.isOpened()):
    ret, frame = cap.read()
debug/2_split_digit_from_video.py
@@ -3,26 +3,31 @@
import cv2
from cv2 import waitKey
import uuid
from _image_clip_setting import image_clip
def save_images(frame):
    image = frame[180:230,250:370]  #frame[176:234,280:426]
    image = frame[image_clip[0]:image_clip[1], image_clip[2]:image_clip[3]]
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    thresh = cv2.threshold(gray, 0, 255,
                       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_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
    contours, hierarchy = cv2.findContours(
        counter, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    contours_count = 0
    #print(contours)
    print(hierarchy)
    for c in contours:
        x, y, w, h = cv2.boundingRect(c)
        if image_h*0.9 > h > image_h * 0.5:
            #print((x, y, w, h))
        print((x, y, w, h))
        print(hierarchy[0][contours_count][3])
        if hierarchy[0][contours_count][3] ==0 :
            #cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
            cv2.imwrite("./images52/"+str(uuid.uuid4())+".jpg",cv2.threshold(cv2.resize(gray[y:y+h,x:x+w],(20,30)), 0, 255,
                       cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1])
        
cap = cv2.VideoCapture("video2.mp4")  # for testing
cap = cv2.VideoCapture("new.mp4")  # for testing
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
debug/3_using_template.py
@@ -14,7 +14,7 @@
def task_init_load_digits():
    # 加载数字模板
    path = './data'    # 这个地方就是获取当前运行目录 获取函数在主函数里面
    path = './templates'    # 这个地方就是获取当前运行目录 获取函数在主函数里面
    #和模板的数字进行匹配
    digits.append([cv2.imread(path + "/@-0.jpg",cv2.IMREAD_GRAYSCALE),'@'])
    digits.append([cv2.imread(path + "/@-1.jpg",cv2.IMREAD_GRAYSCALE),'@'])
debug/__pycache__/_image_clip_setting.cpython-36.pyc
Binary files differ
debug/_image_clip_setting.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__author__ = '上海色宁'
#image_clip = [176,234,278,422]     # for  video.mp4
image_clip = [226,266,220,300]     # for  7122.mp4
image_clip = [176,234,278,422]     # for  video.mp4
#image_clip = [226,266,200,300]     # for  new.mp4
debug/new.mp4
Binary files differ