I use three filter as below, each one if I run individual work well(three output image 'imgThresholded' is difference), but if I use continuously all, the output image 'imgThresholded' is the last one.
void filterBlack(){ inRange(imgHSV, Scalar(Hblack.iLVal / 2, Sblack.iLVal, Vblack.iLVal2.55), Scalar(Hblack.iHVal / 2, Sblack.iHVal2.55, Vblack.iHVal2.55), imgThresholded); erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); //morphological closing (fill small holes in the foreground) dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); imshow(thhdWindow, imgThresholded); } void filterBlue(){ inRange(imgHSV, Scalar(Hblue.iLVal / 2, Sblue.iLVal, Vblue.iLVal2.55), Scalar(Hblue.iHVal / 2, Sblue.iHVal2.55, Vblue.iHVal2.55), imgThresholded); erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); //morphological closing (fill small holes in the foreground) dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); imshow(thhdWindow, imgThresholded); } void filterRed(){ inRange(imgHSV, Scalar(Hred.iLVal / 2, Sred.iLVal, Vred.iLVal2.55), Scalar(Hred.iHVal / 2, Sred.iHVal2.55, Vred.iHVal*2.55), imgThresholded); erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); //morphological closing (fill small holes in the foreground) dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(3, 3))); imshow(thhdWindow, imgThresholded); }