replace pdf
Browse files- main.py +9 -1
- pdfs/jp/沈宇澄日语常用动词近义词辨析/沈宇澄日语常用动词近义词辨析.pdf +2 -2
main.py
CHANGED
|
@@ -151,6 +151,12 @@ def ocr_one_pdf(pth_pdf):
|
|
| 151 |
page_num = int(page_num)
|
| 152 |
page = reader.pages[page_num - 1]
|
| 153 |
text = page.extract_text()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
for idx, image_file_object in enumerate(page.images):
|
| 155 |
img_bytes = image_file_object.data
|
| 156 |
img_buffer_numpy = np.frombuffer(img_bytes, dtype=np.uint8) # 将图片字节码 bytes 转换成一维的 numpy 数组到缓存中
|
|
@@ -205,6 +211,8 @@ def ocr_one_pdf(pth_pdf):
|
|
| 205 |
break
|
| 206 |
|
| 207 |
img_color = get_page_image(reader, nth_page)
|
|
|
|
|
|
|
| 208 |
cv2.imwrite('./tmp.jpg', cv2.cvtColor(img_color, cv2.COLOR_RGB2BGR))
|
| 209 |
|
| 210 |
# 把img 对象编码为jpg 格式
|
|
@@ -329,6 +337,6 @@ if __name__ == '__main__':
|
|
| 329 |
|
| 330 |
# ocr_one_pdf('pdfs/en/TIME片挑200/TIME片挑200.pdf')
|
| 331 |
|
| 332 |
-
ocr_one_pdf('pdfs/jp
|
| 333 |
|
| 334 |
|
|
|
|
| 151 |
page_num = int(page_num)
|
| 152 |
page = reader.pages[page_num - 1]
|
| 153 |
text = page.extract_text()
|
| 154 |
+
try:
|
| 155 |
+
for idx, image_file_object in enumerate(page.images):
|
| 156 |
+
pass
|
| 157 |
+
except Exception:
|
| 158 |
+
return None
|
| 159 |
+
|
| 160 |
for idx, image_file_object in enumerate(page.images):
|
| 161 |
img_bytes = image_file_object.data
|
| 162 |
img_buffer_numpy = np.frombuffer(img_bytes, dtype=np.uint8) # 将图片字节码 bytes 转换成一维的 numpy 数组到缓存中
|
|
|
|
| 211 |
break
|
| 212 |
|
| 213 |
img_color = get_page_image(reader, nth_page)
|
| 214 |
+
if img_color is None:
|
| 215 |
+
continue
|
| 216 |
cv2.imwrite('./tmp.jpg', cv2.cvtColor(img_color, cv2.COLOR_RGB2BGR))
|
| 217 |
|
| 218 |
# 把img 对象编码为jpg 格式
|
|
|
|
| 337 |
|
| 338 |
# ocr_one_pdf('pdfs/en/TIME片挑200/TIME片挑200.pdf')
|
| 339 |
|
| 340 |
+
ocr_one_pdf('pdfs/jp/沈宇澄日语常用动词近义词辨析/沈宇澄日语常用动词近义词辨析.pdf') # 李致雨N2词汇详解 提取的图片几乎不可见,不要了
|
| 341 |
|
| 342 |
|
pdfs/jp/沈宇澄日语常用动词近义词辨析/沈宇澄日语常用动词近义词辨析.pdf
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3284bb4462cbf733471ea40df8204b0e4b5cc5dc67fb5e9dd4c6ed9209b1e4eb
|
| 3 |
+
size 84862607
|