libvibe++ : a generic C++ library for the ViBe algorithm
ViBe_8UC3.cpp
Go to the documentation of this file.
1 /* Copyright - Benjamin Laugraud <blaugraud@ulg.ac.be> - 2016
2  * Copyright - Marc Van Droogenbroeck <m.vandroogenbroeck@ulg.ac.be> - 2016
3  *
4  * ViBe is covered by a patent (see http://www.telecom.ulg.ac.be/research/vibe).
5  *
6  * Permission to use ViBe without payment of fee is granted for nonprofit
7  * educational and research purposes only.
8  *
9  * This work may not be copied or reproduced in whole or in part for any
10  * purpose.
11  *
12  * Copying, reproduction, or republishing for any purpose shall require a
13  * license. Please contact the authors in such cases. All the code is provided
14  * without any guarantee.
15  *
16  * This simple example program takes a path to a video sequence as an argument.
17  * When it is executed, two windows are opened: one displaying the input
18  * sequence, and one displaying the segmentation maps produced by ViBe. Note
19  * that this program uses the a polychromatic version of ViBe with 3 channels.
20  */
21 
22 /**
23  @file ViBe_8UC3.cpp
24  @brief Using ViBe with OpenCV for color images
25 
26  @author Benjamin Laungraud and Marc Van Droogenbroeck
27 
28  @date June 2016
29 
30  @details
31 
32  Full documentation is available online at:
33  http://www.telecom.ulg.ac.be/research/vibe/doc2
34 
35  All technical details are available in the following paper:
36 <em>O. Barnich and M. Van Droogenbroeck. ViBe: A universal background subtraction algorithm for video sequences. IEEE Transactions on Image Processing, 20(6):1709-1724, June 2011.</em>
37 
38 \verbatim
39 BiBTeX information
40 
41  @article{Barnich2011ViBe,
42  title = {{ViBe}: A universal background subtraction algorithm for video sequences},
43  author = {O. Barnich and M. {Van Droogenbroeck}},
44  journal = {IEEE Transactions on Image Processing},
45  volume = {20},
46  number = {6},
47  pages = {1709-1724},
48  month = {June},
49  year = {2011},
50  keywords = {ViBe, Background, Background subtraction, Segmentation, Motion, Motion detection},
51  pdf = {http://orbi.ulg.ac.be/bitstream/2268/145853/1/Barnich2011ViBe.pdf},
52  doi = {10.1109/TIP.2010.2101613},
53  url = {http://hdl.handle.net/2268/145853}
54  }
55 \endverbatim
56 
57 See
58 \cite Barnich2011ViBe
59 */
60 
61 
62 #include <cstddef>
63 #include <ctime>
64 #include <iostream>
65 
66 #ifndef OPENCV_3
67 #include <cv.h>
68 #include <highgui.h>
69 #else
70 #include <opencv2/opencv.hpp>
71 #endif /* OPENCV_3 */
72 
73 #include <libvibe++/ViBe.h>
75 #include <libvibe++/system/types.h>
76 
77 using namespace std;
78 using namespace cv;
79 using namespace ViBe;
80 
81 int main(int argc, char** argv) {
82  if (argc != 2) {
83  cerr << "A video file must be given as an argument to the program!";
84  cerr << endl;
85 
86  return EXIT_FAILURE;
87  }
88 
89  /* Parameterization of ViBe. */
91 
92  /* Random seed. */
93  srand(time(NULL));
94 
95  cv::VideoCapture decoder(argv[1]);
96  cv::Mat frame;
97 
98  int32_t height = decoder.get(CV_CAP_PROP_FRAME_HEIGHT);
99  int32_t width = decoder.get(CV_CAP_PROP_FRAME_WIDTH);
100 
101  ViBe* vibe = NULL;
102  cv::Mat segmentationMap(height, width, CV_8UC1);
103  bool firstFrame = true;
104 
105  while (decoder.read(frame)) {
106  if (firstFrame) {
107  /* Instantiation of ViBe. */
108  vibe = new ViBe(height, width, frame.data);
109  firstFrame = false;
110  }
111 
112  /* Segmentation and update. */
113  vibe->segmentation(frame.data, segmentationMap.data);
114  vibe->update(frame.data, segmentationMap.data);
115 
116  /* Post-processing: 3x3 median filter. */
117  medianBlur(segmentationMap, segmentationMap, 3);
118 
119  imshow("Input video", frame);
120  imshow("Segmentation by ViBe", segmentationMap);
121 
122  cvWaitKey(1);
123  }
124 
125  delete vibe;
126 
127  cvDestroyAllWindows();
128  decoder.release();
129 
130  return EXIT_SUCCESS;
131 }
Distance function for computing the Euclidean distance between the pixel and samples of the model...
Interface for the libvibe++ library.

License/Copyright

This code is copyrighted by the University of Liège, Belgium. 
It is only shared for research purposes. Please do not distribute it. 
B. Laugraud and M. Van Droogenbroeck, May 2016.