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

Updated QT project, removed Amber algorithm (unused), small fixes and improvements

parent ee241fb9
Branches
Tags
No related merge requests found
......@@ -3,7 +3,7 @@
int main(int argc, char *argv[])
{
std::cout << "--------------------------------------------" << std::endl;
std::cout << "Background Subtraction Library v2.0.0 " << std::endl;
std::cout << "Background Subtraction Library v3.0.0 " << std::endl;
std::cout << "https://github.com/andrewssobral/bgslibrary " << std::endl;
std::cout << "by: " << std::endl;
std::cout << "Andrews Sobral (andrewssobral@gmail.com) " << std::endl;
......@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
QCoreApplication::setApplicationName("BGSLibrary");
QCoreApplication::setApplicationVersion("2.0.0");
QCoreApplication::setApplicationVersion("3.0.0");
MainWindow w;
w.show();
......
......@@ -11,18 +11,10 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = bgslibrary_gui
TEMPLATE = app
# For Windows x64 + Visual Studio 2015 + OpenCV 3.1.0
#INCLUDEPATH += C:/OpenCV3.1.0/build/include
#LIBS += -LC:/OpenCV3.1.0/build/x64/vc14/lib -lopencv_world310
# For Windows x64 + Visual Studio 2015 + OpenCV 3.2.0
#INCLUDEPATH += C:/OpenCV3.2.0/build/include
#LIBS += -LC:/OpenCV3.2.0/build/x64/vc14/lib -lopencv_world320
# For Windows x64 + Visual Studio 2017 + OpenCV 3.4.2
INCLUDEPATH += E:/OpenCV3.4.2/build/include
INCLUDEPATH += E:/OpenCV3.4.2/build/include/opencv
LIBS += -LE:/OpenCV3.4.2/build/x64/vc15/lib -lopencv_world342
# For Windows x64 + Visual Studio 2015 + OpenCV 4.1.1
INCLUDEPATH += E:/OpenCV/opencv-4.1.1/build/include
Release:LIBS += -LE:/OpenCV/opencv-4.1.1/build/x64/vc14/lib -lopencv_world411
Debug:LIBS += -LE:/OpenCV/opencv-4.1.1/build/x64/vc14/lib -lopencv_world411d
# For Linux
# INCLUDEPATH += /usr/local/include/opencv
......@@ -37,8 +29,6 @@ SOURCES += bgslibrary_gui.cpp\
../../src/package_analysis/ForegroundMaskAnalysis.cpp \
../../src/package_analysis/PerformanceUtils.cpp \
../../src/package_analysis/PixelUtils.cpp \
../../src/package_bgs/_template_/Amber.cpp \
../../src/package_bgs/_template_/MyBGS.cpp \
../../src/package_bgs/dp/AdaptiveMedianBGS.cpp \
../../src/package_bgs/dp/Eigenbackground.cpp \
../../src/package_bgs/dp/Error.cpp \
......@@ -129,8 +119,8 @@ SOURCES += bgslibrary_gui.cpp\
../../src/package_bgs/VuMeter.cpp \
../../src/package_bgs/WeightedMovingMean.cpp \
../../src/package_bgs/WeightedMovingVariance.cpp \
../../src/package_bgs/_template_/amber/amber.cpp \
../../src/package_bgs/CodeBook.cpp
../../src/package_bgs/_template_/MyBGS.cpp \
HEADERS += mainwindow.h \
qt_utils.h \
......@@ -138,9 +128,6 @@ HEADERS += mainwindow.h \
../../src/package_analysis/ForegroundMaskAnalysis.h \
../../src/package_analysis/PerformanceUtils.h \
../../src/package_analysis/PixelUtils.h \
../../src/package_bgs/_template_/amber/amber.h \
../../src/package_bgs/_template_/Amber.h \
../../src/package_bgs/_template_/MyBGS.h \
../../src/package_bgs/dp/AdaptiveMedianBGS.h \
../../src/package_bgs/dp/Bgs.h \
../../src/package_bgs/dp/BgsParams.h \
......@@ -244,6 +231,7 @@ HEADERS += mainwindow.h \
../../src/package_bgs/WeightedMovingMean.h \
../../src/package_bgs/WeightedMovingVariance.h \
../../src/package_bgs/CodeBook.h
../../src/package_bgs/_template_/MyBGS.h \
FORMS += mainwindow.ui
......
......@@ -24,6 +24,7 @@ namespace bgslibrary
#if CV_MAJOR_VERSION >= 3
map["KNN"] = &createInstance<KNN>; // only on OpenCV 3.x
#endif
#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
map["DPAdaptiveMedian"] = &createInstance<DPAdaptiveMedian>;
map["DPGrimsonGMM"] = &createInstance<DPGrimsonGMM>;
map["DPZivkovicAGMM"] = &createInstance<DPZivkovicAGMM>;
......@@ -50,6 +51,7 @@ namespace bgslibrary
map["KDE"] = &createInstance<KDE>;
map["IndependentMultimodal"] = &createInstance<IndependentMultimodal>;
map["MultiCue"] = &createInstance<MultiCue>;
#endif
map["SigmaDelta"] = &createInstance<SigmaDelta>;
map["SuBSENSE"] = &createInstance<SuBSENSE>;
map["LOBSTER"] = &createInstance<LOBSTER>;
......@@ -80,6 +82,7 @@ namespace bgslibrary
#if CV_MAJOR_VERSION >= 3
stringList.append("KNN"); // only on OpenCV 3.x
#endif
#if CV_MAJOR_VERSION >= 2 && CV_MAJOR_VERSION <= 3
stringList.append("DPAdaptiveMedian");
stringList.append("DPGrimsonGMM");
stringList.append("DPZivkovicAGMM");
......@@ -106,6 +109,7 @@ namespace bgslibrary
stringList.append("KDE");
stringList.append("IndependentMultimodal");
stringList.append("MultiCue");
#endif
stringList.append("SigmaDelta");
stringList.append("SuBSENSE");
stringList.append("LOBSTER");
......@@ -128,7 +132,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->lineEdit_inputdata->setText(fileName);
//fileName = ui->lineEdit_inputdata->text();
timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(startCapture()));
QStringListModel* listModel = new QStringListModel(bgslibrary::get_algs_name(), NULL);
QStringListModel* listModel = new QStringListModel(bgslibrary::get_algs_name(), nullptr);
listModel->sort(0);
ui->listView_algorithms->setModel(listModel);
QModelIndex index = listModel->index(0);
......@@ -285,7 +289,7 @@ void MainWindow::setFrameNumber(long long _frameNumber)
{
//std::cout << "setFrameNumber()" << std::endl;
frameNumber = _frameNumber;
QString txt_frameNumber = QString::fromStdString(its(frameNumber));
QString txt_frameNumber = QString::fromStdString(to_string(frameNumber));
ui->label_framenumber_txt->setText(txt_frameNumber);
}
......@@ -309,12 +313,12 @@ bool MainWindow::setUpCapture()
}
if (useCamera || useVideo) {
int capture_fps = capture.get(CV_CAP_PROP_FPS);
int capture_fps = static_cast<int>(capture.get(CV_CAP_PROP_FPS));
std::cout << "capture_fps: " << capture_fps << std::endl;
}
if (useVideo) {
capture_length = capture.get(CV_CAP_PROP_FRAME_COUNT);
capture_length = static_cast<int>(capture.get(CV_CAP_PROP_FRAME_COUNT));
std::cout << "capture_length: " << capture_length << std::endl;
}
......@@ -333,7 +337,7 @@ void MainWindow::startCapture()
if (useSequence && (frameNumber - 1) < entryList.length())
{
QString file = entryList.at(frameNumber - 1);
QString file = entryList.at(static_cast<int>(frameNumber - 1));
QString filePath = QDir(fileName).filePath(file);
std::cout << "Processing: " << filePath.toStdString() << std::endl;
......@@ -351,15 +355,15 @@ void MainWindow::startCapture()
{
int frame_width = cv_frame.size().width;
int frame_height = cv_frame.size().height;
ui->label_frameresw_txt->setText(QString::fromStdString(its(frame_width)));
ui->label_frameresh_txt->setText(QString::fromStdString(its(frame_height)));
ui->label_frameresw_txt->setText(QString::fromStdString(to_string(frame_width)));
ui->label_frameresh_txt->setText(QString::fromStdString(to_string(frame_height)));
}
if (useVideo && capture_length > 0)
{
double perc = (double(frameNumber) / double(capture_length)) * 100.0;
//std::cout << "perc: " << perc << std::endl;
ui->progressBar->setValue(perc);
ui->progressBar->setValue(static_cast<int>(perc));
}
int startAt = ui->spinBox_startat->value();
......@@ -402,7 +406,7 @@ void MainWindow::processFrame(const cv::Mat &cv_frame)
tic();
bgs->process(cv_frame, cv_fg, cv_bg);
toc();
ui->label_fps_txt->setText(QString::fromStdString(its(fps())));
ui->label_fps_txt->setText(QString::fromStdString(to_string(fps())));
cv::Mat cv_fg_small;
cv::resize(cv_fg, cv_fg_small, cv::Size(250, 250));
......
......@@ -15,6 +15,15 @@
#include <QCollator>
#include <opencv2/opencv.hpp>
//#include <opencv2/imgproc/types_c.h>
//#include <opencv2/imgproc/imgproc_c.h>
//#include <opencv2/highgui/highgui_c.h>
#if CV_MAJOR_VERSION >= 4
#define CV_CAP_PROP_POS_FRAMES cv::CAP_PROP_POS_FRAMES
#define CV_CAP_PROP_FRAME_COUNT cv::CAP_PROP_FRAME_COUNT
#define CV_CAP_PROP_FPS cv::CAP_PROP_FPS
#endif
#include "qt_utils.h"
#include "texteditor.h"
......@@ -38,7 +47,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
......
......@@ -3,19 +3,21 @@
QImage GrayMat2QImage(cv::Mat const& src) {
cv::Mat temp;
src.copyTo(temp);
QImage dest((const uchar *)temp.data, temp.cols, temp.rows, temp.step, QImage::Format_Indexed8);
QImage dest((const uchar *)temp.data, temp.cols, temp.rows, static_cast<int>(temp.step), QImage::Format_Indexed8);
dest.bits();
return dest;
}
QImage Mat2QImage(cv::Mat const& src) {
cv::Mat temp;
cvtColor(src, temp, CV_BGR2RGB);
QImage dest((const uchar *)temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
QImage dest((const uchar *)temp.data, temp.cols, temp.rows, static_cast<int>(temp.step), QImage::Format_RGB888);
dest.bits();
return dest;
}
cv::Mat QImage2Mat(QImage const& src) {
cv::Mat tmp(src.height(), src.width(), CV_8UC3, (uchar*)src.bits(), src.bytesPerLine());
cv::Mat tmp(src.height(), src.width(), CV_8UC3, (uchar*)src.bits(), static_cast<size_t>(src.bytesPerLine()));
cv::Mat result;
cvtColor(tmp, result, CV_RGB2BGR);
return result;
......@@ -26,29 +28,38 @@ QString base64_encode(const QString string) {
ba.append(string);
return ba.toBase64();
}
QString base64_decode(const QString string) {
QByteArray ba;
ba.append(string);
return QByteArray::fromBase64(ba);
}
QString md5_encode(const QString string) {
QByteArray ba;
ba.append(string);
return QString(QCryptographicHash::hash((ba), QCryptographicHash::Md5).toHex());
}
int sti(const std::string &s) {
int str2int(const std::string &s) {
int i;
std::stringstream ss;
ss << s;
ss >> i;
return i;
}
std::string its(int i) {
template<typename T>
std::string to_string(T t) {
std::stringstream ss;
ss << i;
ss << t;
return ss.str();
}
template std::string to_string<double>(double);
template std::string to_string<int>(int);
template std::string to_string<size_t>(size_t);
template std::string to_string<long>(long);
template std::string to_string<long long>(long long);
bool fileExists(QString path) {
QFileInfo check_file(path);
......
......@@ -2,11 +2,14 @@
#include <sstream>
#include <string>
#include <QByteArray>
#include <QImage>
#include <QCryptographicHash>
#include <QFileInfo>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>
QImage GrayMat2QImage(cv::Mat const& src);
QImage Mat2QImage(cv::Mat const& src);
......@@ -16,8 +19,10 @@ QString base64_encode(const QString string);
QString base64_decode(const QString string);
QString md5_encode(const QString);
int sti(const std::string &s);
std::string its(int i);
int str2int(const std::string &s);
template<typename T>
std::string to_string(T t);
bool fileExists(QString path);
......
......@@ -7,8 +7,8 @@
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/types_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/highgui/highgui_c.h>
//#include <opencv2/imgproc/imgproc_c.h>
//#include <opencv2/highgui/highgui_c.h>
#include "package_bgs/ILoadSaveConfig.h"
......
#include "Amber.h"
using namespace bgslibrary::algorithms;
Amber::Amber() : model(nullptr)
{
std::cout << "Amber()" << std::endl;
/* Initialization of the Amber model */
model = libamberModelNew();
setup("./config/Amber.xml");
}
Amber::~Amber()
{
std::cout << "~Amber()" << std::endl;
libamberModelFree(model);
}
void Amber::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel)
{
init(img_input, img_output, img_bgmodel);
if (img_input.empty())
return;
// Start the initialization
unsigned int width = img_input.cols;
unsigned int height = img_input.rows;
if (img_input.channels() != 3)
{
std::cout << "Only works for 3 channels images. Sorry for that" << std::endl;
return;
}
//unsigned int stride = width * 3;
unsigned char* image = static_cast<unsigned char*>(img_input.data);
if (firstTime)
{
/* Create a buffer for the output image */
//img_output = Mat(img_input.rows, img_input.cols, CV_8UC1);
/* Sets default model values */
// libamberModelSetNumberOfSamples(model, nbSamples);
// libamberModelSetMatchingThreshold(model, matchingThreshold);
// libamberModelSetMatchingNumber(model, matchingNumber);
// libamberModelSetUpdateFactor(model, init_subsamplingFactor);
// libamberModelPrintParameters(model);
/* Initiliazes the Amber model */
libamberModelAllocInit_8u_C3R(model, image, width, height);
}
/* Create temporary buffers */
unsigned char* output_segmentationMap = static_cast<unsigned char*>(calloc(width * height, sizeof(unsigned char)));
libamberGetSegmentation_8u_C3R(model, image, output_segmentationMap);
unsigned char* oBuffer = static_cast<unsigned char*>(img_output.data);
unsigned char* tmpSegmentationMap = output_segmentationMap;
for (unsigned int i = 0; i < width * height; i++)
{
*oBuffer = *tmpSegmentationMap;
++oBuffer;
++tmpSegmentationMap;
}
#ifndef MEX_COMPILE_FLAG
if (showOutput)
imshow("Amber", img_output);
#endif
firstTime = false;
free(output_segmentationMap);
}
void Amber::saveConfig()
{
cv::FileStorage fs(config_xml, cv::FileStorage::WRITE);
fs << "showOutput" << showOutput;
fs.release();
}
void Amber::loadConfig()
{
cv::FileStorage fs;
fs.open(config_xml, cv::FileStorage::READ);
fs["showOutput"] >> showOutput;
fs.release();
}
#pragma once
#include <math.h>
#include <sys/types.h>
#include "../IBGS.h"
#include "../ILoadSaveConfig.h"
#include "amber/amber.h"
namespace bgslibrary
{
namespace algorithms
{
class Amber : public IBGS, public ILoadSaveConfig
{
private:
amberModel* model;
public:
Amber();
~Amber();
void process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel);
private:
void saveConfig();
void loadConfig();
};
static BGS_Register<Amber> register_Amber("Amber");
}
}
#include "amber.h"
#define COLOR_BACKGROUND 0
#define COLOR_FOREGROUND 255
amberModel* libamberModelNew()
{
/* model structure alloc */
amberModel* model = NULL;
model = (amberModel*)calloc(1, sizeof(amberModel));
assert(model != NULL);
/* default parameters values */
model->height = 0;
return(model);
}
// --------------------------------------------------
int32_t libamberModelAllocInit_8u_C3R(amberModel* model,
const uint8_t *image_data,
const uint32_t width,
const uint32_t height)
{
/* basic checks */
assert((image_data != NULL) && (model != NULL));
assert((model->width > 0) && (model->height > 0));
/* finish model alloc - parameters values cannot be changed anymore */
model->width = width;
model->height = height;
return(0);
}
// --------------------------------------------------
int32_t libamberGetSegmentation_8u_C3R(amberModel* model,
const uint8_t *image_data,
uint8_t *segmentation_map)
{
/* basic checks */
assert((image_data != NULL) && (model != NULL) && (segmentation_map != NULL));
assert((model->width > 0) && (model->height > 0));
return(0);
}
// --------------------------------------------------
int32_t libamberModelFree(amberModel* model)
{
if (model == NULL)
return(-1);
free(model);
return(0);
}
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#define COLOR_BACKGROUND 0
#define COLOR_FOREGROUND 255
/* For compilation with g++ */
#ifdef __cplusplus
extern "C"
{
#endif
/* end of addition for compilation with g++ */
#ifndef _STDINT_H
// This is used to make it compatible for cross-compilation
typedef unsigned char uint8_t;
typedef int int32_t;
typedef unsigned int uint32_t;
#endif // _STDINT_H
typedef struct {
uint32_t width;
uint32_t height;
} amberModel;
/** Allocation of a new data structure where the background model
will be stored */
amberModel* libamberModelNew();
int32_t libamberModelAllocInit_8u_C3R(amberModel* model,
const uint8_t *image_data,
const uint32_t width,
const uint32_t height);
int32_t libamberGetSegmentation_8u_C3R(amberModel* model,
const uint8_t *image_data,
uint8_t *segmentation_map);
int32_t libamberModelFree(amberModel* model);
/* For compilation with g++ */
#ifdef __cplusplus
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment