diff --git a/CMakeLists.txt b/CMakeLists.txt index d696539..c399dd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ SET( PLAYUVER_VERSION "${PLAYUVER_VERSION_MAJOR}.${PLAYUVER_VERSION_MINOR}.${PLA OPTION( PLAYUVER_BUILD_APP "Build GUI Application" ON ) OPTION( PLAYUVER_BUILD_TOOLS "Build Command Line Application" ON ) +OPTION( PLAYUVER_BUILD_EXEMPLES "Build Examples" ON ) OPTION( USE_SSE "Build with SSE support" OFF ) OPTION( USE_FERVOR "Add Fervor support" OFF ) OPTION( USE_WERROR "Warnings as errors" OFF ) @@ -136,6 +137,10 @@ IF( ${PLAYUVER_BUILD_APP} ) ADD_SUBDIRECTORY( app ) ENDIF() +IF( ${PLAYUVER_BUILD_EXEMPLES} ) + ADD_SUBDIRECTORY( examples ) +ENDIF() + CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h ) ###################################################################################### diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index 7527f3b..d78e2ce 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -90,7 +90,6 @@ QMenu* ModulesHandle::createMenu() m_pcModulesMenu = new QMenu( "&Modules", this ); m_pcModulesActionMapper = new QSignalMapper( this ); - //connect( m_pcModulesActionMapper, SIGNAL( mapped(int) ), this, SLOT( activateModule(int) ) ); UInt i = 0; PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..1e9a867 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,7 @@ +### +### CMakeLists for examples +### + + +ADD_SUBDIRECTORY( modules ) + diff --git a/examples/modules/AbsoluteFrameDifference_APIv2.cpp b/examples/modules/AbsoluteFrameDifference_APIv2.cpp new file mode 100644 index 0000000..b4dc6ff --- /dev/null +++ b/examples/modules/AbsoluteFrameDifference_APIv2.cpp @@ -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 + +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 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 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 + diff --git a/examples/modules/AbsoluteFrameDifference_APIv2.h b/examples/modules/AbsoluteFrameDifference_APIv2.h new file mode 100644 index 0000000..c3663ac --- /dev/null +++ b/examples/modules/AbsoluteFrameDifference_APIv2.h @@ -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 + +namespace plaYUVer +{ + +class AbsoluteFrameDifference: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( AbsoluteFrameDifference ) + +private: + PlaYUVerFrame* m_pcFrameDifference; + +public: + AbsoluteFrameDifference(); + virtual ~AbsoluteFrameDifference() + { + } + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __FRAMEDIFFERENCE_H__ + diff --git a/examples/modules/CMakeLists.txt b/examples/modules/CMakeLists.txt new file mode 100644 index 0000000..a01e7ee --- /dev/null +++ b/examples/modules/CMakeLists.txt @@ -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} ) + diff --git a/examples/modules/FrameBinarization_APIv1.cpp b/examples/modules/FrameBinarization_APIv1.cpp new file mode 100644 index 0000000..d48329f --- /dev/null +++ b/examples/modules/FrameBinarization_APIv1.cpp @@ -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 + diff --git a/examples/modules/FrameBinarization_APIv1.h b/examples/modules/FrameBinarization_APIv1.h new file mode 100644 index 0000000..ceda8ac --- /dev/null +++ b/examples/modules/FrameBinarization_APIv1.h @@ -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__ + diff --git a/lib/PlaYUVerModuleIf.h b/lib/PlaYUVerModuleIf.h index 47261aa..7bc5c23 100644 --- a/lib/PlaYUVerModuleIf.h +++ b/lib/PlaYUVerModuleIf.h @@ -33,6 +33,8 @@ namespace plaYUVer { +#define REGISTER_CLASS_MAKER(X) \ + extern "C" PlaYUVerModuleIf* Maker() { return new AbsoluteFrameDifference; } #define REGISTER_CLASS_FACTORY(X) \ public: \ diff --git a/modules/AbsoluteFrameDifference.cpp b/modules/AbsoluteFrameDifference.cpp index 5dac1ac..0308466 100644 --- a/modules/AbsoluteFrameDifference.cpp +++ b/modules/AbsoluteFrameDifference.cpp @@ -31,14 +31,18 @@ namespace plaYUVer AbsoluteFrameDifference::AbsoluteFrameDifference() { /* Module Definition */ - m_iModuleAPI = MODULE_API_2; - m_iModuleType = FRAME_PROCESSING_MODULE; - m_pchModuleCategory = "Measurements"; - m_pchModuleName = "AbsoluteFrameDifference"; - m_pchModuleTooltip = "Measure the absolute difference between two images (Y plane), e. g., abs( Y1 - Y2 )"; - m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; - m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; + 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 apcFrameList ) diff --git a/modules/PlaYUVerModuleFactory.cpp b/modules/PlaYUVerModuleFactory.cpp index 2148714..f70e913 100644 --- a/modules/PlaYUVerModuleFactory.cpp +++ b/modules/PlaYUVerModuleFactory.cpp @@ -25,6 +25,7 @@ #include "config.h" #include #include +#include #include "PlaYUVerModuleFactory.h" #include "ModulesListHeader.h" @@ -36,8 +37,8 @@ PlaYUVerModuleFactory::PlaYUVerModuleFactory() Register( "FilterComponentLuma", &FilterComponentLuma::Create ); Register( "FilterComponentChromaU", &FilterComponentChromaU::Create ); Register( "FilterComponentChromaV", &FilterComponentChromaV::Create ); + //Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create ); Register( "FrameDifference", &FrameDifference::Create ); - Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create ); Register( "SetChromaHalfScale", &SetChromaHalfScale::Create ); Register( "FrameCrop", &FrameCrop::Create ); Register( "FrameBinarization", &FrameBinarization::Create ); @@ -48,7 +49,6 @@ PlaYUVerModuleFactory::PlaYUVerModuleFactory() Register( "DisparityStereoBM", &DisparityStereoBM::Create ); Register( "DisparityStereoSGBM", &DisparityStereoSGBM::Create ); #endif - } PlaYUVerModuleFactory::~PlaYUVerModuleFactory() @@ -61,6 +61,19 @@ Void PlaYUVerModuleFactory::Register( const char* moduleName, CreateModuleFn pfn m_FactoryMap[moduleName] = pfnCreate; } +Void PlaYUVerModuleFactory::RegisterDl( const char* dlName ) +{ + void *pHndl = dlopen( dlName, RTLD_NOW ); + if( pHndl == NULL ) + { + std::cerr << dlerror() + << std::endl; + exit( -1 ); + } + CreateModuleFn pfnCreate = (CreateModuleFn) dlsym( pHndl, "CreateModule" ); + Register( dlName, pfnCreate ); +} + PlaYUVerModuleIf *PlaYUVerModuleFactory::CreateModule( const char* moduleName ) { PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); diff --git a/modules/PlaYUVerModuleFactory.h b/modules/PlaYUVerModuleFactory.h index 5ea86d5..3f3b3ba 100644 --- a/modules/PlaYUVerModuleFactory.h +++ b/modules/PlaYUVerModuleFactory.h @@ -42,7 +42,10 @@ class PlaYUVerModuleFactory { private: PlaYUVerModuleFactory(); - PlaYUVerModuleFactory &operator=( const PlaYUVerModuleFactory & ) { return *this; } + PlaYUVerModuleFactory &operator=( const PlaYUVerModuleFactory & ) + { + return *this; + } PlaYUVerModuleFactoryMap m_FactoryMap; public: @@ -55,8 +58,13 @@ public: } Void Register( const char* moduleName, CreateModuleFn pfnCreate ); + Void RegisterDl( const char* dlName ); + PlaYUVerModuleIf *CreateModule( const char *moduleName ); - PlaYUVerModuleFactoryMap& getMap(){ return m_FactoryMap; } + PlaYUVerModuleFactoryMap& getMap() + { + return m_FactoryMap; + } }; //// typedef to make it easier to set up our factory