cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\connectedcomponents.cpp:3926: error: (-215:Assertion failed) L.channels() == 1 && I.channels() == 1 in function 'cv::connectedComponents_sub1' code example
Example: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
This error happened because the image didn't load properly.
So you have problem with the previous line cv2.imread my suggestion is :
check if the images exist in the path you give
check the count variable if he have valid number