From 115a5edec271828bca09788237274a4c53d3c534 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 19 Sep 2019 21:00:31 +0100 Subject: [PATCH] Add new modules from private repository --- CMakeLists.txt | 2 +- modules/CMakeLists.txt | 4 + modules/ThreeSixtyFaceConcatenation.cpp | 106 ++++++++++++++ modules/ThreeSixtyFaceConcatenation.h | 48 +++++++ modules/ThreeSixtyFaceExtraction.cpp | 96 +++++++++++++ modules/ThreeSixtyFaceExtraction.h | 49 +++++++ modules/ThreeSixtySpatialtoTemporal.cpp | 177 ++++++++++++++++++++++++ modules/ThreeSixtySpatialtoTemporal.h | 56 ++++++++ 8 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 modules/ThreeSixtyFaceConcatenation.cpp create mode 100644 modules/ThreeSixtyFaceConcatenation.h create mode 100644 modules/ThreeSixtyFaceExtraction.cpp create mode 100644 modules/ThreeSixtyFaceExtraction.h create mode 100644 modules/ThreeSixtySpatialtoTemporal.cpp create mode 100644 modules/ThreeSixtySpatialtoTemporal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 09fb7de..37d6a36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ SET( PROJECT_LIBRARY "Calyp" CACHE INTERNAL "" FORCE ) PROJECT( ${PROJECT_NAME} ) SET( CALYP_VERSION_MAJOR "1" ) -SET( CALYP_VERSION_MINOR "0" ) +SET( CALYP_VERSION_MINOR "1" ) SET( CALYP_VERSION_PATCH "0" ) SET( CALYP_VERSION "${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}" CACHE INTERNAL "" FORCE ) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 883c408..ba97a34 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -46,6 +46,10 @@ 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( 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 ) + IF(EXISTS ${CALYP_EXTRA_MODULES_DIR} ) ADD_EXTRA_MODULES( ${CALYP_EXTRA_MODULES_DIR} ) ENDIF() diff --git a/modules/ThreeSixtyFaceConcatenation.cpp b/modules/ThreeSixtyFaceConcatenation.cpp new file mode 100644 index 0000000..96b4567 --- /dev/null +++ b/modules/ThreeSixtyFaceConcatenation.cpp @@ -0,0 +1,106 @@ +/* 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 ThreeSixtyFaceConcatenation.cpp + */ + +#include "ThreeSixtyFaceConcatenation.h" + +#include +#include + +using cv::InputArray; +using cv::Mat; +using cv::OutputArray; +using cv::Point; +using cv::Rect; +using cv::Size; + +ThreeSixtyFaceConcatenation::ThreeSixtyFaceConcatenation() +{ + /* Module Definition */ + m_iModuleAPI = CLP_MODULE_API_2; + m_iModuleType = CLP_FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "360Video"; + m_pchModuleLongName = "Face Concatenation"; + m_pchModuleName = "ThreeSixtyFaceConcatenation"; + m_pchModuleTooltip = "Concatenate 360 video faces"; + m_uiNumberOfFrames = 1; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULES_VARIABLE_NUM_FRAMES; + + m_cModuleOptions.addOptions() /**/ + ( "projection", m_uiProjectionType, "Projection [1] \n 1: Cubemap" ) /**/ + ; + + m_uiProjectionType = 1; + m_uiFacesX = 0; + m_uiFacesY = 0; +} + +bool ThreeSixtyFaceConcatenation::create( std::vector apcFrameList ) +{ + for( unsigned int i = 0; i < apcFrameList.size(); i++ ) + if( !apcFrameList[i] ) + return false; + + for( unsigned int i = 1; i < apcFrameList.size(); i++ ) + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE | + CalypFrame::MATCH_RESOLUTION | + CalypFrame::MATCH_BITS ) ) + return false; + + switch( m_uiProjectionType ) + { + case 1: + m_uiFacesX = 3; + m_uiFacesY = 2; + break; + default: + assert( 0 ); + } + + unsigned int width = apcFrameList[0]->getWidth() * m_uiFacesX; + unsigned int height = apcFrameList[0]->getHeight() * m_uiFacesY; + + m_pcOutputFrame = new CalypFrame( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); + + return true; +} + +CalypFrame* ThreeSixtyFaceConcatenation::process( std::vector apcFrameList ) +{ + m_pcOutputFrame->reset(); + + for( unsigned i = 0; i < m_uiFacesX * m_uiFacesY; i++ ) + { + CalypFrame* pcFrame = apcFrameList[i]; + unsigned x = i % m_uiFacesX * pcFrame->getWidth(); + unsigned y = i / m_uiFacesX * pcFrame->getHeight(); + m_pcOutputFrame->copyTo( pcFrame, x, y ); + } + return m_pcOutputFrame; +} + +void ThreeSixtyFaceConcatenation::destroy() +{ + if( m_pcOutputFrame ) + delete m_pcOutputFrame; + m_pcOutputFrame = NULL; +} diff --git a/modules/ThreeSixtyFaceConcatenation.h b/modules/ThreeSixtyFaceConcatenation.h new file mode 100644 index 0000000..4f8c762 --- /dev/null +++ b/modules/ThreeSixtyFaceConcatenation.h @@ -0,0 +1,48 @@ +/* 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 ThreeSixtyFaceConcatenation.h + */ + +#ifndef __THREESIXTYFACECONCATENATION_H__ +#define __THREESIXTYFACECONCATENATION_H__ + +// CalypLib +#include "lib/CalypModuleIf.h" + +class ThreeSixtyFaceConcatenation : public CalypModuleIf +{ + REGISTER_CLASS_FACTORY( ThreeSixtyFaceConcatenation ) + +private: + CalypFrame* m_pcTmpFrame; + unsigned m_uiProjectionType; + unsigned m_uiFacesX; + unsigned m_uiFacesY; + +public: + ThreeSixtyFaceConcatenation(); + virtual ~ThreeSixtyFaceConcatenation() {} + bool create( std::vector apcFrameList ); + CalypFrame* process( std::vector apcFrameList ); + void destroy(); +}; + +#endif // __THREESIXTYFACECONCATENATION_H__ diff --git a/modules/ThreeSixtyFaceExtraction.cpp b/modules/ThreeSixtyFaceExtraction.cpp new file mode 100644 index 0000000..a7fbfdf --- /dev/null +++ b/modules/ThreeSixtyFaceExtraction.cpp @@ -0,0 +1,96 @@ +/* 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 ThreeSixtyFaceExtraction.cpp + */ + +#include "ThreeSixtyFaceExtraction.h" + +#include +#include + +using cv::InputArray; +using cv::Mat; +using cv::OutputArray; +using cv::Point; +using cv::Rect; +using cv::Size; + +ThreeSixtyFaceExtraction::ThreeSixtyFaceExtraction() +{ + /* Module Definition */ + m_iModuleAPI = CLP_MODULE_API_2; + m_iModuleType = CLP_FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "360Video"; + m_pchModuleLongName = "Face Extration"; + m_pchModuleName = "ThreeSixtyFaceExtration"; + m_pchModuleTooltip = "Extract a 360 video face"; + m_uiNumberOfFrames = 1; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY; + + m_cModuleOptions.addOptions() /**/ + ( "faceNum", m_uiFaceNum, "360 proejction face to be outputed [0]" ) /**/ + ( "projection", m_uiProjectionType, "Projection [1] \n 1: Cubemap" ) /**/ + ; + + m_uiFaceNum = 2; + m_uiProjectionType = 1; + m_uiFacesX = 0; + m_uiFacesY = 0; +} + +bool ThreeSixtyFaceExtraction::create( std::vector apcFrameList ) +{ + _BASIC_MODULE_API_2_CHECK_ + + switch( m_uiProjectionType ) + { + case 1: + m_uiFacesX = 3; + m_uiFacesY = 2; + break; + default: + assert( 0 ); + } + + unsigned int width = apcFrameList[0]->getWidth() / m_uiFacesX; + unsigned int height = apcFrameList[0]->getHeight() / m_uiFacesY; + + m_pcOutputFrame = new CalypFrame( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); + + return true; +} + +CalypFrame* ThreeSixtyFaceExtraction::process( std::vector apcFrameList ) +{ + m_pcOutputFrame->reset(); + + unsigned x = m_uiFaceNum % m_uiFacesX * m_pcOutputFrame->getWidth(); + unsigned y = ( m_uiFaceNum / m_uiFacesX ) * m_pcOutputFrame->getHeight(); + m_pcOutputFrame->copyFrom( apcFrameList[0], x, y ); + return m_pcOutputFrame; +} + +void ThreeSixtyFaceExtraction::destroy() +{ + if( m_pcOutputFrame ) + delete m_pcOutputFrame; + m_pcOutputFrame = NULL; +} diff --git a/modules/ThreeSixtyFaceExtraction.h b/modules/ThreeSixtyFaceExtraction.h new file mode 100644 index 0000000..5ae6b5d --- /dev/null +++ b/modules/ThreeSixtyFaceExtraction.h @@ -0,0 +1,49 @@ +/* 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 ThreeSixtyFaceExtraction.h + */ + +#ifndef __THREESIXTYFACEEXTRACTION_H__ +#define __THREESIXTYFACEEXTRACTION_H__ + +// CalypLib +#include "lib/CalypModuleIf.h" + +class ThreeSixtyFaceExtraction : public CalypModuleIf +{ + REGISTER_CLASS_FACTORY( ThreeSixtyFaceExtraction ) + +private: + CalypFrame* m_pcTmpFrame; + unsigned m_uiFaceNum; + unsigned m_uiProjectionType; + unsigned m_uiFacesX; + unsigned m_uiFacesY; + +public: + ThreeSixtyFaceExtraction(); + virtual ~ThreeSixtyFaceExtraction() {} + bool create( std::vector apcFrameList ); + CalypFrame* process( std::vector apcFrameList ); + void destroy(); +}; + +#endif // __THREESIXTYFACEEXTRACTION_H__ diff --git a/modules/ThreeSixtySpatialtoTemporal.cpp b/modules/ThreeSixtySpatialtoTemporal.cpp new file mode 100644 index 0000000..16f6982 --- /dev/null +++ b/modules/ThreeSixtySpatialtoTemporal.cpp @@ -0,0 +1,177 @@ +/* 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 ThreeSixtySpatialtoTemporal.cpp + * \brief Convert 360 videos from spatial to temporal + */ + +#include "ThreeSixtySpatialtoTemporal.h" + +ThreeSixtySpatialtoTemporal::ThreeSixtySpatialtoTemporal() +{ + /* Module Definition */ + m_iModuleAPI = CLP_MODULE_API_3; + m_iModuleType = CLP_FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "360Video"; + m_pchModuleLongName = "Spatial to Temporal"; + m_pchModuleName = "ThreeSixtySpatialtoTemporal"; + m_pchModuleTooltip = "Convert 360 video from Cube Map Projection to temporal frames"; + m_uiNumberOfFrames = 1; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULE_REQUIRES_OPTIONS; + + m_cModuleOptions.addOptions() /**/ + ( "spa2temp", m_uiSpatial2Temporal, "Convert from spatial to temporal [1]" ) /**/ + ( "facesX", m_uiFacesX, "Number of horizontal faces[3]" ) /**/ + ( "facesY", m_uiFacesY, "Number of vertical faces[2]" ) /**/ + ( "facesFrame", m_uiFacesPerFrame, "Faces per frame [1]" ); + + m_uiSpatial2Temporal = true; + m_uiFacesX = 3; + m_uiFacesY = 2; + m_uiFacesPerFrame = 1; + + flush(); + m_pcTmpInputFrame = NULL; + m_pcTmpFace = NULL; +} + +bool ThreeSixtySpatialtoTemporal::flush() +{ + CalypModuleIf::flush(); + m_uiCopyX = 0; + m_uiCopyY = 0; + m_uiFacesCount = 0; + return true; +}; + +bool ThreeSixtySpatialtoTemporal::needFrame() +{ + if( m_uiSpatial2Temporal ) + { + if( m_iFrameBufferCount <= 0 ) + return true; + } + else + { + return CalypModuleIf::needFrame(); + } + return false; +} + +bool ThreeSixtySpatialtoTemporal::create( std::vector apcFrameList ) +{ + _BASIC_MODULE_API_2_CHECK_ + + unsigned int iWidth; + unsigned int iHeight; + + if( m_uiSpatial2Temporal ) + { + if( apcFrameList[0]->getWidth() % m_uiFacesX || apcFrameList[0]->getHeight() % m_uiFacesY ) + return false; + + if( m_uiFacesPerFrame > m_uiFacesX * m_uiFacesY ) + return false; + + iWidth = apcFrameList[0]->getWidth() / m_uiFacesX; + iHeight = apcFrameList[0]->getHeight() / m_uiFacesY; + + m_pcTmpInputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel() ); + m_pcTmpFace = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel() ); + iWidth *= m_uiFacesPerFrame; + } + else + { + iWidth = apcFrameList[0]->getWidth() * m_uiFacesX / m_uiFacesPerFrame; + iHeight = apcFrameList[0]->getHeight() * m_uiFacesY; + } + m_pcOutputFrame = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel() ); + return true; +} + +CalypFrame* ThreeSixtySpatialtoTemporal::process( std::vector apcFrameList ) +{ + _BASIC_MODULE_API_3_BREAK_CONDITION_ + + if( m_uiSpatial2Temporal ) + { + if( m_iFrameBufferCount == 0 ) + { + m_pcTmpInputFrame->copyFrom( apcFrameList[0] ); + m_uiCopyX = 0; + m_uiCopyY = 0; + m_iFrameBufferCount = m_uiFacesX * m_uiFacesY; + } + + for( unsigned i = 0; i < m_uiFacesPerFrame; i++ ) + { + m_pcTmpFace->copyFrom( m_pcTmpInputFrame, m_uiCopyX, m_uiCopyY ); + m_pcOutputFrame->copyTo( m_pcTmpFace, m_pcTmpFace->getWidth() * i, 0 ); + m_iFrameBufferCount--; + m_uiCopyX += m_pcTmpFace->getWidth(); + if( m_uiCopyX >= m_pcTmpInputFrame->getWidth() ) + { + m_uiCopyX = 0; + m_uiCopyY += m_pcTmpFace->getHeight(); + } + } + } + else + { + m_pcOutputFrame->copyTo( apcFrameList[0], m_uiCopyX, m_uiCopyY ); + m_uiFacesCount += m_uiFacesPerFrame; + + m_uiCopyX += apcFrameList[0]->getWidth(); + if( m_uiCopyX >= m_pcOutputFrame->getWidth() ) + { + m_uiCopyX = 0; + m_uiCopyY += apcFrameList[0]->getHeight(); + } + if( m_uiFacesCount < ( m_uiFacesX * m_uiFacesY ) ) + { + return NULL; + } + m_iFrameBufferCount = 0; + m_uiCopyX = 0; + m_uiCopyY = 0; + m_uiFacesCount = 0; + return m_pcOutputFrame; + } + + return m_pcOutputFrame; +} + +void ThreeSixtySpatialtoTemporal::destroy() +{ + if( m_pcOutputFrame ) + delete m_pcOutputFrame; + m_pcOutputFrame = NULL; + + if( m_pcTmpInputFrame ) + delete m_pcTmpInputFrame; + m_pcTmpInputFrame = NULL; + + if( m_pcTmpFace ) + delete m_pcTmpFace; + m_pcTmpFace = NULL; +} diff --git a/modules/ThreeSixtySpatialtoTemporal.h b/modules/ThreeSixtySpatialtoTemporal.h new file mode 100644 index 0000000..89a5703 --- /dev/null +++ b/modules/ThreeSixtySpatialtoTemporal.h @@ -0,0 +1,56 @@ +/* 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 ThreeSixtySpatialtoTemporal.h + * \brief Convert 360 videos from spatial to temporal + */ + +#ifndef __THREESIXTYSPATIALTOTEMPORAL_H__ +#define __THREESIXTYSPATIALTOTEMPORAL_H__ + +// CalypLib +#include "lib/CalypModuleIf.h" + +class ThreeSixtySpatialtoTemporal : public CalypModuleIf +{ + REGISTER_CLASS_FACTORY( ThreeSixtySpatialtoTemporal ) + +private: + CalypFrame* m_pcTmpInputFrame; + CalypFrame* m_pcTmpFace; + bool m_uiSpatial2Temporal; + unsigned int m_uiFacesX; + unsigned int m_uiFacesY; + unsigned int m_uiFacesPerFrame; + unsigned int m_uiFacesCount; + unsigned int m_uiCopyX; + unsigned int m_uiCopyY; + +public: + ThreeSixtySpatialtoTemporal(); + virtual ~ThreeSixtySpatialtoTemporal() {} + bool create( std::vector apcFrameList ); + bool needFrame(); + CalypFrame* process( std::vector apcFrameList ); + bool flush(); + void destroy(); +}; + +#endif // __THREESIXTYSPATIALTOTEMPORAL_H__