您好我是圖像分割的新手,我正在嘗試給定的代碼來獲取前景對象,但我得到像「不支持的格式或格式(僅8位,3通道的輸入圖像被支撐)在cvWatershed組合」不支持的格式或格式組合(僅支持8位,3通道輸入圖像)在cvWatershed
cv::Mat img0 = [img toMat];
cv::Mat img1;
cv::cvtColor(img0, img0, CV_RGB2GRAY);
cv::threshold(img0, img0, 100, 255, cv::THRESH_BINARY);
cv::Mat fg;
cv::erode(img0,fg,cv::Mat(),cv::Point(-1,-1),6);
cv::Mat bg;
cv::dilate(img0,bg,cv::Mat(),cv::Point(-1,-1),6);
cv::threshold(bg,bg,1,128,cv::THRESH_BINARY_INV);
cv::Mat markers(img0.size(),CV_8U,cv::Scalar(0));
markers= fg+bg;
// CV :: namedWindow( 「標誌物」); // cv :: imshow(「Markers」,markers);
WatershedSegmenter segmenter;
segmenter.setMarkers(markers);
cv::Mat result1 = segmenter.process(img0);
// cv :: Mat result1; result1.convertTo(result1,CV_8U);
UIImage * result = [UIImage imageWithMat:result1 andImageOrientation:[img imageOrientation]];
return result;
,我嘗試通過調試和線路遇到錯誤提前