@[TOC](error: (-215:Assertion failed) npoints > 0 in function ‘drawContours’)

开发过程中遇到一个问题,很有意思,在这里记录一下

业务代码

    cv2.drawContours(plaque_mask[slice_idx, :, :], contours, -1, tmp, -1)

报错

	cv2.drawContours(plaque_mask[slice_idx, :, :], contours, -1, tmp, -1)
cv2.error: OpenCV(4.6.0) /io/opencv/modules/imgproc/src/drawing.cpp:2502: error: (-215:Assertion failed) npoints > 0 in function 'drawContours'

问题和解决方案

经排查,contours的数据类型不对, 应该为int ,获取到的却是float…
搞不懂,像素坐标, 你还给我一个浮点数…
害的姐姐我调试了好久…(显然我也很菜吧, 没有早点发现问题)

总结

读书,搞钱,旅游

Logo

鸿蒙生态一站式服务平台。

更多推荐