diff --git a/lib/CalypOpenCVModuleIf.cpp b/lib/CalypOpenCVModuleIf.cpp index fdd6055..207f898 100644 --- a/lib/CalypOpenCVModuleIf.cpp +++ b/lib/CalypOpenCVModuleIf.cpp @@ -39,12 +39,17 @@ bool CalypOpenCVModuleIf::create( std::vector apcFrameList ) acMatList[i] = new Mat; apcFrameList[i]->toMat( *acMatList[i], m_bConvertToGray ); } - if( create_using_opencv( acMatList ) ) + Mat* outputMat = create_using_opencv( acMatList ); + if( outputMat ) { unsigned pelFormat = m_bConvertToGray ? CalypFrame::findPixelFormat( "GRAY" ) : apcFrameList[0]->getPelFormat(); - m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), pelFormat, apcFrameList[0]->getBitsPel() ); + 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]; diff --git a/lib/CalypOpenCVModuleIf.h b/lib/CalypOpenCVModuleIf.h index ea4ef34..16b7662 100644 --- a/lib/CalypOpenCVModuleIf.h +++ b/lib/CalypOpenCVModuleIf.h @@ -57,7 +57,7 @@ public: void destroy(); // API using OpenCV - virtual bool create_using_opencv( std::vector apcFrameList ) { return true; }; + virtual cv::Mat* create_using_opencv( std::vector apcFrameList ) { return NULL; }; virtual cv::Mat* process_using_opencv( std::vector apcFrameList ) = 0; virtual void destroy_using_opencv(){}; }; diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index ba97a34..69fed69 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -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 ) diff --git a/modules/FrameResampling.cpp b/modules/FrameResampling.cpp new file mode 100644 index 0000000..d8e2963 --- /dev/null +++ b/modules/FrameResampling.cpp @@ -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 + +// OpenCV +#include +#include + +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 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 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; +} diff --git a/modules/FrameResampling.h b/modules/FrameResampling.h new file mode 100644 index 0000000..bde5ded --- /dev/null +++ b/modules/FrameResampling.h @@ -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 apcFrameList ); + CalypFrame* process( std::vector apcFrameList ); + void destroy(); +}; + +#endif // __FRAMERESAMPLING_H__ diff --git a/modules/SaliencyDetection.cpp b/modules/SaliencyDetection.cpp index d895901..90755b7 100644 --- a/modules/SaliencyDetection.cpp +++ b/modules/SaliencyDetection.cpp @@ -63,11 +63,11 @@ SaliencyDetectionSpectral::SaliencyDetectionSpectral() m_bBinaryMap = false; } -bool SaliencyDetectionSpectral::create_using_opencv( std::vector apcMatList ) +cv::Mat* SaliencyDetectionSpectral::create_using_opencv( std::vector apcMatList ) { - m_pcvSaliency = new Mat; m_ptrSaliencyAlgorithm = StaticSaliencySpectralResidual::create(); - return true; + m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); + return m_pcvSaliency; } Mat* SaliencyDetectionSpectral::process_using_opencv( std::vector apcMatList ) @@ -93,11 +93,11 @@ SaliencyDetectionFineGrained::SaliencyDetectionFineGrained() m_pchModuleTooltip = "Measure saliency using fine grained method"; } -bool SaliencyDetectionFineGrained::create_using_opencv( std::vector apcMatList ) +Mat* SaliencyDetectionFineGrained::create_using_opencv( std::vector apcMatList ) { - m_pcvSaliency = new Mat; m_ptrSaliencyAlgorithm = cv::saliency::StaticSaliencyFineGrained::create(); - return true; + m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); + return m_pcvSaliency; } Mat* SaliencyDetectionFineGrained::process_using_opencv( std::vector apcMatList ) @@ -114,13 +114,13 @@ SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014() m_pchModuleTooltip = "Measure saliency using a fast self-tuning background subtraction algorithm"; } -bool SaliencyDetectionBinWangApr2014::create_using_opencv( std::vector apcMatList ) +Mat* SaliencyDetectionBinWangApr2014::create_using_opencv( std::vector apcMatList ) { - m_pcvSaliency = new Mat; m_ptrSaliencyAlgorithm = MotionSaliencyBinWangApr2014::create(); m_ptrSaliencyAlgorithm.dynamicCast()->setImagesize( apcMatList[0]->cols, apcMatList[0]->rows ); m_ptrSaliencyAlgorithm.dynamicCast()->init(); - return true; + m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); + return m_pcvSaliency; } Mat* SaliencyDetectionBinWangApr2014::process_using_opencv( std::vector apcMatList ) diff --git a/modules/SaliencyDetection.h b/modules/SaliencyDetection.h index 62075e0..5974e48 100644 --- a/modules/SaliencyDetection.h +++ b/modules/SaliencyDetection.h @@ -75,7 +75,7 @@ private: public: SaliencyDetectionSpectral(); virtual ~SaliencyDetectionSpectral() {} - bool create_using_opencv( std::vector apcMatList ); + Mat* create_using_opencv( std::vector apcMatList ); Mat* process_using_opencv( std::vector apcMatList ); }; @@ -95,7 +95,7 @@ class SaliencyDetectionFineGrained : public SaliencyDetectionModule public: SaliencyDetectionFineGrained(); virtual ~SaliencyDetectionFineGrained() {} - bool create_using_opencv( std::vector apcMatList ); + Mat* create_using_opencv( std::vector apcMatList ); Mat* process_using_opencv( std::vector apcMatList ); }; @@ -112,7 +112,7 @@ class SaliencyDetectionBinWangApr2014 : public SaliencyDetectionModule public: SaliencyDetectionBinWangApr2014(); virtual ~SaliencyDetectionBinWangApr2014() {} - bool create_using_opencv( std::vector apcMatList ); + Mat* create_using_opencv( std::vector apcMatList ); Mat* process_using_opencv( std::vector apcMatList ); };