diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5100d72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,135 @@ +# Created by https://www.gitignore.io/api/c++,clion,linux +# Edit at https://www.gitignore.io/?templates=c++,clion,linux + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### CLion ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +bin/ +build/ +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### CLion Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# End of https://www.gitignore.io/api/c++,clion,linux \ No newline at end of file diff --git a/.idea/calyp.iml b/.idea/calyp.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/calyp.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8822db8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6f76545 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 093438f..3122edf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,7 +157,7 @@ IF (NOT CMAKE_BUILD_TYPE ) SET(CMAKE_BUILD_TYPE "Release") ENDIF() -SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-deprecated-declarations" ) +SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) ADD_DEFINITIONS(-DQT_NO_CAST_TO_ASCII #-DQT_NO_CAST_FROM_ASCII @@ -175,6 +175,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op" ) endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations" ) endif() IF( USE_WERROR ) diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index c9c05c2..57a4732 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -321,8 +321,9 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog ) { m_pCurrStream = new CalypStream; } - - bool bConfig = guessFormat( cFilename, Width, Height, InputFormat, BitsPel, Endianness ) || bForceDialog; + bool bConfig = true; + if( !bForceDialog ) + bConfig = guessFormat( cFilename, Width, Height, InputFormat, BitsPel, Endianness, FrameRate ); bool bRet = false; for( int iPass = 0; iPass < 2 && !bRet; iPass++ ) { @@ -334,8 +335,15 @@ bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog ) return false; } } - bRet = m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate, - true ); + try + { + bRet = m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate, true ); + } + catch( CalypFailure& e ) + { + if( iPass == 1 ) + throw( e ); + } } m_sStreamInfo.m_cFilename = cFilename; @@ -435,7 +443,7 @@ void VideoSubWindow::updateVideoWindowInfo() } bool VideoSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel, - int& rEndianness ) + int& rEndianness, unsigned int& rFrameRate ) { std::vector stdResList = CalypStream::stdResolutionSizes(); bool bGuessed = true; @@ -483,7 +491,7 @@ bool VideoSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsign QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( FilenameShort ); if( resolutionMatch.hasMatch() ) { - QString resolutionString = resolutionMatch.captured( 0 ); + QString resolutionString = resolutionMatch.captured( resolutionMatch.lastCapturedIndex() ); if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) ) { resolutionString.remove( "_" ); @@ -532,7 +540,7 @@ bool VideoSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsign QRegularExpressionMatch BppMatch = QRegularExpression( "_\\d*bpp" ).match( FilenameShort ); if( BppMatch.hasMatch() ) { - QString matchString = BppMatch.captured( 0 ); + QString matchString = BppMatch.captured( BppMatch.lastCapturedIndex() ); matchString.remove( "_" ); matchString.remove( "bpp" ); rBitsPerPixel = matchString.toUInt(); @@ -542,6 +550,20 @@ bool VideoSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsign } } + // Guess frame rate - match %dbpp + QRegularExpressionMatch FpsMatch = QRegularExpression( "_\\d*fps" ).match( FilenameShort ); + if( FpsMatch.hasMatch() ) + { + QString matchString = FpsMatch.captured( FpsMatch.lastCapturedIndex() ); + matchString.remove( "_" ); + matchString.remove( "fps" ); + rFrameRate = matchString.toUInt(); + if( rFrameRate < 0 ) + { + rFrameRate = 30; + } + } + // Guess Endianness if( FilenameShort.contains( QStringLiteral( "be" ), Qt::CaseInsensitive ) ) { diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 16cba96..59019c4 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -192,7 +192,7 @@ private: bool goToNextFrame( bool bThreaded = false ); static bool guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel, - int& rEndianness ); + int& rEndianness, unsigned int& rFrameRate ); bool hasRunningModule(); diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index a370890..f7008d7 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -81,6 +81,11 @@ int CalypFrame::findPixelFormat( const ClpString& name ) return -1; } +int CalypFrame::pelformatColorSpace( const int idx ) +{ + return g_CalypPixFmtDescriptorsMap.at( idx ).colorSpace; +} + struct CalypFramePrivate { public: @@ -346,6 +351,8 @@ bool CalypFrame::haveSameFmt( const CalypFrame& other, unsigned int match ) cons bRet &= ( getBitsPel() == other.getBitsPel() ); if( match & MATCH_COLOR_SPACE_IGNORE_GRAY ) bRet &= ( getColorSpace() == CLP_COLOR_GRAY || getColorSpace() == other.getColorSpace() ); + if( match & MATCH_BYTES_PER_FRAME ) + bRet &= ( getBytesPerFrame() == other.getBytesPerFrame() ); return bRet; } @@ -423,7 +430,7 @@ unsigned int CalypFrame::getBitsPel() const return d->m_uiBitsPel; } -ClpULong CalypFrame::getBytesPerFrame() +ClpULong CalypFrame::getBytesPerFrame() const { return getBytesPerFrame( d->m_uiWidth, d->m_uiHeight, d->m_iPixelFormat, d->m_uiBitsPel ); } @@ -432,10 +439,10 @@ ClpULong CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeig { const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( iPixelFormat ) ); unsigned int bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1; - unsigned long long int numberBytes = uiWidth * uiHeight; + ClpULong numberBytes = uiWidth * uiHeight; if( pcPelFormat->numberChannels > 1 ) { - unsigned long long int numberBytesChroma = + ClpULong numberBytesChroma = CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight ); numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma; } @@ -524,11 +531,11 @@ void CalypFrame::setPixel( unsigned int xPos, unsigned int yPos, CalypPixel pixe void CalypFrame::copyFrom( const CalypFrame& other ) { - if( !haveSameFmt( other, MATCH_ALL ) ) + if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_BYTES_PER_FRAME | MATCH_BITS ) ) return; d->m_bHasRGBPel = false; d->m_bHasHistogram = false; - memcpy( &( d->m_pppcInputPel[CLP_LUMA][0][0]), &(other.getPelBufferYUV()[CLP_LUMA][0][0]), getTotalNumberOfPixels() * sizeof( ClpPel ) ); + memcpy( &( d->m_pppcInputPel[0][0][0]), &(other.getPelBufferYUV()[0][0][0]), getTotalNumberOfPixels() * sizeof( ClpPel ) ); } void CalypFrame::copyFrom( const CalypFrame* other ) @@ -539,7 +546,7 @@ void CalypFrame::copyFrom( const CalypFrame* other ) void CalypFrame::copyFrom( const CalypFrame& other, unsigned int xPos, unsigned int yPos ) { - if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_PEL_FMT | MATCH_BITS ) ) + if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_BYTES_PER_FRAME | MATCH_BITS ) ) return; // TODO: Protect width and height ClpPel*** pInput = other.getPelBufferYUV(); @@ -699,7 +706,7 @@ void CalypFrame::frameToBuffer( ClpByte* output_buffer, int iEndianness ) step = ( d->m_pcPelFormat->comp[ch].step_minus1 ) * bytesPixel; pTmpPel = d->m_pppcInputPel[ch][0]; - pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane]; + pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane] + ( d->m_pcPelFormat->comp[ch].offset_plus1 - 1 ) * bytesPixel; for( i = 0; i < CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ); i++ ) { diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index cdcb2b8..7036f19 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -100,6 +100,7 @@ public: static std::vector supportedPixelFormatListNames( int colorSpace ); static int numberOfFormats(); static int findPixelFormat( const ClpString& name ); + static int pelformatColorSpace( const int idx ); /** * Creates a new frame using the following configuration @@ -145,6 +146,7 @@ public: MATCH_PEL_FMT = 4, MATCH_BITS = 8, MATCH_COLOR_SPACE_IGNORE_GRAY = 16, + MATCH_BYTES_PER_FRAME = 32, MATCH_ALL = 0xFFFF, }; @@ -236,7 +238,7 @@ public: * Get number of bytes per frame of an existing frame * @return number of bytes per frame */ - ClpULong getBytesPerFrame(); + ClpULong getBytesPerFrame() const; /** * Get number of bytes per frame of a specific pixel format diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index b035578..b140407 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -78,6 +78,7 @@ std::vector CalypStream::stdResolutionSizes() std::vector stdResList; CalypStandardResolution stdResElement; + REGIST_CALYP_STANDARD_RESOLUTION( "QCIF", 176, 144 ); REGIST_CALYP_STANDARD_RESOLUTION( "CIF", 352, 288 ); REGIST_CALYP_STANDARD_RESOLUTION( "VGA", 640, 480 ); REGIST_CALYP_STANDARD_RESOLUTION( "WVGA", 832, 480 ); diff --git a/lib/StreamHandlerLibav.cpp b/lib/StreamHandlerLibav.cpp index b1e9321..36d67b8 100644 --- a/lib/StreamHandlerLibav.cpp +++ b/lib/StreamHandlerLibav.cpp @@ -31,7 +31,7 @@ #include #include -#if( ( LIBAVCODEC_VERSION_MAJOR >= 57 ) && ( LIBAVCODEC_VERSION_MINOR >= 37 ) ) +#if( ( LIBAVCODEC_VERSION_MAJOR > 57 ) || ( LIBAVCODEC_VERSION_MAJOR == 57 ) && ( LIBAVCODEC_VERSION_MINOR >= 37 ) ) #define FF_SEND_RECEIVE_API #define FF_USER_CODEC_PARAM #endif diff --git a/lib/StreamHandlerOpenCV.cpp b/lib/StreamHandlerOpenCV.cpp index 0779d45..0a967ef 100644 --- a/lib/StreamHandlerOpenCV.cpp +++ b/lib/StreamHandlerOpenCV.cpp @@ -29,6 +29,9 @@ #include #include +#if CV_MAJOR_VERSION >= 4 +#include +#endif using cv::Mat; using cv::VideoCapture; @@ -45,7 +48,6 @@ std::vector StreamHandlerOpenCV::supportedReadFormats() std::vector StreamHandlerOpenCV::supportedWriteFormats() { INI_REGIST_CALYP_SUPPORTED_FMT; - REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Portable PixMap ", "ppm" ); REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Portable Network Graphics", "png" ); REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Joint Photographic Experts Group", "jpg" ); REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerOpenCV::Create, "Windows Bitmap", "bmp" ); @@ -78,8 +80,13 @@ bool StreamHandlerOpenCV::openHandler( ClpString strFilename, bool bInput ) m_strFormatName = "DEV"; m_strCodecName = "Raw Video"; pcVideoCapture = new VideoCapture( iDeviceId ); + #if CV_MAJOR_VERSION >= 4 + m_uiWidth = pcVideoCapture->get( cv::CAP_PROP_FRAME_WIDTH ); + m_uiHeight = pcVideoCapture->get( cv::CAP_PROP_FRAME_HEIGHT ); + #else m_uiWidth = pcVideoCapture->get( CV_CAP_PROP_FRAME_WIDTH ); m_uiHeight = pcVideoCapture->get( CV_CAP_PROP_FRAME_HEIGHT ); + #endif m_dFrameRate = 25; } else diff --git a/lib/StreamHandlerPortableMap.cpp b/lib/StreamHandlerPortableMap.cpp index 588b4a0..20d092c 100644 --- a/lib/StreamHandlerPortableMap.cpp +++ b/lib/StreamHandlerPortableMap.cpp @@ -33,7 +33,7 @@ std::vector StreamHandlerPortableMap::supportedReadFormats() { INI_REGIST_CALYP_SUPPORTED_FMT; - //REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable BitMap ", "pbm" ); + REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable BitMap ", "pbm" ); REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable GrayMap ", "pgm" ); REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable PixMap ", "ppm" ); END_REGIST_CALYP_SUPPORTED_FMT; @@ -42,7 +42,9 @@ std::vector StreamHandlerPortableMap::supportedReadFormats() std::vector StreamHandlerPortableMap::supportedWriteFormats() { INI_REGIST_CALYP_SUPPORTED_FMT; + REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable BitMap ", "pbm" ); REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable GrayMap ", "pgm" ); + REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerPortableMap::Create, "Portable PixMap ", "ppm" ); END_REGIST_CALYP_SUPPORTED_FMT; } @@ -84,18 +86,20 @@ bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput ) } else { + int colorSpace = CalypFrame::pelformatColorSpace( m_iPixelFormat ); m_iMaxValue = ( 1 << m_uiBitsPerPixel ) - 1; if( m_uiBitsPerPixel == 1 ) { m_iMagicNumber = 4; } - else if( m_iPixelFormat == CLP_GRAY ) + else if( colorSpace == CLP_COLOR_GRAY ) { m_iMagicNumber = 5; } - else if( m_iPixelFormat == CLP_RGB24 ) + else if( colorSpace == CLP_COLOR_RGB ) { m_iMagicNumber = 6; + m_iPixelFormat = CalypFrame::findPixelFormat("RGB"); } else { @@ -103,7 +107,7 @@ bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput ) return false; } } - m_iEndianness = 0; + m_iEndianness = CLP_BIG_ENDIAN; m_dFrameRate = 1; m_uiTotalNumberFrames = 1; return true; @@ -141,13 +145,16 @@ bool StreamHandlerPortableMap::read( CalypFrame* pcFrame ) bool StreamHandlerPortableMap::write( CalypFrame* pcFrame ) { + CalypFrame pcRGBFrame( pcFrame->getWidth(), pcFrame->getHeight(), + m_iPixelFormat, pcFrame->getBitsPel() ); + pcRGBFrame.copyFrom( pcFrame ); fseek( m_pFile, 0, SEEK_SET ); fprintf( m_pFile, "P%d\n%d %d\n", m_iMagicNumber, m_uiWidth, m_uiHeight ); if( m_iMagicNumber > 4 ) { fprintf( m_pFile, "%d\n", m_iMaxValue ); } - pcFrame->frameToBuffer( m_pStreamBuffer, CLP_BIG_ENDIAN ); + pcRGBFrame.frameToBuffer( m_pStreamBuffer, m_iEndianness ); unsigned long long int processed_bytes = fwrite( m_pStreamBuffer, sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); if( processed_bytes != m_uiNBytesPerFrame ) return false; diff --git a/modules/AbsoluteFrameDifference.cpp b/modules/AbsoluteFrameDifference.cpp index daa71bb..41c4f85 100644 --- a/modules/AbsoluteFrameDifference.cpp +++ b/modules/AbsoluteFrameDifference.cpp @@ -49,13 +49,11 @@ bool AbsoluteFrameDifference::create( std::vector apcFrameList ) _BASIC_MODULE_API_2_CHECK_ for( unsigned int i = 1; i < apcFrameList.size(); i++ ) - if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE | - CalypFrame::MATCH_RESOLUTION | - CalypFrame::MATCH_BITS ) ) + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE_IGNORE_GRAY + | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION | CalypFrame::MATCH_BITS ) ) return false; - m_pcFrameDifference = - new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY ); + m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, apcFrameList[0]->getBitsPel() ); return true; } @@ -68,13 +66,18 @@ CalypFrame* AbsoluteFrameDifference::process( std::vector apcFrameL ClpPel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0]; int aux_pel_1, aux_pel_2; - for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) - for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ ) + for( unsigned int ch = 0; ch < m_pcFrameDifference->getNumberChannels(); ch++ ) + { + for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) { - aux_pel_1 = *pInput1PelYUV++; - aux_pel_2 = *pInput2PelYUV++; - *pOutputPelYUV++ = abs( aux_pel_1 - aux_pel_2 ); + for( unsigned int 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; } diff --git a/modules/DisparityStereoSGBM.cpp b/modules/DisparityStereoSGBM.cpp index cfa7e4c..6158527 100644 --- a/modules/DisparityStereoSGBM.cpp +++ b/modules/DisparityStereoSGBM.cpp @@ -58,7 +58,7 @@ bool DisparityStereoSGBM::create( std::vector apcFrameList ) } m_uiNumberOfDisparities = ( ( apcFrameList[0]->getWidth() / 8 ) + 15 ) & -16; int cn = apcFrameList[0]->getNumberChannels(); -#if( CV_MAJOR_VERSION == 3 ) +#if( CV_MAJOR_VERSION >= 3 ) m_cStereoMatch = cv::StereoSGBM::create( 0, 16, m_uiBlockSize ); m_cStereoMatch->setPreFilterCap( 63 ); @@ -99,7 +99,7 @@ CalypFrame* DisparityStereoSGBM::process( std::vector apcFrameList return m_pcDisparityFrame; } cv::Mat disparityImage, disparityImage8; -#if( CV_MAJOR_VERSION == 3 ) +#if( CV_MAJOR_VERSION >= 3 ) m_cStereoMatch->compute( leftImage, rightImage, disparityImage ); #else m_cStereoMatch( leftImage, rightImage, disparityImage ); diff --git a/modules/DisparityStereoSGBM.h b/modules/DisparityStereoSGBM.h index 8fc9483..515e0ec 100644 --- a/modules/DisparityStereoSGBM.h +++ b/modules/DisparityStereoSGBM.h @@ -60,7 +60,7 @@ private: bool m_bUseHH; int m_uiNumberOfDisparities; unsigned int m_uiBlockSize; -#if( CV_MAJOR_VERSION == 3 ) +#if( CV_MAJOR_VERSION >= 3 ) cv::Ptr m_cStereoMatch; #else cv::StereoSGBM m_cStereoMatch; diff --git a/modules/FrameDifference.cpp b/modules/FrameDifference.cpp index f98dcf4..2acb61a 100644 --- a/modules/FrameDifference.cpp +++ b/modules/FrameDifference.cpp @@ -52,8 +52,7 @@ bool FrameDifference::create( std::vector apcFrameList ) unsigned int uiMaxBitsPixel = 0; for( unsigned int i = 0; i < apcFrameList.size(); i++ ) { - if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], - CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION ) ) + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_PEL_FMT | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION ) ) return false; if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel ) { @@ -70,7 +69,7 @@ bool FrameDifference::create( std::vector apcFrameList ) m_iMaxDiffValue = ( 1 << ( m_uiBitsPixel - 1 ) ); m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), - CLP_GRAY, m_uiBitsPixel ); + apcFrameList[0]->getPelFormat(), m_uiBitsPixel ); return true; } @@ -82,19 +81,20 @@ CalypFrame* FrameDifference::process( std::vector apcFrameList ) int aux_pel_1, aux_pel_2; int diff = 0; - for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) - for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); 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 ); + 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++ ) + { + 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; - *pOutputPelYUV++ = diff; - } + diff += m_iMaxDiffValue; + *pOutputPelYUV++ = diff; + } return m_pcFrameDifference; } diff --git a/modules/MeasureOpticalFlowDualTVL1.cpp b/modules/MeasureOpticalFlowDualTVL1.cpp index ffba0a6..40ec989 100644 --- a/modules/MeasureOpticalFlowDualTVL1.cpp +++ b/modules/MeasureOpticalFlowDualTVL1.cpp @@ -23,6 +23,9 @@ */ #include "MeasureOpticalFlowDualTVL1.h" +#if CV_MAJOR_VERSION >= 4 +#include +#endif using cv::Mat; using cv::Mat_; @@ -61,7 +64,11 @@ bool MeasureOpticalFlowDualTVL1::create( std::vector apcFrameList ) return false; m_iStep = 16; + #if CV_MAJOR_VERSION >= 4 + m_cTvl1 = cv::optflow::createOptFlow_DualTVL1(); + #else m_cTvl1 = cv::createOptFlow_DualTVL1(); + #endif m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY ); return true; diff --git a/modules/OpticalFlow.cpp b/modules/OpticalFlow.cpp index cd4b464..b23e2c8 100644 --- a/modules/OpticalFlow.cpp +++ b/modules/OpticalFlow.cpp @@ -166,7 +166,11 @@ bool OpticalFlowDualTVL1::create( std::vector apcFrameList ) bool bRet = commonCreate( apcFrameList ); if( !bRet ) return bRet; + #if CV_MAJOR_VERSION >= 4 + m_cOpticalFlow = cv::optflow::createOptFlow_DualTVL1(); + #else m_cOpticalFlow = cv::createOptFlow_DualTVL1(); + #endif return bRet; } diff --git a/update_upstream_and_merge_into_master.sh b/update_upstream_and_merge_into_master.sh new file mode 100755 index 0000000..d508df7 --- /dev/null +++ b/update_upstream_and_merge_into_master.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +git checkout upstream +git pull https://github.com/pixlra/calyp.git master +git push origin upstream + +git checkout master +git pull origin master +git merge upstream +git push origin master \ No newline at end of file