Search code examples
pythonopencvimage-processingscikit-learnscikit-image

Error when Label connected components using scikit-image


I have below the following binary mask image form a video frames

mask

The target object to be detected is the white spot in the middle (the below white spot is noise )

regardless of filtering the object of interest based on area and ratio, i 'm trying to label connected components and then find their properties which is very straight forward using skimage module. Therefore i tried the following code:

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()

When i run the code the following error occurs:

 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'

According to my knowledge, This error occurs when the image is either none or can't be read. So anyone knows where the problem is ?

Thanks in advance


Solution

  • The problem was in the image type. must converted to --> uint8 Credit to @Mark Setchell