问题描述
我在下面的二进制蒙版图像下面有一个视频帧
要检测的目标对象是中间的白点(下面的白点是噪声)
不管基于面积和比率过滤感兴趣的对象,我都试图标记连接的组件,然后找到它们的属性,使用skimage模块非常简单。因此,我尝试了以下代码:
import cv2
from skimage.measure import label
mask=cv2.imread(r'C:/Users/kjbaili/.spyder-py3/Mean_Shift/MST_with_3D_projection/mask6.jpg')
Label1,Num=label(mask,neighbors=4,background=0,return_num=True,connectivity=2)
#thresh=Label1.astype(np.uint8)
cv2.imshow('mask',mask)
cv2.imshow('label',Label1)
cv2.waitKey(0)
cv2.destroyAllWindows()
运行代码时,发生以下错误:
line 17,in <module> cv2.imshow('label',Label1)
error: OpenCV(4.2.0) C:/projects/opencv-python/opencv/modules/highgui/src/precomp.hpp:137: error:
(-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'
据我所知,当图像不存在或无法读取时,会发生此错误。所以有人知道问题出在哪里吗?
预先感谢
解决方法
问题出在图像类型上。必须转换为-> uint8 归功于@Mark Setchell