Watershed returns an error

Hey, everyone! I am trying to complete a watershed algorithm, but it returns a following error about cv.watershed function:

Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\pythonProject\main.py", line 23, in <module>
    marks = cv.watershed(hsv_mask, marks)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\segmentation.cpp:161: error: (-215:Assertion failed) src.type() == CV_8UC3 && dst.type() == CV_32SC1 in function 'cv::watershed'

Here is the code:

import cv2 as cv
import numpy as np

image = cv.imread(r'C:\\Users\User\Desktop\im.png')
low_cube = (120, 50, 50)
high_cube = (155, 255, 255)
hsv_im = cv.cvtColor(image, cv.COLOR_BGR2HSV)
hsv_mask = cv.inRange(hsv_im, low_cube, high_cube)

cnt, _ = cv.findContours(hsv_mask, cv.RETR_CCOMP, cv.CHAIN_APPROX_NONE)
c = max(cnt, key=cv.contourArea)

# cv.drawContours(image, c, -1, (0,0,255), thickness=3)
dist = cv.distanceTransform(hsv_mask, cv.DIST_L2, 5)
val, res = cv.threshold(dist, 0.4 * dist.max(), 255, cv.THRESH_BINARY)
sure_bg = cv.dilate(res, np.ones((3, 3)), iterations=3)
unknown = cv.subtract(sure_bg, res)
sure_bg = sure_bg.astype(np.uint8)
ret, marks = cv.connectedComponents(sure_bg)
marks += 1
marks[unknown == 255] = 0
hsv_mask = np.asarray(hsv_mask)
marks = cv.watershed(hsv_mask, marks)

I wonder if anyone helps…

check the types. what are the types?

both are numpy arrays

of course, but what’s the dtype of each? and what’s their .shape?

I’m betting hsv_mask isn’t 3-channel, but that assertion says it needs to be.

please read the assertion that failed. it conveys meaning. it’s not just a string of expletives from an angry compiler.