init
Browse files- .gitattributes +2 -1
- .gitignore +33 -0
- config_default.py +15 -0
- main.py +274 -0
- pdfs/jp/高木直子学日语文法不要想太多/0001.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0001.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0002.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0002.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0003.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0003.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0004.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0004.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0005.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0005.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0006.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0006.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0007.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0007.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0008.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0008.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0009.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0009.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0010.jpg +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/0010.json +3 -0
- pdfs/jp/高木直子学日语文法不要想太多/高木直子学日语文法不要想太多.pdf +3 -0
.gitattributes
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
@@ -57,4 +59,3 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
-
*.pdf filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
pdfs/**/*.json filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 6 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 59 |
# Video files - compressed
|
| 60 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 61 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
world\[trim\]
|
| 3 |
+
sqlean/
|
| 4 |
+
llama.cpp/
|
| 5 |
+
__pycache__
|
| 6 |
+
flagged
|
| 7 |
+
exported
|
| 8 |
+
package-lock.json
|
| 9 |
+
package.json
|
| 10 |
+
config.py
|
| 11 |
+
tmp.jpg
|
| 12 |
+
asr.txt
|
| 13 |
+
only_speech.wav
|
| 14 |
+
japanesevector.db
|
| 15 |
+
doaxvv.db
|
| 16 |
+
jpdict.db
|
| 17 |
+
jpdict_mingjing.db
|
| 18 |
+
dachilingdict.db
|
| 19 |
+
jpdict_sakurallm.db
|
| 20 |
+
jpdict__.db
|
| 21 |
+
jpdict.db__
|
| 22 |
+
t.html
|
| 23 |
+
t.txt
|
| 24 |
+
t.txt__
|
| 25 |
+
t.json
|
| 26 |
+
str_parts.txt
|
| 27 |
+
daciling.txt
|
| 28 |
+
daciling.json
|
| 29 |
+
daciling_pre.json
|
| 30 |
+
daciling_zh.txt
|
| 31 |
+
*.aac
|
| 32 |
+
bt.jpeg
|
| 33 |
+
*log.txt
|
config_default.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# see huggingface/project/zh_jp_auto_selection.py
|
| 3 |
+
# see huggingface/rwkv5-jp-trimvd/config.py
|
| 4 |
+
# see huggingface/rwkv5-jp-trimvd/appv4.py # aliocr first then autuo pdf trim
|
| 5 |
+
|
| 6 |
+
# https://market.aliyun.com/apimarket/detail/cmapi028554#sku=yuncode22554000016
|
| 7 |
+
|
| 8 |
+
__all__ = [ 'alicr_config' ]
|
| 9 |
+
|
| 10 |
+
alicr_config = {
|
| 11 |
+
"api":'https://gjbsb.market.alicloudapi.com/ocrservice/advanced',
|
| 12 |
+
"app_code":'',
|
| 13 |
+
"appSecret": ''
|
| 14 |
+
}
|
| 15 |
+
|
main.py
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# aliocr first then autuo pdf trim
|
| 2 |
+
# see huggingface/project/zh_jp_auto_selection.py
|
| 3 |
+
# see huggingface/rwkv5-jp-trimvd/config.py
|
| 4 |
+
# see huggingface/rwkv5-jp-trimvd/appv4.py # aliocr first then autuo pdf trim
|
| 5 |
+
# see huggingface/PPOCRLabel use this to correct ocr result
|
| 6 |
+
|
| 7 |
+
from config import alicr_config
|
| 8 |
+
|
| 9 |
+
def ali_ocr(img_data, config):
|
| 10 |
+
|
| 11 |
+
# https://market.aliyun.com/apimarket/detail/cmapi028554#sku=yuncode22554000016
|
| 12 |
+
|
| 13 |
+
import requests
|
| 14 |
+
import json
|
| 15 |
+
|
| 16 |
+
api = config['api']
|
| 17 |
+
app_code = config['app_code']
|
| 18 |
+
appSecret = config['appSecret']
|
| 19 |
+
try:
|
| 20 |
+
# 设置请求头
|
| 21 |
+
headers = {
|
| 22 |
+
"Authorization": f"APPCODE {app_code}",
|
| 23 |
+
"Content-Type": "application/json;charset=UTF-8"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# 设置请求体
|
| 27 |
+
payload = json.dumps({
|
| 28 |
+
"img": img_data,
|
| 29 |
+
"prob": True,
|
| 30 |
+
"charInfo": True,
|
| 31 |
+
"table": True,
|
| 32 |
+
"sortPage": True,
|
| 33 |
+
"NeedRotate": True
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
# 发送POST请求
|
| 37 |
+
response = requests.post(api, headers=headers, data=payload, timeout=120)
|
| 38 |
+
|
| 39 |
+
# 检查响应状态
|
| 40 |
+
if response.status_code != 200:
|
| 41 |
+
return None, {"error_code": response.status_code, "error_msg": response.text}
|
| 42 |
+
|
| 43 |
+
# 解析返回结果
|
| 44 |
+
try:
|
| 45 |
+
ali_result = response.json()
|
| 46 |
+
except Exception as ex:
|
| 47 |
+
print("#####ERROR: aliyun ocr parse error.")
|
| 48 |
+
print(ex)
|
| 49 |
+
print("Response Text:", response.text)
|
| 50 |
+
return None, {"error_code": "JSON_PARSE_ERROR", "error_msg": str(ex)}
|
| 51 |
+
|
| 52 |
+
return ali_result, None
|
| 53 |
+
|
| 54 |
+
except requests.RequestException as error:
|
| 55 |
+
print('#####ERROR: aliyun ocr fail.')
|
| 56 |
+
print(error)
|
| 57 |
+
return None, {"error_code": "REQUEST_ERROR", "error_msg": str(error)}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def ocr_one_img():
|
| 61 |
+
import numpy as np
|
| 62 |
+
import cv2, base64
|
| 63 |
+
np_array = np.fromfile('data/no_think_more.png', dtype=np.uint8)
|
| 64 |
+
img = cv2.imdecode(np_array, -1)
|
| 65 |
+
# bytes = img.tobytes() # 转字节数组 # 或者使用img.tostring(),两者是等价的
|
| 66 |
+
# 注意了:得到的bytes数据并不等价于open(file,"rb")数据
|
| 67 |
+
|
| 68 |
+
if len(img.shape) != 3: # 转彩图
|
| 69 |
+
img_color = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
|
| 70 |
+
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) # DBNet 原版只能处理彩图,这里转一下
|
| 71 |
+
|
| 72 |
+
else:
|
| 73 |
+
img_color = img.copy()
|
| 74 |
+
|
| 75 |
+
# 把img 对象编码为jpg 格式
|
| 76 |
+
success, encoded_image = cv2.imencode(".jpg", img)
|
| 77 |
+
# 将数组转为bytes
|
| 78 |
+
img_bts = encoded_image.tobytes() # 等价于tostring()
|
| 79 |
+
img_b64_str = base64.b64encode(img_bts).decode('utf-8')
|
| 80 |
+
|
| 81 |
+
jsn, error = ali_ocr(img_b64_str, alicr_config)
|
| 82 |
+
|
| 83 |
+
wordsInfo = jsn['prism_wordsInfo']
|
| 84 |
+
for j in range(len(wordsInfo)):
|
| 85 |
+
jo = wordsInfo[j]
|
| 86 |
+
word = jo["word"]
|
| 87 |
+
|
| 88 |
+
# prism-wordsInfo 里的 angle 文字块的角度,这个角度只影响width和height,当角度为-90、90、-270、270,width和height的值需要自行互换
|
| 89 |
+
angle = jo['angle']
|
| 90 |
+
|
| 91 |
+
word_x = jo['x']
|
| 92 |
+
word_y = jo['y']
|
| 93 |
+
word_width = jo['width']
|
| 94 |
+
word_height = jo['height']
|
| 95 |
+
|
| 96 |
+
if abs(angle) == 90 or abs(angle) == 270:
|
| 97 |
+
word_width = jo['height']
|
| 98 |
+
word_height = jo['width']
|
| 99 |
+
|
| 100 |
+
pos = jo['pos']
|
| 101 |
+
|
| 102 |
+
# 四个角的位置 左上、右上、右下、左下 顺时针方向
|
| 103 |
+
lu = [pos[0]['x'], pos[0]['y']]
|
| 104 |
+
ru = [pos[1]['x'], pos[1]['y']]
|
| 105 |
+
rd = [pos[2]['x'], pos[2]['y']]
|
| 106 |
+
ld = [pos[3]['x'], pos[3]['y']]
|
| 107 |
+
|
| 108 |
+
x1 = min( pos[0]['x'], pos[3]['x'] ) # 当前行的极左
|
| 109 |
+
x2 = max( pos[1]['x'], pos[2]['x'] ) # 当前行的极右
|
| 110 |
+
|
| 111 |
+
y1 = min( pos[0]['y'], pos[1]['y'] ) # 当前行的极上
|
| 112 |
+
y2 = max( pos[2]['y'], pos[3]['y'] ) # 当前行的极下
|
| 113 |
+
|
| 114 |
+
# img_color = cv2.rectangle(img_color, (x1, y1), (x2, y2), (0, 255, 0), 2) # 矩形的左上角, 矩形的右下角
|
| 115 |
+
img_color = cv2.rectangle(img_color, (lu[0], lu[1]), (rd[0], rd[1]), (0, 255, 0), 2) # 矩形的左上角, 矩形的右下角
|
| 116 |
+
|
| 117 |
+
# cv2.imshow("green", img_color)
|
| 118 |
+
# cv2.waitKey(0)
|
| 119 |
+
|
| 120 |
+
cv2.imwrite('./tmp.jpg', img_color)
|
| 121 |
+
|
| 122 |
+
if error:
|
| 123 |
+
print("Error occurred:", error)
|
| 124 |
+
else:
|
| 125 |
+
print("Result:", jsn)
|
| 126 |
+
# ocr_one_img()
|
| 127 |
+
|
| 128 |
+
def ocr_one_pdf(pth_pdf):
|
| 129 |
+
"""
|
| 130 |
+
see huggingface/PPOCRLabel use this to correct ocr result
|
| 131 |
+
"""
|
| 132 |
+
import cv2
|
| 133 |
+
import numpy as np
|
| 134 |
+
import base64
|
| 135 |
+
import hashlib
|
| 136 |
+
from pathlib import Path
|
| 137 |
+
import os
|
| 138 |
+
import json
|
| 139 |
+
|
| 140 |
+
base = Path(pth_pdf).stem
|
| 141 |
+
dir = os.path.dirname(pth_pdf)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def get_page_image(reader, page_num):
|
| 145 |
+
page_num = int(page_num)
|
| 146 |
+
page = reader.pages[page_num - 1]
|
| 147 |
+
text = page.extract_text()
|
| 148 |
+
for idx, image_file_object in enumerate(page.images):
|
| 149 |
+
img_bytes = image_file_object.data
|
| 150 |
+
img_buffer_numpy = np.frombuffer(img_bytes, dtype=np.uint8) # 将图片字节码 bytes 转换成一维的 numpy 数组到缓存中
|
| 151 |
+
ocr_frame = cv2.imdecode(img_buffer_numpy, 1) # 从指定的内存缓存中读取一维 numpy 数据,并把数据转换(解码)成图像矩阵格式
|
| 152 |
+
ocr_frame = cv2.cvtColor(ocr_frame, cv2.COLOR_BGR2RGB)
|
| 153 |
+
# cv2.imshow('test', self.ocr_frame)
|
| 154 |
+
# cv2.waitKey(0)
|
| 155 |
+
break
|
| 156 |
+
return ocr_frame
|
| 157 |
+
|
| 158 |
+
def md5_file(fname):
|
| 159 |
+
hash_md5 = hashlib.md5()
|
| 160 |
+
with open(fname, "rb") as f:
|
| 161 |
+
for chunk in iter(lambda: f.read(4096), b""):
|
| 162 |
+
hash_md5.update(chunk)
|
| 163 |
+
return hash_md5.hexdigest()
|
| 164 |
+
|
| 165 |
+
def md5_bytes(bts):
|
| 166 |
+
hash_md5 = hashlib.md5()
|
| 167 |
+
chunk_size = 4096
|
| 168 |
+
for i in range(0, len(bts), chunk_size):
|
| 169 |
+
chunk = bts[i:i+chunk_size]
|
| 170 |
+
hash_md5.update(chunk)
|
| 171 |
+
return hash_md5.hexdigest()
|
| 172 |
+
|
| 173 |
+
def jsonparse(s):
|
| 174 |
+
return json.loads(s, strict=False )
|
| 175 |
+
|
| 176 |
+
def jsonstring(d):
|
| 177 |
+
return json.dumps(d, ensure_ascii=False)
|
| 178 |
+
|
| 179 |
+
from pypdf import PdfReader
|
| 180 |
+
reader = PdfReader(pth_pdf)
|
| 181 |
+
number_of_pages = len(reader.pages)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
for nth_page in range(1, number_of_pages+1):
|
| 185 |
+
|
| 186 |
+
if nth_page > 10:
|
| 187 |
+
break
|
| 188 |
+
|
| 189 |
+
img_color = get_page_image(reader, nth_page)
|
| 190 |
+
cv2.imwrite('./tmp.jpg', cv2.cvtColor(img_color, cv2.COLOR_RGB2BGR))
|
| 191 |
+
|
| 192 |
+
# 把img 对象编码为jpg 格式
|
| 193 |
+
success, encoded_image = cv2.imencode(".jpg", cv2.cvtColor(img_color, cv2.COLOR_RGB2BGR))
|
| 194 |
+
# 将数组转为bytes
|
| 195 |
+
img_bts = encoded_image.tobytes() # 等价于tostring()
|
| 196 |
+
|
| 197 |
+
m51 = md5_bytes(img_bts)
|
| 198 |
+
with open('tmp.jpg', 'wb') as f:
|
| 199 |
+
f.write(img_bts)
|
| 200 |
+
m52 = md5_file('tmp.jpg')
|
| 201 |
+
assert m51 == m52
|
| 202 |
+
|
| 203 |
+
img_b64_str = base64.b64encode(img_bts).decode('utf-8')
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
img_name = "{:04d}.jpg".format(nth_page)
|
| 208 |
+
pth_img = os.path.join(dir, img_name)
|
| 209 |
+
jsn_name = "{:04d}.json".format(nth_page)
|
| 210 |
+
pth_jsn = os.path.join(dir, jsn_name)
|
| 211 |
+
|
| 212 |
+
if not os.path.exists(pth_jsn):
|
| 213 |
+
jsn, error = ali_ocr(img_b64_str, alicr_config)
|
| 214 |
+
with open(pth_jsn, 'w', encoding='utf-8') as f:
|
| 215 |
+
f.write( jsonstring(jsn) )
|
| 216 |
+
|
| 217 |
+
with open(pth_img, 'wb') as f:
|
| 218 |
+
f.write(img_bts)
|
| 219 |
+
else:
|
| 220 |
+
print(f'### this page ocr already: {pth_jsn}')
|
| 221 |
+
continue
|
| 222 |
+
|
| 223 |
+
wordsInfo = jsn['prism_wordsInfo']
|
| 224 |
+
for j in range(len(wordsInfo)):
|
| 225 |
+
jo = wordsInfo[j]
|
| 226 |
+
word = jo["word"]
|
| 227 |
+
|
| 228 |
+
# prism-wordsInfo 里的 angle 文字块的角度,这个角度只影响width和height,当角度为-90、90、-270、270,width和height的值需要自行互换
|
| 229 |
+
angle = jo['angle']
|
| 230 |
+
|
| 231 |
+
word_x = jo['x']
|
| 232 |
+
word_y = jo['y']
|
| 233 |
+
word_width = jo['width']
|
| 234 |
+
word_height = jo['height']
|
| 235 |
+
|
| 236 |
+
if abs(angle) == 90 or abs(angle) == 270:
|
| 237 |
+
word_width = jo['height']
|
| 238 |
+
word_height = jo['width']
|
| 239 |
+
|
| 240 |
+
pos = jo['pos']
|
| 241 |
+
|
| 242 |
+
# 四个角的位置 左上、右上、右下、左下 顺时针方向
|
| 243 |
+
lu = [pos[0]['x'], pos[0]['y']]
|
| 244 |
+
ru = [pos[1]['x'], pos[1]['y']]
|
| 245 |
+
rd = [pos[2]['x'], pos[2]['y']]
|
| 246 |
+
ld = [pos[3]['x'], pos[3]['y']]
|
| 247 |
+
|
| 248 |
+
x1 = min( pos[0]['x'], pos[3]['x'] ) # 当前行的极左
|
| 249 |
+
x2 = max( pos[1]['x'], pos[2]['x'] ) # 当前行的极右
|
| 250 |
+
|
| 251 |
+
y1 = min( pos[0]['y'], pos[1]['y'] ) # 当前行的极上
|
| 252 |
+
y2 = max( pos[2]['y'], pos[3]['y'] ) # 当前行的极下
|
| 253 |
+
|
| 254 |
+
# img_color = cv2.rectangle(img_color, (x1, y1), (x2, y2), (0, 255, 0), 2) # 矩形的左上角, 矩形的右下角
|
| 255 |
+
img_color = cv2.rectangle(img_color, (lu[0], lu[1]), (rd[0], rd[1]), (0, 255, 0), 2) # 矩形的左上角, 矩形的右下角
|
| 256 |
+
|
| 257 |
+
# cv2.imshow("green", img_color)
|
| 258 |
+
# cv2.waitKey(0)
|
| 259 |
+
|
| 260 |
+
cv2.imwrite('./tmp.jpg', cv2.cvtColor(img_color, cv2.COLOR_RGB2BGR))
|
| 261 |
+
|
| 262 |
+
if error:
|
| 263 |
+
raise Exception(f"Error occurred: {error}")
|
| 264 |
+
else:
|
| 265 |
+
print("Result:", jsn)
|
| 266 |
+
pass
|
| 267 |
+
|
| 268 |
+
print( f'one page done. {nth_page} / {number_of_pages}' )
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
if __name__ == '__main__':
|
| 272 |
+
|
| 273 |
+
ocr_one_pdf('pdfs/jp/高木直子学日语文法不要想太多/高木直子学日语文法不要想太多.pdf')
|
| 274 |
+
|
pdfs/jp/高木直子学日语文法不要想太多/0001.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0001.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75fe2a6bb23f3f915ca6d57b62bbc7dd70b8f1eb02ae27f4ad9ae2d4ee649b6f
|
| 3 |
+
size 12031
|
pdfs/jp/高木直子学日语文法不要想太多/0002.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0002.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:61436429725bbc94d7891e8680d0cf7ed03926a59614c94191709c47ba6531a5
|
| 3 |
+
size 70110
|
pdfs/jp/高木直子学日语文法不要想太多/0003.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0003.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b07b5abc045b3ed457f08a51d8c46e8543d240559bf70918216aba437b89d91
|
| 3 |
+
size 4352
|
pdfs/jp/高木直子学日语文法不要想太多/0004.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0004.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a41785db57048d81ac6d4743929f65f722e259ebe257946ba65f1b375f913ac
|
| 3 |
+
size 49150
|
pdfs/jp/高木直子学日语文法不要想太多/0005.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0005.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0e2f18d07883bbfcfe0105f0cb7ef41616cfd355d572f1502ea76b8007d7a4d8
|
| 3 |
+
size 45963
|
pdfs/jp/高木直子学日语文法不要想太多/0006.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0006.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1bcb5701031588cf610292d00d37e993131d8e24c489c92cc09fb41b8781dc72
|
| 3 |
+
size 53030
|
pdfs/jp/高木直子学日语文法不要想太多/0007.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0007.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92db54bd9c297f8caf4bc9a73eca8da69639a698037ff67ec7c23cc2ea32b4ff
|
| 3 |
+
size 45581
|
pdfs/jp/高木直子学日语文法不要想太多/0008.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0008.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b57b42d0aab12efbad4f5f5ee4f5dbf76ddadd10bb7db208f2090cecf0062e21
|
| 3 |
+
size 38887
|
pdfs/jp/高木直子学日语文法不要想太多/0009.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0009.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a2b16e4fb5dbbfb9294caa0a29f6965ec4907db3652b27ec294f36869aa832d
|
| 3 |
+
size 1684
|
pdfs/jp/高木直子学日语文法不要想太多/0010.jpg
ADDED
|
Git LFS Details
|
pdfs/jp/高木直子学日语文法不要想太多/0010.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:25b0ec4536d3deb4c471e08e5ea7c5f34bccbc6ef3e6efa40302f653e4f21f5c
|
| 3 |
+
size 26656
|
pdfs/jp/高木直子学日语文法不要想太多/高木直子学日语文法不要想太多.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d8c7104a7e6a6a3bc7c297fc9294ca33c4973560fe82ce47607b2063ef55fc0c
|
| 3 |
+
size 31748221
|