diff --git a/Demo.py b/Demo.py
index b1f6c02e954144f25b9b08dd6725c42afe665766..174857eb6ef1591803c4f1521af650d95530ecf0 100644
--- a/Demo.py
+++ b/Demo.py
@@ -45,6 +45,7 @@ bgs = libbgs.FrameDifference()
 #bgs = libbgs.WeightedMovingVariance()
 #bgs = libbgs.TwoPoints()
 #bgs = libbgs.ViBe()
+#bgs = libbgs.CodeBook()
 
 video_file = "dataset/video.avi"
 
diff --git a/VideoCapture.cpp b/VideoCapture.cpp
index c7e12ea13739f5c6872af4477cf252d996be3898..ed8964dda284e387ad9d0f590f09370184ec4a41 100644
--- a/VideoCapture.cpp
+++ b/VideoCapture.cpp
@@ -135,14 +135,18 @@ namespace bgslibrary
     if (useVideo)  setUpVideo();
     //if (!capture)  std::cerr << "Capture error..." << std::endl;
 
-    using namespace std::chrono_literals;
+    //using namespace std::chrono_literals;
     do
     {
       capture >> frame;
       if (frame.empty())
       {
         std::cout << "Frame is not ready" << std::endl;
-        std::this_thread::sleep_for(1s);
+        std::string dummy;
+        std::cout << "Enter to continue..." << std::endl;
+        std::getline(std::cin, dummy);
+        //cv::waitKey(1000);
+        //std::this_thread::sleep_for(1s);
       }
       else
         break;
@@ -193,7 +197,7 @@ namespace bgslibrary
             std::cout << "Set ROI (press ESC to skip)" << std::endl;
             VC_ROI::img_input1 = new IplImage(img_input);
             cvSetMouseCallback("Input", VC_ROI::VideoCapture_on_mouse, NULL);
-            key = cvWaitKey(0);
+            key = cv::waitKey(0);
             delete VC_ROI::img_input1;
           }
           else
@@ -239,17 +243,17 @@ namespace bgslibrary
 
       //cvResetImageROI(frame);
 
-      key = cvWaitKey(loopDelay);
+      key = cv::waitKey(loopDelay);
       //std::cout << "key: " << key << std::endl;
 
       if (key == KEY_SPACE)
-        key = cvWaitKey(0);
+        key = cv::waitKey(0);
 
       if (key == KEY_ESC)
         break;
 
       if (stopAt > 0 && stopAt == frameNumber)
-        key = cvWaitKey(0);
+        key = cv::waitKey(0);
 
       firstTime = false;
     } while (1);
diff --git a/VideoCapture.h b/VideoCapture.h
index b7876824cde2b2b5f27641f1cff785d620d61091..8b7cd6306dbcd8352dba52861eccb3b1a412fe45 100644
--- a/VideoCapture.h
+++ b/VideoCapture.h
@@ -17,8 +17,9 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #pragma once
 
 #include <iostream>
-#include <chrono>
-#include <thread>
+#include <fstream>
+//#include <chrono>
+//#include <thread>
 #include <opencv2/opencv.hpp>
 #include <opencv2/imgproc/imgproc_c.h>
 #include <opencv2/imgproc/types_c.h>
diff --git a/wrapper_matlab/backgroundSubtractor_wrapper.cpp b/wrapper_matlab/backgroundSubtractor_wrapper.cpp
index 547012070adb5a3318282452faa650bf5aa3f6a7..96fb4a6b9d7df57e6e4c938cf2d93f8fd25aa23b 100644
--- a/wrapper_matlab/backgroundSubtractor_wrapper.cpp
+++ b/wrapper_matlab/backgroundSubtractor_wrapper.cpp
@@ -66,6 +66,7 @@
 #include "PAWCS.h"
 #include "TwoPoints.h"
 #include "ViBe.h"
+#include "CodeBook.h"
 
 using namespace bgslibrary::algorithms;
 
@@ -165,6 +166,8 @@ namespace bgslibrary
       return (IBGS *)mxCalloc(1, sizeof(TwoPoints));
     if (alg_name.compare("ViBe") == 0)
       return (IBGS *)mxCalloc(1, sizeof(ViBe));
+    if (alg_name.compare("CodeBook") == 0)
+      return (IBGS *)mxCalloc(1, sizeof(CodeBook));
     return NULL;
   }
 
@@ -260,6 +263,8 @@ namespace bgslibrary
       return new (ptrBGS) TwoPoints();
     if (alg_name.compare("ViBe") == 0)
       return new (ptrBGS) ViBe();
+    if (alg_name.compare("CodeBook") == 0)
+      return new (ptrBGS) CodeBook();
     return NULL;
   }
 }
diff --git a/wrapper_matlab/compile.m b/wrapper_matlab/compile.m
index 078834e21c860526ad45ea26e7a8b60f2f6785fe..36ddf8436c335a8a1c7d10fc2b6e958573185a95 100644
--- a/wrapper_matlab/compile.m
+++ b/wrapper_matlab/compile.m
@@ -91,4 +91,5 @@ mexOpenCV -v -DMEX_COMPILE_FLAG -I"../package_bgs" backgroundSubtractor_wrapper.
   "../package_bgs/ViBe.cpp" ...
   "../package_bgs/ViBe/vibe-background-sequential.cpp" ...
   "../package_bgs/TwoPoints.cpp" ...
-  "../package_bgs/TwoPoints/two_points.cpp"
+  "../package_bgs/TwoPoints/two_points.cpp" ...
+  "../package_bgs/CodeBook.cpp"
diff --git a/wrapper_matlab/run_demo.m b/wrapper_matlab/run_demo.m
index d7afed4efcc9934251857b2d0a6a0c6cce6fd2df..72307dea9a0e23f8e5742baf2eead9a7626c264e 100644
--- a/wrapper_matlab/run_demo.m
+++ b/wrapper_matlab/run_demo.m
@@ -56,4 +56,5 @@ demo;
 % demo('LOBSTER')
 % demo('PAWCS')
 % demo('TwoPoints')
-% demo('ViBe')
\ No newline at end of file
+% demo('ViBe')
+% demo('CodeBook')
\ No newline at end of file
diff --git a/wrapper_python/bgslibrary_module.cpp b/wrapper_python/bgslibrary_module.cpp
index edb75a8552bbc29d4e27ef72485d7859e38851c8..a8aa6247353d06e7e1c585dd2fdfcdde298d01fb 100644
--- a/wrapper_python/bgslibrary_module.cpp
+++ b/wrapper_python/bgslibrary_module.cpp
@@ -260,6 +260,11 @@ namespace fs
 				.def("apply", &ViBe::apply)
 				.def("getBackgroundModel", &ViBe::getBackgroundModel)
 				;
+
+			py::class_<CodeBook>("CodeBook")
+				.def("apply", &CodeBook::apply)
+				.def("getBackgroundModel", &CodeBook::getBackgroundModel)
+				;
 		}
 	} // namespace fs
 } // namespace python