python error: (-215:Assertion failed) _src.depth() == CV_8U in function 'Canny'

在运用cgt = cv2.Canny(no0_gt, 100, 100)时,报错:

cv2.error: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/canny.cpp:829: error: (-215:Assertion failed) _src.depth() == CV_8U in function 'Canny'

我的出错原因是:图像类型不符合要求。

正常图像一个点的类型 type(image[0][0]) 为:
在这里插入图片描述
而我的图像一个点的类型 type(image[0][0]) 是这样的:
<class ’ numpy.float64’>
所以我通过以下任一方式对图像类型进行了改正:
1.两种方式:array.dtype=np.uint8 或是 array=array.astype( np.uint8 )

2.使用array=array.astype( np.uint8 )的时候必须astype后赋值,只是用array.astype( np.uint8 ) 是不会改变数据类型的,必须写成array=array.astype( np.uint8 )。

关于python-opencv边缘检测的运用,可见该博客:https://blog.csdn.net/qq_42333641/article/details/90201179

  • 9
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值