Python 在Powershell中使用CV2和Skimage时出现内存错误
因此,我有一个python脚本,它使用CV2和Skimage比较文件路径中的所有图像,并返回最接近的匹配。它已经过测试,可以工作了Python 在Powershell中使用CV2和Skimage时出现内存错误,python,powershell,Python,Powershell,因此,我有一个python脚本,它使用CV2和Skimage比较文件路径中的所有图像,并返回最接近的匹配。它已经过测试,可以工作了 import os from skimage.metrics import structural_similarity as ssim import cv2 from shutil import copyfile def Compare_Images(testDir, reference): os.chdir(testDir) testlist
import os
from skimage.metrics import structural_similarity as ssim
import cv2
from shutil import copyfile
def Compare_Images(testDir, reference):
os.chdir(testDir)
testlist = os.listdir(testDir)
smax = 0
closest = 'null'
'''s = ssim(imageA, imageB)'''
for i in range(len(testlist)):
Reference = cv2.imread(reference)
Check = cv2.imread(testlist[i])
Reference = cv2.cvtColor(Reference, cv2.COLOR_BGR2GRAY)
Check = cv2.cvtColor(Check, cv2.COLOR_BGR2GRAY)
s= ssim(Reference, Check)
if (s>smax):
smax = s
closest = testlist[i]
NewPath = "C:\Localdata" + "\\" + closest
OldPath = testDir + "\\" + closest
copyfile(closest, NewPath)
print (closest)
return closest
然后,我将其修改为从powershell脚本调用(通过为TestDir设置等于sys.argv[1]的输入参数,为引用设置等于sys.argv[2]):
但是,当我从Powershell调用它时,会出现以下错误:
python : Traceback (most recent call last):
At C:\...\pythonpasserTest4.ps1:16 char:1
+ python $arg3 $arg1 $arg2
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
File "C:\...\ImagecompareV2.py", line 45, in <module>
s= ssim(Reference, Check)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\skimage\metrics\_structural_similarity.py", line 205, in structural_similarity
ux ** 2 + uy ** 2 + C1,
MemoryError: Unable to allocate array with shape (4032, 3024) and data type float64
如何解决这个问题?问题是我在Spyder中测试了它,Powershell试图在32位python中运行它。卸载32位python和安装64位python解决了这个问题。这是完整的错误消息吗?此外,变量和函数名称应遵循带有下划线的
小写形式。使用完整错误更新。您可以共享所有相关代码和数据吗?请看:。对不起,我刚刚添加了我所有的。图片由该公司分类,但python代码有效。任何JPG文件都可以代替它们。你做过分析吗?
python : Traceback (most recent call last):
At C:\...\pythonpasserTest4.ps1:16 char:1
+ python $arg3 $arg1 $arg2
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
File "C:\...\ImagecompareV2.py", line 45, in <module>
s= ssim(Reference, Check)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\skimage\metrics\_structural_similarity.py", line 205, in structural_similarity
ux ** 2 + uy ** 2 + C1,
MemoryError: Unable to allocate array with shape (4032, 3024) and data type float64
$env:Path += ";C:\Program Files (x86)\Python37-32";
$env:PATHEXT += ";.py"
$arg1 = 'C:\...\Test Pictures'
$arg2 = 'C:\...\IMG123.JPG'
$arg3 = 'C:\...\ImagecompareV2.py'
python $arg3 $arg1 $arg2