天天看点

TypeError: Layout of the output array image is incompatible with cv::Mat (step[ndims-1] != elemsiz

问题描述

使用​

​opencv-python​

​​的​

​cv2.findContours​

​,曝出如题错误:

TypeError: Layout of the output array image is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)

源码:

t=cv2.findContours(segments2,mode=cv2.RETR_LIST,
    method=cv2.CHAIN_APPROX_SIMPLE)      

解决方法

segments2=segments2.astype(np.uint8)
t=cv2.findContours(segments2,mode=cv2.RETR_LIST,
    method=cv2.CHAIN_APPROX_SIMPLE)