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

Fix error can't open image files in Python3. #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions recognizer/crnn/lib/create_lmdb_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import lmdb
import cv2
import numpy as np
Expand Down Expand Up @@ -26,7 +25,9 @@ def checkImageIsValid(imageBin):

def writeCache(env, cache):
with env.begin(write=True) as txn:
for k, v in cache.items():
for _k, _v in cache.items():
k = _k.encode() if type(_k) == str else _k
v = _v.encode() if type(_v) == str else _v
txn.put(k, v)


Expand Down Expand Up @@ -54,7 +55,7 @@ def createDataset(outputPath, imagePathList, labelList, lexiconList=None, checkV
# print('%s does not exist' % imagePath)
# continue

with open(imagePath, 'r') as f:
with open(imagePath, 'rb') as f:
imageBin = f.read()

if checkValid:
Expand Down
2 changes: 1 addition & 1 deletion recognizer/crnn/lib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __getitem__(self, index):
img = self.transform(img)

label_key = 'label-%09d' % index
label = txn.get(label_key.encode())
label = txn.get(label_key.encode()).decode()

if self.target_transform is not None:
label = self.target_transform(label)
Expand Down
22 changes: 22 additions & 0 deletions recognizer/crnn/lib/get_alphabets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'changxin'
__mtime__ = '2019/3/14'
"""


def get_alphabets(filelists):
a = []
for x in filelists:
with open(x) as f:
strings = f.readlines()
string = [y.strip().split(' ')[1] for y in strings]
tmp = []
for z in ''.join(string):
tmp.append(z)
a = a + tmp
with open('alphabets.py', 'w') as e:
e.write("#coding=utf8\n")
e.write('\"\"\"' + ''.join(list(set(a))) + '\"\"\"')