I have a color image sourceImage
and I would copy this image on a new larger color image destImage
: the source image should be centered over the new image. In order to perform this procedure, I wrote the following code:
destHeight: the height of the new larger image destWidth: the width of the new larger image
sourceFilename: the path of the source image
sourceImage = cv2.imread(sourceFilename,1)
imgHeight, imgWidth, imgChannels = sourceImage.shape[:3]
#print sourceImage.shape[:3]
destImage = np.zeros((destHeight,destWidth,imgChannels), np.uint8)
#print destImage.shape[:3]
yBorder = (destHeight-imgHeight)/2
xBorder = (destWidth-imgWidth)/2
#print yBorder, xBorder
destImage[yBorder:imgHeight,xBorder:imgWidth] = sourceImage
cv2.imshow('dst', destImage)
cv2.waitKey(0)
But when I run the script, the python interpreter displays the following error:
Traceback (most recent call last):
File "examples.py", line 30, in <module>
destImage[yBorder:imgHeight,xBorder:imgWidth] = sourceImage
ValueError: shape mismatch: objects cannot be broadcast to a single shape
What is the reason for this error? How to solve it?