Skip to content
Snippets Groups Projects
Commit d71ebc42 authored by Andrews Sobral's avatar Andrews Sobral
Browse files

Fixes for CodeBook algorithm

parent 63cd049d
Branches
Tags
No related merge requests found
...@@ -45,6 +45,7 @@ bgs = libbgs.FrameDifference() ...@@ -45,6 +45,7 @@ bgs = libbgs.FrameDifference()
#bgs = libbgs.WeightedMovingVariance() #bgs = libbgs.WeightedMovingVariance()
#bgs = libbgs.TwoPoints() #bgs = libbgs.TwoPoints()
#bgs = libbgs.ViBe() #bgs = libbgs.ViBe()
#bgs = libbgs.CodeBook()
video_file = "dataset/video.avi" video_file = "dataset/video.avi"
......
...@@ -135,14 +135,18 @@ namespace bgslibrary ...@@ -135,14 +135,18 @@ namespace bgslibrary
if (useVideo) setUpVideo(); if (useVideo) setUpVideo();
//if (!capture) std::cerr << "Capture error..." << std::endl; //if (!capture) std::cerr << "Capture error..." << std::endl;
using namespace std::chrono_literals; //using namespace std::chrono_literals;
do do
{ {
capture >> frame; capture >> frame;
if (frame.empty()) if (frame.empty())
{ {
std::cout << "Frame is not ready" << std::endl; 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 else
break; break;
...@@ -193,7 +197,7 @@ namespace bgslibrary ...@@ -193,7 +197,7 @@ namespace bgslibrary
std::cout << "Set ROI (press ESC to skip)" << std::endl; std::cout << "Set ROI (press ESC to skip)" << std::endl;
VC_ROI::img_input1 = new IplImage(img_input); VC_ROI::img_input1 = new IplImage(img_input);
cvSetMouseCallback("Input", VC_ROI::VideoCapture_on_mouse, NULL); cvSetMouseCallback("Input", VC_ROI::VideoCapture_on_mouse, NULL);
key = cvWaitKey(0); key = cv::waitKey(0);
delete VC_ROI::img_input1; delete VC_ROI::img_input1;
} }
else else
...@@ -239,17 +243,17 @@ namespace bgslibrary ...@@ -239,17 +243,17 @@ namespace bgslibrary
//cvResetImageROI(frame); //cvResetImageROI(frame);
key = cvWaitKey(loopDelay); key = cv::waitKey(loopDelay);
//std::cout << "key: " << key << std::endl; //std::cout << "key: " << key << std::endl;
if (key == KEY_SPACE) if (key == KEY_SPACE)
key = cvWaitKey(0); key = cv::waitKey(0);
if (key == KEY_ESC) if (key == KEY_ESC)
break; break;
if (stopAt > 0 && stopAt == frameNumber) if (stopAt > 0 && stopAt == frameNumber)
key = cvWaitKey(0); key = cv::waitKey(0);
firstTime = false; firstTime = false;
} while (1); } while (1);
......
...@@ -17,8 +17,9 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>. ...@@ -17,8 +17,9 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>.
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <chrono> #include <fstream>
#include <thread> //#include <chrono>
//#include <thread>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc_c.h> #include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/imgproc/types_c.h> #include <opencv2/imgproc/types_c.h>
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include "PAWCS.h" #include "PAWCS.h"
#include "TwoPoints.h" #include "TwoPoints.h"
#include "ViBe.h" #include "ViBe.h"
#include "CodeBook.h"
using namespace bgslibrary::algorithms; using namespace bgslibrary::algorithms;
...@@ -165,6 +166,8 @@ namespace bgslibrary ...@@ -165,6 +166,8 @@ namespace bgslibrary
return (IBGS *)mxCalloc(1, sizeof(TwoPoints)); return (IBGS *)mxCalloc(1, sizeof(TwoPoints));
if (alg_name.compare("ViBe") == 0) if (alg_name.compare("ViBe") == 0)
return (IBGS *)mxCalloc(1, sizeof(ViBe)); return (IBGS *)mxCalloc(1, sizeof(ViBe));
if (alg_name.compare("CodeBook") == 0)
return (IBGS *)mxCalloc(1, sizeof(CodeBook));
return NULL; return NULL;
} }
...@@ -260,6 +263,8 @@ namespace bgslibrary ...@@ -260,6 +263,8 @@ namespace bgslibrary
return new (ptrBGS) TwoPoints(); return new (ptrBGS) TwoPoints();
if (alg_name.compare("ViBe") == 0) if (alg_name.compare("ViBe") == 0)
return new (ptrBGS) ViBe(); return new (ptrBGS) ViBe();
if (alg_name.compare("CodeBook") == 0)
return new (ptrBGS) CodeBook();
return NULL; return NULL;
} }
} }
......
...@@ -91,4 +91,5 @@ mexOpenCV -v -DMEX_COMPILE_FLAG -I"../package_bgs" backgroundSubtractor_wrapper. ...@@ -91,4 +91,5 @@ mexOpenCV -v -DMEX_COMPILE_FLAG -I"../package_bgs" backgroundSubtractor_wrapper.
"../package_bgs/ViBe.cpp" ... "../package_bgs/ViBe.cpp" ...
"../package_bgs/ViBe/vibe-background-sequential.cpp" ... "../package_bgs/ViBe/vibe-background-sequential.cpp" ...
"../package_bgs/TwoPoints.cpp" ... "../package_bgs/TwoPoints.cpp" ...
"../package_bgs/TwoPoints/two_points.cpp" "../package_bgs/TwoPoints/two_points.cpp" ...
"../package_bgs/CodeBook.cpp"
...@@ -56,4 +56,5 @@ demo; ...@@ -56,4 +56,5 @@ demo;
% demo('LOBSTER') % demo('LOBSTER')
% demo('PAWCS') % demo('PAWCS')
% demo('TwoPoints') % demo('TwoPoints')
% demo('ViBe') % demo('ViBe')
\ No newline at end of file % demo('CodeBook')
\ No newline at end of file
...@@ -260,6 +260,11 @@ namespace fs ...@@ -260,6 +260,11 @@ namespace fs
.def("apply", &ViBe::apply) .def("apply", &ViBe::apply)
.def("getBackgroundModel", &ViBe::getBackgroundModel) .def("getBackgroundModel", &ViBe::getBackgroundModel)
; ;
py::class_<CodeBook>("CodeBook")
.def("apply", &CodeBook::apply)
.def("getBackgroundModel", &CodeBook::getBackgroundModel)
;
} }
} // namespace fs } // namespace fs
} // namespace python } // namespace python
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment