I'm working on an image to text OCR system and I kept receiving an error on the console stating
我正在处理一个图像到文本OCR系统,我不断收到控制台声明的错误
Traceback (most recent call last):
File "crack_test.py", line 48, in <module>
temp.append(buildvector(Image.open("./iconset/%s/%s"%(letter,img))))
File "/Users/seng_kin/anaconda/lib/python2.7/site-packages/PIL/Image.py", line 2290, in open
% (filename if filename else fp))
IOError: cannot identify image file './characterset/a/.DS_Store'
I have a folder in a ../OCR/characterset/
directory which has 26 subfolders representing 26 characters whereby each subfolder contains a .PNG of a character.
我有一个文件夹在…/OCR/字符集/目录,其中有26个子文件夹,表示每个子文件夹包含一个字符的. png。
The score_test.py is stored in ../OCR/
score_test。py存储在./OCR/中。
score_test.py Code:
score_test。py代码:
from PIL import Image
import os, sys
import math
****def functions****
iconset = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','y','z']
imageset = []
for letter in iconset:
for img in os.listdir('./characterset/%s/'%(letter)):
temp = []
if img != "Thumbs.db": #windows check...
temp.append(buildvector(Image.open("./characterset/%s/%s"%(letter, img))))
imageset.append({letter:temp})
I saw other solutions on the website but all is related to the absence of from PIL import Image
. Am I missing something?
我在网站上看到了其他的解决方案,但都与PIL import Image的缺失有关。我遗漏了什么东西?
1 个解决方案
#1
2
.DS_Store
is a "hidden" file in directories on Mac OS X.
. ds_store是Mac OS X目录中的“隐藏”文件。
In your if img != "Thumbs.db"
check, you should add:
在你的if img != "拇指"。db" check,你应该加上:
if not img.startswith('.') and img != 'Thumbs.db':
this way you filter out all "hidden" files.
这样可以过滤掉所有“隐藏”文件。
#1
2
.DS_Store
is a "hidden" file in directories on Mac OS X.
. ds_store是Mac OS X目录中的“隐藏”文件。
In your if img != "Thumbs.db"
check, you should add:
在你的if img != "拇指"。db" check,你应该加上:
if not img.startswith('.') and img != 'Thumbs.db':
this way you filter out all "hidden" files.
这样可以过滤掉所有“隐藏”文件。