fasdfsa commited on
Commit
daf89d9
·
1 Parent(s): 519dd17

图重复了

Browse files
Files changed (1) hide show
  1. ocr/gendata.py +16 -6
ocr/gendata.py CHANGED
@@ -29,6 +29,7 @@ with open(pth_txt, 'r', encoding='utf-8') as f:
29
 
30
 
31
  dic = {}
 
32
  num = 0
33
  for PageId in PageIds:
34
  print(PageId)
@@ -41,11 +42,18 @@ for PageId in PageIds:
41
  assert len(images) > 0
42
  pth_img = images[0]
43
  pth_img = str( Path(pth_img).resolve() )
44
- img = cv2.imread(pth_img)
45
- if len(img.shape) != 3: # 转彩图
46
- img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
47
- img_color = img.copy()
48
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  txt = fp.read()
51
  data = json.loads(txt)
@@ -77,8 +85,10 @@ for PageId in PageIds:
77
  print(charText, end='')
78
  print("\n\n\n")
79
 
80
- cv2.imwrite(f"./out2/{num:04d}{image_id}.webp", img_color)
81
- num += 1
 
 
82
 
83
 
84
  pass
 
29
 
30
 
31
  dic = {}
32
+ dic_img = {}
33
  num = 0
34
  for PageId in PageIds:
35
  print(PageId)
 
42
  assert len(images) > 0
43
  pth_img = images[0]
44
  pth_img = str( Path(pth_img).resolve() )
 
 
 
 
45
 
46
+ new_img = False
47
+ if PageId not in dic_img:
48
+ new_img = True
49
+ img = cv2.imread(pth_img)
50
+ if len(img.shape) != 3: # 转彩图
51
+ img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
52
+ img_color = img.copy()
53
+ dic_img[PageId] = { "img_color": img_color, "img": img }
54
+ else:
55
+ img = dic_img[PageId]["img"]
56
+ img_color = dic_img[PageId]["img_color"]
57
 
58
  txt = fp.read()
59
  data = json.loads(txt)
 
85
  print(charText, end='')
86
  print("\n\n\n")
87
 
88
+
89
+ if new_img:
90
+ cv2.imwrite(f"./out2/{num:04d}_{image_id}.webp", img_color)
91
+ num += 1
92
 
93
 
94
  pass