Commit faa868fd authored by 叶璨铭's avatar 叶璨铭
Browse files

feat: 修复初始无法保存图片的bug,增加stub机制以便自动跳过无图的页

parent fdc075ee
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -12,6 +12,7 @@ from commons import *
from pathlib import Path
from pathlib import Path
import json
import json


debug = False


this_file = Path(__file__).resolve()
this_file = Path(__file__).resolve()
this_directory = this_file.parent
this_directory = this_file.parent
@@ -82,6 +83,7 @@ def process(img, visual_steps):
    valid_rects = list(filter(lambda rect:
    valid_rects = list(filter(lambda rect:
                    1<=(max(rect[2:])/min(rect[2:]))<=(var_dict['max_length_width_ratio']['value']/percents*10)
                    1<=(max(rect[2:])/min(rect[2:]))<=(var_dict['max_length_width_ratio']['value']/percents*10)
        , rects))
        , rects))
    if debug:
        for rect in valid_rects:
        for rect in valid_rects:
            print((max(rect[2:])/min(rect[2:])))
            print((max(rect[2:])/min(rect[2:])))
    new_img = img.copy()
    new_img = img.copy()
@@ -106,10 +108,13 @@ def save_rois(image, rects):
    path = f"{var_dict['number']['value']}-*.png"
    path = f"{var_dict['number']['value']}-*.png"
    for f in output_folder.glob(path):
    for f in output_folder.glob(path):
        f.unlink()
        f.unlink()
    if len(rects)==0:
        with open(output_folder/f"{var_dict['number']['value']}-stub.png", 'w') as f:
            f.write("该页没有文物图片。\n")
    for i, rect in enumerate(rects):
    for i, rect in enumerate(rects):
        roi = image[rect[1]:rect[1]+rect[3], rect[0]:rect[0]+rect[2]]
        roi = image[rect[1]:rect[1]+rect[3], rect[0]:rect[0]+rect[2]]
        cv2.imwrite((output_folder/f"{var_dict['number']['value']}-{i}.png").as_posix(), roi)
        cv2.imwrite((output_folder/f"{var_dict['number']['value']}-{i}.png").as_posix(), roi)
    print(f"enter: 确认标注,已保存标注结果到{path}")
    print(f"enter: 确认标注,已保存标注结果到{output_folder/path}")


import time
import time
last_prompt_time = time.time()
last_prompt_time = time.time()
@@ -141,6 +146,7 @@ def update(x):




def init():
def init():
    global current_img, visual_res, valid_rects
    cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
    cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
    cv2.resizeWindow(window_name, *window_size)
    cv2.resizeWindow(window_name, *window_size)
    
    
+2 −0
Original line number Original line Diff line number Diff line
{"number": {"range": [1, 256], "value": 4, "comment": "\u8fd9\u662f\u5f53\u524d\u5904\u7406\u7684\u56fe\u7247\u7f16\u53f7\u3002"}, "processing_step": {"range": [0, 3], "value": 3, "comment": "0\u8868\u793a\u663e\u793a\u539f\u56fe\uff0c1\u8868\u793a\u663e\u793a\u9ed1\u767d\u5904\u7406\u56fe\uff0c2\u8868\u793a\u8f6e\u5ed3\u56fe\uff0c3\u8868\u793a\u76ee\u6807\u6846\u9009\u56fe\u3002"}, "blur_ksize": {"range": [0, 10], "value": 0, "comment": "0\u8868\u793a\u4e0d\u8fdb\u884c\u5e73\u6ed1\uff0c1-10\u8868\u793a\u6ee4\u6ce2\u7684\u8303\u56f4\u5927\u5c0f\u3002"}, "black_threshold": {"range": [0, 255], "value": 240, "comment": "\u8fd9\u662f\u7528\u4e8e\u4e8c\u503c\u5316\u56fe\u7247\u4e3a\u9ed1\u767d\u56fe\u7247\u7684\u9608\u503c\uff0c\u5927\u4e8e\u8fd9\u4e2a\u4eae\u5ea6\u503c\u7684\u50cf\u7d20\u4f1a\u53d8\u6210\u9ed1\u8272\uff0c\u5176\u4ed6\u5730\u65b9\u662f\u767d\u8272\u3002"}, "min_valid_area": {"range": [0, 1000], "value": 1, "comment": "\u8fd9\u662f\u60f3\u8981\u68c0\u6d4b\u7684\u5185\u56fe\u6700\u5c0f\u53ef\u4ee5\u63a5\u53d7\u7684\u9762\u79ef\u3002(\u5355\u4f4d\u662f1000\u5206\u6570)"}, "max_valid_area": {"range": [0, 1000], "value": 998, "comment": "\u8fd9\u662f\u60f3\u8981\u68c0\u6d4b\u7684\u5185\u56fe\u6700\u5927\u53ef\u4ee5\u63a5\u53d7\u7684\u9762\u79ef\u3002(\u5355\u4f4d\u662f1000\u5206\u6570)"}, "max_length_width_ratio": {"range": [0, 1000], "value": 1000, "comment": "\u8fd9\u662f\u60f3\u8981\u68c0\u6d4b\u7684\u5185\u56fe\u6700\u5927\u7684\u957f\u5bbd\u6bd4\u3002(\u5355\u4f4d\u662f1000\u5206\u6bd4\uff0c\u53d6\u52301000/1000\u65f6\u6700\u5927\u957f\u5bbd\u6bd4\u662f10\u3002)"}}
 No newline at end of file