pip install PPOCRLabel==2.1.3
PPOCRLabel --lang ch
'NoneType' object has no attribute 'shape'
Traceback (most recent call last):
File "D:\ProgramData\Anaconda3\envs\paddle\lib\site-packages\PPOCRLabel\libs\autoDialog.py", line 41, in run
h, w, _ = cv2.imdecode(np.fromfile(Imgpath, dtype=np.uint8), 1).shape
AttributeError: 'NoneType' object has no attribute 'shape'
h, w, _ = cv2.imdecode(np.fromfile(Imgpath, dtype=np.uint8), 1).shape
# 修改文件:"D:\ProgramData\Anaconda3\envs\paddle\lib\site-packages\PPOCRLabel\libs\autoDialog.py", line 41
# 增加PIL读取图片函数
from PIL import Image
def load_image(image_path: str, return_chw: bool = True, size: tuple = None):
image = Image.open(image_path).convert("RGB")
if size is not None:
image = image.resize(size) # resize image
image = np.asarray(image)
image = image[:, :, ::-1] # flip color channels from RGB to BGR
w, h = image.shape[1], image.shape[0] # update size after resize
if return_chw:
image = image.transpose(2, 0, 1)
return image, (w, h)
# 替换上面代码
try:
image_data, (w, h) = load_image(Imgpath, return_chw=False)
except Exception as e:
print(f"load file {Imgpath} fail!")
continue
Traceback (most recent call last):
File "D:\ProgramData\Anaconda3\envs\paddle\lib\site-packages\PPOCRLabel\PPOCRLabel.py", line 1889, in saveFile
self._saveFile(imgidx, mode=mode)
File "D:\ProgramData\Anaconda3\envs\paddle\lib\site-packages\PPOCRLabel\PPOCRLabel.py", line 1934, in _saveFile
self.openNextImg()
File "D:\ProgramData\Anaconda3\envs\paddle\lib\site-packages\PPOCRLabel\PPOCRLabel.py", line 1880, in openNextImg
self.loadFile(filename)
File "D:\ProgramData\Anaconda3\envs\paddle\lib\site-packages\PPOCRLabel\PPOCRLabel.py", line 1550, in loadFile
height, width, depth = cvimg.shape
AttributeError: 'NoneType' object has no attribute 'shape'
# 修改: File "D:\ProgramData\Anaconda3\envs\paddle\lib\site-packages\PPOCRLabel\PPOCRLabel.py", line 1550, in loadFile
# cvimg = cv2.imdecode(np.fromfile(unicodeFilePath, dtype=np.uint8), 1)
cvimg, _ = load_image(unicodeFilePath, return_chw=False)
报错:error: (-215:Assertion failed) _src.total() > 0 in function ‘cv::warpPerspective’
Can not recognise the detection box in xxxx,png. Please change manually'
unicodeFilePath is J:\data\mllm-data\xxxxxxxxx\wKh2CWERPJOAY2x-AAE62o598k0620.png
OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function 'cv::warpPerspective'
解决:
依旧是修改PPOCRLabel源码, 把cv2读取改为PIL读取,就不惯着cv2的臭毛病…
# 修改如下代码
def reRecognition(self):
#img = cv2.imdecode(np.fromfile(self.filePath,dtype=np.uint8),1)
img, _ = load_image(self.filePath, return_chw=False)
- File "G:\dongyongfei786\paddle\PaddleOCR\ppstructure\predict_system.py", line 82, in __init__
self.return_word_box = args.return_word_box
AttributeError: 'Namespace' object has no attribute 'return_word_box'
# extended function
parser.add_argument("--return_word_box", type=str2bool, default=False, help='Whether return the bbox of each word (split by space) or chinese character. Only used in ppstructure for layout recovery')