首页 > 其他分享 >TypeError: Layout of the output array image is incompatible with cv::Mat (step[ndims-1] != elemsiz

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

时间:2022-10-26 21:33:23浏览次数:58  
标签:APPROX TypeError Layout Mat findContours cv2 step segments2


问题描述

使用​​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​​​为​​numpy.ndarray​​ 类型,代表二值图像。

解决方法

在使用​​segments2​​之前,转为无符号整型8位。

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


标签:APPROX,TypeError,Layout,Mat,findContours,cv2,step,segments2
From: https://blog.51cto.com/u_15847885/5798585

相关文章