无法在Python中合成两个图像

无法在Python中合成两个图像,python,opencv,Python,Opencv,我正在尝试将两个图像合并为一个。但我得到了: import cv2 import keras from matplotlib import pyplot as plt def writeImage(file, x): cv2.imwrite(file, x) def showImage(data): plt.imshow(data) plt.show() def composite(X, Y, out): writeImage(X, "/tmp/A

我正在尝试将两个图像合并为一个。但我得到了:

import cv2
import keras
from matplotlib import pyplot as plt

def writeImage(file, x):
    cv2.imwrite(file, x)

def showImage(data):
    plt.imshow(data)
    plt.show()

def composite(X, Y, out):
    writeImage(X, "/tmp/A.png")
    writeImage(Y, "/tmp/B.png")
    A = cv2.imread("/tmp/A.png", 0)
    B = cv2.imread("/tmp/B.png", 0)
    C = np.dstack((A, B))
    writeImage(C, out)
    return C

(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
showImage(x_train[0])
showImage(x_train[5])
composite(x_train[0], x_train[5], "/tmp/ImageCompositeExample.jpg")
SystemError:返回NULL而未设置错误
---------------------------------------------------------------------------
系统错误回溯(最近一次调用上次)
在里面
---->1复合(x_序列[0],x_序列[5],“/tmp/ImageCompositeExample.jpg”)
输入复合(X,Y,out)
1个def组合(X、Y、out):
---->2 writeImage(X,“/tmp/A.png”)
3 writeImage(Y,“/tmp/B.png”)
4a=cv2.imread(“/tmp/A.png”,0)
5b=cv2.imread(“/tmp/B.png”,0)
写入图像(文件,x)
1 def writeImage(文件,x):
---->2 cv2.imwrite(文件,x)
SystemError:返回NULL而未设置错误

交换函数调用中的参数,此时正在传递(x,file)

SystemError: <built-in function imwrite> returned NULL without setting an error 

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-15-f533fdd71378> in <module>
----> 1 composite(x_train[0], x_train[5], "/tmp/ImageCompositeExample.jpg")

<ipython-input-11-ff434edc5914> in composite(X, Y, out)
      1 def composite(X, Y, out):
----> 2     writeImage(X, "/tmp/A.png")
      3     writeImage(Y, "/tmp/B.png")
      4     A = cv2.imread("/tmp/A.png", 0)
      5     B = cv2.imread("/tmp/B.png", 0)

<ipython-input-9-5ef37533556e> in writeImage(file, x)
      1 def writeImage(file, x):
----> 2     cv2.imwrite(file, x)

SystemError: <built-in function imwrite> returned NULL without setting an error

交换函数调用中的参数,您现在正在传递(x,file)

SystemError: <built-in function imwrite> returned NULL without setting an error 

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-15-f533fdd71378> in <module>
----> 1 composite(x_train[0], x_train[5], "/tmp/ImageCompositeExample.jpg")

<ipython-input-11-ff434edc5914> in composite(X, Y, out)
      1 def composite(X, Y, out):
----> 2     writeImage(X, "/tmp/A.png")
      3     writeImage(Y, "/tmp/B.png")
      4     A = cv2.imread("/tmp/A.png", 0)
      5     B = cv2.imread("/tmp/B.png", 0)

<ipython-input-9-5ef37533556e> in writeImage(file, x)
      1 def writeImage(file, x):
----> 2     cv2.imwrite(file, x)

SystemError: <built-in function imwrite> returned NULL without setting an error

向函数writeImage传递参数时出错

writeImage("/tmp/A.png", X)
writeImage("/tmp/B.png", Y)
def复合(X,Y,out):

#writeImage(X,“/tmp/A.png”)向函数writeImage传递参数时出错

writeImage("/tmp/A.png", X)
writeImage("/tmp/B.png", Y)
def复合(X,Y,out):

#writeImage(X,“/tmp/A.png”)请进行完全回溯。@超级格式化程序在writeImage中添加了反向参数,首先是文件路径,然后是图像。请进行完全回溯。@超级格式化程序在writeImage中添加了反向参数,首先是文件路径,然后是图像。