19 changed files with 490 additions and 156 deletions
+15 -12
View File
@@ -24,6 +24,8 @@
#include "ModulesHandle.h"
#include <cstdio>
#include "MainWindow.h"
#include "ModulesHandleOptDialog.h"
#include "SubWindowHandle.h"
@@ -32,8 +34,6 @@
#include "VideoSubWindow.h"
#include "modules/CalypModulesFactory.h"
#include <cstdio>
ModulesHandle::ModulesHandle( QWidget* parent, SubWindowHandle* windowManager, VideoHandle* moduleVideo )
: QWidget( parent ), m_pcParent( parent ), m_pcMainWindowManager( windowManager ), m_appModuleVideo( moduleVideo )
{
@@ -112,20 +112,23 @@ void ModulesHandle::buildMenu()
ModuleIfinternalName = QString::fromLocal8Bit( it->first );
currSubMenu = NULL;
if( pcCurrModuleIf->m_pchModuleCategory )
if( pcCurrModuleIf->m_iModuleAPI <= CLP_MODULE_API_2 )
{
for( int j = 0; j < m_pcModulesSubMenuList.size(); j++ )
if( pcCurrModuleIf->m_pchModuleCategory )
{
if( m_pcModulesSubMenuList.at( j )->title() == QString( pcCurrModuleIf->m_pchModuleCategory ) )
for( int j = 0; j < m_pcModulesSubMenuList.size(); j++ )
{
currSubMenu = m_pcModulesSubMenuList.at( j );
break;
if( m_pcModulesSubMenuList.at( j )->title() == QString( pcCurrModuleIf->m_pchModuleCategory ) )
{
currSubMenu = m_pcModulesSubMenuList.at( j );
break;
}
}
if( !currSubMenu )
{
currSubMenu = m_pcModulesMenu->addMenu( pcCurrModuleIf->m_pchModuleCategory );
m_pcModulesSubMenuList.append( currSubMenu );
}
}
if( !currSubMenu )
{
currSubMenu = m_pcModulesMenu->addMenu( pcCurrModuleIf->m_pchModuleCategory );
m_pcModulesSubMenuList.append( currSubMenu );
}
}
+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()
@@ -57,6 +59,7 @@ set(Calyp_Lib_HEADERS
CalypStream.h
CalypOptions.h
CalypModuleIf.h
CalypOpenCVModuleIf.h
)
CONFIGURE_FILE( CalypConfig.cmake.in CalypConfig.cmake @ONLY)
+30 -15
View File
@@ -102,6 +102,7 @@ public:
int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats)
unsigned int m_uiBitsPel; //!< Bits per pixel/channel
unsigned int m_uiHalfPelValue; //!< Bits per pixel/channel
bool m_bHasNegativeValues; //!< Half of the scale correspond to negative values
ClpPel*** m_pppcInputPel;
@@ -118,15 +119,12 @@ public:
/** Numbers of histogram segments depending of image bytes depth*/
unsigned int m_uiHistoSegments;
/**
* Common constructor function of a frame
*
* @param width width of the frame
* @param height height of the frame
* @param pel_format pixel format index (always use PixelFormats enum)
*
*/
void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel )
{
init( width, height, pel_format, bitsPixel, false );
}
void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel, bool has_negative_values )
{
m_bInit = false;
m_bHasRGBPel = false;
@@ -137,6 +135,7 @@ public:
m_iPixelFormat = pel_format;
m_uiBitsPel = bitsPixel < 8 ? 8 : bitsPixel;
m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 );
m_bHasNegativeValues = has_negative_values;
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 )
{
@@ -265,10 +264,16 @@ CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat,
d->init( width, height, pelFormat, bitsPixel );
}
CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel, bool has_negative_values )
: d( new CalypFramePrivate )
{
d->init( width, height, pelFormat, bitsPixel, has_negative_values );
}
CalypFrame::CalypFrame( const CalypFrame& other )
: d( new CalypFramePrivate )
{
d->init( other.getWidth(), other.getHeight(), other.getPelFormat(), other.getBitsPel() );
d->init( other.getWidth(), other.getHeight(), other.getPelFormat(), other.getBitsPel(), other.getHasNegativeValues() );
copyFrom( &other );
}
@@ -277,7 +282,7 @@ CalypFrame::CalypFrame( const CalypFrame* other )
{
if( other )
{
d->init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel() );
d->init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel(), other->getHasNegativeValues() );
copyFrom( other );
}
}
@@ -397,6 +402,11 @@ unsigned CalypFrame::getHeight( unsigned channel ) const
return CHROMASHIFT( d->m_uiHeight, channel > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0 );
}
bool CalypFrame::getHasNegativeValues() const
{
return d->m_bHasNegativeValues;
}
ClpULong CalypFrame::getPixels( unsigned channel ) const
{
return getWidth( channel ) * getHeight( channel );
@@ -490,19 +500,24 @@ unsigned char* CalypFrame::getRGBBuffer() const
return NULL;
}
ClpPel CalypFrame::operator()( unsigned int ch, unsigned int xPos, unsigned int yPos )
ClpPel CalypFrame::operator()( unsigned int ch, unsigned int xPos, unsigned int yPos, bool absolute ) const
{
int retValue = 0;
if( ch < d->m_pcPelFormat->numberChannels )
return d->m_pppcInputPel[ch][yPos][xPos];
return 0;
{
retValue = d->m_pppcInputPel[ch][yPos][xPos];
if( !absolute && d->m_bHasNegativeValues )
retValue = retValue - int(d->m_uiHalfPelValue);
}
return ClpPel( retValue );
}
CalypPixel CalypFrame::operator()( unsigned int xPos, unsigned int yPos )
CalypPixel CalypFrame::operator()( unsigned int xPos, unsigned int yPos ) const
{
return getPixel( xPos, yPos );
}
CalypPixel CalypFrame::getPixel( unsigned int xPos, unsigned int yPos )
CalypPixel CalypFrame::getPixel( unsigned int xPos, unsigned int yPos ) const
{
CalypPixel PixelValue( d->m_pcPelFormat->colorSpace );
for( unsigned int ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ )
+23 -4
View File
@@ -113,6 +113,17 @@ public:
*/
CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
/**
* Creates a new frame using the following configuration
*
* @param width width of the frame
* @param height height of the frame
* @param pel_format pixel format index (always use PixelFormats enum)
*
* @note this function might misbehave if the pixel format enum is not correct
*/
CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel, bool has_negative_values );
/**
* Copy contructor
*
@@ -197,6 +208,12 @@ public:
*/
unsigned int getHeight( unsigned channel = 0 ) const;
/**
* Check if frame has negative values
* @return Boolean with the flag value
*/
bool getHasNegativeValues() const;
/**
* Get number of pixels of the frame
* @param channel/component
@@ -257,13 +274,14 @@ public:
unsigned char* getRGBBuffer() const;
/**
* Get pixel value at coordinates
* Get pixel value at coordinates
* @param ch frame channel
* @param xPos position in X axis
* @param yPos position in Y axis
* @param absolute whether it should return positive/negative values
* @return pixel value
*/
ClpPel operator()( unsigned int ch, unsigned int xPos, unsigned int yPos );
ClpPel operator()( unsigned int ch, unsigned int xPos, unsigned int yPos, bool absolute = true ) const;
/**
* Get pixel value at coordinates
@@ -271,7 +289,7 @@ public:
* @param yPos position in Y axis
* @return pixel value
*/
CalypPixel operator()( unsigned int xPos, unsigned int yPos );
CalypPixel operator()( unsigned int xPos, unsigned int yPos ) const;
/**
* Get pixel value at coordinates
@@ -279,7 +297,8 @@ public:
* @param yPos position in Y axis
* @return pixel value
*/
CalypPixel getPixel( unsigned int xPos, unsigned int yPos );
CalypPixel getPixel( unsigned int xPos, unsigned int yPos ) const;
/**
* Get pixel value at coordinates
+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__
+11 -5
View File
@@ -103,11 +103,11 @@ private:
unsigned int m_uiIndex;
public:
CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, int bitsPixel )
CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, int bitsPixel, bool hasNegative )
{
for( unsigned int i = 0; i < size; i++ )
{
CalypFrame* pFrame = new CalypFrame( width, height, pelFormat, bitsPixel );
CalypFrame* pFrame = new CalypFrame( width, height, pelFormat, bitsPixel, hasNegative );
m_apcFrameBuffer.push_back( pFrame );
}
m_uiIndex = 0;
@@ -238,7 +238,7 @@ ClpString CalypStream::getCodecName() const
return !d->handler ? "" : d->handler->getCodecName();
}
bool CalypStream::open( ClpString filename, ClpString resolution, ClpString input_format_name, unsigned int bitsPel, int endianness,
bool CalypStream::open( ClpString filename, ClpString resolution, ClpString input_format_name, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool bInput )
{
unsigned int width = 0;
@@ -261,11 +261,17 @@ bool CalypStream::open( ClpString filename, ClpString resolution, ClpString inpu
break;
}
}
return open( filename, width, height, input_format, bitsPel, endianness, frame_rate, bInput );
return open( filename, width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, bInput );
}
bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, bool bInput )
{
return open( filename, width, height, input_format, bitsPel, endianness, false, frame_rate, bInput );
}
bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool bInput )
{
if( d->isInit )
{
@@ -314,7 +320,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
try
{
d->frameBuffer = new CalypStreamBufferPrivate( d->isInput ? 3 : 1, d->handler->m_uiWidth, d->handler->m_uiHeight,
d->handler->m_iPixelFormat, d->handler->m_uiBitsPerPixel );
d->handler->m_iPixelFormat, d->handler->m_uiBitsPerPixel, hasNegative );
}
catch( CalypFailure& e )
{
+4 -1
View File
@@ -72,10 +72,13 @@ public:
ClpString getCodecName() const;
;
bool open( ClpString filename, ClpString resolution, ClpString input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate,
bool open( ClpString filename, ClpString resolution, ClpString input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate,
bool bInput );
bool open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate,
bool bInput );
bool open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate,
bool bInput );
bool reload();
void close();
+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 )
+1 -1
View File
@@ -31,7 +31,7 @@ EightBitsSampling::EightBitsSampling()
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "Conversions";
m_pchModuleName = "BitsResampling";
m_pchModuleLongName = "Re-sampling frame";
m_pchModuleLongName = "Re-sampling frame (bpp)";
m_pchModuleTooltip = "Re-sampling frame to a different value of bits per pixel";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS;
+31 -22
View File
@@ -38,9 +38,12 @@ FrameDifference::FrameDifference()
m_uiNumberOfFrames = 2;
m_cModuleOptions.addOptions() /**/
( "Bits per pixel", m_uiBitsPixel, "Bits per pixel (use zero to avoid scaling) [0]" );
( "BitsPerpixel", m_uiBitsPixel, "Bits per pixel (use zero to avoid scaling) [0]" ) /**/
( "SumOperation", m_uiSumOperation, "Sum instead of difference [0]" );
m_uiBitsPixel = 0;
m_uiSumOperation = 0;
m_iOperation = 1;
m_pcFrameDifference = NULL;
}
@@ -49,6 +52,8 @@ bool FrameDifference::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_uiSumOperation = m_uiSumOperation > 1 ? 0 : m_uiSumOperation;
unsigned int uiMaxBitsPixel = 0;
for( unsigned int i = 0; i < apcFrameList.size(); i++ )
{
@@ -57,42 +62,46 @@ bool FrameDifference::create( std::vector<CalypFrame*> apcFrameList )
if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel )
{
uiMaxBitsPixel = apcFrameList[i]->getBitsPel();
if( apcFrameList[i]->getHasNegativeValues() )
uiMaxBitsPixel -= 1;
}
}
if( !m_uiBitsPixel )
{
m_uiBitsPixel = ( uiMaxBitsPixel + 1 ) & 0x0F;
}
uiMaxBitsPixel = m_uiSumOperation ? uiMaxBitsPixel : uiMaxBitsPixel + 1;
m_uiBitsPixel = !m_uiBitsPixel ? uiMaxBitsPixel & 0x0F : m_uiBitsPixel;
m_iDiffBitShift = ( uiMaxBitsPixel + 1 ) - m_uiBitsPixel;
m_iMaxDiffValue = ( 1 << ( m_uiBitsPixel - 1 ) );
m_iDiffBitShift = uiMaxBitsPixel - m_uiBitsPixel;
m_iMaxDiffValue = ( 1 << ( m_uiSumOperation ? m_uiBitsPixel : m_uiBitsPixel - 1 ) );
m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(),
apcFrameList[0]->getPelFormat(), m_uiBitsPixel );
apcFrameList[0]->getPelFormat(), m_uiBitsPixel, m_uiSumOperation == 1 ? false : true );
m_iOperation = m_uiSumOperation == 0 ? -1 : 1 ;
return true;
}
CalypFrame* FrameDifference::process( std::vector<CalypFrame*> apcFrameList )
{
ClpPel* pInput1PelYUV = apcFrameList[0]->getPelBufferYUV()[0][0];
ClpPel* pInput2PelYUV = apcFrameList[1]->getPelBufferYUV()[0][0];
const CalypFrame& frame1 = apcFrameList[0];
const CalypFrame& frame2 = apcFrameList[1];
ClpPel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0];
int aux_pel_1, aux_pel_2;
int diff = 0;
short aux_pel_1, aux_pel_2;
short diff = 0;
for( unsigned int ch = 0; ch < m_pcFrameDifference->getNumberChannels(); ch++ )
for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ )
for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ )
for( unsigned int y = 0; y < m_pcFrameDifference->getHeight( ch ); y++ )
for( unsigned int x = 0; x < m_pcFrameDifference->getWidth( ch ); x++ )
{
aux_pel_1 = *pInput1PelYUV++;
aux_pel_2 = *pInput2PelYUV++;
diff = aux_pel_1 - aux_pel_2;
diff = m_iDiffBitShift > 0 ? diff >> m_iDiffBitShift : diff << m_iDiffBitShift;
diff = std::min( diff, m_iMaxDiffValue - 1 );
diff = std::max( diff, -m_iMaxDiffValue );
diff += m_iMaxDiffValue;
aux_pel_1 = frame1(ch, x, y, false );
aux_pel_2 = frame2(ch, x, y, false );
diff = aux_pel_1 + m_iOperation * aux_pel_2;
diff = m_iDiffBitShift > 0 ? diff >> m_iDiffBitShift : diff << -m_iDiffBitShift;
diff = std::min<short>( diff, m_iMaxDiffValue - 1 );
if( m_uiSumOperation == 0 )
{
diff = std::max<short>( diff, -m_iMaxDiffValue );
diff += m_iMaxDiffValue;
}
*pOutputPelYUV++ = diff;
}
return m_pcFrameDifference;
+3 -1
View File
@@ -34,8 +34,10 @@ class FrameDifference : public CalypModuleIf
private:
unsigned int m_uiBitsPixel;
unsigned int m_uiSumOperation;
int m_iOperation;
int m_iDiffBitShift;
int m_iMaxDiffValue;
short m_iMaxDiffValue;
CalypFrame* m_pcFrameDifference;
public:
+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 (Spatial)";
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__
+10 -5
View File
@@ -23,12 +23,12 @@
*/
#include "CalypTools.h"
#include "config.h"
#include <climits>
#include <cstring>
#include <iostream>
#include "config.h"
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
#include "lib/CalypStream.h"
@@ -79,13 +79,14 @@ int CalypTools::openInputs()
ClpString fmtString( "yuv420p" );
unsigned int uiBitsPerPixel = 8;
unsigned int uiEndianness = 0;
bool hasNegativeValues = false;
CalypStream* pcStream;
for( unsigned int i = 0; i < inputFileNames.size() && i < MAX_NUMBER_INPUTS; i++ )
{
if( Opts().hasOpt( "size" ) )
{
resolutionString = GET_PARAM( m_strResolution, 0 );
resolutionString = GET_PARAM( m_strResolution, i );
}
if( Opts().hasOpt( "pel_fmt" ) )
{
@@ -106,10 +107,14 @@ int CalypTools::openInputs()
uiEndianness = 1;
}
}
if( Opts().hasOpt( "has_negative" ) )
{
hasNegativeValues = std::stoi( GET_PARAM( m_strHasNegativeValues, i ).c_str() ) == 0 ? false : true;
}
pcStream = new CalypStream;
try
{
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitsPerPixel, uiEndianness, 1, true ) )
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitsPerPixel, uiEndianness, hasNegativeValues, 1, true ) )
{
log( CLP_LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
return -1;
@@ -172,11 +177,11 @@ int CalypTools::Open( int argc, char* argv[] )
m_uiOutEndianness = 0;
if( Opts().hasOpt( "endianness" ) )
{
if( m_strEndianness[0] == "big" )
if( GET_PARAM( m_strEndianness, 9999 ) == "big" )
{
m_uiOutEndianness = 0;
}
else if( m_strEndianness[0] == "little" )
else if( GET_PARAM( m_strEndianness, 9999 ) == "little" )
{
m_uiOutEndianness = 1;
}
+5 -4
View File
@@ -24,15 +24,15 @@
#include "CalypToolsCmdParser.h"
#include <cstdarg>
#include <cstring>
#include <iostream>
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
#include "lib/CalypStream.h"
#include "modules/CalypModulesFactory.h"
#include <cstdarg>
#include <cstring>
#include <iostream>
CalypToolsCmdParser::CalypToolsCmdParser()
{
m_uiLogLevel = 0;
@@ -66,6 +66,7 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] )
( "pel_fmt,p", m_strPelFmt, "pixel format" ) /**/
( "bits_pel", m_strBitsPerPixel, "bits per pixel" ) /**/
( "endianness", m_strEndianness, "File endianness (big, little)" ) /**/
( "has_negative", m_strHasNegativeValues, "Flag for files with negatie values" ) /**/
( "frames,f", m_iFrames, "number of frames to parse" ) /**/
( "quality", m_strQualityMetric, "select a quality metric" ) /**/
( "module", m_strModule, "select a module (use internal name)" ) /**/
+1
View File
@@ -69,6 +69,7 @@ protected:
std::vector<ClpString> m_strPelFmt;
std::vector<ClpString> m_strBitsPerPixel;
std::vector<ClpString> m_strEndianness;
std::vector<ClpString> m_strHasNegativeValues;
ClpString m_strOutput;
long m_iFrames;
unsigned m_uiOutEndianness;