Opencv drawContours 失败原因之通道数目不符

为何drawcontours失败无法绘制,搞清楚通道数很重要
摘要由CSDN通过智能技术生成
predicted=predicteds*255
predicted.shape
>>>(300,300)
img = np.array(predicted, dtype=np.uint8)
#img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
mask = np.zeros(img.shape,dtype=np.uint8)
print(np.shape(img))

# 先利用二值化去除图片噪声
ret, thresh = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
plt.subplot(1,2,1)
plt.imshow(thresh)
plt.subplot(1,2,2)
plt.imshow(mask)

 

 需要画出二维图像的轮廓,发现轮廓线无法绘制上去

contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
cv2.drawContours(img, contours, -1, (0,0,255), 2)
# n = len(contours)  # 轮廓的个数
# print(n)
# cv_contours = []
# for contour in contours:
#     area = cv2.contourArea(contour)
#     if area <= 800:
#         cv_contours.append(contour)
#         cv2.drawContours(mask, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值