Major changes in OpenCV handling

CalypFrame to Mat conversion
Remove custom modules
This commit is contained in:
jfmcarreira committed 2019-04-03 16:37:32 +01:00
1 parent 97c2fccf1a
commit e42f0d02bb
10 files changed
+121 -585

No files matched your search

+4 -3
View File
@@ -3,6 +3,7 @@
###
OPTION( CALYP_THREADED_MODULES "Use threads for modules" OFF )
SET( CALYP_EXTRA_MODULES "CALYP_EXTRA_MODULES" CACHE PATH "Location of extra Calyp modules")
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
@@ -42,9 +43,9 @@ 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( ThreeSixtyDownsampling "ThreeSixtyDownsampling" VERSION 3.1.0 MODULES core )
ADD_MODULE_USE_OPENCV( ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core )
ADD_MODULE_USE_OPENCV( ThreeSixtyTemporaltoSpatial "ThreeSixtyTemporaltoSpatial" VERSION 3.1.0 MODULES core )
IF(EXISTS ${CALYP_EXTRA_MODULES})
ADD_SUBDIRECTORY( ${CALYP_EXTRA_MODULES} )
ENDIF()
#
# Create header and auxiliar files
+1 -1
View File
@@ -90,6 +90,7 @@ CalypFrame* DisparityStereoBM::process( std::vector<CalypFrame*> apcFrameList )
{
return m_pcDisparityFrame;
}
cv::Mat disparityImage, disparityImage8;
#if( CV_MAJOR_VERSION == 2 )
@@ -99,7 +100,6 @@ CalypFrame* DisparityStereoBM::process( std::vector<CalypFrame*> apcFrameList )
#endif
disparityImage.convertTo( disparityImage8, CV_8U );
m_pcDisparityFrame->fromMat( disparityImage8 );
return m_pcDisparityFrame;
}
-149
View File
@@ -1,149 +0,0 @@
/* 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 ThreeSixtyDownsampling.cpp
* \brief Downsampling ERP to NxN
*/
#include "ThreeSixtyDownsampling.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc.hpp>
using cv::InputArray;
using cv::Mat;
using cv::OutputArray;
using cv::Size;
ThreeSixtyDownsampling::ThreeSixtyDownsampling()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "360Video";
m_pchModuleName = "ThreeSixtyDownsampling";
m_pchModuleLongName = "ERP to NxN";
m_pchModuleTooltip = "Downsampling ERP to NxN";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULE_REQUIRES_OPTIONS;
m_cModuleOptions.addOptions() /**/
( "Downsampling", m_bDownsampling, "ERP to NxN [true]" ) /**/
( "Interpolation", m_iInterpolation, "Interpolation method (1-5) [1]" );
// INTER_NEAREST - a nearest-neighbor interpolation
// INTER_LINEAR - a bilinear interpolation (used by default)
// INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method.
// INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood
// INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood
m_bDownsampling = true;
m_iInterpolation = 1;
m_pcOutputFrame = NULL;
}
bool ThreeSixtyDownsampling::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
m_isOdd = !( m_pcOutputFrame->getHeight() % 2 );
switch( m_iInterpolation )
{
case 2:
m_iInterpolation = cv::INTER_LINEAR;
break;
case 3:
m_iInterpolation = cv::INTER_AREA;
break;
case 4:
m_iInterpolation = cv::INTER_CUBIC;
break;
case 5:
m_iInterpolation = cv::INTER_LANCZOS4;
break;
default:
m_iInterpolation = cv::INTER_NEAREST;
}
return true;
}
CalypFrame* ThreeSixtyDownsampling::process( std::vector<CalypFrame*> apcFrameList )
{
Mat cvIn;
apcFrameList[0]->toMat( cvIn, true );
m_pcOutputFrame->reset();
memcpy( &m_pcOutputFrame->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2][0],
&apcFrameList[0]->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2][0],
m_pcOutputFrame->getWidth() * sizeof( ClpPel ) );
if( m_isOdd )
{
memcpy( &m_pcOutputFrame->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2 - 1][0],
&apcFrameList[0]->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2 - 1][0],
m_pcOutputFrame->getWidth() * sizeof( ClpPel ) );
}
for( int line = 1; line < m_pcOutputFrame->getHeight() / 2; line++ )
{
for( int hemisfer = -1; hemisfer < 2; hemisfer += 2 )
{
Mat cvOutput;
// calculate destination sizes
unsigned int ypos = m_pcOutputFrame->getHeight() / 2 + line * hemisfer + ( hemisfer == -1 ? ( m_isOdd ? -1 : 0 ) : 0 );
unsigned int lineWidth = ( m_pcOutputFrame->getHeight() / 2 - line ) * 4 + 2;
unsigned int xpos = ( m_pcOutputFrame->getWidth() - lineWidth ) / 2;
Mat cvDownsample( 1, lineWidth, CV_8UC1 );
Mat cvUpsample( 1, m_pcOutputFrame->getWidth(), CV_8UC1 );
// resize
if( m_bDownsampling )
{
cv::resize( cvIn.row( ypos ), cvDownsample, cvDownsample.size(), 0, 0, m_iInterpolation );
cvOutput = cvDownsample;
}
else
{
Mat cvauxin = cvIn.row( ypos ).colRange( xpos, xpos + lineWidth );
cvauxin.copyTo( cvDownsample );
cv::resize( cvDownsample, cvUpsample, cvUpsample.size(), 0, 0, m_iInterpolation );
cvOutput = cvUpsample;
}
// copy to output
ClpPel* outpel = &m_pcOutputFrame->getPelBufferYUV()[0][ypos][xpos * m_bDownsampling];
unsigned char* pchar = cvOutput.data;
for( unsigned int i = 0; i < cvOutput.cols; i++ )
{
*outpel++ = *pchar++;
}
}
}
return m_pcOutputFrame;
}
void ThreeSixtyDownsampling::destroy()
{
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
}
-47
View File
@@ -1,47 +0,0 @@
/* 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 ThreeSixtyDownsampling.h
* \brief Downsampling ERP to NxN
*/
#ifndef __THREESIXTYDOWNSAMPLING_H__
#define __THREESIXTYDOWNSAMPLING_H__
// CalypLib
#include "lib/CalypModuleIf.h"
class ThreeSixtyDownsampling : public CalypModuleIf
{
REGISTER_CLASS_FACTORY( ThreeSixtyDownsampling )
private:
bool m_isOdd;
bool m_bDownsampling;
int m_iInterpolation;
public:
ThreeSixtyDownsampling();
virtual ~ThreeSixtyDownsampling() {}
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
void destroy();
};
#endif // __THREESIXTYDOWNSAMPLING_H__
-114
View File
@@ -1,114 +0,0 @@
/* 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 = "SpatialtoTemporal";
m_pchModuleTooltip = "Convert 360 video from Cube Map Projection to temporal frames";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY;
m_uiFacesX = 3;
m_uiFacesY = 2;
flush();
}
bool ThreeSixtySpatialtoTemporal::flush()
{
CalypModuleIf::flush();
m_uiCopyX = 0;
m_uiCopyY = 0;
return true;
};
bool ThreeSixtySpatialtoTemporal::needFrame()
{
if( m_iFrameBufferCount <= 0 )
{
return true;
}
return false;
};
bool ThreeSixtySpatialtoTemporal::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
unsigned int iWidth;
unsigned int iHeight;
iWidth = apcFrameList[0]->getWidth() / m_uiFacesX;
iHeight = apcFrameList[0]->getHeight() / m_uiFacesY;
m_pcOutputFrame = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel() );
m_pcTmpFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel() );
return true;
}
CalypFrame* ThreeSixtySpatialtoTemporal::process( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_3_BREAK_CONDITION_
if( m_iFrameBufferCount == 0 )
{
m_pcTmpFrame->copyFrom( apcFrameList[0], 0, 0 );
m_uiCopyX = 0;
m_uiCopyY = 0;
m_iFrameBufferCount = m_uiFacesX * m_uiFacesY;
}
m_pcOutputFrame->copyFrom( m_pcTmpFrame, m_uiCopyX, m_uiCopyY );
m_iFrameBufferCount--;
m_uiCopyX += m_pcOutputFrame->getWidth();
if( m_uiCopyX >= m_pcTmpFrame->getWidth() )
{
m_uiCopyX = 0;
m_uiCopyY += m_pcOutputFrame->getHeight();
}
return m_pcOutputFrame;
}
void ThreeSixtySpatialtoTemporal::destroy()
{
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
if( m_pcTmpFrame )
delete m_pcTmpFrame;
m_pcTmpFrame = NULL;
}
-52
View File
@@ -1,52 +0,0 @@
/* 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_pcTmpFrame;
unsigned int m_uiFacesX;
unsigned int m_uiFacesY;
unsigned int m_uiCopyX;
unsigned int m_uiCopyY;
public:
ThreeSixtySpatialtoTemporal();
virtual ~ThreeSixtySpatialtoTemporal() {}
bool create( std::vector<CalypFrame*> apcFrameList );
bool needFrame();
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
bool flush();
void destroy();
};
#endif // __THREESIXTYSPATIALTOTEMPORAL_H__
-101
View File
@@ -1,101 +0,0 @@
/* 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 ThreeSixtyTemporaltoSpatial.cpp
* \brief Convert 360 videos from temporal to spatial
*/
#include "ThreeSixtyTemporaltoSpatial.h"
ThreeSixtyTemporaltoSpatial::ThreeSixtyTemporaltoSpatial()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_3;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "360Video";
m_pchModuleLongName = "Temporal to Spatial";
m_pchModuleName = "TemporaltoSpatial";
m_pchModuleTooltip = "Convert 360 video from temporal frames to Cube Map Projection";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY;
m_uiFacesX = 3;
m_uiFacesY = 2;
flush();
}
bool ThreeSixtyTemporaltoSpatial::flush()
{
CalypModuleIf::flush();
m_uiCopyX = 0;
m_uiCopyY = 0;
m_uiFacesCount = 0;
return true;
};
bool ThreeSixtyTemporaltoSpatial::needFrame()
{
return CalypModuleIf::needFrame();
};
bool ThreeSixtyTemporaltoSpatial::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
unsigned int iWidth;
unsigned int iHeight;
iWidth = apcFrameList[0]->getWidth() * m_uiFacesX;
iHeight = apcFrameList[0]->getHeight() * m_uiFacesY;
m_pcOutputFrame = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel() );
return true;
}
CalypFrame* ThreeSixtyTemporaltoSpatial::process( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_3_BREAK_CONDITION_
m_pcOutputFrame->copyTo( apcFrameList[0], m_uiCopyX, m_uiCopyY );
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_uiCopyX = 0;
m_uiCopyY = 0;
m_uiFacesCount = 0;
return m_pcOutputFrame;
}
void ThreeSixtyTemporaltoSpatial::destroy()
{
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
}
-52
View File
@@ -1,52 +0,0 @@
/* 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 ThreeSixtyTemporaltoSpatial.h
* \brief Convert 360 videos from temporal to spatial
*/
#ifndef __THREESIXTYTEMPORALTOSPATIAL_H__
#define __THREESIXTYTEMPORALTOSPATIAL_H__
// CalypLib
#include "lib/CalypModuleIf.h"
class ThreeSixtyTemporaltoSpatial : public CalypModuleIf
{
REGISTER_CLASS_FACTORY( ThreeSixtyTemporaltoSpatial )
private:
unsigned int m_uiFacesX;
unsigned int m_uiFacesY;
unsigned int m_uiCopyX;
unsigned int m_uiCopyY;
unsigned int m_uiFacesCount;
public:
ThreeSixtyTemporaltoSpatial();
virtual ~ThreeSixtyTemporaltoSpatial() {}
bool create( std::vector<CalypFrame*> apcFrameList );
bool needFrame();
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
bool flush();
void destroy();
};
#endif // __THREESIXTYTEMPORALTOSPATIAL_H__