从shape广播输入数组时出错。通常,这似乎是由转换某个维度数组引起的
p
在某个维度数组中:
p+1
或
p-1
. 然而,我的输入和输出的形状似乎是一样的:3个维度。所以我的问题是,我做错了什么,我该如何着手解决这个问题?
ValueErrorTraceback (most recent call last)
<ipython-input-21-e821b7e8e0de> in <module>()
108 "overlay_glasses.shape: ", overlay_glasses.shape)
109
111
下面是print语句的输出,以便更好地理解上述代码。
'overlay_img.shape: ' , (365, 365, 3),
'overlay_glasses.shape: ', ( 34, 99, 3)
'x: ', 623.26, 'y: ', 265.9
'h: ', 34, 'w: ', 99
较大的代码段:
[omitted code here]
if len(centers)>0:
glasses_width = 2.16*abs(centers[1][0]-centers[0][0])
overlay_img = np.ones(shape = roi_color.shape,
dtype = np.uint8)*255
h,w = glass_img.shape[:2]
scaling_factor = glasses_width/w
overlay_glasses = cv2.resize(src = glass_img,
dsize = None,
fx = scaling_factor,
fy = scaling_factor,
interpolation = cv2.INTER_AREA)
x = centers[0][0] if centers[0][0] < centers[1][0] else centers[1][0]
x -= 0.26*overlay_glasses.shape[1]
y += 0.85*overlay_glasses.shape[0]
print("x: ", x,
"y: ", y)
h, w = overlay_glasses.shape[:2]
print("h: ", h,
"w: ", w)
print("overlay_img.shape: ", overlay_img.shape,
"overlay_glasses.shape: ", overlay_glasses.shape)
overlay_img[int(y):int(y+h),int(x):int(x+w)] = overlay_glasses