Add FrameMask module
Fix module to work with mismatch pixel formats (this is usefull for gray masks)
This commit is contained in:
1 parent
6d1ce190ae
commit
6841e57135
5 files changed
+166
-1
No files matched your search
@@ -35,6 +35,7 @@ ADD_MODULE( FilterComponentLuma "FilterComponent" )
|
||||
ADD_MODULE( FilterComponentChromaU "FilterComponent" )
|
||||
ADD_MODULE( FilterComponentChromaV "FilterComponent" )
|
||||
ADD_MODULE( FrameDifference "FrameDifference" )
|
||||
ADD_MODULE( FrameMask "FrameMask" )
|
||||
ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" )
|
||||
ADD_MODULE( FrameBinarization "FrameBinarization" )
|
||||
ADD_MODULE( FrameShift "FrameShift" )
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/* 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 FrameMask.cpp
|
||||
* \brief Frame Difference module
|
||||
*/
|
||||
|
||||
#include "FrameMask.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
FrameMask::FrameMask()
|
||||
{
|
||||
/* Module Definition */
|
||||
m_iModuleAPI = MODULE_API_2;
|
||||
m_iModuleType = FRAME_PROCESSING_MODULE;
|
||||
m_pchModuleCategory = "Utilities";
|
||||
m_pchModuleName = "FrameMask";
|
||||
m_pchModuleTooltip = "Applies a mask to the selected image (first image)";
|
||||
m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW;
|
||||
m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES;
|
||||
|
||||
m_dWeigth = 0.3;
|
||||
|
||||
m_pcFrameMask = NULL;
|
||||
}
|
||||
|
||||
Bool FrameMask::create( std::vector<PlaYUVerFrame*> apcFrameList )
|
||||
{
|
||||
_BASIC_MODULE_API_2_CHECK_
|
||||
|
||||
for( UInt i = 0; i < apcFrameList.size(); i++ )
|
||||
{
|
||||
if( !apcFrameList[i]->haveSameFmt( apcFrameList[i], PlaYUVerFrame::MATCH_COLOR_SPACE |
|
||||
PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_pcFrameMask = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() );
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaYUVerFrame* FrameMask::process( std::vector<PlaYUVerFrame*> apcFrameList )
|
||||
{
|
||||
Pel* pInput1PelYUV = apcFrameList[0]->getPelBufferYUV()[0][0];
|
||||
Pel* pInput2PelYUV = apcFrameList[1]->getPelBufferYUV()[0][0];
|
||||
Pel* pOutputPelYUV = m_pcFrameMask->getPelBufferYUV()[0][0];
|
||||
Double aux_pel_1, aux_pel_2, aux_pel_mask;
|
||||
|
||||
for( UInt y = 0; y < m_pcFrameMask->getHeight(); y++ )
|
||||
for( UInt x = 0; x < m_pcFrameMask->getWidth(); x++ )
|
||||
{
|
||||
aux_pel_1 = *pInput1PelYUV++;
|
||||
aux_pel_2 = *pInput2PelYUV++;
|
||||
aux_pel_mask = aux_pel_1 * ( 1 - m_dWeigth ) + aux_pel_2 * m_dWeigth;
|
||||
*pOutputPelYUV++ = aux_pel_mask;
|
||||
}
|
||||
|
||||
for( UInt c = 1; c < m_pcFrameMask->getNumberChannels(); c++ )
|
||||
for( UInt y = 0; y < m_pcFrameMask->getChromaHeight(); y++ )
|
||||
for( UInt x = 0; x < m_pcFrameMask->getChromaWidth(); x++ )
|
||||
{
|
||||
aux_pel_1 = *pInput1PelYUV++;
|
||||
aux_pel_2 = *pInput2PelYUV++;
|
||||
aux_pel_mask = aux_pel_1 * ( 1 - m_dWeigth ) + aux_pel_2 * m_dWeigth;
|
||||
*pOutputPelYUV++ = aux_pel_mask;
|
||||
}
|
||||
|
||||
return m_pcFrameMask;
|
||||
}
|
||||
|
||||
Void FrameMask::destroy()
|
||||
{
|
||||
if( m_pcFrameMask )
|
||||
{
|
||||
delete m_pcFrameMask;
|
||||
}
|
||||
m_pcFrameMask = NULL;
|
||||
}
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* 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 FrameMask.h
|
||||
* \brief Module to aapply a mask to an image
|
||||
*/
|
||||
|
||||
#ifndef __FRAMEMASK_H__
|
||||
#define __FRAMEMASK_H__
|
||||
|
||||
#include "lib/PlaYUVerModuleIf.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace plaYUVer
|
||||
{
|
||||
|
||||
class FrameMask: public PlaYUVerModuleIf
|
||||
{
|
||||
REGISTER_CLASS_FACTORY( FrameMask )
|
||||
|
||||
private:
|
||||
Double m_dWeigth;
|
||||
PlaYUVerFrame* m_pcFrameMask;
|
||||
|
||||
public:
|
||||
FrameMask();
|
||||
virtual ~FrameMask()
|
||||
{
|
||||
}
|
||||
Bool create( std::vector<PlaYUVerFrame*> apcFrameList );
|
||||
PlaYUVerFrame* process( std::vector<PlaYUVerFrame*> apcFrameList );
|
||||
Void destroy();
|
||||
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
#endif // __FRAMEMASK_H__
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ PlaYUVerFrame* FrameShift::process( std::vector<PlaYUVerFrame*> apcFrameList )
|
||||
}
|
||||
|
||||
Int iShiftHorChroma = CHROMASHIFT( m_iShiftHor, m_pcProcessedFrame->getChromaWidthRatio() );
|
||||
Int iShiftVerChroma = CHROMASHIFT( m_iShiftVer, m_pcProcessedFrame->getChromaWidthRatio() );
|
||||
Int iShiftVerChroma = CHROMASHIFT( m_iShiftVer, m_pcProcessedFrame->getChromaHeightRatio() );
|
||||
|
||||
xStartOut = iShiftHorChroma >= 0 ? iShiftHorChroma : 0;
|
||||
xStartIn = iShiftHorChroma >= 0 ? 0 : -iShiftHorChroma;
|
||||
|
||||
@@ -41,6 +41,7 @@ PlaYUVerModuleFactory::PlaYUVerModuleFactory()
|
||||
Register( "FilterComponentChromaV", &FilterComponentChromaV::Create );
|
||||
Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create );
|
||||
Register( "FrameDifference", &FrameDifference::Create );
|
||||
Register( "FrameMask", &FrameMask::Create );
|
||||
Register( "SetChromaHalfScale", &SetChromaHalfScale::Create );
|
||||
Register( "FrameCrop", &FrameCrop::Create );
|
||||
Register( "FrameBinarization", &FrameBinarization::Create );
|
||||
|
||||
Reference in new issue
Block a user