TypeError: cannot unpack non-iterable numpy.intc object

TypeError: cannot unpack non-iterable numpy.intc object

使用cv2.connectedComponentsWithStats得到bbox,其中bbox是一个二维数组:l_x, l_y, w, h, 连通图

def mask_find_bboxs(mask):
    retval, labels, stats, centroids = cv2.connectedComponentsWithStats(mask, connectivity=8)  # connectivity参数的默认值为8
    stats = stats[stats[:, 4].argsort()]
    return stats[:-1]  # 排除最外层的连通图
    # 连通图的左上角坐标和连通图的宽高。

bboxs数据写入txt文件中

def wirte_txt(bboxs, image_name):
    print(bboxs[0])
    x_center = bboxs[0][0] + bboxs[0][2] / 2
    y_center = bboxs[0][1] + bboxs[0][3] / 2
    w = bboxs[0][2]
    h = bboxs[0][3]
    file_txt_path_name = os.path.join(file_path, image_name.split('.')[0] + '.txt')
    with open(file_txt_path_name, 'w') as file_txt:
        file_txt.write(str(x_center) + ' ' + str(y_center) + ' ' + str(w) + ' ' + str(h) + '\n')

    file_txt.close()

如果把

   //代码1
    w = bboxs[0][2]
    h = bboxs[0][3]

换成

	//代码2
    w = bboxs[0][2],h = bboxs[0][3]

则会报错:
TypeError: cannot unpack non-iterable numpy.intc object
如果使用代码2,那么w和h则会是一个tuple类型。tuple里面的为numpy.intc。其实使用代码1类型依然是numpy.intc,为什么可以赋值了呢???唉。。不懂!!!!!!!!!!

reference:
-参考1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值