1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
void Traitement :: Watershed (Image &image)
{
Mat gray, thresh ;
cvtColor(image.getResult(), gray, COLOR_BGR2GRAY);
threshold(gray, thresh, 0, 255, THRESH_OTSU);
// Traitement avant-plan
Mat foreground;
erode( thresh, foreground, Mat(), Point(-1, -1), 2 );
// Traitement arrière plan
Mat background, back;
dilate ( thresh, background, Mat(), Point(-1, -1), 3 );
threshold(background, back, 1, 128, 1);
// Création des marqueurs
Mat markers ;
markers = foreground + back;
Mat markers32, img;
// Le problème commence à la conversion (image noire)
markers.convertTo(markers32, CV_32SC1);
gray.convertTo(img, CV_8UC3);
watershed(img, markers32);
image.setResult(markers32);
image.addTraitement("Watershed");
} |
Partager