我正在测试我在互联网上看到的代码,但我遇到了一些问题。我想得到一个答案,为什么我的存档没有正确打开,它保持加载和加载,我不能查看当时发生的事情。正确的是在0到255之间有许多数字(RGB颜色)。我认为这个问题出现在'np.seterr(over ='ignore')'中,但是如果这个问题出了问题,那么我还有另一个问题,所以,我不知道。代码确实:识别数据库中的图像。提前谢谢。
CODE:
let query: [String: Any] = [
kSecClass as String: kSecClassIdentity,
kSecReturnRef as String: kCFBooleanTrue,
kSecMatchLimit as String: kSecMatchLimitAll
]
var items: CFTypeRef?
// Get list of all SecIdentity from Keychain without limiting search and without any filtering applied
guard SecItemCopyMatching(query as CFDictionary, &items) == errSecSuccess, let array = items as? NSArray else {
return
}
for item in array {
let identity = item as! SecIdentity
var certificate: SecCertificate?
// Get SecCertificate out of SecIdentity object (it contains both SecCertificate and SecKey
if SecIdentityCopyCertificate(identity, &certificate) == errSecSuccess {
var commonName: CFString?
// Print name for each certificate
if SecCertificateCopyCommonName(certificate!, &commonName) == errSecSuccess {
print(commonName! as String)
}
}
}
答案 0 :(得分:1)
我假设您已根据项目here
创建代码很难准确判断出哪些内容已损坏,因为我无法访问您正在使用的JPEG文件(原始项目使用PNG文件)。
但是,以下版本的代码可以与GitHub项目中提供的PNG文件一起使用,存储在您可以看到的相同目录结构中(图像/数字)。我删除了threshold()
函数,因为它没有被调用。
希望您可以将此作为起点。
from PIL import Image
from matplotlib import pyplot as plt
import numpy as np
import time
from collections import Counter
def createExamples():
numberArrayExamples=open('numArEx.txt','w') # replace, do not append
numbersWeHave=range(1,3)
versionsWeHave=range(1,10)
for eachNum in numbersWeHave:
for eachVer in versionsWeHave:
#print str(eachNum)+'.'+str(eachVer)
imgFilePath = 'images/numbers/'+str(eachNum)+'.'+str(eachVer)+'.png'
ei=Image.open(open(imgFilePath,'rb'))
eiar=np.array(ei)
eiar1=str(eiar.tolist())
lineToWrite=str(eachNum)+'::'+eiar1+'\n'
numberArrayExamples.write(lineToWrite)
numberArrayExamples.close()
def whatNumIsThis(filePath):
matchedAr=[]
loadExamps=open('numArEx.txt','r').read()
loadExamps=loadExamps.split('\n')
i=Image.open(open(filePath,'rb'))
iar=np.array(i)
iar1=iar.tolist()
inQuestion=str(iar1)
for eachExample in loadExamps:
if len(eachExample) > 3:
splitEx=eachExample.split('::')
currentNum=splitEx[0]
currentAr=splitEx[1]
eachPixEx = currentAr.split(']')
eachPixInQ=inQuestion.split(']')
x = 0
while x<len(eachPixEx):
if eachPixEx[x]==eachPixInQ[x]:
matchedAr.append(int(currentNum))
x+=1
print (matchedAr)
x=Counter(matchedAr)
print (x)
createExamples()
whatNumIsThis('images/test.png')
whatNumIsThis('images/test1.png')