前提・実現したいこと
pythonでクロマキーがしたいです。
サンプルコードそのままのはずなのですがエラーが出てしまい、調べてもよくわかりません。
macでnumpyやopencvはちゃんと入っています。
発生している問題・エラーメッセージ
OpenCV(3.4.1) Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file /Users/travis/build/skvark/opencv-python/opencv/modules/core/src/arithm.cpp, line 659
Traceback (most recent call last):
File "runrun.py", line 51, in <module>
main()
File "runrun.py", line 44, in main
keyed = cv2.add(bg_key, fg_key)
cv2.error: OpenCV(3.4.1) /Users/travis/build/skvark/opencv-python/opencv/modules/core/src/arithm.cpp:659: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function arithm_op
エラーメッセージ
該当のソースコード
使っているコードは
import numpy as np
import cv2
def main():
"""
aaaa
"""
# default cam matrix rows and columns
cap = cv2.VideoCapture(0) # use external cam
# get the background and resize it. img_back = cv2.imread('/Users/reraito/desktop/background.jpg') background_color = np.uint8([[[0, 255, 0]]]) hls_background_color = cv2.cvtColor(background_color, cv2.COLOR_BGR2HLS) hls_background_color = hls_background_color[0][0] while True: _, frame = cap.read() cols, rows = frame.shape[:2] background = img_back[0:cols, 0:rows] frame = cv2.flip(frame, 1, frame) hls_image = cv2.cvtColor(frame, cv2.COLOR_BGR2HLS) hue = hls_image[:, :, 0] binary_hue = cv2.inRange(hue, 100, 120) mask = np.zeros(hls_image.shape, dtype=np.uint8) mask[:, :, 0] = binary_hue mask[:, :, 1] = binary_hue mask[:, :, 2] = binary_hue blured = cv2.GaussianBlur(mask, (11, 11), 0) blured_inverted = cv2.bitwise_not(blured) bg_key = cv2.bitwise_and(background,background, blured) fg_key = cv2.bitwise_and(frame,frame, blured_inverted) cv2.imwrite('bg.jpg', bg_key) cv2.imwrite('fg.jpg', fg_key) keyed = cv2.add(bg_key, fg_key) cv2.imshow('frame', keyed) k = cv2.waitKey(33) if k == 27: # ESC break
if name == "main":
main()

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/11 14:34 編集
2018/07/11 14:33
2018/07/11 14:55
2018/07/11 15:36
2018/07/11 16:04