- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的任务是遍历包含一些图像的zip文件,每个图像都是报纸的一页,目标是在页面中搜索单词并显示该页面中识别出的所有面孔。
我将数据存储在字典中,其中的键是图像文件的名称,值是,首先是pytesseract生成的文本,其次是该图像的ZipInfo对象。
生成字典的函数工作正常,因为它生成了我想要的东西,但是问题出在其他两个函数中,wordCheck()和detectFaces()是因为返回了一个空列表
这是代码:
def getDict(zippedFile):
'''
This function gets a .zip file containing images and returns a dictionary whose keys are the image names
and the values are the images text content.
'''
j = 0
i = 0
dic = {}
contents = []
imageObject = []
with zipfile.ZipFile(zippedFile) as file:
for single_info in file.infolist():
imageObject.append(single_info)
with file.open(single_info) as imageInfo:
img = Image.open(imageInfo)
text = pytesseract.image_to_string(img)
contents.append(text)
for name in file.namelist():
dic[name] = [contents[j], imageObject[j]]
j += 1
return dic
def detectFaces(imageName, dic):
'''
This function gets and image name, that is in a .zip file and returns a list containing bounding boxes for
faces detected on the given image.
'''
boundingBoxes = []
with zipfile.ZipFile('readonly/small_img.zip') as file:
imageInfo = dic[imageName][1]
PILImage = Image.open(imageInfo)
display(PILImage)
img = cv.imread(PILImage)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
print(gray)
faceBoxes = face_cascade.detectMultiScale(gray)
for item in faceBoxes:
print(item)
boundingBoxes.append(item[0])
return boundingBoxes
def checkWord(word, dic):
'''
'''
bBoxes = []
for key in dic:
if word in dic[key]:
print('Results found in {}'.format(key))
bBoxes.append(detectFaces(key, dic))
return bBoxes
dictera = getDict('readonly/small_img.zip')
result = checkWord('Senator', dictera)
print(result)
最佳答案
还有其他一些问题,并且已经解决了,但弄清楚我要返回的列表从未提及。杜尔!
关于python - 麻烦与代码-> Python识别报纸上的面孔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61207231/
尝试安装包失败并出现以下错误。我用谷歌搜索并安装了 setuptools - 仍然遇到同样的错误。 命令:pip install newspaper Collecting nltk==2.0.5 (f
我正在尝试使用 Python 库 newspaper来自 Wayback Machine 的文件,存储已存档的旧版本网站。理论上,可以从这些文件中查询和下载旧的新闻文章。 例如,下面的代码查询文件 C
因此,基本上我的问题是:报亭工具包可以在单个应用程序中用于几种不同的杂志订阅吗?从wwdc 504 session 来看,这并不是真的。以我的理解,杂志/报纸订阅似乎与1个应用程序结合在一起。例如,U
我的 wordpress 主题中的 css 图像宽度样式有问题。图像宽度设置为 100%,但图像以其原始大小显示。并且溢出以某种方式被隐藏了。但是我无法弄清楚是哪个元素导致了这种行为以及如何解决它?
有没有什么 CSS 技术或好的 js 技术来布局内容,让你有一个像“报纸”一样的页面。给定一个包含一堆内容的 div(或其他),将该内容拆分为 N 列,总宽度为一些预定义的宽度。 假设 N = 3,假
我正在尝试从我可以通过网络(例如 Safari)浏览的文章中下载文本。 错误是: newspaper.article.ArticleException: Article `download()` fa
我是一名优秀的程序员,十分优秀!