Skip to content

Commit 94cc9de

Browse files
sunlingzhangslz
andauthored
支持中文路径 (#23)
* fixed: support Chinese path * fixed: support Chinese path --------- Co-authored-by: slz <[email protected]>
1 parent aa42016 commit 94cc9de

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

PPOCRLabel.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,9 +1248,10 @@ def createPolygon(self):
12481248

12491249
def rotateImg(self, filename, k, _value):
12501250
self.actions.rotateRight.setEnabled(_value)
1251-
pix = cv2.imread(filename)
1251+
pix = cv2.imdecode(np.fromfile(filename, dtype=np.uint8), cv2.IMREAD_COLOR)
12521252
pix = np.rot90(pix, k)
1253-
cv2.imwrite(filename, pix)
1253+
ext = os.path.splitext(filename)[1]
1254+
cv2.imencode(ext, pix)[1].tofile(filename)
12541255
self.canvas.update()
12551256
self.loadFile(filename)
12561257

@@ -2387,7 +2388,9 @@ def _saveFile(self, annotationFilePath, mode="Manual"):
23872388

23882389
if mode == "Manual":
23892390
self.result_dic_locked = []
2390-
img = cv2.imread(self.filePath)
2391+
img = cv2.imdecode(
2392+
np.fromfile(self.filePath, dtype=np.uint8), cv2.IMREAD_COLOR
2393+
)
23912394
width, height = self.image.width(), self.image.height()
23922395
for shape in self.canvas.lockedShapes:
23932396
box = [[int(p[0] * width), int(p[1] * height)] for p in shape["ratio"]]
@@ -2823,7 +2826,7 @@ def TableRecognition(self):
28232826
import time
28242827

28252828
start = time.time()
2826-
img = cv2.imread(self.filePath)
2829+
img = cv2.imdecode(np.fromfile(self.filePath, dtype=np.uint8), cv2.IMREAD_COLOR)
28272830
res = self.table_ocr(img, return_ocr_result_in_table=True)
28282831

28292832
TableRec_excel_dir = self.lastOpenDir + "/tableRec_excel_output/"
@@ -2954,7 +2957,7 @@ def cellreRecognition(self):
29542957
"""
29552958
re-recognise text in a cell
29562959
"""
2957-
img = cv2.imread(self.filePath)
2960+
img = cv2.imdecode(np.fromfile(self.filePath, dtype=np.uint8), cv2.IMREAD_COLOR)
29582961
for shape in self.canvas.selectedShapes:
29592962
box = [[int(p.x()), int(p.y())] for p in shape.points]
29602963

0 commit comments

Comments
 (0)