|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | +#include "test_precomp.hpp" |
| 6 | +#include "opencv2/video/background_segm.hpp" |
| 7 | + |
| 8 | +namespace opencv_test { namespace { |
| 9 | + |
| 10 | +using namespace cv; |
| 11 | + |
| 12 | +///////////////////////// MOG2 ////////////////////////////// |
| 13 | +TEST(BackgroundSubtractorMOG2, KnownForegroundMaskShadowsTrue) |
| 14 | +{ |
| 15 | + Ptr<BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2(500, 16, true); |
| 16 | + |
| 17 | + //Black Frame |
| 18 | + Mat input = Mat::zeros(480,640 , CV_8UC3); |
| 19 | + |
| 20 | + //White Rectangle |
| 21 | + Mat knownFG = Mat::zeros(input.size(), CV_8U); |
| 22 | + |
| 23 | + rectangle(knownFG, Rect(3,3,5,5), Scalar(255,255,255), -1); |
| 24 | + |
| 25 | + Mat output; |
| 26 | + mog2->apply(input, knownFG, output); |
| 27 | + |
| 28 | + for(int y = 3; y < 8; y++) |
| 29 | + { |
| 30 | + for (int x = 3; x < 8; x++){ |
| 31 | + EXPECT_EQ(255,output.at<uchar>(y,x)) << "Expected foreground at (" << x << "," << y << ")"; |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +TEST(BackgroundSubtractorMOG2, KnownForegroundMaskShadowsFalse) |
| 37 | +{ |
| 38 | + Ptr<BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2(500, 16, false); |
| 39 | + |
| 40 | + //Black Frame |
| 41 | + Mat input = Mat::zeros(480,640 , CV_8UC3); |
| 42 | + |
| 43 | + //White Rectangle |
| 44 | + Mat knownFG = Mat::zeros(input.size(), CV_8U); |
| 45 | + |
| 46 | + rectangle(knownFG, Rect(3,3,5,5), Scalar(255,255,255), FILLED); |
| 47 | + |
| 48 | + Mat output; |
| 49 | + mog2->apply(input, knownFG, output); |
| 50 | + |
| 51 | + for(int y = 3; y < 8; y++) |
| 52 | + { |
| 53 | + for (int x = 3; x < 8; x++){ |
| 54 | + EXPECT_EQ(255,output.at<uchar>(y,x)) << "Expected foreground at (" << x << "," << y << ")"; |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +///////////////////////// KNN ////////////////////////////// |
| 60 | + |
| 61 | +TEST(BackgroundSubtractorKNN, KnownForegroundMaskShadowsTrue) |
| 62 | +{ |
| 63 | + Ptr<BackgroundSubtractorKNN> knn = createBackgroundSubtractorKNN(500, 400.0, true); |
| 64 | + |
| 65 | + //Black Frame |
| 66 | + Mat input = Mat::zeros(480,640 , CV_8UC3); |
| 67 | + |
| 68 | + //White Rectangle |
| 69 | + Mat knownFG = Mat::zeros(input.size(), CV_8U); |
| 70 | + |
| 71 | + rectangle(knownFG, Rect(3,3,5,5), Scalar(255,255,255), FILLED); |
| 72 | + |
| 73 | + Mat output; |
| 74 | + knn->apply(input, knownFG, output); |
| 75 | + |
| 76 | + for(int y = 3; y < 8; y++) |
| 77 | + { |
| 78 | + for (int x = 3; x < 8; x++){ |
| 79 | + EXPECT_EQ(255,output.at<uchar>(y,x)) << "Expected foreground at (" << x << "," << y << ")"; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +TEST(BackgroundSubtractorKNN, KnownForegroundMaskShadowsFalse) |
| 85 | +{ |
| 86 | + Ptr<BackgroundSubtractorKNN> knn = createBackgroundSubtractorKNN(500, 400.0, false); |
| 87 | + |
| 88 | + //Black Frame |
| 89 | + Mat input = Mat::zeros(480,640 , CV_8UC3); |
| 90 | + |
| 91 | + //White Rectangle |
| 92 | + Mat knownFG = Mat::zeros(input.size(), CV_8U); |
| 93 | + |
| 94 | + rectangle(knownFG, Rect(3,3,5,5), Scalar(255,255,255), FILLED); |
| 95 | + |
| 96 | + Mat output; |
| 97 | + knn->apply(input, knownFG, output); |
| 98 | + |
| 99 | + for(int y = 3; y < 8; y++) |
| 100 | + { |
| 101 | + for (int x = 3; x < 8; x++){ |
| 102 | + EXPECT_EQ(255,output.at<uchar>(y,x)) << "Expected foreground at (" << x << "," << y << ")"; |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +}} // namespace |
| 108 | +/* End of file. */ |
0 commit comments