gpt4 book ai didi

python - 麻烦与代码-> Python识别报纸上的面孔

转载 作者:行者123 更新时间:2023-12-02 16:34:20 26 4
gpt4 key购买 nike

我的任务是遍历包含一些图像的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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com