Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试将映像用作数组时不支持的操作数类型_Python_Python Imaging Library_Typeerror - Fatal编程技术网

Python 尝试将映像用作数组时不支持的操作数类型

Python 尝试将映像用作数组时不支持的操作数类型,python,python-imaging-library,typeerror,Python,Python Imaging Library,Typeerror,这是我的功能,用于保存连接到计算机的摄像头的图像。 我得到的错误是: def SaveImg(img, path, data): #image, temp = Image.fromarray((img-bg+127).astype(np.uint8)), data['temps'] img=img.astype(np.uint8) #y=127 #x=y.astype(np.uint8) image, temp = Image.fromarray(img-bg), data['temp

这是我的功能,用于保存连接到计算机的摄像头的图像。 我得到的错误是:

def SaveImg(img, path, data):
    #image, temp = Image.fromarray((img-bg+127).astype(np.uint8)), data['temps']

img=img.astype(np.uint8)
#y=127
#x=y.astype(np.uint8)
image, temp = Image.fromarray(img-bg), data['temps']
outFile=path+"/%s - %f-%f C.png" % (datetime.now().strftime("%Y-%m-%d %H.%M.%S"), temp[0], temp[1])
image.save(outFile)
print "Saving to", outFile
#time.sleep(5)
我不明白问题出在哪里。另外,我正在更改一个我没有编写的代码,函数的第一行应该是正确的,但它给了我相同的错误


我试着打印出来看看有什么问题,但我看不到任何是非类型的;当我打印时,我没有得到
NoneType
或全零数组。

我发现这行代码中有一个问题:

image,temp=image.fromarray(img bg),数据['temps']

bg
显然是
None
。不能从某个值中减去
None
,因此出现“不支持的操作数类型”错误


从您展示的代码中,无法推断出
bg
应该是什么,或者它的初始化或计算位置。从名称上看,我怀疑这是一个没有任何东西的相机视图(即“背景”)。从另一张图片中减去背景图片是有意义的,但如果没有背景图片,则会失败。。。有没有办法查看代码的其余部分?这是来自某个开源项目吗?

self.bg=self.cm.imgInterface.snap()行中,获取了背景图片。您能否验证
self.bg
当时是否确实包含有效的图像?此外,我在您提供的代码中找不到您在代码片段中显示的操作
img bg
,因此我看不出您的代码在更大的整体中是如何匹配的。例如,您可能应该使用
img-self.bg
,但这只是一个猜测。你能把你的全部代码发布到某个地方吗?我看到你在字符串中使用反斜杠(\)。您要么必须转义它们,要么使用“原始”字符串。因此,无论是
'D:\\pavo th\\pictures'
还是
r'D:\pavo th\pictures'
,或者更好的方法是,使用
os.path.join
组合文件名和目录名。我不确定这是否是唯一的问题,但这很重要。
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'