Bläddra i källkod

修复印章检测的问题

luojiehua 2 år sedan
förälder
incheckning
bb075061d6
2 ändrade filer med 8 tillägg och 0 borttagningar
  1. 4 0
      format_convert/convert_image.py
  2. 4 0
      format_convert/convert_need_interface.py

+ 4 - 0
format_convert/convert_image.py

@@ -121,6 +121,8 @@ def image_process(image_np, image_path, is_from_pdf=False, is_from_docx=False, u
         # cv2.imwrite(idc_path, image_np)
 
         # isr模型去除印章
+        image_np_source = image_np
+        _isr_time = time.time()
         if count_red_pixel(image_np):
             # 红色像素达到一定值才过模型
             with open(image_path, "rb") as f:
@@ -134,9 +136,11 @@ def image_process(image_np, image_path, is_from_pdf=False, is_from_docx=False, u
             # [1]代表检测不到印章,直接返回
             if isinstance(image_np, list) and image_np == [1]:
                 log("no seals detected!")
+                image_np = image_np_source
             else:
                 isr_path = image_path.split(".")[0] + "_isr." + image_path.split(".")[-1]
                 cv2.imwrite(isr_path, image_np)
+        log("isr total time"+str(time.time()-_isr_time))
 
         # otr模型识别表格,需要图片resize成模型所需大小, 写入另一个路径
         best_h, best_w = get_best_predict_size(image_np)

+ 4 - 0
format_convert/convert_need_interface.py

@@ -493,6 +493,7 @@ def from_otr_interface(image_stream, is_from_pdf=False, from_remote=FROM_REMOTE)
 
 def from_isr_interface(image_stream, from_remote=FROM_REMOTE):
     log("into from_isr_interface")
+    # os.environ["CUDA_VISIBLE_DEVICES"] = "0"
     start_time = time.time()
     try:
         base64_stream = base64.b64encode(image_stream)
@@ -557,6 +558,9 @@ def from_isr_interface(image_stream, from_remote=FROM_REMOTE):
         log("from_isr_interface error!")
         traceback.print_exc()
         return [-11]
+    finally:
+        # os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
+        pass
 
 
 def from_idc_interface(image_stream, from_remote=FROM_REMOTE):