Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持中文路径 #23

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions PPOCRLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ def createPolygon(self):

def rotateImg(self, filename, k, _value):
self.actions.rotateRight.setEnabled(_value)
pix = cv2.imread(filename)
pix = cv2.imdecode(np.fromfile(filename, dtype=np.uint8), cv2.IMREAD_COLOR)
pix = np.rot90(pix, k)
cv2.imwrite(filename, pix)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is cv2.imwrite affected by Chinese paths?

Copy link
Contributor Author

@sunlingzhang sunlingzhang Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for the Chinese path, cv2.imwrite(file_name, img) should be modified to cv2.imencode(".jpg", img)[1].tofile(file_name).

Copy link
Collaborator

@Gmgge Gmgge Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

根据linux(centos7.9),windows系统(win10)测试,以及opencv仓库下的 issue 4292确认,在windows下,imread、imwrite不兼容中文路径。

因此该提交可以增加在windows系统上对中文路径图像读写的能力。

self.canvas.update()
Expand Down Expand Up @@ -2387,7 +2387,9 @@ def _saveFile(self, annotationFilePath, mode="Manual"):

if mode == "Manual":
self.result_dic_locked = []
img = cv2.imread(self.filePath)
img = cv2.imdecode(
np.fromfile(self.filePath, dtype=np.uint8), cv2.IMREAD_COLOR
)
width, height = self.image.width(), self.image.height()
for shape in self.canvas.lockedShapes:
box = [[int(p[0] * width), int(p[1] * height)] for p in shape["ratio"]]
Expand Down Expand Up @@ -2823,7 +2825,7 @@ def TableRecognition(self):
import time

start = time.time()
img = cv2.imread(self.filePath)
img = cv2.imdecode(np.fromfile(self.filePath, dtype=np.uint8), cv2.IMREAD_COLOR)
res = self.table_ocr(img, return_ocr_result_in_table=True)

TableRec_excel_dir = self.lastOpenDir + "/tableRec_excel_output/"
Expand Down Expand Up @@ -2954,7 +2956,7 @@ def cellreRecognition(self):
"""
re-recognise text in a cell
"""
img = cv2.imread(self.filePath)
img = cv2.imdecode(np.fromfile(self.filePath, dtype=np.uint8), cv2.IMREAD_COLOR)
for shape in self.canvas.selectedShapes:
box = [[int(p.x()), int(p.y())] for p in shape.points]

Expand Down