def frame_processing(frame):
out_frame = np.zeros((frame.shape[0],frame.shape[1],4),dtype = np.uint8)
b,g,r = cv2.split(frame)
alpha = np.zeros_like(b , dtype=np.uint8)
print(out_frame.shape)
print(b.shape);print(g.shape);print(r.shape);print(alpha.shape)
for i in range(frame.shape[0]):
for j in range(frame.shape[1]):
a = (frame[i,j,0],frame[i,j,1],frame[i,j,2])
b = (225,225,225)
if all(i > j for i, j in zip(a,b)): #all(a>b) :
alpha[i,j] = 0
else:
alpha[i,j] = 255
out_frame[:,:,0] = b
out_frame[:,:,1] = g
out_frame[:,:,2] = r
out_frame[:,:,3] = alpha
#out_frame = cv2.merge((b,g,r,alpha))
return out_frame
Хотел добавить альфа-канал;пробовал cv2.Merge()
и ручная укладка каналов, но не удалось.
При использовании cv2.merge()
:
error: OpenCV(3.4.2) C:\projects\opencv-
python\opencv\modules\core\src\merge.cpp:458: error: (-215:Assertion failed)
mv[i].size == mv[0].size && mv[i].depth() == depth in function 'cv::merge'
При добавлении каналов вручную:
ValueError: could not broadcast input array from shape (3) into shape
(225,225)