Merge branch 'master' into develPythonModules

This commit is contained in:
jfmcarreira committed 2019-11-23 01:26:22 +00:00
commit 53ddd3e6bf
8 files changed
+356 -86

No files matched your search

+4 -1
View File
@@ -29,12 +29,12 @@ set(Calyp_Lib_SRCS
CalypOptions.cpp
# Modules
CalypModuleIf.h
CalypOpenCVModuleIf.h
)
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${PROJECT_LIBRARY} )
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR} )
IF( USE_FFMPEG )
LIST( APPEND Calyp_Lib_SRCS StreamHandlerLibav.h )
LIST( APPEND Calyp_Lib_SRCS StreamHandlerLibav.cpp )
@@ -47,6 +47,8 @@ IF( USE_OPENCV )
LIST( APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.h )
LIST( APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.cpp )
LIST( APPEND Calyp_Lib_SRCS CalypOpenCVModuleIf.cpp )
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${OpenCV_LIBRARIES} )
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS} )
ENDIF()
@@ -63,6 +65,7 @@ set(Calyp_Lib_HEADERS
CalypStream.h
CalypOptions.h
CalypModuleIf.h
CalypOpenCVModuleIf.h
)
CONFIGURE_FILE( CalypConfig.cmake.in CalypConfig.cmake @ONLY)
+83
View File
@@ -0,0 +1,83 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2019 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file CalypOpenCVModuleIf.cpp
* \brief Calyp modules interface for OpenCV
*/
#include "CalypOpenCVModuleIf.h"
// OpenCV
#include <opencv2/opencv.hpp>
using cv::Mat;
bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
bool bRet = false;
std::vector<Mat*> acMatList( apcFrameList.size() );
for( unsigned i = 0; i < apcFrameList.size(); i++ )
{
acMatList[i] = new Mat;
apcFrameList[i]->toMat( *acMatList[i], m_bConvertToGray );
}
Mat* outputMat = create_using_opencv( acMatList );
if( outputMat )
{
unsigned pelFormat = m_bConvertToGray ? CalypFrame::findPixelFormat( "GRAY" ) : apcFrameList[0]->getPelFormat();
m_pcOutputFrame = new CalypFrame( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() );
bRet = true;
}
else
{
return false;
}
for( unsigned i = 0; i < apcFrameList.size(); i++ )
{
delete acMatList[i];
}
return bRet;
}
CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList )
{
m_pcOutputFrame->reset();
std::vector<Mat*> acMatList( apcFrameList.size() );
for( unsigned i = 0; i < apcFrameList.size(); i++ )
{
acMatList[i] = new Mat;
apcFrameList[i]->toMat( *acMatList[i], m_bConvertToGray );
}
Mat* cvOutput = process_using_opencv( acMatList );
m_pcOutputFrame->fromMat( *cvOutput );
for( unsigned i = 0; i < apcFrameList.size(); i++ )
{
delete acMatList[i];
}
return m_pcOutputFrame;
}
void CalypOpenCVModuleIf::destroy()
{
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
}
+65
View File
@@ -0,0 +1,65 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2019 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file CalypOpenCVModuleIf.h
* \ingroup CalypLibGroup
* \brief Calyp modules interface for OpenCV
*/
#ifndef __CALYPOPENCVMODULEIF_H__
#define __CALYPOPENCVMODULEIF_H__
#include "CalypModuleIf.h"
namespace cv
{
class Mat;
}
/**
* \class CalypOpenCVModuleIf
* \ingroup CalypLib Calyp_Modules
* \brief Abstract class for modules using OpenCV library
*/
class CalypOpenCVModuleIf : public CalypModuleIf
{
protected:
const char* m_pchPythonFunctionName;
bool m_bConvertToGray;
public:
CalypOpenCVModuleIf()
{
m_bConvertToGray = false;
};
virtual ~CalypOpenCVModuleIf() {}
// Common API
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
void destroy();
// API using OpenCV
virtual cv::Mat* create_using_opencv( std::vector<cv::Mat*> apcFrameList ) { return NULL; };
virtual cv::Mat* process_using_opencv( std::vector<cv::Mat*> apcFrameList ) = 0;
virtual void destroy_using_opencv(){};
};
#endif // __CALYPOPENCVMODULEIF_H__
+2
View File
@@ -46,6 +46,8 @@ ADD_MODULE_USE_OPENCV( SaliencyDetectionSpectral "SaliencyDetection" VERSION 3.3
ADD_MODULE_USE_OPENCV( SaliencyDetectionFineGrained "SaliencyDetection" VERSION 3.3.0 MODULES saliency )
ADD_MODULE_USE_OPENCV( SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency )
ADD_MODULE_USE_OPENCV( FrameResampling "FrameResampling" VERSION 3.3.0 MODULES core )
ADD_MODULE_USE_OPENCV( ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core )
ADD_MODULE_USE_OPENCV( ThreeSixtyFaceExtraction "ThreeSixtyFaceExtraction" VERSION 3.1.0 MODULES core )
ADD_MODULE_USE_OPENCV( ThreeSixtyFaceConcatenation "ThreeSixtyFaceConcatenation" VERSION 3.1.0 MODULES core )
+104
View File
@@ -0,0 +1,104 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2019 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file FrameResampling.cpp
* \brief Modules to resampling frames
*/
#include "FrameResampling.h"
#include <cstdlib>
// OpenCV
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc.hpp>
using cv::Mat;
using cv::Size;
FrameResampling::FrameResampling()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "Utilities";
m_pchModuleName = "FrameResampling";
m_pchModuleLongName = "Frame Resampling";
m_pchModuleTooltip = "Resampling frame to an abritary resolution";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS;
m_cModuleOptions.addOptions() /**/
( "width", m_iWidth, "Width of the crop region [-1]" ) /**/
( "height", m_iHeight, "Height of the crop region [-1]" ) /**/
( "Interpolation", m_iInterpolation, "Interpolation method (1-4) [4]" ) ;
m_iInterpolation = 4;
m_iWidth = -1;
m_iHeight = -1;
}
bool FrameResampling::create( std::vector<CalypFrame*> apcFrameList )
{
switch( m_iInterpolation )
{
case 2:
m_iInterpolation = cv::INTER_LINEAR;
break;
case 3:
m_iInterpolation = cv::INTER_CUBIC;
break;
case 4:
m_iInterpolation = cv::INTER_LANCZOS4;
break;
default:
m_iInterpolation = cv::INTER_NEAREST;
}
if( m_iWidth == -1 )
{
m_iWidth = apcFrameList[0]->getWidth();
}
if( m_iHeight == -1 )
{
m_iHeight = apcFrameList[0]->getHeight() * double( m_iWidth ) / double( apcFrameList[0]->getWidth() );
}
m_pcOutputFrame = new CalypFrame( m_iWidth, m_iHeight, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() );
return m_pcOutputFrame;
}
CalypFrame* FrameResampling::process( std::vector<CalypFrame*> apcFrameList )
{
m_pcOutputFrame->reset();
for( unsigned ch = 0; ch < apcFrameList[0]->getNumberChannels(); ch++ )
{
Mat inputFrame, outputFrame;
cv::Size outSize( m_pcOutputFrame->getWidth( ch ), m_pcOutputFrame->getHeight( ch ) );
apcFrameList[0]->toMat( inputFrame, true, false, ch );
cv::resize( inputFrame, outputFrame, outSize, 0, 0, m_iInterpolation );
m_pcOutputFrame->fromMat( outputFrame, ch );
}
return m_pcOutputFrame;
}
void FrameResampling::destroy()
{
if( m_pcOutputFrame )
delete m_pcOutputFrame;
}
+54
View File
@@ -0,0 +1,54 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2019 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file FrameResampling.h
* \brief Modules to resampling frames
*/
#ifndef __FRAMERESAMPLING_H__
#define __FRAMERESAMPLING_H__
// CalypLib
#include "lib/CalypModuleIf.h"
/**
* \ingroup Calyp_Modules
* @defgroup Calyp_Modules_Saliency Saliency
* @{
* Frame processing modules for saliency detection
* @}
*/
class FrameResampling : public CalypModuleIf
{
REGISTER_CLASS_FACTORY( FrameResampling )
private:
int m_iWidth;
int m_iHeight;
int m_iInterpolation;
public:
FrameResampling();
virtual ~FrameResampling() {}
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
void destroy();
};
#endif // __FRAMERESAMPLING_H__
+31 -69
View File
@@ -40,34 +40,12 @@ SaliencyDetectionModule::SaliencyDetectionModule()
m_pchModuleCategory = "Saliency";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_NEW_WINDOW;
m_pcSaliencyFrame = NULL;
m_bConvertToGray = true;
}
bool SaliencyDetectionModule::commonCreate( std::vector<CalypFrame*> apcFrameList )
void SaliencyDetectionModule::destroy_using_opencv()
{
_BASIC_MODULE_API_2_CHECK_
m_pcSaliencyFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
return true;
}
bool SaliencyDetectionModule::commonProcess( std::vector<CalypFrame*> apcFrameList )
{
Mat cvFrame;
if( !apcFrameList[0]->toMat( cvFrame, true ) )
{
return m_pcSaliencyFrame;
}
cvFrame.copyTo( m_matSaliency );
return m_ptrSaliencyAlgorithm->computeSaliency( cvFrame, m_matSaliency );
}
void SaliencyDetectionModule::destroy()
{
if( m_pcSaliencyFrame )
delete m_pcSaliencyFrame;
delete m_pcvSaliency;
}
SaliencyDetectionSpectral::SaliencyDetectionSpectral()
@@ -85,36 +63,26 @@ SaliencyDetectionSpectral::SaliencyDetectionSpectral()
m_bBinaryMap = false;
}
bool SaliencyDetectionSpectral::create( std::vector<CalypFrame*> apcFrameList )
cv::Mat* SaliencyDetectionSpectral::create_using_opencv( std::vector<Mat*> apcMatList )
{
bool bRet = commonCreate( apcFrameList );
if( !bRet )
return bRet;
m_ptrSaliencyAlgorithm = StaticSaliencySpectralResidual::create();
return true;
m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 );
return m_pcvSaliency;
}
CalypFrame* SaliencyDetectionSpectral::process( std::vector<CalypFrame*> apcFrameList )
Mat* SaliencyDetectionSpectral::process_using_opencv( std::vector<Mat*> apcMatList )
{
if( commonProcess( apcFrameList ) )
Mat cvSaliency;
m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], cvSaliency );
Mat cvBinaryMap;
StaticSaliencySpectralResidual spec;
spec.computeBinaryMap( cvSaliency, *m_pcvSaliency );
if( !m_bBinaryMap )
{
Mat matBinaryMap;
StaticSaliencySpectralResidual spec;
spec.computeBinaryMap( m_matSaliency, matBinaryMap );
if( m_bBinaryMap )
{
m_pcSaliencyFrame->fromMat( matBinaryMap );
}
else
{
m_matSaliency *= 255;
m_matSaliency.convertTo( m_matSaliency, CV_8UC1 );
m_pcSaliencyFrame->fromMat( m_matSaliency );
}
cvSaliency *= 255;
cvSaliency.convertTo( *m_pcvSaliency, CV_8UC1 );
}
return m_pcSaliencyFrame;
return m_pcvSaliency;
}
SaliencyDetectionFineGrained::SaliencyDetectionFineGrained()
@@ -125,20 +93,17 @@ SaliencyDetectionFineGrained::SaliencyDetectionFineGrained()
m_pchModuleTooltip = "Measure saliency using fine grained method";
}
bool SaliencyDetectionFineGrained::create( std::vector<CalypFrame*> apcFrameList )
Mat* SaliencyDetectionFineGrained::create_using_opencv( std::vector<Mat*> apcMatList )
{
bool bRet = commonCreate( apcFrameList );
if( !bRet )
return bRet;
m_ptrSaliencyAlgorithm = cv::saliency::StaticSaliencyFineGrained::create();
return true;
m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 );
return m_pcvSaliency;
}
CalypFrame* SaliencyDetectionFineGrained::process( std::vector<CalypFrame*> apcFrameList )
Mat* SaliencyDetectionFineGrained::process_using_opencv( std::vector<Mat*> apcMatList )
{
if( commonProcess( apcFrameList ) )
m_pcSaliencyFrame->fromMat( m_matSaliency );
return m_pcSaliencyFrame;
m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], *m_pcvSaliency );
return m_pcvSaliency;
}
SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014()
@@ -149,25 +114,22 @@ SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014()
m_pchModuleTooltip = "Measure saliency using a fast self-tuning background subtraction algorithm";
}
bool SaliencyDetectionBinWangApr2014::create( std::vector<CalypFrame*> apcFrameList )
Mat* SaliencyDetectionBinWangApr2014::create_using_opencv( std::vector<Mat*> apcMatList )
{
bool bRet = commonCreate( apcFrameList );
if( !bRet )
return bRet;
m_ptrSaliencyAlgorithm = MotionSaliencyBinWangApr2014::create();
m_ptrSaliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->setImagesize( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight() );
m_ptrSaliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->setImagesize( apcMatList[0]->cols, apcMatList[0]->rows );
m_ptrSaliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->init();
return true;
m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 );
return m_pcvSaliency;
}
CalypFrame* SaliencyDetectionBinWangApr2014::process( std::vector<CalypFrame*> apcFrameList )
Mat* SaliencyDetectionBinWangApr2014::process_using_opencv( std::vector<Mat*> apcMatList )
{
if( commonProcess( apcFrameList ) )
if( m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], *m_pcvSaliency ) )
{
m_matSaliency *= 255;
m_matSaliency.convertTo( m_matSaliency, CV_8UC1 );
*m_pcvSaliency *= 255;
m_pcvSaliency->convertTo( *m_pcvSaliency, CV_8UC1 );
//cv::cvtColor(m_matSaliency, m_matSaliency, cv::COLOR_BGR2GRAY);
m_pcSaliencyFrame->fromMat( m_matSaliency );
}
return m_pcSaliencyFrame;
return m_pcvSaliency;
}
+13 -16
View File
@@ -25,12 +25,14 @@
#ifndef __SALIENCYDETECTION_H__
#define __SALIENCYDETECTION_H__
// CalypLib
#include "lib/CalypOpenCVModuleIf.h"
// OpenCV
#include <opencv2/core/core.hpp>
#include <opencv2/saliency.hpp>
// CalypLib
#include "lib/CalypModuleIf.h"
using cv::Mat;
/**
* \ingroup Calyp_Modules
@@ -40,21 +42,16 @@
* @}
*/
class SaliencyDetectionModule : public CalypModuleIf
class SaliencyDetectionModule : public CalypOpenCVModuleIf
{
protected:
CalypFrame* m_pcSaliencyFrame;
Mat* m_pcvSaliency;
cv::Ptr<cv::saliency::Saliency> m_ptrSaliencyAlgorithm;
cv::Mat m_matSaliency;
bool commonCreate( std::vector<CalypFrame*> apcFrameList );
bool commonProcess( std::vector<CalypFrame*> apcFrameList );
public:
SaliencyDetectionModule();
virtual ~SaliencyDetectionModule() {}
void destroy();
void destroy_using_opencv();
};
/**
@@ -78,8 +75,8 @@ private:
public:
SaliencyDetectionSpectral();
virtual ~SaliencyDetectionSpectral() {}
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
Mat* create_using_opencv( std::vector<Mat*> apcMatList );
Mat* process_using_opencv( std::vector<Mat*> apcMatList );
};
/**
@@ -98,8 +95,8 @@ class SaliencyDetectionFineGrained : public SaliencyDetectionModule
public:
SaliencyDetectionFineGrained();
virtual ~SaliencyDetectionFineGrained() {}
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
Mat* create_using_opencv( std::vector<Mat*> apcMatList );
Mat* process_using_opencv( std::vector<Mat*> apcMatList );
};
/**
@@ -115,8 +112,8 @@ class SaliencyDetectionBinWangApr2014 : public SaliencyDetectionModule
public:
SaliencyDetectionBinWangApr2014();
virtual ~SaliencyDetectionBinWangApr2014() {}
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
Mat* create_using_opencv( std::vector<Mat*> apcMatList );
Mat* process_using_opencv( std::vector<Mat*> apcMatList );
};
#endif // __SALIENCYDETECTION_H__