From e17539939ac11256f60301d3280f417617342a19 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 17 May 2014 18:53:27 +0100 Subject: [PATCH] Add a new module to measure disparity using the StereoVar method of opencv --- cmake/ModuleDefault.cmake | 4 ++ source/modules/DisparityCVVar.cpp | 88 +++++++++++++++++++++++++++++++ source/modules/DisparityCVVar.h | 61 +++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 source/modules/DisparityCVVar.cpp create mode 100644 source/modules/DisparityCVVar.h diff --git a/cmake/ModuleDefault.cmake b/cmake/ModuleDefault.cmake index 999e42c..8263fa1 100644 --- a/cmake/ModuleDefault.cmake +++ b/cmake/ModuleDefault.cmake @@ -6,3 +6,7 @@ ADD_MODULE( FilterFrame "FilterFrame.cpp" ) ADD_MODULE( FrameDifference "FrameDifference.cpp" ) #ADD_MODULE( MeasurePSNR "MeasurePSNR.cpp" ) +IF( USE_OPENCV ) + ADD_MODULE( DisparityCVVar "DisparityCVVar.cpp" ) +ENDIF() + diff --git a/source/modules/DisparityCVVar.cpp b/source/modules/DisparityCVVar.cpp new file mode 100644 index 0000000..1d1c105 --- /dev/null +++ b/source/modules/DisparityCVVar.cpp @@ -0,0 +1,88 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 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 DisparityCVVar.cpp + * \brief Measure the disparity between two images using the Stereo Var method (OpenCV) + */ + +#include + +#include "DisparityCVVar.h" +#include "PlaYUVerFrame.h" + +namespace plaYUVer +{ + +static PlaYUVerModuleDefinition DisparityCVVarDef = +{ + FRAME_LEVEL_MODULE, + "Disparity", + "StereoVar", + "Measure the disparity between two images using the Stereo Var method (OpenCV)", + MODULE_REQUIRES_TWO_FRAMES, + MODULE_REQUIRES_NEW_WINDOW, }; + +DisparityCVVar::DisparityCVVar() +{ + setModuleDefinition( DisparityCVVarDef ); + m_pcDisparityFrame = NULL; + m_cStereoVar.levels = 3; // ignored with USE_AUTO_PARAMS + m_cStereoVar.pyrScale = 0.5; // ignored with USE_AUTO_PARAMS + m_cStereoVar.nIt = 25; + + m_cStereoVar.maxDisp = 0; + m_cStereoVar.poly_n = 3; + m_cStereoVar.poly_sigma = 0.0; + m_cStereoVar.fi = 15.0f; + m_cStereoVar.lambda = 0.03f; + m_cStereoVar.penalization = m_cStereoVar.PENALIZATION_TICHONOV; // ignored with USE_AUTO_PARAMS + m_cStereoVar.cycle = m_cStereoVar.CYCLE_V; // ignored with USE_AUTO_PARAMS + m_cStereoVar.flags = m_cStereoVar.USE_SMART_ID | m_cStereoVar.USE_AUTO_PARAMS | m_cStereoVar.USE_INITIAL_DISPARITY | m_cStereoVar.USE_MEDIAN_FILTERING; +} + +Void DisparityCVVar::create( PlaYUVerFrame* InputFrame ) +{ + m_pcDisparityFrame = new PlaYUVerFrame( InputFrame->getWidth(), InputFrame->getHeight(), PlaYUVerFrame::GRAY ); + m_cStereoVar.minDisp = -( ( ( InputFrame->getWidth() / 8 ) + 15 ) & -16 ); +} + +PlaYUVerFrame* DisparityCVVar::process( PlaYUVerFrame* InputLeft, PlaYUVerFrame* InputRight ) +{ +// cv::Mat leftImage = InputLeft->getCvMat(); +// cv::Mat rightImage = InputRight->getCvMat(); + cv::Mat disparityImage, disparityImage8; + +// m_cStereoVar(leftImage,rightImage,disparityImage); +// disparityImage.convertTo(disparityImage8,CV_8U); + disparityImage8 = InputLeft->getCvMat(); + + m_pcDisparityFrame->copyFrom(&disparityImage8); + return m_pcDisparityFrame; +} + +Void DisparityCVVar::destroy() +{ + if( m_pcDisparityFrame ) + delete m_pcDisparityFrame; + m_pcDisparityFrame = NULL; +} + +} // NAMESPACE + diff --git a/source/modules/DisparityCVVar.h b/source/modules/DisparityCVVar.h new file mode 100644 index 0000000..77e9ac8 --- /dev/null +++ b/source/modules/DisparityCVVar.h @@ -0,0 +1,61 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 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 DisparityCVVar.h + * \brief Measure the disparity between two images using the Stereo Var method (OpenCV) + */ + +#ifndef __DISPARITYCVVAR_H__ +#define __DISPARITYCVVAR_H__ + +#include "config.h" + +#include +#include +#include "TypeDef.h" +#include "PlaYUVerFrame.h" +#include "PlaYUVerModuleIf.h" +#include + +#include + +namespace plaYUVer +{ + +class DisparityCVVar: public PlaYUVerModuleIf +{ +private: + PlaYUVerFrame* m_pcDisparityFrame; + cv::StereoVar m_cStereoVar; +public: + DisparityCVVar(); + virtual ~DisparityCVVar() + { + } + + Void create( PlaYUVerFrame* InputFrame ); + PlaYUVerFrame* process( PlaYUVerFrame* InputLeft, PlaYUVerFrame* InputRight ); + Void destroy(); +}; + +} // NAMESPACE + +#endif // __DISPARITYCVVAR_H__ +