在运用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