I am trying to segment input image using watershed method. In that i am using threshold(), however my program gets aborted with the following error on the terminal unsupported format or combination of formats () in cv::threshold The format of the function used is threshold(bw, bw, 40, 255, THRESH_BINARY); where bw is the binarised image in grayscale form.