Add new module FrameResampling and change opencv interface
This commit is contained in:
1 parent
ce82d0a17d
commit
3ed8b0916f
7 files changed
+180
-15
No files matched your search
@@ -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 )
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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__
|
||||
@@ -63,11 +63,11 @@ SaliencyDetectionSpectral::SaliencyDetectionSpectral()
|
||||
m_bBinaryMap = false;
|
||||
}
|
||||
|
||||
bool SaliencyDetectionSpectral::create_using_opencv( std::vector<Mat*> apcMatList )
|
||||
cv::Mat* SaliencyDetectionSpectral::create_using_opencv( std::vector<Mat*> 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<Mat*> apcMatList )
|
||||
@@ -93,11 +93,11 @@ SaliencyDetectionFineGrained::SaliencyDetectionFineGrained()
|
||||
m_pchModuleTooltip = "Measure saliency using fine grained method";
|
||||
}
|
||||
|
||||
bool SaliencyDetectionFineGrained::create_using_opencv( std::vector<Mat*> apcMatList )
|
||||
Mat* SaliencyDetectionFineGrained::create_using_opencv( std::vector<Mat*> 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<Mat*> 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<Mat*> apcMatList )
|
||||
Mat* SaliencyDetectionBinWangApr2014::create_using_opencv( std::vector<Mat*> apcMatList )
|
||||
{
|
||||
m_pcvSaliency = new Mat;
|
||||
m_ptrSaliencyAlgorithm = MotionSaliencyBinWangApr2014::create();
|
||||
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;
|
||||
}
|
||||
|
||||
Mat* SaliencyDetectionBinWangApr2014::process_using_opencv( std::vector<Mat*> apcMatList )
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
public:
|
||||
SaliencyDetectionSpectral();
|
||||
virtual ~SaliencyDetectionSpectral() {}
|
||||
bool create_using_opencv( std::vector<Mat*> apcMatList );
|
||||
Mat* create_using_opencv( std::vector<Mat*> apcMatList );
|
||||
Mat* process_using_opencv( std::vector<Mat*> apcMatList );
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ class SaliencyDetectionFineGrained : public SaliencyDetectionModule
|
||||
public:
|
||||
SaliencyDetectionFineGrained();
|
||||
virtual ~SaliencyDetectionFineGrained() {}
|
||||
bool create_using_opencv( std::vector<Mat*> apcMatList );
|
||||
Mat* create_using_opencv( std::vector<Mat*> apcMatList );
|
||||
Mat* process_using_opencv( std::vector<Mat*> apcMatList );
|
||||
};
|
||||
|
||||
@@ -112,7 +112,7 @@ class SaliencyDetectionBinWangApr2014 : public SaliencyDetectionModule
|
||||
public:
|
||||
SaliencyDetectionBinWangApr2014();
|
||||
virtual ~SaliencyDetectionBinWangApr2014() {}
|
||||
bool create_using_opencv( std::vector<Mat*> apcMatList );
|
||||
Mat* create_using_opencv( std::vector<Mat*> apcMatList );
|
||||
Mat* process_using_opencv( std::vector<Mat*> apcMatList );
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user