Skip to content
Snippets Groups Projects
Unverified Commit 1d9d7ca1 authored by Andrews Sobral's avatar Andrews Sobral Committed by GitHub
Browse files

use smart pointers (sprint 1) (#157)

parent 7fb89288
No related branches found
No related tags found
No related merge requests found
......@@ -41,10 +41,10 @@ int main(int argc, char **argv)
frame_counter++;
std::stringstream ss;
ss << frame_counter;
std::string fileName = "dataset/frames/" + ss.str() + ".png";
auto fileName = "dataset/frames/" + ss.str() + ".png";
std::cout << "reading " << fileName << std::endl;
cv::Mat img_input = cv::imread(fileName, CV_LOAD_IMAGE_COLOR);
auto img_input = cv::imread(fileName, CV_LOAD_IMAGE_COLOR);
if (img_input.empty())
break;
......
......@@ -38,11 +38,11 @@ namespace bgslibrary
try
{
int key = KEY_ESC;
auto key = KEY_ESC;
do
{
VideoAnalysis* videoAnalysis = new VideoAnalysis;
auto videoAnalysis = std::make_unique<VideoAnalysis>();
if (videoAnalysis->setup(argc, argv))
{
......@@ -56,7 +56,6 @@ namespace bgslibrary
}
cv::destroyAllWindows();
delete videoAnalysis;
} while (key == KEY_REPEAT);
}
......
......@@ -132,8 +132,8 @@ namespace bgslibrary
do
{
videoCapture = new VideoCapture;
frameProcessor = new FrameProcessor;
videoCapture = std::make_unique<VideoCapture>();
frameProcessor = std::make_shared<FrameProcessor>();
frameProcessor->init();
frameProcessor->frameToStop = frameToStop;
......@@ -154,16 +154,10 @@ namespace bgslibrary
frameProcessor->finish();
int key = cvWaitKey(500);
auto key = cv::waitKey(500);
if (key == KEY_ESC)
break;
delete frameProcessor;
delete videoCapture;
} while (1);
delete frameProcessor;
delete videoCapture;
}
}
......@@ -27,8 +27,8 @@ namespace bgslibrary
class VideoAnalysis
{
private:
VideoCapture* videoCapture;
FrameProcessor* frameProcessor;
std::unique_ptr<VideoCapture> videoCapture;
std::shared_ptr<FrameProcessor> frameProcessor;
bool use_file;
std::string filename;
bool use_camera;
......
......@@ -90,7 +90,7 @@ namespace bgslibrary
std::cout << "~VideoCapture()" << std::endl;
}
void VideoCapture::setFrameProcessor(IFrameProcessor* frameProcessorPtr)
void VideoCapture::setFrameProcessor(std::shared_ptr<IFrameProcessor> frameProcessorPtr)
{
frameProcessor = frameProcessorPtr;
}
......
......@@ -18,6 +18,7 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
#include <fstream>
#include <memory>
//#include <chrono>
//#include <thread>
#include <opencv2/opencv.hpp>
......@@ -32,7 +33,7 @@ namespace bgslibrary
class VideoCapture
{
private:
IFrameProcessor* frameProcessor;
std::shared_ptr<IFrameProcessor> frameProcessor;
cv::VideoCapture capture;
cv::Mat frame;
int key;
......@@ -65,7 +66,7 @@ namespace bgslibrary
VideoCapture();
~VideoCapture();
void setFrameProcessor(IFrameProcessor* frameProcessorPtr);
void setFrameProcessor(std::shared_ptr<IFrameProcessor> frameProcessorPtr);
void setCamera(int cameraIndex);
void setVideo(std::string filename);
void start();
......
......@@ -56,8 +56,6 @@ namespace bgslibrary
}
virtual void process(const cv::Mat &img_input, cv::Mat &img_foreground, cv::Mat &img_background) = 0;
virtual ~IBGS() {}
//static IBGS* create(const std::string alg_name);
//static std::list<std::string> get_algs_name();
protected:
bool firstTime = true;
bool showOutput = true;
......
......@@ -22,7 +22,7 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>.
#include "StaticFrameDifference.h"
#include "WeightedMovingMean.h"
#include "WeightedMovingVariance.h"
#include "MixtureOfGaussianV1.h" // Only for OpenCV >= 2
#include "MixtureOfGaussianV1.h" // Only for OpenCV == 2
#include "MixtureOfGaussianV2.h"
#include "AdaptiveBackgroundLearning.h"
#include "AdaptiveSelectiveBackgroundLearning.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment