cv2.error:OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474/work/modules/core/src/arithm.cpp:223:error:(-209:sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar' nor 'scalar op array' in function 'binary_op'

 

 

Python의 OpenCV(cv2)에서 cv2.bitwise_and()를 사용할 때 발생했던 에러입니다.

 

 

해당 오류가 발생하는 이유는 굉장히 다양해서, 해당 에러에 대한 해결방안을 적은 블로그 글에서 조차 다양한 해결방안을 제시하고 있습니다.

 

 

해당 에러에서의 핵심은 'where arrays have the same size and type'이라고 보여지며, 말 그대로 opencv 연산을 하고자 하는 array의 size와 type이 같아야 한다는 점입니다.

 

 

제 케이스에서는 size가 같았으나 에러가 나서, 변수의 .dtype을 찍어보니 하나는 float32였고, 다른 하나는 float64이였습니다.

 

 

이에 대응하고자 float64인 이미지를 .astype(np.float32)로 처리하여 float32로 맞춰주었더니 해결되었습니다.

 

 

 

+ Recent posts