Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ped-dyn-emp/petrack
1 result
Show changes
Commits on Source (39)
Showing
with 278 additions and 805 deletions
......@@ -2,6 +2,8 @@ stages:
- build_environment
- build
- test
- build_installer
- deploy
###############################################################################
# Linux CI
......@@ -48,20 +50,19 @@ unit_test_linux:
reports:
junit: "build/tests/unit_test/unit_test_report.xml"
# Currently disabled
# Execute regression tests
#regression_test_linux:
# image: $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG}_linux
# stage: test
# script:
# - cd tests/regression_test/tests
# - python -m pytest --path=../../../build/petrack --junitxml=pytest_report.xml >> "RegressionTestLog.txt"
# artifacts:
# when: on_failure
# paths:
# - "tests/regression_test/tests/RegressionTestLog.txt"
# reports:
# junit: "tests/regression_test/tests/pytest_report.xml"
regression_test_linux:
image: $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG}_linux
stage: test
script:
- cd tests/regression_test/tests
- python -m pytest --path=../../../build/petrack --junitxml=pytest_report.xml >> "RegressionTestLog.txt"
artifacts:
when: on_failure
paths:
- "tests/regression_test/tests/RegressionTestLog.txt"
reports:
junit: "tests/regression_test/tests/pytest_report.xml"
###############################################################################
......@@ -115,3 +116,38 @@ regression_test_windows:
reports:
junit: "tests/regression_test/tests/pytest_report.xml"
needs: ["build_windows"]
build_windows_installer:
stage: build_installer
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
tags:
- windows
script:
- mkdir -Force build
- $env:Path += ";C:\Program Files\CMake\bin"
- cd build
- Remove-Item -Force -Recurse -Path *
- cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_UNIT_TESTS=ON -DUSE_3RD_PARTY=ON ..
- cpack -C Release
artifacts:
paths:
- "build/petrack-installer-*"
expire_in: 2hrs
make_release:
image: alpine
stage: deploy
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
needs: ["build_windows_installer"]
script:
- apk --no-cache add curl
- cd build
- winInst=$(echo petrack-installer-*)
- curl -k -T $winInst -u "${SCIEBO_TOKEN}:" https://fz-juelich.sciebo.de/public.php/webdav/$winInst
......@@ -18,7 +18,7 @@
# Project setup
################################################################################
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(petrack LANGUAGES CXX)
project(petrack LANGUAGES CXX VERSION 0.8.14)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
......@@ -50,9 +50,6 @@ print_var(STEREO)
option(AVI "Use Avi File from Point Grey (currently not supported)" OFF)
print_var(AVI)
option(LIBELAS "Use Libelas" OFF)
print_var(LIBELAS)
option(DISABLE_STEREO "Disable Stereo features (currently must be taken)" ON)
print_var(DISABLE_STEREO)
......@@ -122,7 +119,7 @@ find_package(
REQUIRED)
# OpenCV
find_package(OpenCV 4.0.0 REQUIRED )
find_package(OpenCV 4.2.0 EXACT REQUIRED )
message("Building with OpenCV${OpenCV_VERSION_MAJOR}(${OpenCV_VERSION})")
# QWT
......@@ -147,6 +144,7 @@ set(CMAKE_AUTOUIC ON)
list(APPEND CMAKE_AUTOUIC_SEARCH_PATHS "${CMAKE_SOURCE_DIR}/ui" "./src")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(AUTOGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_autogen")
#**********************************************************
# Create library and exectuable *
......@@ -155,7 +153,6 @@ add_library(petrack_core STATIC)
add_executable(petrack src/main.cpp)
target_link_libraries(petrack PRIVATE petrack_core)
# TODO we should remove this compile option and be more strict
target_compile_options(petrack_core PRIVATE ${COMMON_COMPILE_OPTIONS})
target_compile_definitions(petrack_core PUBLIC STEREO_DISABLED)
......@@ -188,14 +185,14 @@ target_link_libraries(petrack_core PUBLIC ${OpenCV_LIBS})
# Linking QWT *
#*****************************************************************
if(APPLE)
target_link_directories(petrack_core PUBLIC ${QWT})
target_link_directories(petrack_core PUBLIC "${QWT}")
else()
target_compile_definitions(
petrack_core PRIVATE
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:USE_3RD_PARTY>>:QWT QWT_DLL>)
target_include_directories(petrack_core PUBLIC ${QWT_INCLUDE_DIR})
target_link_libraries(petrack_core PUBLIC ${QWT_LIBRARY})
target_include_directories(petrack_core PUBLIC "${QWT_INCLUDE_DIR}")
target_link_libraries(petrack_core PUBLIC Qwt::Qwt)
endif()
target_sources(petrack_core PRIVATE src/analysePlot.cpp)
......@@ -203,19 +200,6 @@ target_sources(petrack_core PRIVATE src/analysePlot.cpp)
#*************************************************************
# Handling of Options *
#*************************************************************
if(LIBELAS)
target_compile_definitions(petrack_core PRIVATE LIBELAS)
add_library(elas STATIC
src/libelas/elasDescriptor.cpp
src/libelas/elas.cpp
src/libelas/elasFilter.cpp
src/libelas/elasMatrix.cpp
src/libelas/elasTriangle.cpp
)
target_include_directories(elas PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_options(elas PRIVATE "-fpermissive")
target_link_libraries(petrack_core PRIVATE elas)
endif(LIBELAS)
# TODO currently not available
if(AVI)
......@@ -406,3 +390,9 @@ endif(${STEREO})
# # fuer pgrAviFile win32:LIBS += -lavifil32 win32:LIBS += -lmsvfw32 win64:LIBS
# += -lavifil32 win64:LIBS += -lmsvfw32
#####################################################
# Installer #
#####################################################
include(install_helper)
The software PeTrack is free.
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.
\ No newline at end of file
# PeTrack
Software for tracking pedestrians.
## Installation, Uninstallation:
To obtain the installer by following in the steps at https://www.fz-juelich.de/ias/ias-7/EN/Expertise/Software/PeTrack/petrackDownload.html.
Afterwards just execute `petrack-installer_<version>.exe` and follow the instructions.
To uninstall PeTrack execute `Uninstall.exe` in the PeTrack application folder.
## Usage:
The command line options can be displayed by calling
```bash
petrack -help
```
Key bindings can be found in the help menu of the program.
For more information see https://www.fz-juelich.de/ias/ias-7/EN/Expertise/Software/PeTrack/petrack.html.
Normal usage is interactive usage.
## Example:
To generate trajectories from a single image sequence starting with frame000.jpg to
with settings stored in project.pet, export tracker file tracker_file and exit
with saving the project to project.pet again:
```bash
petrack.exe -project project.pet -sequence frame000.jpg -autoTrack tracker_file -autoSave project.pet
```
## Changelog:
v0.8 : slanted view for external calibration, coordinate system and grid is possible, introduced multicolor marker with black dot, video support for various codecs <br/>
v0.7 : introduce stereo cameras; alternate height <br/>
background subtraction especially for stereo cameras; recognition of unmarked pedestrians; integration of 4 disparity algorithms <br/>
filter to swap picture; more video codecs; color blobs as marker using HSV triangle <br/>
marker with two dots added; export of viewing direction <br/>
v0.6 : bug fixes; improve speed; expand visualization possibilities; add variable tracking region adapted to head size; provide program combine to merge trajectories <br/>
v0.5 : improve robustness of tracking with interpolation and extrapolation; first analysis functionality <br/>
v0.4 : tracking import and export; manual adding and deleting of trackpoints <br/>
v0.3 : recognition; tracking; color mapping <br/>
v0.2 : add first recognition <br/>
v0.1 : only camera calibration is supported; import and export of video and image sequence <br/>
## Dependencies:
* Qwt (https://qwt.sf.net)
* Qt (https://www.qt.io/)
* OpenCV (https://opencv.org/)
#########################################################
# INSTALL #
#########################################################
include(InstallRequiredSystemLibraries)
include(GNUInstallDirs)
install(TARGETS petrack)
# install Qwt and OpenCV
install(CODE "
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/petrack${CMAKE_EXECUTABLE_SUFFIX}\" \"\" \"\")
")
# NOTE: For Future Mac installer, use macdeployqt utility (think about the licenses as well)
if (WIN32)
# Install Qt dlls
set (WINDEPLOYQT_APP \"${Qt5Core_DIR}/../../../bin/windeployqt\")
install(CODE "
message(\"\${CMAKE_INSTALL_PREFIX}/petrack.exe\")
execute_process(COMMAND ${WINDEPLOYQT_APP} \"\${CMAKE_INSTALL_PREFIX}/bin/petrack.exe\")
")
install(FILES "${OpenCV_LIB_PATH}/../bin/opencv_videoio_ffmpeg${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}_64.dll" DESTINATION ${CMAKE_INSTALL_BINDIR})
# NOTE: Paths might be platform specific
install(DIRECTORY "${Qt5Core_DIR}/../../../../../Licenses" DESTINATION "Licenses/Qt_Licenses")
install(DIRECTORY "${OpenCV_DIR}/etc/licenses" DESTINATION "Licenses/OpenCV_Licenses")
install(FILES "${OpenCV_DIR}/LICENSE/" DESTINATION "Licenses/OpenCV_Licenses")
endif()
install(FILES "${CMAKE_SOURCE_DIR}/ReadMe.md" "${CMAKE_SOURCE_DIR}/LICENSE" DESTINATION ".")
##################################################################
# PACKAGE #
##################################################################
set(CPACK_PACKAGE_FILE_NAME "petrack-installer-${PROJECT_VERSION}")
set(CPACK_PACKAGE_VENDOR "Forschungszentrum Juelich GmbH")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERISON_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERISON_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERISON_PATCH})
set(CPACK_PACKAGE_DESCRIPTION "PeTrack is a software for the automated extraction of pedestrian trajectories from videos.")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/ReadMe.md")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.fz-juelich.de/ias/ias-7/EN/Expertise/Software/PeTrack/petrack.html")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/ReadMe.md")
set(CPACK_PACKAGE_EXECUTABLES "petrack;PeTrack")
set(CPACK_MONOLITHIC_INSTALL TRUE)
set(CPACK_CREATE_DESKTOP_LINKS petrack)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
if(WIN32)
set(CPACK_GENERATOR "NSIS")
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}\\\\petrack.ico")
set(CPACK_NSIS_MODIFY_PATH ON)
set(CPACK_NSIS_DISPLAY_NAME "PeTrack")
set(CPACK_NSIS_PACKAGE_NAME "PeTrack")
set(CPACK_NSIS_INSTALLED_ICON_NAME "${CMAKE_SOURCE_DIR}\\\\petrack.ico")
set(CPACK_NSIS_HELP_LINK "https://www.fz-juelich.de/ias/ias-7/EN/Expertise/Software/PeTrack/petrack.html")
set(CPACK_NSIS_URL_INFO_ABOUT ${CPACK_NSIS_HELP_LINK})
set(CPACK_NSIS_CONTACT "petrack@fz-juelich.de")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
WriteRegStr HKCU 'Software\\\\Forschungszentrum Juelich GmbH\\\\PeTrack' 'fileExtension' 'pet'
WriteRegStr HKCU 'Software\\\\Forschungszentrum Juelich GmbH\\\\PeTrack' 'home' '$INSTDIR\\\\bin'
WriteRegStr HKCR '.pet' '' 'petfile'
WriteRegStr HKCR 'petfile' '' 'PeTrack Project File'
WriteRegStr HKCR 'petfile\\\\DefaultIcon' '' '$INSTDIR\\\\bin\\\\petrack.exe,0'
WriteRegStr HKCR 'petfile\\\\shell\\\\open\\\\command' '' '$INSTDIR\\\\bin\\\\petrack.exe %1'
WriteRegStr HKLM 'Software\\\\RegisteredApplications' 'petrack' '$INSTDIR\\\\petrack.exe'
WriteRegStr HKCU 'Software\\\\RegisteredApplications' 'petrack' '$INSTDIR\\\\petrack.exe'
WriteRegStr HKCU 'Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Explorer\\\\FileExts\\\\.pet\\\\OpenWithList' 'a' '$INSTDIR\\\\bin\\\\petrack.exe'
")
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
DeleteRegKey HKCU 'Software\\\\Forschungszentrum Juelich GmbH\\\\PeTrack'
DeleteRegKey HKCR '.pet'
DeleteRegKey HKCR 'petfile'
DeleteRegKey HKLM 'Software\\\\RegisteredApplications\\\\petrack'
DeleteRegKey HKCU 'Software\\\\RegisteredApplications\\\\petrack'
DeleteRegKey HKCU 'Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Explorer\\\\FileExts\\\\.pet'
")
endif()
include(CPack)
......@@ -3,6 +3,7 @@ FROM archlinux:20200705
# Update the repositories
RUN pacman -Syy
# Install the needed tools
RUN pacman -Syu --needed --noconfirm \
git \
gcc \
......@@ -11,14 +12,23 @@ RUN pacman -Syu --needed --noconfirm \
base-devel \
glew
# Install the needed libraries
RUN pacman -Syu --needed --noconfirm \
qt5-base \
opencv hdf5 vtk\
qwt \
catch2
# Install python
RUN pacman -Syu --needed --noconfirm \
python \
python-pip
RUN pip install pytest
# Install opencv 4.2 (last command to avoid any updates by pacman)
RUN pacman --needed --noconfirm -U \
https://archive.archlinux.org/packages/h/hdf5/hdf5-1.10.5-1-x86_64.pkg.tar.xz \
https://archive.archlinux.org/packages/v/vtk/vtk-8.2.0-9-x86_64.pkg.tar.xz \
https://archive.archlinux.org/packages/g/glew/glew-2.1.0-1-x86_64.pkg.tar.xz \
https://archive.archlinux.org/packages/o/openexr/openexr-2.4.0-6-x86_64.pkg.tar.xz \
https://archive.archlinux.org/packages/o/opencv/opencv-4.2.0-1-x86_64.pkg.tar.xz
......@@ -103,7 +103,6 @@ private:
// RectPlotItem *mRectItem;
// ViewAnalysePlotItem *mViewAnalyseItem;
QwtPlotZoomer *mZoomer;
int mGreyDiff;
int mActFrame;
};
......
......@@ -107,6 +107,7 @@ public:
// Returns the FPS of the current animation if it is a video
double getFPS();
double getOriginalFPS();
void setFPS(double fps);
......@@ -170,6 +171,7 @@ private:
// Number of frames per second in video
double mFps;
double mOriginalFps;
// the time (seconds since 1.1.1970 0 uhr, microseconds (.000001s)) when the first frame was recorded (bumblebee .time file)
int mFirstSec;
......
......@@ -142,11 +142,7 @@ protected:
long int m_liBytesWritten;
/** avi file name */
#ifdef WINDOWS
char m_szAVIDestFile[ _MAX_PATH ];
#else
char m_szAVIDestFile[ PATH_MAX ];
#endif
std::string m_szAVIDestFile;
char* m_fourCC;
//int m_fourCC;
......
......@@ -25,11 +25,8 @@ private:
public:
CalibFilter();
// IplImage* act(IplImage *img, IplImage *res);
cv::Mat act(cv::Mat &img, cv::Mat &res);
// bool changed();
Parameter *getFx();
Parameter *getFy();
Parameter *getCx();
......
......@@ -46,67 +46,67 @@ private slots:
QDesktopServices::openUrl(QUrl("http://docs.opencv.org/trunk/d1/dcd/structcv_1_1aruco_1_1DetectorParameters.html#details", QUrl::TolerantMode));
QDesktopServices::openUrl(QUrl("http://docs.opencv.org/3.1.0/d5/dae/tutorial_aruco_detection.html", QUrl::TolerantMode));
}
void on_dictList_currentIndexChanged(int index)
void on_dictList_currentIndexChanged(int /*index*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_minMarkerPerimeter_valueChanged(double val)
void on_minMarkerPerimeter_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_maxMarkerPerimeter_valueChanged(double val)
void on_maxMarkerPerimeter_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_adaptiveThreshWinSizeMin_valueChanged(int i)
void on_adaptiveThreshWinSizeMin_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_adaptiveThreshWinSizeMax_valueChanged(int i)
void on_adaptiveThreshWinSizeMax_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_adaptiveThreshWinSizeStep_valueChanged(int i)
void on_adaptiveThreshWinSizeStep_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_adaptiveThreshConstant_valueChanged(int i)
void on_adaptiveThreshConstant_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_polygonalApproxAccuracyRate_valueChanged(double val)
void on_polygonalApproxAccuracyRate_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_minCornerDistance_valueChanged(double val)
void on_minCornerDistance_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_minDistanceToBorder_valueChanged(int i)
void on_minDistanceToBorder_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_minMarkerDistance_valueChanged(double val)
void on_minMarkerDistance_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
......@@ -118,55 +118,55 @@ private slots:
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_cornerRefinementWinSize_valueChanged(int i)
void on_cornerRefinementWinSize_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_cornerRefinementMaxIterations_valueChanged(int i)
void on_cornerRefinementMaxIterations_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_cornerRefinementMinAccuracy_valueChanged(double val)
void on_cornerRefinementMinAccuracy_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_markerBorderBits_valueChanged(int i)
void on_markerBorderBits_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_perspectiveRemovePixelPerCell_valueChanged(int i)
void on_perspectiveRemovePixelPerCell_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_perspectiveRemoveIgnoredMarginPerCell_valueChanged(double val)
void on_perspectiveRemoveIgnoredMarginPerCell_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_maxErroneousBitsInBorderRate_valueChanged(double val)
void on_maxErroneousBitsInBorderRate_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_errorCorrectionRate_valueChanged(double val)
void on_errorCorrectionRate_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_minOtsuStdDev_valueChanged(double val)
void on_minOtsuStdDev_valueChanged(double /*val*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
......
......@@ -41,60 +41,60 @@ private slots:
// if (mMainWindow && (mMainWindow->getScene()))
// mMainWindow->getScene()->update();
// }
void on_maskMask_stateChanged(int i)
void on_maskMask_stateChanged(int /*i*/)
{
mMainWindow->getScene()->update();
}
void on_opacity_valueChanged(int i)
void on_opacity_valueChanged(int /*i*/)
{
mMainWindow->getScene()->update();
}
// functions which force a new recognition
void on_inversHue_stateChanged(int i)
void on_inversHue_stateChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_useOpen_stateChanged(int i)
void on_useOpen_stateChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_useClose_stateChanged(int i)
void on_useClose_stateChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_closeRadius_valueChanged(int i)
void on_closeRadius_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_openRadius_valueChanged(int i)
void on_openRadius_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_minArea_valueChanged(int i)
void on_minArea_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_maxArea_valueChanged(int i)
void on_maxArea_valueChanged(int /*i*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
mMainWindow->updateImage();
}
void on_maxRatio_valueChanged(double d)
void on_maxRatio_valueChanged(double /*d*/)
{
mMainWindow->setRecognitionChanged(true);// flag indicates that changes of recognition parameters happens
if( !mMainWindow->isLoading() )
......
......@@ -260,36 +260,36 @@ private slots:
void on_trackRegionLevels_valueChanged(int i);
void on_trackShowSearchSize_stateChanged(int i);
void on_trackShowOnlyVisible_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowOnlyVisible_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
// void on_trackShowOnlyNr_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowCurrentPoint_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowCurrentPoint_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackGotoNr_clicked();
void on_trackGotoStartNr_clicked();
void on_trackGotoEndNr_clicked();
void on_trackHeadSized_stateChanged(int i);
void on_trackShowPoints_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowPointsColored_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowPath_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowColColor_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowColorMarker_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowNumber_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowGroundPosition_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowGroundPath_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowHeightIndividual_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackNumberBold_stateChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackCurrentPointSize_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackPointSize_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackPathWidth_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackColColorSize_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackColorMarkerSize_valueChanged(int i) { mScene->update(); }
void on_trackNumberSize_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackGroundPositionSize_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackGroundPathSize_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowBefore_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowAfter_valueChanged(int i) { if (!isLoading()) mScene->update(); }
void on_trackShowPoints_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowPointsColored_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowPath_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowColColor_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowColorMarker_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowNumber_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowGroundPosition_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowGroundPath_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowHeightIndividual_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackNumberBold_stateChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackCurrentPointSize_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackPointSize_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackPathWidth_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackColColorSize_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackColorMarkerSize_valueChanged(int /*i*/) { mScene->update(); }
void on_trackNumberSize_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackGroundPositionSize_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackGroundPathSize_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowBefore_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_trackShowAfter_valueChanged(int /*i*/) { if (!isLoading()) mScene->update(); }
void on_performRecognition_stateChanged(int i);
void on_markerBrightness_valueChanged(int i);
......
......@@ -22,7 +22,7 @@ public:
MyEllipse();
MyEllipse(double x, double y, double r1, double r2, double angle);
MyEllipse(QPointF center, QSizeF size, double angle);
MyEllipse(const MyEllipse &ellipse);
MyEllipse(const MyEllipse &ellipse) = default;
Vec2F center() const;
QSizeF size() const;
......
......@@ -57,7 +57,7 @@ inline std::ostream& operator<<(std::ostream& s, const QString& t)
#include "cxcore.h"
void copyToQImage(QImage *qImg, IplImage *iplImg); // war static functin in animatioln class
#endif
void copyToQImage(QImage *qImg, cv::Mat &img);
void copyToQImage(QImage &qImg, cv::Mat &img);
#include <QLabel>
#ifndef STEREO_DISABLED
......@@ -199,7 +199,7 @@ inline QTextStream& operator>>(QTextStream& s, QColor& col)
inline QString getExistingFile(const QString &fileList, const QString &relToFileName)
{
QStringList list;
list = fileList.split(";", QString::SkipEmptyParts);
list = fileList.split(";", Qt::SkipEmptyParts);
for (int i = 0; i < list.size(); ++i)
{
if (QFile(list.at(i)).exists())
......
/*
Copyright 2011. All rights reserved.
Institute of Measurement and Control Systems
Karlsruhe Institute of Technology, Germany
This file is part of libelas.
Authors: Andreas Geiger
libelas 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 3 of the License, or any later version.
libelas 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
libelas; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
// Main header file. Include this to use libelas in your code.
#ifndef __ELAS_H__
#define __ELAS_H__
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <emmintrin.h>
// define fixed-width datatypes for Visual Studio projects
//#ifndef _MSC_VER
#include <stdint.h>
//#else
// typedef __int8 int8_t;
// typedef __int16 int16_t;
// typedef __int32 int32_t;
// typedef __int64 int64_t;
// typedef unsigned __int8 uint8_t;
// typedef unsigned __int16 uint16_t;
// typedef unsigned __int32 uint32_t;
// typedef unsigned __int64 uint64_t;
//#endif
#ifdef PROFILE
#include "timer.h"
#endif
class Elas {
public:
enum setting {ROBOTICS,MIDDLEBURY};
// parameter settings
struct parameters {
int32_t disp_min; // min disparity
int32_t disp_max; // max disparity
float support_threshold; // max. uniqueness ratio (best vs. second best support match)
int32_t support_texture; // min texture for support points
int32_t candidate_stepsize; // step size of regular grid on which support points are matched
int32_t incon_window_size; // window size of inconsistent support point check
int32_t incon_threshold; // disparity similarity threshold for support point to be considered consistent
int32_t incon_min_support; // minimum number of consistent support points
bool add_corners; // add support points at image corners with nearest neighbor disparities
int32_t grid_size; // size of neighborhood for additional support point extrapolation
float beta; // image likelihood parameter
float gamma; // prior constant
float sigma; // prior sigma
float sradius; // prior sigma radius
int32_t match_texture; // min texture for dense matching
int32_t lr_threshold; // disparity threshold for left/right consistency check
float speckle_sim_threshold; // similarity threshold for speckle segmentation
int32_t speckle_size; // maximal size of a speckle (small speckles get removed)
int32_t ipol_gap_width; // interpolate small gaps (left<->right, top<->bottom)
bool filter_median; // optional median filter (approximated)
bool filter_adaptive_mean; // optional adaptive mean filter (approximated)
bool postprocess_only_left; // saves time by not postprocessing the right image
bool subsampling; // saves time by only computing disparities for each 2nd pixel
// note: for this option D1 and D2 must be passed with size
// width/2 x height/2 (rounded towards zero)
// constructor
parameters (setting s=ROBOTICS) {
// default settings in a robotics environment
// (do not produce results in half-occluded areas
// and are a bit more robust towards lighting etc.)
if (s==ROBOTICS) {
disp_min = 0;
disp_max = 255;
support_threshold = 0.85;
support_texture = 10;
candidate_stepsize = 5;
incon_window_size = 5;
incon_threshold = 5;
incon_min_support = 5;
add_corners = 0;
grid_size = 20;
beta = 0.02;
gamma = 3;
sigma = 1;
sradius = 2;
match_texture = 1;
lr_threshold = 2;
speckle_sim_threshold = 1;
speckle_size = 200;
ipol_gap_width = 3;
filter_median = 0;
filter_adaptive_mean = 1;
postprocess_only_left = 1;
subsampling = 0;
// default settings for middlebury benchmark
// (interpolate all missing disparities)
} else {
disp_min = 0;
disp_max = 255;
support_threshold = 0.95;
support_texture = 10;
candidate_stepsize = 5;
incon_window_size = 5;
incon_threshold = 5;
incon_min_support = 5;
add_corners = 1;
grid_size = 20;
beta = 0.02;
gamma = 5;
sigma = 1;
sradius = 3;
match_texture = 0;
lr_threshold = 2;
speckle_sim_threshold = 1;
speckle_size = 200;
ipol_gap_width = 5000;
filter_median = 1;
filter_adaptive_mean = 0;
postprocess_only_left = 0;
subsampling = 0;
}
}
};
// constructor, input: parameters
Elas (parameters param) : param(param) {}
// deconstructor
~Elas () {}
// matching function
// inputs: pointers to left (I1) and right (I2) intensity image (uint8, input)
// pointers to left (D1) and right (D2) disparity image (float, output)
// dims[0] = width of I1 and I2
// dims[1] = height of I1 and I2
// dims[2] = bytes per line (often equal to width, but allowed to differ)
// note: D1 and D2 must be allocated before (bytes per line = width)
// if subsampling is not active their size is width x height,
// otherwise width/2 x height/2 (rounded towards zero)
void process (uint8_t* I1,uint8_t* I2,float* D1,float* D2,const int32_t* dims);
private:
struct support_pt {
int32_t u;
int32_t v;
int32_t d;
support_pt(int32_t u,int32_t v,int32_t d):u(u),v(v),d(d){}
};
struct triangle {
int32_t c1,c2,c3;
float t1a,t1b,t1c;
float t2a,t2b,t2c;
triangle(int32_t c1,int32_t c2,int32_t c3):c1(c1),c2(c2),c3(c3){}
};
inline uint32_t getAddressOffsetImage (const int32_t& u,const int32_t& v,const int32_t& width) {
return v*width+u;
}
inline uint32_t getAddressOffsetGrid (const int32_t& x,const int32_t& y,const int32_t& d,const int32_t& width,const int32_t& disp_num) {
return (y*width+x)*disp_num+d;
}
// support point functions
void removeInconsistentSupportPoints (int16_t* D_can,int32_t D_can_width,int32_t D_can_height);
void removeRedundantSupportPoints (int16_t* D_can,int32_t D_can_width,int32_t D_can_height,
int32_t redun_max_dist, int32_t redun_threshold, bool vertical);
void addCornerSupportPoints (std::vector<support_pt> &p_support);
inline int16_t computeMatchingDisparity (const int32_t &u,const int32_t &v,uint8_t* I1_desc,uint8_t* I2_desc,const bool &right_image);
std::vector<support_pt> computeSupportMatches (uint8_t* I1_desc,uint8_t* I2_desc);
// triangulation & grid
std::vector<triangle> computeDelaunayTriangulation (std::vector<support_pt> p_support,int32_t right_image);
void computeDisparityPlanes (std::vector<support_pt> p_support,std::vector<triangle> &tri,int32_t right_image);
void createGrid (std::vector<support_pt> p_support,int32_t* disparity_grid,int32_t* grid_dims,bool right_image);
// matching
inline void updatePosteriorMinimum (__m128i* I2_block_addr,const int32_t &d,const int32_t &w,
const __m128i &xmm1,__m128i &xmm2,int32_t &val,int32_t &min_val,int32_t &min_d);
inline void updatePosteriorMinimum (__m128i* I2_block_addr,const int32_t &d,
const __m128i &xmm1,__m128i &xmm2,int32_t &val,int32_t &min_val,int32_t &min_d);
inline void findMatch (int32_t &u,int32_t &v,float &plane_a,float &plane_b,float &plane_c,
int32_t* disparity_grid,int32_t *grid_dims,uint8_t* I1_desc,uint8_t* I2_desc,
int32_t *P,int32_t &plane_radius,bool &valid,bool &right_image,float* D);
void computeDisparity (std::vector<support_pt> p_support,std::vector<triangle> tri,int32_t* disparity_grid,int32_t* grid_dims,
uint8_t* I1_desc,uint8_t* I2_desc,bool right_image,float* D);
// L/R consistency check
void leftRightConsistencyCheck (float* D1,float* D2);
// postprocessing
void removeSmallSegments (float* D);
void gapInterpolation (float* D);
// optional postprocessing
void adaptiveMean (float* D);
void median (float* D);
// parameter set
parameters param;
// memory aligned input images + dimensions
uint8_t *I1,*I2;
int32_t width,height,bpl;
// profiling timer
#ifdef PROFILE
Timer timer;
#endif
};
#endif
/*
Copyright 2011. All rights reserved.
Institute of Measurement and Control Systems
Karlsruhe Institute of Technology, Germany
This file is part of libelas.
Authors: Andreas Geiger
libelas 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 3 of the License, or any later version.
libelas 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
libelas; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
// NOTE: This descripter is a sparse approximation to the 50-dimensional
// descriptor described in the paper. It produces similar results, but
// is faster to compute.
#ifndef __DESCRIPTOR_H__
#define __DESCRIPTOR_H__
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
// Define fixed-width datatypes for Visual Studio projects
//#ifndef _MSC_VER
#include <stdint.h>
//#else
// typedef __int8 int8_t;
// typedef __int16 int16_t;
// typedef __int32 int32_t;
// typedef __int64 int64_t;
// typedef unsigned __int8 uint8_t;
// typedef unsigned __int16 uint16_t;
// typedef unsigned __int32 uint32_t;
// typedef unsigned __int64 uint64_t;
//#endif
class Descriptor {
public:
// constructor creates filters
Descriptor(uint8_t* I,int32_t width,int32_t height,int32_t bpl,bool half_resolution);
// deconstructor releases memory
~Descriptor();
// descriptors accessible from outside
uint8_t* I_desc;
private:
// build descriptor I_desc from I_du and I_dv
void createDescriptor(uint8_t* I_du,uint8_t* I_dv,int32_t width,int32_t height,int32_t bpl,bool half_resolution);
};
#endif
/*
Copyright 2011. All rights reserved.
Institute of Measurement and Control Systems
Karlsruhe Institute of Technology, Germany
This file is part of libelas.
Authors: Julius Ziegler, Andreas Geiger
libelas 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 3 of the License, or any later version.
libelas 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
libelas; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __FILTER_H__
#define __FILTER_H__
#include <emmintrin.h>
#include <pmmintrin.h>
// define fixed-width datatypes for Visual Studio projects
//#ifndef _MSC_VER
#include <stdint.h>
//#else
// typedef __int8 int8_t;
// typedef __int16 int16_t;
// typedef __int32 int32_t;
// typedef __int64 int64_t;
// typedef unsigned __int8 uint8_t;
// typedef unsigned __int16 uint16_t;
// typedef unsigned __int32 uint32_t;
// typedef unsigned __int64 uint64_t;
//#endif
// fast filters: implements 3x3 and 5x5 sobel filters and
// 5x5 blob and corner filters based on SSE2/3 instructions
namespace filter {
// private namespace, public user functions at the bottom of this file
namespace detail {
void integral_image( const uint8_t* in, int32_t* out, int w, int h );
void unpack_8bit_to_16bit( const __m128i a, __m128i& b0, __m128i& b1 );
void pack_16bit_to_8bit_saturate( const __m128i a0, const __m128i a1, __m128i& b );
// convolve image with a (1,4,6,4,1) row vector. Result is accumulated into output.
// output is scaled by 1/128, then clamped to [-128,128], and finally shifted to [0,255].
void convolve_14641_row_5x5_16bit( const int16_t* in, uint8_t* out, int w, int h );
// convolve image with a (1,2,0,-2,-1) row vector. Result is accumulated into output.
// This one works on 16bit input and 8bit output.
// output is scaled by 1/128, then clamped to [-128,128], and finally shifted to [0,255].
void convolve_12021_row_5x5_16bit( const int16_t* in, uint8_t* out, int w, int h );
// convolve image with a (1,2,1) row vector. Result is accumulated into output.
// This one works on 16bit input and 8bit output.
// output is scaled by 1/4, then clamped to [-128,128], and finally shifted to [0,255].
void convolve_121_row_3x3_16bit( const int16_t* in, uint8_t* out, int w, int h );
// convolve image with a (1,0,-1) row vector. Result is accumulated into output.
// This one works on 16bit input and 8bit output.
// output is scaled by 1/4, then clamped to [-128,128], and finally shifted to [0,255].
void convolve_101_row_3x3_16bit( const int16_t* in, uint8_t* out, int w, int h );
void convolve_cols_5x5( const unsigned char* in, int16_t* out_v, int16_t* out_h, int w, int h );
void convolve_col_p1p1p0m1m1_5x5( const unsigned char* in, int16_t* out, int w, int h );
void convolve_row_p1p1p0m1m1_5x5( const int16_t* in, int16_t* out, int w, int h );
void convolve_cols_3x3( const unsigned char* in, int16_t* out_v, int16_t* out_h, int w, int h );
}
void sobel3x3( const uint8_t* in, uint8_t* out_v, uint8_t* out_h, int w, int h );
void sobel5x5( const uint8_t* in, uint8_t* out_v, uint8_t* out_h, int w, int h );
// -1 -1 0 1 1
// -1 -1 0 1 1
// 0 0 0 0 0
// 1 1 0 -1 -1
// 1 1 0 -1 -1
void checkerboard5x5( const uint8_t* in, int16_t* out, int w, int h );
// -1 -1 -1 -1 -1
// -1 1 1 1 -1
// -1 1 8 1 -1
// -1 1 1 1 -1
// -1 -1 -1 -1 -1
void blob5x5( const uint8_t* in, int16_t* out, int w, int h );
};
#endif
/*
Copyright 2011. All rights reserved.
Institute of Measurement and Control Systems
Karlsruhe Institute of Technology, Germany
This file is part of libelas.
Authors: Andreas Geiger
libelas 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 3 of the License, or any later version.
libelas 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
libelas; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
// basic image I/O, based on Pedro Felzenszwalb's code
#ifndef IMAGE_H
#define IMAGE_H
#include <cstdlib>
#include <climits>
#include <cstring>
#include <fstream>
// use imRef to access image data.
#define imRef(im, x, y) (im->access[y][x])
// use imPtr to get pointer to image data.
#define imPtr(im, x, y) &(im->access[y][x])
#define BUF_SIZE 256
typedef unsigned char uchar;
typedef struct { uchar r, g, b; } rgb;
inline bool operator==(const rgb &a, const rgb &b) {
return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
}
// image class
template <class T> class image {
public:
// create image
image(const int width, const int height, const bool init = false);
// delete image
~image();
// init image
void init(const T &val);
// deep copy
image<T> *copy() const;
// get image width/height
int width() const { return w; }
int height() const { return h; }
// image data
T *data;
// row pointers
T **access;
private:
int w, h;
};
template <class T> image<T>::image(const int width, const int height, const bool init) {
w = width;
h = height;
data = new T[w * h]; // allocate space for image data
access = new T*[h]; // allocate space for row pointers
// initialize row pointers
for (int i = 0; i < h; i++)
access[i] = data + (i * w);
// init to zero
if (init)
memset(data, 0, w * h * sizeof(T));
}
template <class T> image<T>::~image() {
delete [] data;
delete [] access;
}
template <class T> void image<T>::init(const T &val) {
T *ptr = imPtr(this, 0, 0);
T *end = imPtr(this, w-1, h-1);
while (ptr <= end)
*ptr++ = val;
}
template <class T> image<T> *image<T>::copy() const {
image<T> *im = new image<T>(w, h, false);
memcpy(im->data, data, w * h * sizeof(T));
return im;
}
class pnm_error {};
void pnm_read(std::ifstream &file, char *buf) {
char doc[BUF_SIZE];
char c;
file >> c;
while (c == '#') {
file.getline(doc, BUF_SIZE);
file >> c;
}
file.putback(c);
file.width(BUF_SIZE);
file >> buf;
file.ignore();
}
image<uchar> *loadPGM(const char *name) {
char buf[BUF_SIZE];
// read header
std::ifstream file(name, std::ios::in | std::ios::binary);
pnm_read(file, buf);
if (strncmp(buf, "P5", 2)) {
std::cout << "ERROR: Could not read file " << name << std::endl;
throw pnm_error();
}
pnm_read(file, buf);
int width = atoi(buf);
pnm_read(file, buf);
int height = atoi(buf);
pnm_read(file, buf);
if (atoi(buf) > UCHAR_MAX) {
std::cout << "ERROR: Could not read file " << name << std::endl;
throw pnm_error();
}
// read data
image<uchar> *im = new image<uchar>(width, height);
file.read((char *)imPtr(im, 0, 0), width * height * sizeof(uchar));
return im;
}
void savePGM(image<uchar> *im, const char *name) {
int width = im->width();
int height = im->height();
std::ofstream file(name, std::ios::out | std::ios::binary);
file << "P5\n" << width << " " << height << "\n" << UCHAR_MAX << "\n";
file.write((char *)imPtr(im, 0, 0), width * height * sizeof(uchar));
}
#endif
/*
Copyright 2011. All rights reserved.
Institute of Measurement and Control Systems
Karlsruhe Institute of Technology, Germany
This file is part of libviso2.
Authors: Andreas Geiger
libviso2 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 any later version.
libviso2 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
libviso2; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef MATRIX_H
#define MATRIX_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
//#ifndef _MSC_VER
#include <stdint.h>
//#else
// typedef __int8 int8_t;
// typedef __int16 int16_t;
// typedef __int32 int32_t;
// typedef __int64 int64_t;
// typedef unsigned __int8 uint8_t;
// typedef unsigned __int16 uint16_t;
// typedef unsigned __int32 uint32_t;
// typedef unsigned __int64 uint64_t;
//#endif
#define endll endl << endl // double end line definition
typedef double FLOAT; // double precision
//typedef float FLOAT; // single precision
class Matrix {
public:
// constructor / deconstructor
Matrix (); // init empty 0x0 matrix
Matrix (const int32_t m,const int32_t n); // init empty mxn matrix
Matrix (const int32_t m,const int32_t n,const FLOAT* val_); // init mxn matrix with values from array 'val'
Matrix (const Matrix &M); // creates deepcopy of M
~Matrix ();
// assignment operator, copies contents of M
Matrix& operator= (const Matrix &M);
// copies submatrix of M into array 'val', default values copy whole row/column/matrix
void getData(FLOAT* val_,int32_t i1=0,int32_t j1=0,int32_t i2=-1,int32_t j2=-1);
// set or get submatrices of current matrix
Matrix getMat(int32_t i1,int32_t j1,int32_t i2=-1,int32_t j2=-1);
void setMat(const Matrix &M,const int32_t i,const int32_t j);
// set sub-matrix to scalar (default 0), -1 as end replaces whole row/column/matrix
void setVal(FLOAT s,int32_t i1=0,int32_t j1=0,int32_t i2=-1,int32_t j2=-1);
// set (part of) diagonal to scalar, -1 as end replaces whole diagonal
void setDiag(FLOAT s,int32_t i1=0,int32_t i2=-1);
// clear matrix
void zero();
// extract columns with given index
Matrix extractCols (std::vector<int> idx);
// create identity matrix
static Matrix eye (const int32_t m);
void eye ();
// create diagonal matrix with nx1 or 1xn matrix M as elements
static Matrix diag(const Matrix &M);
// returns the m-by-n matrix whose elements are taken column-wise from M
static Matrix reshape(const Matrix &M,int32_t m,int32_t n);
// create 3x3 rotation matrices (convention: http://en.wikipedia.org/wiki/Rotation_matrix)
static Matrix rotMatX(const FLOAT &angle);
static Matrix rotMatY(const FLOAT &angle);
static Matrix rotMatZ(const FLOAT &angle);
// simple arithmetic operations
Matrix operator+ (const Matrix &M); // add matrix
Matrix operator- (const Matrix &M); // subtract matrix
Matrix operator* (const Matrix &M); // multiply with matrix
Matrix operator* (const FLOAT &s); // multiply with scalar
Matrix operator/ (const Matrix &M); // divide elementwise by matrix (or vector)
Matrix operator/ (const FLOAT &s); // divide by scalar
Matrix operator- (); // negative matrix
Matrix operator~ (); // transpose
FLOAT l2norm (); // euclidean norm (vectors) / frobenius norm (matrices)
FLOAT mean (); // mean of all elements in matrix
// complex arithmetic operations
static Matrix cross (const Matrix &a, const Matrix &b); // cross product of two vectors
static Matrix inv (const Matrix &M); // invert matrix M
bool inv (); // invert this matrix
FLOAT det (); // returns determinant of matrix
bool solve (const Matrix &M,FLOAT eps=1e-20); // solve linear system M*x=B, replaces *this and M
bool lu(int32_t *idx, FLOAT &d, FLOAT eps=1e-20); // replace *this by lower upper decomposition
void svd(Matrix &U,Matrix &W,Matrix &V); // singular value decomposition *this = U*diag(W)*V^T
// print matrix to stream
friend std::ostream& operator<< (std::ostream& out,const Matrix& M);
// direct data access
FLOAT **val;
int32_t m,n;
private:
void allocateMemory (const int32_t m_,const int32_t n_);
void releaseMemory ();
inline FLOAT pythag(FLOAT a,FLOAT b);
};
#endif // MATRIX_H