我想要做的是让我可以将 4 个视频源堆叠在一起,RGB、B、G、R channel 在四帧源中。这是我的代码,我收到错误“所有输入数组必须具有相同的维数。我想知道是否有办法解决或解决这个问题?如果你在 RGB 所在的位置插入 GRAY,你可以看到整体结果我我想要的不是 RGB 帧,而是灰色帧所在的位置。
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
while(True):
ret, frame = cap.read()
# Resizing down the image to fit in the screen.
b,g,r = cv2.split(frame)
RGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
GRAY = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# creating another frame.
channels = cv2.split(frame)
frame_merge = cv2.merge(channels)
# horizintally concatenating the two frames.
final_frame = cv2.hconcat((frame, frame_merge))
final_frame2 = cv2.hconcat((frame, frame_merge))
final = cv2.vconcat((final_frame, final_frame2))
frame1 = np.hstack((RGB,b))
frame2 = np.hstack((g,r))
final = np.vstack((frame1,frame2))
cv2.imshow('frame', final)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
最佳答案
这是我的解决方案:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
red = np.zeros(frame.shape, 'uint8')
green = np.zeros(frame.shape, 'uint8')
blue = np.zeros(frame.shape, 'uint8')
while(True):
ret, frame = cap.read()
b, g, r = cv2.split(frame)
red[..., 0], red[..., 1], red[..., 2] = r, r, r
green[..., 0], green[..., 1], green[..., 2] = g, g, g
blue[..., 0], blue[..., 1], blue[..., 2] = b, b, b
final = cv2.vconcat((
cv2.hconcat((frame, blue)),
cv2.hconcat((green, red))
))
cv2.imshow('frame', final)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
关于python - 将RGB channel 和单 channel 的cv2帧堆叠在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960411/