Same output threshold image
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.iLVal*2.55), Scalar(Hblack.iHVal / 2, Sblack.iHVal*2.55, Vblack.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);
}
void filterBlue(){
inRange(imgHSV, Scalar(Hblue.iLVal / 2, Sblue.iLVal, Vblue.iLVal*2.55), Scalar(Hblue.iHVal / 2, Sblue.iHVal*2.55, Vblue.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);
}
void filterRed(){
inRange(imgHSV, Scalar(Hred.iLVal / 2, Sred.iLVal, Vred.iLVal*2.55), Scalar(Hred.iHVal / 2, Sred.iHVal*2.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);
}
Hah that is because imgThresholded is a pointer, and thus calling functions subsequently will work on the same data, starting from imgHSV. Inside your function you want to have at least a local imgThresholded defined, in which you want to store the result. Global variables never work well ...