Add examples dir and create function to dynamically load new modules

This commit is contained in:
2015-07-29 18:09:12 +01:00
parent 193c41fddd
commit ae0f861988
12 changed files with 336 additions and 12 deletions
+7
View File
@@ -0,0 +1,7 @@
###
### CMakeLists for examples
###
ADD_SUBDIRECTORY( modules )
@@ -0,0 +1,84 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@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 AbsoluteFrameDifference_APIv2.cpp
* \brief Absolute Frame Difference module
*/
#include "AbsoluteFrameDifference_APIv2.h"
#include <cstdlib>
namespace plaYUVer
{
REGISTER_CLASS_MAKER( AbsoluteFrameDifference )
AbsoluteFrameDifference::AbsoluteFrameDifference()
{
/* Module Definition */
m_iModuleAPI = MODULE_API_2; // Use API version 2 (recommended).
// See this example for details on the functions prototype
m_iModuleType = FRAME_PROCESSING_MODULE; // Apply module to the frames or to the whole sequence.
m_pchModuleCategory = "Measurements"; // Category (sub-menu)
m_pchModuleName = "AbsoluteFrameDifference"; // Name
m_pchModuleTooltip = "Measure the absolute difference " // Description
"between two images (Y plane), e. g., abs( Y1 - Y2 )";
m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES)
m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; // Module requirements (check PlaYUVerModulesIf.h).
// Several requirements should be "or" between each others.
m_pcFrameDifference = NULL;
}
Bool AbsoluteFrameDifference::create( std::vector<PlaYUVerFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY );
return true;
}
PlaYUVerFrame* AbsoluteFrameDifference::process( std::vector<PlaYUVerFrame*> apcFrameList )
{
PlaYUVerFrame* Input1 = apcFrameList[0];
PlaYUVerFrame* Input2 = apcFrameList[1];
Pel* pInput1PelYUV = Input1->getPelBufferYUV()[0][0];
Pel* pInput2PelYUV = Input2->getPelBufferYUV()[0][0];
Pel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0];
Int aux_pel_1, aux_pel_2;
for( UInt y = 0; y < m_pcFrameDifference->getHeight(); y++ )
for( UInt x = 0; x < m_pcFrameDifference->getWidth(); x++ )
{
aux_pel_1 = *pInput1PelYUV++;
aux_pel_2 = *pInput2PelYUV++;
*pOutputPelYUV++ = abs( aux_pel_1 - aux_pel_2 );
}
return m_pcFrameDifference;
}
Void AbsoluteFrameDifference::destroy()
{
if( m_pcFrameDifference )
delete m_pcFrameDifference;
m_pcFrameDifference = NULL;
}
} // NAMESPACE
@@ -0,0 +1,56 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@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 AbsoluteFrameDifference_APIv2.h
* \brief Absolute Frame Difference module
*/
#ifndef __ABSOLUTEFRAMEDIFFERENCE_H__
#define __ABSOLUTEFRAMEDIFFERENCE_H__
#include "PlaYUVerModuleIf.h"
#include <cassert>
namespace plaYUVer
{
class AbsoluteFrameDifference: public PlaYUVerModuleIf
{
REGISTER_CLASS_FACTORY( AbsoluteFrameDifference )
private:
PlaYUVerFrame* m_pcFrameDifference;
public:
AbsoluteFrameDifference();
virtual ~AbsoluteFrameDifference()
{
}
Bool create( std::vector<PlaYUVerFrame*> apcFrameList );
PlaYUVerFrame* process( std::vector<PlaYUVerFrame*> apcFrameList );
Void destroy();
};
} // NAMESPACE
#endif // __FRAMEDIFFERENCE_H__
+19
View File
@@ -0,0 +1,19 @@
###
### CMakeLists for modules_example
###
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.9 )
PROJECT( "modules_example" )
FIND_PACKAGE( PlaYUVer )
INCLUDE_DIRECTORIES( ${PLAYUVER_INCLUDE_DIRS} )
ADD_LIBRARY(FrameBinarization SHARED FrameBinarization_APIv1.cpp)
TARGET_LINK_LIBRARIES( FrameBinarization ${PLAYUVER_LINKER_LIBS} )
ADD_LIBRARY(AbsoluteFrameDifference SHARED AbsoluteFrameDifference_APIv2.cpp)
TARGET_LINK_LIBRARIES( AbsoluteFrameDifference ${PLAYUVER_LINKER_LIBS} )
@@ -0,0 +1,73 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@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 FrameBinarization_APIv1.cpp
* \brief Binarize frame module (example of APIv1)
*/
#include "FrameBinarization_APIv1.h"
namespace plaYUVer
{
FrameBinarization::FrameBinarization()
{
/* Module Definition */
m_iModuleType = FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "Utilities";
m_pchModuleName = "FrameBinarization";
m_pchModuleTooltip = "Binarize frame";
m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME;
m_uiModuleRequirements = MODULE_REQUIRES_OPTIONS;
m_cModuleOptions.addOptions()/**/
( "threshold", m_uiThreshold, "Threshold level for binarization (0-255) [128]" );
m_pcBinFrame = NULL;
m_uiThreshold = 128;
}
Void FrameBinarization::create( PlaYUVerFrame* frame )
{
m_pcBinFrame = NULL;
m_pcBinFrame = new PlaYUVerFrame( frame->getWidth(), frame->getHeight(), PlaYUVerFrame::GRAY, 8 );
}
PlaYUVerFrame* FrameBinarization::process( PlaYUVerFrame* frame )
{
Pel* pPelInput = frame->getPelBufferYUV()[0][0];
Pel* pPelBin = m_pcBinFrame->getPelBufferYUV()[0][0];
for( UInt y = 0; y < frame->getHeight(); y++ )
for( UInt x = 0; x < frame->getWidth(); x++ )
{
*pPelBin++ = *pPelInput++ >= m_uiThreshold ? 255 : 0;
}
return m_pcBinFrame;
}
Void FrameBinarization::destroy()
{
if( m_pcBinFrame )
delete m_pcBinFrame;
m_pcBinFrame = NULL;
}
} // NAMESPACE
@@ -0,0 +1,54 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@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 FrameBinarization_APIv1.h
* \brief Binarize frame module (example of APIv1)
*/
#ifndef __FRAMEBINARIZATION_H__
#define __FRAMEBINARIZATION_H__
#include "PlaYUVerModuleIf.h"
namespace plaYUVer
{
class FrameBinarization: public PlaYUVerModuleIf
{
REGISTER_CLASS_FACTORY( FrameBinarization )
private:
PlaYUVerFrame* m_pcBinFrame;
UInt m_uiThreshold;
public:
FrameBinarization();
virtual ~FrameBinarization()
{
}
Void create( PlaYUVerFrame* );
PlaYUVerFrame* process( PlaYUVerFrame* );
Void destroy();
};
} // NAMESPACE
#endif // __FRAMEBINARIZATION_H__