commit 7c12323accfe21b28c6cd05ec7f5012c1f560191 Author: Kristian Krsnik Date: Tue Jan 30 00:24:37 2024 +0100 initial commit diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..10a6982 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,51 @@ +################################################################################ +2015-09-26; by Dominik Rue + +- removed a bug which prevented saving on clicking on the save button + +- disabled disabling of saving button (user can choose to overwrite) + +################################################################################ +2015-09-25; by Dominik Rue + +- removed a bug which caused an application crash on loading images + +- added successful saving information text on status bar + +- removed a bug which caused backslashes in filepath to not save files + +- removed a bug which caused an exception on exiting the program + +- removed a bug which prevented saving when non existing directory was specified + +- added "uninstall before install" which tries to uninstall old versions + +- removed some fixed paths and settings for cmake + +- added bit information (i.e. 32/64) to about dialog + + +################################################################################ +2015-08; by Dominik Rue + +- added mutex to decrease maximum memory consumption + (useful for the 32bit vresions) + +- added online documentation to docs folder + +- A new selection can now also be created by clicking twice + (used to be only by dragging) + +- faster extraction of preview in previously bloccking situations + +- made some changes to the online documentation, i.e. howto install + +- added the online documentation to the source package + +- fixed a bug which would not reload already seen 16bit images + +- fixed a bug which caused the application to crash on closing it + +################################################################################ +2015-08; by Dominik Rue +First release diff --git a/CMakeModules/Findliblbfgs.cmake b/CMakeModules/Findliblbfgs.cmake new file mode 100644 index 0000000..8ed487b --- /dev/null +++ b/CMakeModules/Findliblbfgs.cmake @@ -0,0 +1,110 @@ +# +# Try to find the Liblbfgs library and include path. +# Once done this will define +# +# LIBLBFGS_FOUND +# LIBLBFGS_INCLUDE_PATH +# LIBLBFGS_LIBRARY + +if(MAKE_RPM) + + FIND_PATH( LIBLBFGS_INCLUDE_PATH lbfgs.h + PATHS ${MANUAL_LBFGS}/include + DOC "The directory where lbfgs.h resides" + + [NO_DEFAULT_PATH] + [NO_CMAKE_ENVIRONMENT_PATH] + [NO_CMAKE_PATH] + [NO_SYSTEM_ENVIRONMENT_PATH] + [NO_CMAKE_SYSTEM_PATH]) + + FIND_LIBRARY( LIBLBFGS_LIBRARY + NAMES liblbfgs lbfgs + PATHS ${MANUAL_LBFGS}/lib/.libs + ${MANUAL_LBFGS}/lib + DOC "The Lbfgs library" + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + +else(MAKE_RPM) + FIND_PATH( LIBLBFGS_INCLUDE_PATH lbfgs.h + PATHS + /usr/include + /usr/include/lbfgs + /usr/local/include + /usr/local/include/lbfgs + /sw/include + /sw/include/lbfgs + /opt/local/include + /opt/local/include/lbfgs + DOC "The directory where lbfgs.h resides") + + FIND_LIBRARY( LIBLBFGS_LIBRARY + NAMES liblbfgs lbfgs + PATHS + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /sw/lib + /opt/local/lib + DOC "The Lbfgs library") +endif(MAKE_RPM) + +if(WIN32) + FIND_LIBRARY( LIBLBFGS_LIBRARY_DLL + NAMES liblbfgs-1-10.dll + PATHS + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /sw/lib + /opt/local/lib + DOC "The Lbfgs library") + + IF (LIBLBFGS_INCLUDE_PATH AND LIBLBFGS_LIBRARY AND LIBLBFGS_LIBRARY_DLL) + SET( LIBLBFGS_FOUND TRUE CACHE BOOL "Set to TRUE if liblbfgs is found, FALSE otherwise") + ENDIF (LIBLBFGS_INCLUDE_PATH AND LIBLBFGS_LIBRARY AND LIBLBFGS_LIBRARY_DLL) + MARK_AS_ADVANCED( + LIBLBFGS_FOUND + LIBLBFGS_LIBRARY + LIBLBFGS_LIBRARY_DLL + LIBLBFGS_INCLUDE_PATH) +else() + + IF (LIBLBFGS_INCLUDE_PATH AND LIBLBFGS_LIBRARY) + SET( LIBLBFGS_FOUND TRUE CACHE BOOL "Set to TRUE if liblbfgs is found, FALSE otherwise") + ENDIF (LIBLBFGS_INCLUDE_PATH AND LIBLBFGS_LIBRARY) + MARK_AS_ADVANCED( + LIBLBFGS_FOUND + LIBLBFGS_LIBRARY + LIBLBFGS_INCLUDE_PATH) +endif() + +if(UNIX AND NOT LIBLBFGS_FOUND) + message(WARNING "LIBLBFGS not found") +elseif(UNIX) + set ( MY_LIBS + ${MY_LIBS} + ${LIBLBFGS_LIBRARY} + ) + + if (NOT ${LIBLBFGS_INCLUDE_PATH} STREQUAL "/usr/include/lbfgs") + include_directories ( + "${LIBLBFGS_INCLUDE_PATH}/../" + "${LIBLBFGS_INCLUDE_PATH}") + endif() +else() + include_directories ( + "${LIBLBFGS_INCLUDE_PATH}" + ) + set ( MY_LIBS + ${MY_LIBS} + ${LIBLBFGS_LIBRARY_DLL} + ) +endif(UNIX AND NOT LIBLBFGS_FOUND) + diff --git a/CMakeModules/Findmisc.cmake b/CMakeModules/Findmisc.cmake new file mode 100644 index 0000000..41f9f64 --- /dev/null +++ b/CMakeModules/Findmisc.cmake @@ -0,0 +1,18 @@ +cmake_minimum_required (VERSION 2.8.1) + + + +set (PACKAGE_NAME "misc") + +set (ADD_DIRECTORY "module_${PACKAGE_NAME}") +include(${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/NewIfNotExists.cmake) + + +include_directories ( + ${CMAKE_CURRENT_LIST_DIR}/../${ADD_DIRECTORY} + ) + +set ( MY_LIBS + ${MY_LIBS} + ${PACKAGE_NAME} + ) \ No newline at end of file diff --git a/CMakeModules/Findversioning.cmake b/CMakeModules/Findversioning.cmake new file mode 100644 index 0000000..e04e191 --- /dev/null +++ b/CMakeModules/Findversioning.cmake @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 2.8.1) + +set (PACKAGE_NAME "versioning") + +set (ADD_DIRECTORY "module_${PACKAGE_NAME}") + +set (QT_USE_QTMAIN TRUE) +set (QT_USE_SVG TRUE) +set (QT_USE_NETWORK TRUE) +set (QT_MORE_COMPONENTS ${QT_MORE_COMPONENTS} QtSvg QtNetwork) +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/qt5.cmake ) +find_package(Qt5Network) +find_package(Qt5Xml) + +include_directories ( + ${CMAKE_CURRENT_LIST_DIR}/../${ADD_DIRECTORY} + ) diff --git a/CMakeModules/NewIfNotExists.cmake b/CMakeModules/NewIfNotExists.cmake new file mode 100644 index 0000000..e74dd39 --- /dev/null +++ b/CMakeModules/NewIfNotExists.cmake @@ -0,0 +1,35 @@ +# will include modules/thirdparty if needed for out of source building +# make sure PROJECTNAME and PACKAGE_NAME are set properly + +set(BUILDFILE "${CMAKE_BINARY_DIR}/built/${PACKAGE_NAME}") + +# has it been built yet ? +if(NOT EXISTS "${BUILDFILE}") + set(FROMDIR ${CMAKE_CURRENT_LIST_DIR}/../${ADD_DIRECTORY}) + set(TODIR ${CMAKE_BINARY_DIR}/${SUBDIR_STANDALONE}/${ADD_DIRECTORY}) + + # projectname must not equal package name, + # this happens if projectname finds itself, for instance + if(NOT ${PROJECTNAME} STREQUAL ${PACKAGE_NAME} AND NOT EXISTS "${BUILDFILE}") + add_subdirectory (${FROMDIR} ${TODIR}) + endif() +endif() + +# # add as target, if it does not exist already +# # this makes it possible to separately +# # compile different programs + +# set(DEST_DIR_TMP "${CMAKE_BINARY_DIR}/${ADD_DIRECTORY}") +# if (NOT ${PROJECTNAME} STREQUAL ${PACKAGE_NAME}) +# if (NOT TARGET ${PACKAGE_NAME}) +# If(NOT IS_DIRECTORY ${DEST_DIR_TMP}) +# set(TRGTDIR "${CMAKE_BINARY_DIR}/${ADD_DIRECTORY}") +# add_subdirectory ( +# "${CMAKE_CURRENT_LIST_DIR}/../${ADD_DIRECTORY}" +# ${TRGTDIR} +# ) +# set (LINK_DIRECTORIES ${TRGTDIR} ${LINK_DIRECTORIES}) +# endif() +# endif() +# endif() + diff --git a/CMakeModules/PATCH_NO b/CMakeModules/PATCH_NO new file mode 100644 index 0000000..1fb8d9e --- /dev/null +++ b/CMakeModules/PATCH_NO @@ -0,0 +1 @@ +601 \ No newline at end of file diff --git a/CMakeModules/addtranslation.cmake b/CMakeModules/addtranslation.cmake new file mode 100644 index 0000000..36dc3d5 --- /dev/null +++ b/CMakeModules/addtranslation.cmake @@ -0,0 +1,59 @@ +#### translation stuff ##### +# http://www.cmake.org/cmake/help/v2.8.9/cmake.html +####### + +find_package(Qt5Widgets REQUIRED) +find_package(Qt5LinguistTools REQUIRED) + +SET(${PROJECTNAME}_TRANSPREFIX + trans_${PROJECTNAME}_de +) + +SET(${PROJECTNAME}_TRANSLATIONS + ${${PROJECTNAME}_TRANSPREFIX}.ts +) + +SET(${PROJECTNAME}_TRANSLATIONS_COMPILED + ${${PROJECTNAME}_TRANSPREFIX}.qm +) + +QT5_CREATE_TRANSLATION (${PROJECTNAME}_TRANSLATION_FILES + ${${PROJECTNAME}_FORMS} + ${${PROJECTNAME}_HEADERS} + ${${PROJECTNAME}_SOURCES} + ${${PROJECTNAME}_RESSOURCES} + ${${PROJECTNAME}_TRANSLATIONS} +) + +SET(AddQtRessourceFiles + "${CMAKE_CURRENT_BINARY_DIR}/${${PROJECTNAME}_TRANSLATIONS_COMPILED}" + ${AddQtRessourceFiles} +) + +file(GLOB_RECURSE TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${${PROJECTNAME}_TRANSLATIONS}") +# do not install since normally it's included in the exe file +# if(UNIX) +# install(FILES ${TS_FILES} ${QM_FILES} +# DESTINATION "${CMAKE_INSTALL_PREFIX}/${PROJECTNAME}/translations" +# COMPONENT main +# ) +# # qm is created by make, so cmake won't find it +# # directly install it +# install(FILES +# "${CMAKE_CURRENT_BINARY_DIR}/${${PROJECTNAME}_TRANSLATIONS_COMPILED}" +# DESTINATION "${CMAKE_INSTALL_PREFIX}/${PROJECTNAME}/translations" +# COMPONENT main +# ) +# else() +# install(FILES ${TS_FILES} ${QM_FILES} +# DESTINATION translations +# COMPONENT main +# ) +# # qm is created by make, so cmake won't find it +# # directly install it +# install(FILES +# "${CMAKE_CURRENT_BINARY_DIR}/${${PROJECTNAME}_TRANSLATIONS_COMPILED}" +# DESTINATION translations +# COMPONENT main +# ) +# endif() diff --git a/CMakeModules/buildPackage.cmake b/CMakeModules/buildPackage.cmake new file mode 100644 index 0000000..552a99d --- /dev/null +++ b/CMakeModules/buildPackage.cmake @@ -0,0 +1,72 @@ +### tell cpack which components ### +if ( DEFINED USE_COMPONENTS ) + message ("For installation only use specified components: ${USE_COMPONENTS}") + set(CPACK_COMPONENTS_ALL ${USE_COMPONENTS}) +else() + set(CPACK_COMPONENTS_ALL main header lib data ${CPACK_COMPONENTS_ALL}) +endif() + +### set display names for single components ### +if( DEFINED MAIN_DISPLAY_NAME ) + set(CPACK_COMPONENT_MAIN_DISPLAY_NAME ${MAIN_DISPLAY_NAME}) +else() + set(CPACK_COMPONENT_MAIN_DISPLAY_NAME "Main Application") +endif() + +set(CPACK_COMPONENT_LIB_DISPLAY_NAME "Development Libraries") +set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "Development Headers") +set(CPACK_COMPONENT_DATA_DISPLAY_NAME "Sample Data / Additional Data") + +## define installation groups for components ### +# set(CPACK_COMPONENT_MAIN_GROUP "MainGroup") +# set(CPACK_COMPONENT_BINARIES_GROUP "MainGroup") +# set(CPACK_COMPONENT_DATA_GROUP "DataGroup") +# set(CPACK_COMPONENT_LIB_GROUP "DevelopmentGroup") +# set(CPACK_COMPONENT_HEADER_GROUP "DevelopmentGroup") + +## provide installation groups display names ### +# set(CPACK_COMPONENT_GROUP_MAINGROUP_DISPLAY_NAME "Application Binaries") +# set(CPACK_COMPONENT_GROUP_DATAGROUP_DISPLAY_NAME "Extra Data") +# set(CPACK_COMPONENT_GROUP_DEVELOPMENTGROUP_DISPLAY_NAME "Development Files") + +### set executable - symbol pairs ### +set(CPACK_PACKAGE_EXECUTABLES + "${PROJECTNAME}" "${CPACK_COMPONENT_MAIN_DISPLAY_NAME}") + +#include(InstallRequiredSystemLibraries) +set(CPACK_PROJECTNAME "${CPACK_COMPONENT_MAIN_DISPLAY_NAME}") +set(CPACK_PACKAGE_NAME "${CPACK_COMPONENT_MAIN_DISPLAY_NAME}") +set(CPACK_PACKAGE_VENDOR "Dominik Rue") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_COMPONENT_MAIN_DISPLAY_NAME} - Installation Program") +if ( NOT DEFINED VERSION_MAJOR ) + SET(VERSION_MAJOR 0) +endif() +if ( NOT DEFINED VERSION_MINOR ) + SET(VERSION_MINOR 1) +endif() +if ( NOT DEFINED VERSION_PATCH ) + SET(VERSION_PATCH 1) +endif() +set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") +set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECTNAME}") + +if (WIN32) + IF(CMAKE_CL_64) + SET(CMAKE_SYSTEM_PROCESSOR "X86") + SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") + #SET(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} (Win64)") + SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION} (Win64)") + ELSE() + SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES") + #SET(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}") + SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}") + ENDIF() +endif(WIN32) + +# and finally +include(CPack) diff --git a/CMakeModules/installDesktop.cmake b/CMakeModules/installDesktop.cmake new file mode 100644 index 0000000..003d7b2 --- /dev/null +++ b/CMakeModules/installDesktop.cmake @@ -0,0 +1,79 @@ +## this macro will look for the local applications path +## and write a .desktop file + +macro (INSTALL_DESKTOP_LOCAL execflags comment importerpath iconsubpath iconsize additionalText) + if (UNIX) + set(ICON_INSTALL "/usr/share/icons/hicolor/") + + set(dir "$ENV{HOME}/.local/share/applications/") + IF(EXISTS ${dir}) + set(DESKTOP_FILENAME "${dir}${PROJECTNAME}.desktop") + set(DESKTOP_FILENAME_BUILD "${CMAKE_CURRENT_BINARY_DIR}/${PROJECTNAME}.desktop") + #NOTE: copying desktop file to ${DESKTOP_FILENAME} . \nThis will ensure" + # a nice icon and possibly offer \"${PROJECTNAME}\" to the user" + # on certain file or device events\n Even without make install." (GNOME) + + execute_process( + COMMAND whoami + OUTPUT_VARIABLE user OUTPUT_STRIP_TRAILING_WHITESPACE) + if (NOT ${user} STREQUAL "root" ) + file(WRITE ${DESKTOP_FILENAME} + "[Desktop Entry]\n" + "Version=1.0\n" + "Name=${PROJECTNAME}\n" + "Comment=${comment}\n" + "Exec=${CMAKE_CURRENT_BINARY_DIR}/${PROJECTNAME}${execflags}\n" + "Icon=${CMAKE_CURRENT_SOURCE_DIR}/${iconsubpath}/${PROJECTNAME}.png\n" + ${additionalText}) + endif() + + file(WRITE ${DESKTOP_FILENAME_BUILD} + "[Desktop Entry]\n" + "Version=1.0\n" + "Name=${PROJECTNAME}\n" + "Comment=${comment}\n" + "Exec=${PROJECTNAME}\n" + "Icon=${ICON_INSTALL}128x128/apps/${PROJECTNAME}.png\n" + ${additionalText}) + + set(DESKTOP_DIR "/usr/share/applications/") + if(EXISTS ${DESKTOP_DIR}) + INSTALL(FILES + ${DESKTOP_FILENAME_BUILD} + DESTINATION ${DESKTOP_DIR} + RENAME ${PROJECTNAME}.desktop + COMPONENT main + ) + else() + message("Warning: not installing desktop file, ${DESKTOP_DIR} not found or changed ?") + endif() + + if(EXISTS ${ICON_INSTALL}) + #GET_FILENAME_COMPONENT(iconSuffix ${CMAKE_CURRENT_SOURCE_DIR}/${iconsubpath} EXT) + FOREACH (size ${iconsize}) + set(ICON_INSTALL "/usr/share/icons/hicolor/${size}/apps/") + INSTALL(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/${iconsubpath}/${PROJECTNAME}${size}.png" + + DESTINATION ${ICON_INSTALL} + RENAME "${PROJECTNAME}.png" + COMPONENT main + ) + ENDFOREACH(size) + else() + message("Warning: not installing icon for unix, dir ${ICON_INSTALL} not found or changed?") + endif() + + set(KDE_ACTIONS "/usr/share/kde4/apps/solid/actions/") + if(EXISTS ${KDE_ACTIONS} AND NOT ${importerpath} STREQUAL "") + INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/${importerpath} + DESTINATION ${KDE_ACTIONS} + COMPONENT main + ) + endif() + else() + message("applications path not found") + endif() + endif(UNIX) +endmacro (INSTALL_DESKTOP_LOCAL) diff --git a/CMakeModules/installQt5.cmake b/CMakeModules/installQt5.cmake new file mode 100644 index 0000000..c8404c1 --- /dev/null +++ b/CMakeModules/installQt5.cmake @@ -0,0 +1,147 @@ +set (QT_VERSION_MAJOR 5) + +IF(WIN32) + if(QT_USE_SVG) + get_target_property(QtSvg_location Qt5::Svg LOCATION_Release) + #find_file(qsvgicon qsvgicon${QT_VERSION_MAJOR}.dll PATHS ${QT_PLUGINS_DIR}/iconengines NO_DEFAULT_PATH) + #find_file(qsvg qsvg${QT_VERSION_MAJOR}.dll PATHS ${QT_PLUGINS_DIR}/iconengines NO_DEFAULT_PATH) + #install(FILES ${qsvgicon} + # DESTINATION bin/iconengines + # COMPONENT main + # ) + INSTALL(FILES + "${QtSvg_location}" + DESTINATION bin + COMPONENT main + ) + endif() + + get_target_property(_loc Qt5::QWindowsIntegrationPlugin LOCATION) + get_filename_component(_loc_iconengine ${_loc} PATH) + get_filename_component(_loc_iconengine "${_loc_iconengine}/../iconengines/" ABSOLUTE) + + file(GLOB PLUGINS_ICONENGINE "${_loc_iconengine}/*[^d].dll") + INSTALL(FILES + ${PLUGINS_ICONENGINE} + DESTINATION bin/iconengines + COMPONENT main + ) + + get_target_property(_loc Qt5::QWindowsIntegrationPlugin LOCATION) + get_filename_component(_loc_platform ${_loc} PATH) + file(GLOB PLUGINS_PLATFORM "${_loc_platform}/*[^d].dll") + INSTALL(FILES + ${PLUGINS_PLATFORM} + DESTINATION bin/platforms + COMPONENT main + ) + + get_target_property(_loc_gif Qt5::QGifPlugin LOCATION) + #message(${_loc_gif}) + get_filename_component(_loc_image_plugins ${_loc_gif} PATH) + file(GLOB PLUGINS_IMAGE "${_loc_image_plugins}/*[^d].dll") + INSTALL(FILES + ${PLUGINS_IMAGE} + DESTINATION bin/imageformats + COMPONENT main + ) + + + if (QT_USE_NETWORK) + get_target_property(QtNetwork_location Qt5::Network LOCATION_Release) + INSTALL(FILES + "${QtNetwork_location}" + DESTINATION bin + COMPONENT main + ) + endif() + + if (QT_USE_XML) + get_target_property(QtXml_location Qt5::Xml LOCATION_Release) + INSTALL(FILES + "${QtXml_location}" + DESTINATION bin + COMPONENT main + ) + endif() + + if (QT_USE_MULTIMEDIA) + get_target_property(QtMultimedia_location Qt5::Multimedia LOCATION_Release) + INSTALL(FILES + "${QtMultimedia_location}" + DESTINATION bin + COMPONENT main + ) + endif() + + if (QT_USE_MULTIMEDIA_WIDGETS) + get_target_property(QtMultimediaWidgets_location Qt5::MultimediaWidgets LOCATION_Release) + INSTALL(FILES + "${QtMultimediaWidgets_location}" + DESTINATION bin + COMPONENT main + ) + endif() + + if (QT_USE_SQL) + get_target_property(QtSql_location Qt5::Sql LOCATION_Release) + INSTALL(FILES + "${QtSql_location}" + DESTINATION bin + COMPONENT main + ) + endif() + + # base files always + get_target_property(QtCore_location Qt5::Core LOCATION_Release) + get_target_property(QtWidgets_location Qt5::Widgets LOCATION_Release) + get_target_property(QtGui_location Qt5::Gui LOCATION_Release) + # find_package(Qt5OpenGL REQUIRED) + #GET_TARGET_PROPERTY(QtOpenGL_location Qt5::OpenGL LOCATION_Release) + INSTALL(FILES + "${QtCore_location}" + "${QtWidgets_location}" + "${QtGui_location}" + #"${QtOpenGL_location}" + DESTINATION bin + COMPONENT main + ) + + # include required DLLs, based on the assumption that these + # are within the Qt5 bin dir. This is the case if you download + # the precompiled minGW version of Qt5 (tested with 5.2) + get_filename_component(QT5LOC ${QtCore_location} PATH) + + file(GLOB DLL_FILES1 "${QT5LOC}/libgcc_s_dw*.dll") + INSTALL(FILES ${DLL_FILES1} + DESTINATION bin + COMPONENT main + ) + + + file(GLOB DLL_FILES2 "${QT5LOC}/libstdc++*.dll") + INSTALL(FILES ${DLL_FILES2} + DESTINATION bin + COMPONENT main + ) + + file(GLOB DLL_FILES3 "${QT5LOC}/libwinpthread*.dll") + INSTALL(FILES ${DLL_FILES3} + DESTINATION bin + COMPONENT main + ) + + file(GLOB DLL_FILES4 "${QT5LOC}/icu*.dll") + INSTALL(FILES ${DLL_FILES4} + DESTINATION bin + COMPONENT main + ) + + if (${ARCH_DIR} STREQUAL "win32") + INSTALL(FILES "${QT5LOC}/libEGL.dll" "${QT5LOC}/libGLESv2.dll" + DESTINATION bin + COMPONENT main + ) + endif() + +ENDIF(WIN32) diff --git a/CMakeModules/onTheFlyResourceFile.cmake b/CMakeModules/onTheFlyResourceFile.cmake new file mode 100644 index 0000000..c719826 --- /dev/null +++ b/CMakeModules/onTheFlyResourceFile.cmake @@ -0,0 +1,79 @@ +# Copyright (c) 2006-2011 Peter Kümmel, +# 2012, Kornel Benko, +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# To call this script, one has to proved following parameters +# RESOURCE_NAME # full path of the resulting resource-file +# MAPPED_DIR # Path-prefix to be removed from the file names + +find_package (Qt5LinguistTools REQUIRED) +get_target_property(_qmake Qt5::qmake LOCATION) +execute_process( COMMAND ${_qmake} -query QT_INSTALL_TRANSLATIONS OUTPUT_VARIABLE QT_TRANSLATIONS_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ) + +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +set(resource_name ${RESOURCE_NAME}) + +message(STATUS "Generating ${resource_name}") + +file(WRITE ${resource_name} "\n") +file(APPEND ${resource_name} "\n") + +foreach (_current_FILE ${AddQtRessourceFiles}) + get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE) + string(REGEX REPLACE "${MAPPED_DIR}" "" _file_name ${_abs_FILE}) + file(APPEND ${resource_name} " ${_abs_FILE}\n") +endforeach (_current_FILE) + +# add QT translation file, if available +message("Translations dir: ${QT_TRANSLATIONS_DIR}") +find_file(QT_GERMAN qt_de.qm "${QT_TRANSLATIONS_DIR}") +if (QT_GERMAN) + file(APPEND ${resource_name} " ${QT_TRANSLATIONS_DIR}/qt_de.qm\n") +endif() +find_file(QT_BASE qtbase_de.qm "${QT_TRANSLATIONS_DIR}") +if (QT_BASE) + file(APPEND ${resource_name} " ${QT_TRANSLATIONS_DIR}/qtbase_de.qm\n") +endif() +find_file(QT_GERMAN_HELP qt_help_de.qm "${QT_TRANSLATIONS_DIR}") +if (QT_GERMAN_HELP) + file(APPEND ${resource_name} " ${QT_TRANSLATIONS_DIR}/qt_help_de.qm\n") +endif() +find_file(QT_GERMAN_BASE qtbase_de.qm "${QT_TRANSLATIONS_DIR}") +if(QT_GERMAN_BASE) + file(APPEND ${resource_name} " ${QT_TRANSLATIONS_DIR}/qtbase_de.qm\n") +endif() + +# finish ressource file +file(APPEND ${resource_name} "\n") +file(APPEND ${resource_name} "\n") + +add_custom_target(Ressoures.qrc DEPENDS ${resource_name}) +qt5_add_resources(${PROJECTNAME}_RESOURCES_RCC ${resource_name}) + +# add qt translation, as well +#/usr/share/qt4/translations/qt_de.qm + +#QT4_ADD_RESOURCES (${PROJECTNAME}_RESOURCES_TRANSLATIONS_RCC "${resource_name}.qrc") diff --git a/CMakeModules/qt5.cmake b/CMakeModules/qt5.cmake new file mode 100644 index 0000000..446d514 --- /dev/null +++ b/CMakeModules/qt5.cmake @@ -0,0 +1,9 @@ +find_package(Qt5Core REQUIRED) +find_package(Qt5Widgets REQUIRED) + +# As moc files are generated in the binary dir, tell CMake +# to always look for includes there: +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) diff --git a/CMakeModules/settings.cmake b/CMakeModules/settings.cmake new file mode 100644 index 0000000..68baca6 --- /dev/null +++ b/CMakeModules/settings.cmake @@ -0,0 +1,166 @@ +cmake_minimum_required (VERSION 2.8.8) + +ENABLE_TESTING() +#CONFIGURE_FILE(${CMAKE_CURRENT_LIST_DIR}/CTestCustom.cmake ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake) + +# set CMake modules path +set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) + +set(filenameBITTest "${CMAKE_BINARY_DIR}/testBITs.cpp") +file(WRITE ${filenameBITTest} " +// http://stackoverflow.com/a/1505664 +#include +template void DoMyOperationHelper(); +template<> void DoMyOperationHelper<4>() { + std::cout << 32; +} +template<> void DoMyOperationHelper<8>() { + std::cout << 64; +} +// helper function just to hide clumsy syntax +inline void DoMyOperation() { DoMyOperationHelper(); } +int main(){ + // appropriate function will be selected at compile time + DoMyOperation(); + return 0; +}" ) +try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR + ${CMAKE_BINARY_DIR} ${filenameBITTest} + COMPILE_OUTPUT_VARIABLE comp + RUN_OUTPUT_VARIABLE run + ) +if( "64" STREQUAL "${run}") + if (WIN32) + set(ARCH_DIR "win64") + else() + set(ARCH_DIR "unix64") + endif() +else() + if (WIN32) + set(ARCH_DIR "win32") + else() + set(ARCH_DIR "unix32") + endif() +endif() + +message("Build architecture ${ARCH_DIR}") + +# set default build type to release +# (None Debug Release RelWithDebInfo MinSizeRel) +#set (CMAKE_BUILD_TYPE "Debug") + +# for debug version +#set (CMAKE_DEBUG_POSTFIX "d") + +# detect svn version +# if existant + +set(PATCH_NO_FILE "${CMAKE_CURRENT_LIST_DIR}/PATCH_NO") + + + + +file (STRINGS ${PATCH_NO_FILE} CURRENT_PATCH_NUMBER) +FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/patchnumber.h" + "#ifndef DR_PATCH_NUMBER\n#define DR_PATCH_NUMBER ${CURRENT_PATCH_NUMBER}\n#endif\n" ) + + +# save which project is currently being built. +# this allows for dynamic insertion of dependencies, if not met +# ALso two ways of building can be realized: +# - build ALL modules, thirdparty and projects +# - build particular module and it's dependencies, only +# (e.g. for windows installer) +if (DEFINED PROJECTNAME) + ## FRESH_RUN is set per CMAKE run + # if it is not set, the state of included dependency projects + # is deleted + # this enforces the same route of dependencies being taking + # no matter if it is the first run or concecutive runs... + # + # together with standalone.cmake this ensures correct binding of + # dependencies outside from the current source tree. Also this + # ensures changes of outside source trees being committed to a + # new buildRTYFRESH_RUN) + if(NOT DEFINED FRESH_RUN) + set(FRESH_RUN 1) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/built/") + endif(NOT DEFINED FRESH_RUN) + + # used for standalone.cmake, here save that this current project + # is already being built + set(BUILDFILE "${CMAKE_BINARY_DIR}/built/${PROJECTNAME}") + IF (NOT EXISTS ${BUILDFILE}) + FILE (WRITE ${BUILDFILE} "this project has already been included for build\n") + ENDIF (NOT EXISTS ${BUILDFILE}) +endif() + + #enable std 2011 Standard for GNU + if(NOT MSVC) + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion + OUTPUT_VARIABLE GCC_VERSION) + #if (CMAKE_COMPILER_IS_GNUCC AND (GCC_VERSION VERSION_LESS 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)) + #message(STATUS "Version <= 4.7") + if ( (NOT (${PROJECTNAME} STREQUAL "libjpeg")) ) + add_definitions("-std=c++11") + #endif() + else() + remove_definitions("-std=c++11") + endif() + endif() +#-static -static-libgcc -static-libstdc++ +if (MINGW) + # for windows, make sure the required STD libs is linked statically into the executable + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -static-libstdc++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") + set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static-libgcc -static-libstdc++") + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++" ) + SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++" ) + #SET_TARGET_PROPERTIES(${PROJECTNAME} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++") +endif() + +# set warning levels +# http://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake +if(MSVC) + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() +elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") +endif() + +if (WIN32) + get_filename_component(MINGW_BIN_DIR ${CMAKE_CXX_COMPILER} DIRECTORY) + + if (${ARCH_DIR} STREQUAL "win64") + INSTALL(FILES + "${MINGW_BIN_DIR}/libgcc_s_seh-1.dll" + DESTINATION bin + COMPONENT main + ) + endif() + INSTALL(FILES + "${MINGW_BIN_DIR}/libstdc++-6.dll" + "${MINGW_BIN_DIR}/libwinpthread-1.dll" + "${MINGW_BIN_DIR}/libgomp-1.dll" + DESTINATION bin + COMPONENT main + ) +endif() + +#message ( "${ARCH_DIR}, SVN revision: ${CURRENT_PATCH_NUMBER}") + +# ... +#link_directories(${CMAKE_BINARY_DIR}/lib) +#link_directories(${CURRENT_LIST_DIR}/../lib) + +include_directories(${CMAKE_BINARY_DIR}/include) +include_directories(${CMAKE_BINARY_DIR}/${PROJECT_NAME}) +include_directories(${CMAKE_BINARY_DIR}/module_${PROJECT_NAME}) + +set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON") +SET(CPACK_NSIS_CONTACT "info@dominik-ruess.de") diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 3 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, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README b/README new file mode 100644 index 0000000..b4af270 --- /dev/null +++ b/README @@ -0,0 +1,81 @@ +/*********************************************************************** + * This file is part of Scanned Image Extractor. + * + * Scanned Image Extractor 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 + * (at your option) any later version. + * + * Scanned Image Extractor 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 Scanned Image Extractor. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +Homepage of Scanned Image Extractor: +http://dominik-ruess.de/scannerExtract/ + +####################################################################### +# Content: # +####################################################################### + +1. How to install binaries on different systems +2. How to compile on unix systems + +####################################################################### +# Installing Binaries: # +####################################################################### + +WINDOWS: download the binaries and install. + There are no dependencies for the installation binary + tested with Windows 7 + +Linux-DEB: + tested Ubuntu 15.04 with and Ubuntu 14.04 LTS + 1. Pre-requisites: + sudo apt-get install libqt5core5a libqt5network5 \ + libqt5gui5 libqt5svg5 libqt5widgets5 liblbfgs0 \ + libopencv-core2.4 libopencv-highgui2.4 \ + libopencv-imgproc2.4 + 2. install debian package: + sudo dpkg -i scannerExtract-x.y.z.deb + +Linux-RPM: + tested with Fedora 22 + 1. Pre-requisites, adapt to your architecture here: + sudo dnf install opencv-core.x86_64 qt5-qtsvg.x86_64 \ + qt5-qtbase.x86_64 liblbfgs-devel.x86_64 \ + opencv.x86_64 + 2. install RPM package: + rpm --install -p scannerExtract-x.y.z.rpm + +####################################################################### +# Compile on unix systems: # +####################################################################### + +Tested with Ubuntu 15.04 + +1. pre-requisites + sudo apt-get install liblbfgs-dev libopencv-dev libqt5svg5-dev \ + qttools5-dev-tools qttools5-dev qtbase5-dev cmake + +2. build (tested on Ubuntu 15.04) + - commands: + mkdir build + cd build + cmake path/to/scannerExtract-X.Y.Z/scannerExtract/ \ + -DCMAKE_BUILD_TYPE=release -DOPENCV2=1 + make + (make install) + - note: if you use OpenCV2 (e.g. Ubuntu 15.04) then add + -DOPENCV2=1 to your cmake call + +3. run + "./scannedImageExtractor" or if installed "scannedImageExtractor" + diff --git a/WARRANTY b/WARRANTY new file mode 100644 index 0000000..38ea708 --- /dev/null +++ b/WARRANTY @@ -0,0 +1 @@ +This software is licensed under the GPL, see source code for details. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/doc/images/SIE.png b/doc/images/SIE.png new file mode 100644 index 0000000..586780c Binary files /dev/null and b/doc/images/SIE.png differ diff --git a/doc/images/multiplace.png b/doc/images/multiplace.png new file mode 100644 index 0000000..3192451 Binary files /dev/null and b/doc/images/multiplace.png differ diff --git a/doc/images/note.png b/doc/images/note.png new file mode 100644 index 0000000..df1e0a9 Binary files /dev/null and b/doc/images/note.png differ diff --git a/doc/images/overview.png b/doc/images/overview.png new file mode 100644 index 0000000..de86fa9 Binary files /dev/null and b/doc/images/overview.png differ diff --git a/doc/images/scannerpos.png b/doc/images/scannerpos.png new file mode 100644 index 0000000..494cbea Binary files /dev/null and b/doc/images/scannerpos.png differ diff --git a/doc/scannerExtract.css b/doc/scannerExtract.css new file mode 100644 index 0000000..f6ebf26 --- /dev/null +++ b/doc/scannerExtract.css @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2001, 2003, 2010 The FreeBSD Documentation Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: doc/share/misc/docbook.css,v 1.21 2012/01/25 22:16:36 wblock Exp $ + */ + +BODY ADDRESS { + line-height: 1.3; + margin: .6em 0; +} + +BODY BLOCKQUOTE { + margin-top: .75em; + line-height: 1.3; + margin-bottom: .75em; +} + +HTML BODY { + margin: 1em 8% 1em 10%; + line-height: 1.2; +} + +/* .LEGALNOTICE { */ +/* font-size: small; */ +/* font-variant: small-caps; */ +/* } */ + +/* legal notice box */ +div.legalnotice +{ + /* list of fonts provides fallbacks if a font is not present */ + font-family: Verdana, Arial, Helvetica, Sans-Serif; + + /* font size, relative to body font size */ + font-size: 85%; + + /* color: black */ + color: #000; + + /* background color: gray */ + background-color: #ddd; + + /* margin settings are top - right - bottom - left (think clockwise) */ + margin: 5px 45px 5px 45px; + + /* padding ("inner margin") settings are top - right - bottom - left */ + /* (think clockwise) */ + padding: 0px 5px 0px 5px; + + /* solid black border, 1px wide */ + border: 1px solid #000; +} + + +BODY DIV { + margin: 0; +} + +DL { + margin: .8em 0; + line-height: 1.2; +} + +DIV.CALLOUTLIST DT { + float: left; + width: 1em; +} + +DIV.CALLOUTLIST DD { + clear: right; + margin-bottom: 1ex; +} + +BODY FORM { + margin: .6em 0; +} + +H1, H2, H3, H4, H5, H6, +DIV.EXAMPLE P B, +.QUESTION, +DIV.TABLE P B, +DIV.PROCEDURE P B { + color: #000066; +} + +BODY H1, BODY H2, BODY H3, BODY H4, BODY H5, BODY H6 { + line-height: 1.3; + margin-left: 0; +} + +BODY H1, BODY H2 { + margin: .8em 0 0 -4%; +} + +BODY H3, BODY H4 { + margin: .8em 0 0 -3%; +} + +BODY H5 { + margin: .8em 0 0 -2%; +} + +BODY H6 { + margin: .8em 0 0 -1%; +} + +BODY HR { + margin: .6em; + border-width: 0 0 1px 0; + border-style: solid; + border-color: #cecece; +} + +BODY IMG.NAVHEADER { + margin: 0 0 0 -4%; +} + +OL { + margin: 0 0 0 5%; + line-height: 1.2; +} + +BODY PRE { + margin: .75em 0; + line-height: 1.0; + font-family: monospace; +} + +BODY TD, BODY TH { + line-height: 1.2; +} + +UL, BODY DIR, BODY MENU { + margin: 0 0 0 5%; + line-height: 1.2; +} + +HTML { + margin: 0; + padding: 0; +} + +BODY P B.APPLICATION { + color: #000000; +} + +P { + text-align: justify; +} + +.FILENAME { + color: #007a00; +} + +SVNREF { + color: #007a00; +} + +.GUIMENU, .GUIMENUITEM, .GUISUBMENU, +.GUILABEL, .INTERFACE, +.SHORTCUT, .SHORTCUT .KEYCAP { + font-weight: bold; +} + +.GUIBUTTON { + background-color: #CFCFCF; + padding: 2px; +} + +.ACCEL { + background-color: #F0F0F0; + text-decoration: underline; +} + +.SCREEN { + padding: 1ex; +} + +.PROGRAMLISTING { + padding: 1ex; + background-color: #eee; + border: 1px solid #ccc; + line-height: 1.1; +} + +@media screen { /* hide from IE3 */ + a[href]:hover { background: #ffa } +} + +.INFORMALTABLE, .TABLE TH { + padding-left: 02.em; + text-align: left; +} + +BLOCKQUOTE, .EXAMPLE, .PROGRAMLISTING { + -moz-border-radius: 6px; + -webkit-border-radius: 6px; + -khtml-border-radius: 6px; + border-radius: 6px; +} + +BLOCKQUOTE { + padding: 0 2ex; +} + +BLOCKQUOTE.NOTE { + color: #222; + background: #eee; + border: 1px solid #ccc; + width: 85%; +} + +BLOCKQUOTE.TIP { + color: #004F00; + background: #d8ecd6; + border: 1px solid green; + width: 85%; +} + +BLOCKQUOTE.IMPORTANT { + font-style:italic; + border: 1px solid #a00; + border-left: 12px solid #c00; +} + +BLOCKQUOTE.WARNING { + color: #9F1313; + background: #f8e8e8; + border: 1px solid #e59595; + width: 85%; +} + +BLOCKQUOTE.CAUTION { + color: #3E3535; + background: #FFC; + border: 1px solid #e59595; + width: 85%; +} + +.EXAMPLE { + background: #fefde6; + border: 1px solid #f1bb16; + margin: 1em 0; + padding: 0.2em 2em; + width: 90%; +} + +.INFORMALTABLE TABLE.CALSTABLE TR TD { + padding-left: 1em; + padding-right: 1em; +} + +.figure +{ + /* margin settings are top - right - bottom - left (think clockwise) */ + margin: 0 75px 0 75px; + + /* no padding ("inner border") */ + padding-top: 15px; + padding-bottom: 15px; + + color: black; + + /* center text */ + text-align: center; + + /* background color: gray */ + background-color: #bbb; + + /* solid black border, 1px wide */ + /* border: 1px solid #000; */ + border: 0 +} + +/* admonitions */ + +.warning, .caution, .tip, .note, .important { + border: 1px dashed grey; + padding: .5em; + margin-top: 1em; +} + +.note{ + background-color: #ddffff; + background: #deffce url("images/note.png") no-repeat left center; +} + +.note h3, .warning h3, .caution h3, .tip h3, .important h3 { + margin: 0 0 0 2.5em; +} + +.note p, .warning p, .caution p, .tip p, .important p { + margin-left: 3em; +} + +/* FIXME: background colours are cheezy :S ... */ +/* see language specific css for content: */ +.warning { + background-color: red; +} +.caution { + background-color: yellow; +} +.tip { + background-color: #aaaddd; +} + +.important { + background-color: plum; +} + diff --git a/doc/scannerExtract_help_de.html b/doc/scannerExtract_help_de.html new file mode 100644 index 0000000..7cfe742 --- /dev/null +++ b/doc/scannerExtract_help_de.html @@ -0,0 +1,219 @@ + +Scanned Image Extractor

Back to main page, + English Version

Scanned Image Extractor

Rechtshinweise

+

+ Dieser Artikel ist Bestandteil von Scanned Image Extractor. + Scanned Image Extractor ist freie Software. + Sie können es unter den Bedingungen der GNU General Public + License, wie von der Free Software Foundation veröffentlicht, + weitergeben und/oder modifizieren, entweder gemäß Version + 3 der Lizenz oder (nach Ihrer Option) jeder späteren Version. +

+

+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, + daß es Ihnen von Nutzen sein wird, + aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite Garantie + der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN + ZWECK. + Details finden Sie in der GNU General Public License. +

+

+ In Abschnitt 6, „GNU General Public License“ ist ein Verweis auf die Lizenz zu finden, + oder alternativ direkt unter + http://www.gnu.org/licenses/ +

+


1. Vorwort 1: Open Source und unterstützte Platformen

+ Diese Software App is Open Source. + Das heißt, dass ich nicht extrem viel Zeit und Geld in das Testen und Erwerben von verschiedenen Systemen bzw. Platformen investieren kann. + Der Vorteil von Open Source liegt in Freiheit und Offenheit (im Gegensatz zu Kommerzieller Software, Freeware oder Shareware). + Manchmal ist Open Source aber nicht ganz kostenlos - der Benutzer hat Kosten in dem Sinne, dass er dem Entwickler Feedback oder Fehlermeldungen zurück gibt. +

+ Ich habe diese Software für verschiedene Platformen herausgegeben (z.B. Windows, Ubuntu, Fedora). + Ich kann das aber nur für Systeme tun, die ich selbst besitze. + Wenn eine Platform nicht unterstützt ist, senden Sie mir doch einen Vorschlag. + Ich würde auch liebend gerne die Software für Mac OS X herausgeben. + Leider besitze ich keinen Mac. + Wenn Sie hieran interessiert sind, denken Sie über eine Spende nach (Abschnitt 5.2, „Spenden an den Autor“), + dann kann ich hoffentlich bald einen Mac erwerben und die Software dafür anpassen und vor allem dauerhaft supporten. +

2. Vorwort 2: Sichern Sie Ihre Daten

+ Erstellen Sie immer Sicherungen von Ihren Dateien, auch + wenn Sie Scanned Image Extractor benutzen !!! +

Anmerkung

+Das reine Scannen von Alben oder Bildern ist sehr zeitaufwändig. Behalten Sie daher am besten eine Kopie der Original-Scannerdaten an einem anderen Ort auf. +

3. Was ist Scanned Image Extractor ?

+

+Scanned Image Extractor is ein Werkzeug um schnell und effizient rechteckige Fotografien aus Albums- oder (mehreren) Fotografie-Scans zu extrahieren. Das Programm is halb-automatisch und versucht Fotografien zu erkennen. Sie können diese Vorschläge akzeptieren, modifizieren, löschen oder ggf. selbst hinzufügen. +

3.1. Liste der Möglichkeiten mit Scanned Image Extractor

+ Scanned Image Extractor bietet eine interessante Liste von Eigenschaften + und Fähigkeiten. + Um ein paar dieser Möglichkeiten beschrieben zu sehen, + gehen Sie zu Abschnitt 4, „Benutzung:“. + Mit Scanned Image Extractor können Sie: +

  • +effizient eine oder mehrere Fotografien aus Scannerbildern extrahieren. +

  • + mit 16 Bit Eingangs- und Ausgangsbildern arbeiten (nützlich, falls Sie danach z.B. noch mit Gimp 2.9+ oder Lightroom arbeiten) +

  • + automatische Fotografieerkennungen vorgeschlagen bekomen. Falls diese falsch sind, können Sie diese manuell korrigieren, löschen oder neu erstellen. +

  • +Das Seitenverhältnis der extrahierten Fotografien kontrollieren. +

  • +Tastenkürzel für einen noch effizienteren Arbeitsablauf benutzen. +

+

3.2. Scanned Image Extractor herunterladen

+ Gehen Sie zu sourceforge und laden sie die Dateien dort herunter: + sourceforge.net/p/scannedimageextractor/ -> + Files. Wählen Sie die aktuelle + Version und die passende Datei für Ihr Betriebssystem aus (vor allem für 32/64 Bit Windows). +

3.3. Wo können Sprachschwächen, Programmfehler + und Anforderungswünsche verfasst werden ?

+ Gehen Sie zu sourceforge und verfassen Sie Ihren Beitrag dort. + Am besten auf Englisch, dann können Ihnen auch andere Benutzer helfen. + Es geht aber auch auf Deutsch: + sourceforge.net/p/scannedimageextractor/ -> + Tickets +

3.4. Was tun, wenn meine Scannerbilder nicht gut erkannt werden?

+ Jedes Fotoalbum sieht anders aus. + Wenn Sie ein Album haben, von dessen Scans die Fotografien nur schlecht erkannt werden, senden Sie mir ein paar Beispiele (volle Auflösung) an scannerextract at dominik-ruess.de. + Für eine gute, automatische Erkennung sollten Sie aber immer die Hinweise in Abschnitt 4.3, „Wie Sie Scanned Image Extractor benutzen“ und Abschnitt 4.4, „Tipps und Tricks für Scanned Image Extractor beachten. +

4. Benutzung:

4.1. Installation von Scanned Imaged Extractor

+ Laden Sie die neueste Datei für Ihr Betriebssystem von Scanned Image Extractor Files herunter. + Wenn Sie ein 64bit Betriebssystem benutzen (sehr wahrscheinlich heutzutage), dann empfehle ich die 64bit Version von Scanned Imaged Extractor. +

4.1.1. Microsoft Windows

+ Die Installationsdatei (endet auf win32.exe oder win64.exe) ist selbsteklärend. Laden Sie sie herunter und führen Sie sie aus. + Getestet mit Windows 7 (64bit). +

4.1.2. GNU Linux

+ Für Debian-ähnliche Systeme (mit Ubuntu getestet) laden Sie die passende .DEB-Datei herunter. + Installieren Sie die Voraussetzungen: + + sudo apt-get install libqt5core5a libqt5network5 + libqt5gui5 libqt5svg5 libqt5widgets5 liblbfgs0 + libopencv-core2.4 libopencv-highgui2.4 + libopencv-imgproc2.4 + . + Installieren Sie nun Scanned Imaged Extractor mit + sudo dpkg -i scannerExtract-x.y.z.deb. + Das Programm kann mit scannedImagedExtractor gestartet werden. +

+ Für RPM-basierte Systeme (mit Fedora getestet) installieren Sie die Vorraussetzungen: + sudo dnf install opencv-core qt5-qtsvg + qt5-qtbase liblbfgs + opencv. + Installieren Sie nun Scanned Imaged Extractor mittels + rpm --install -p scannerExtract-x.y.z.rpm + Das Programm kann mit scannedImagedExtractor gestartet werden. +

+ Getestet mit Ubuntu 14.04, 15.04 und Fedora 22-3 (alle jeweils mit 32 und 64bit). +

4.1.3. Von den Quellen bauen

+ Sie benötigen cmake und die Module OpenCV (Version 2.4 or 3), liblbfgs und Qt5. + Wenn Sie Version 2 von OpenCV benutzen, dann müssen Sie "-DOPENCV2=1" zur CMAKE-Kommandezeile hinzufügen. +Wenn Sie zum Beispiel unter Ubuntu bauen wollen, dann so: + sudo apt-get install liblbfgs-dev libopencv-dev libqt5svg5-dev + qttools5-dev-tools qttools5-dev qtbase5-dev cmake . +Nun Scanned Image Extractor bauen: +


+                mkdir build
+                cd build
+                cmake path/to/scannerExtract-X.Y.Z/scannerExtract/ -DCMAKE_BUILD_TYPE=release -DOPENCV2=1
+                make
+                (make install)

+ + +

4.2. Übersicht des gesamten Album-Scannes

+ Dieser Abschnitt illustriert die Benutzung von + Scanned Image Extractor + als kurze Übersicht: +

  1. +Scannen Sie die Alben mit einer Auflösung von mindestens 300dpi (gerade für ältere Fotografien sollten 600dpi ausreichen). +Als Dokumenttyp wählen Sie Fotografie/Bilder. +Der Schritt alle Alben zu scannen wird am längsten dauern. +Um diesen Teil effizienter zu gestalten, beachten Sie bitte die folgenden Hinweise. +Weitere Hinweise gibt es in Abschnitt 4.4, „Tipps und Tricks für Scanned Image Extractor. +

    Anmerkung

    + Benutzen Sie nicht das Vorschau-System Ihres Scanners. Das benötigt extrem viel Zeit. Scannen Sie einfach den größtmöglichen Bereich. +

    +

    Anmerkung

    + Testen Sie den Prozess bevor Sie alle Alben scannen. D.h. probieren Sie alle hier aufgeführten Schritte für ein paar Albenseiten aus, bevor Sie alles einscannen. +

    +

    Anmerkung

    + Falls Ihre Fotografien qualitativ noch hochwertig sind und sie die Daten in einem 16-Bit Porgramm weiterverarbeiten möchten (Gimp 2.9+, Lightroom, ...), dann stellen Sie in Ihrer Scanner-Software 16Bit Farbtiefe ein. +

    +

  2. + Nach dem alles eingescannt wurde, benutzen Sie Scanned Image Extractor um die Fotografien zu extrahieren (sehen Sie auch unter Abschnitt 4.3, „Wie Sie Scanned Image Extractor benutzen“). +

  3. + Organisieren Sie Ihre Fotografien auf Dateeibene. + D.h. erstellen Sie Verzeichnisse, bennen Sie Ihre Dateien passend um, usw. + Auch hilft es, mögliche schriftliche Kommentare, in den Alben neben den Bildern, in den Dateinamen einzutragen. + Ein Programm wie mein freies pivot - photo, image and video organization tool kann Ihnen dabei behilflich sein. +

  4. + Organisieren Sie Ihre Fotografien auf der (Meta-)Datenebene. Verstichworten Sie Ihre Dateien, manipulieren Sie die Farben, usw. + Hier können Sie auf freie Programme wie + digiKam oder kommerzielle Programme wie Lightroom zurückgreifen. +

+

4.3. Wie Sie Scanned Image Extractor benutzen

+Die Benutzeroberfläche von Scanned Image Extractor ist nicht sehr kompliziert. +Sie besteht aus drei Hauptbereichen. +Einer davon stellt das Scan-Bild und die möglichen Fotografien dar (1), +ein weiterer Bereich stellt die Vorschau dar (2) +und zuletzt gibt es ein Bereich für schnelle Einstellungen (3), davon am wichtigsten das Seitenverhältnis (4) und die Ausrichtung (5). +Sehen Sie das beispielhaft auch in Abbildung 1, „Scanned Image Extractor Screenshot“. +

Abbildung 1. Scanned Image Extractor Screenshot

Scanned Image Extractor Screenshot

+ Starten Sie damit, ein Bild zu laden (Datei-Menü). + Wenn Sie alle Bilder bearbeiten wollen, wählen Sie am besten das Erste Bild. + Nach einer kurzen Berechnung sehen Sie die Vorschläge der Fotografie-Detektion - in blauen, überlargerten Rechtecken. + Diese Rechtecke werden bei der Speicherung aus den Scandaten extrahiert und in das Zielverzeichnis gespeichert (siehe auch "einstellungen" im Menü). + Sobald Sie mit dem aktuellen Bild fertig sind, klicken Sie zum nächsten Bild. + Die Ausgangsbilder des vorherigen Bildes werden automatisch gespeichert - Sie müssen also nicht jedesmal auf "Speichern" klicken. +

+ Drücken Sie die Tasten 1-9 und 0 um ein bestimmtes Seitenverhältnis zu erzwingen. +

+ Drücken Sie die Tasten "a", "s", "d" oder "f" um schnell die Ausrichtung des akt. Ausgangsbildes zu ändern. +

+ Wenn die aktuellen Detektionen falsch sind, können Sie sie manipulieren, löschen oder manuell hinzufügen + Wenn Sie bei einem ausgewählten Rechteck die Ecken oder Kanten ziehen, wird dieses entsprechend vergrößert. + Halten Sie die STRG-Taste dabei gedrückt, findet das Ganze symmetrisch statt. + Halten Sie die Umschalt-Taste gedrückt bevor Sie auf eine Ecke klicken - dann können Sie das Rechteck drehen. + Um ein neues Rechteck hinzuzufügen, wählen Sie alle Rechtecke ab (irgendwo ins Leere klicken) und klicken Sie auf eine Ecke der gewünschten Fotografie. + Danach halten Sie die Maus gedrückt und ziehen Sie den roten Balken entlang zu einer zweiten Ecke (über die Lange Seite ist es genauer). + Lassen Sie los, nun können Sie das neue Rechteck in der Größe verändern. + Nach einem letzten Klick ist das neue Rechteck fertig und Sie haben ein Kopierziel hinzugefügt. +

4.4. Tipps und Tricks für Scanned Image Extractor

Anmerkung

+ Die meisten Alben haben ein Format, dass nicht komplett auf einen Scanner passt. + Scannen Sie eine Albenseite in zwei Schritten: + Richten Sie die obere linke Ecke an Ihrem Scanner aus und drehen Sie danach die Seite um die untere-rechte (dann neue obere linke) Ecke nochmals an Ihrem Scanner auszurichten und ebenfalls zu scannen. + In den meisten Fällen sichert diese Methode, dass Ihre Fotografien in mindestens einem der beiden Scans enthalten sind. + Sie können die Klappe auch auflassen, das spart Zeit. +

Abbildung 2. Scanned Image Extractor Platzierung von Alben

Scanned Image Extractor Platzierung von Alben

Anmerkung

+ ICH ÜBERNEHME KEINERLEI HAFTUNG FÜR BESCHÄDIGUNGEN IHRES SCANNERS. + Wenden Sie folgenden Hinweis also nur auf eigene Verantwortung an: + Wenn Sie mit Ihrer Hand auf den Albenrücken drücken, werden die Bilder etwas besser angepresst und sind weniger gewölbt. + (see also Abbildung 2, „Scanned Image Extractor Platzierung von Alben“) +

Anmerkung

+ Wenn Sie mehrere Einzelbilder (d.h. ohne Album) einscannen wollen, platzieren Sie sie nicht direkt an den Rand des Scanners. + Lassen Sie Platz, zum Rand und zu den anderen Bildern. + Dies reduziert das Risiko von Verschiebungen über den Rand des Scanners hinaus. + Außerdem erleichtern Sie der automatischen Erkennung von Fotografien die Arbeit. +

Abbildung 3. Scanned Image Extractor Mehrere Fotografien

Scanned Image Extractor Mehrere Fotografien

Anmerkung

+ Versuchen Sie immer das Seitenverhältnis zu erzwingen, mit so wenig wie nötigen Seitenverhältnisse. + Für den Betrachter der Ergebnisse ist das eine deutlich angenehmere Erfahrung. +

5. Weitere Hilfe

5.1. Hilfe für bestimmte Bedienelemente

+ Wenn bestimmte Bedienelemente der Anwendung nicht klar sind, + halten Sie ihren Mauszeiger über diesem Element. + In der Statusanzeige wird dann eine Hilfe angezeigt. +

+ Auch können Sie in den Hilfe-Modus gehen, indem Sie auf das + Fragezeichen Symbol klicken und danach auf das unbekannte + Bedienelement. +

5.2. Spenden an den Autor

+ Wenn Ihnen diese Anwendung gefällt, Sie danke schön sagen wollen oder Sie + einfach die weitere Entwicklung der Anwendung unterstützen möchten, + überlegen Sie sich zu spenden. + Sie können das direkt über "sourceforge donation page", + https://sourceforge.net/p/scannedimageextractor/donate, + erledigen, oder schreiben Sie eine E-Mail an donate at dominik-ruess.de. + Vielen Dank. +

6. GNU General Public License

Den offiziellen englischen Originaltext finden Sie unter + http://www.gnu.org/licenses/gpl.html. + Eine Kopie der Version 3 der Lizenz ist in den Quelldateien enthalten. +

\ No newline at end of file diff --git a/doc/scannerExtract_help_en.html b/doc/scannerExtract_help_en.html new file mode 100644 index 0000000..fbce272 --- /dev/null +++ b/doc/scannerExtract_help_en.html @@ -0,0 +1,201 @@ + +Scanned Image Extractor

Back to main page, + Deutsche Version

Scanned Image Extractor

Legal Notices

+

+ This article is part of Scanned Image Extractor. + Scanned Image Extractor 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 + (at your option) any later version. +

+

+ Scanned Image Extractor 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. +

+

+ In Section 6, “GNU General Public License” you can find a link to the license, + or go directly to: + http://www.gnu.org/licenses/ +

+


1. Preface 1: Open Source and Supported Platforms

+ This software app is open source. + This means I was not able to invest a lot of time and money into buying and testing different systems/platforms etc. + The advantage of open source being completely free and open (as compared to commercial software, freeware or shareware) is usually not always completely free - + the user may help the developers by sending them errors or improvement suggestions. + Lastly, a note: please respect the GPL: If you use (parts of) this software in your own project, publish the complete source code of your own project, as well. +

+ I developed this software app for different platforms (e.g. Windows, Ubuntu, Fedora). + However, I can only develop for platforms which I own myself. + If you think an important platform is missing, send me a suggestion. + + I would love to also deploy this software for Mac OS X, too. + I just don't own a Mac. + If you're interested, consider donating to this project and I'll hopefully soon be able to buy a Mac (Section 5.2, “Donate to the Author”) + and adapt and permanently support this software for it. +

2. Preface 2: Do Backups !

+ Always backup your files, also before using Scanned Image Extractor!!! +

Note

+ The pure process of scanning pictures or albums is very time comsuming. Keep a copy of unedited original scans in a separate location. +

3. What is Scanned Image Extractor ?

+

+ Scanned Image Extractor is a tool for efficiently extracting rectangular photographs from album or (multiple) photograph scans. It is semi-automated, hence it tries to suggest recognized photographs but you have to verify, delete bad suggestions and possibly add missing photographs manually. +For a list of features, refer to Section 3.1, “Features of Scanned Image Extractor. +

3.1. Features of Scanned Image Extractor

+ Scanned Image Extractor comes with an interesting list of features. + If you're not sure how to make use of these features, you may want to + refer to Section 4, “How to:”. + With Scanned Image Extractor, you can: +

  • + efficiently extract one or more photographs per scanner image. +

  • + work on 16bit input images and have 16bit output images (useful e.g. for Gimp 2.9+ or Lightroom users). +

  • + have detections presented from automated photograph detection. If these detections are wrong, correct, delete or add them, manually. +

  • + constrain aspect ratios of output photographs +

  • + use keyboard shortcuts for an even more efficient work flow +

+

3.2. Download Scanned Image Extractor

+ Go to sourceforge and download from there: + sourceforge.net/p/scannedimageextractor/ -> + Files. Make sure + you select the current version and an appropriate file for your operating system +(i.e. windows installer for 32/64 bit windows). +

3.3. Where to post language flaws, bugs and feature requests ?

+ Go to sourceforge and post your issue there: + sourceforge.net/p/scannedimageextractor/ -> + Tickets +

3.4. What if my scanned images are not recognized well?

+ Every Photo-Album looks different. + Whenever your type of album is difficult send me a couple of example scans (full resolution) to scannerextract at dominik-ruess.de. + I will not use these for anything else than improving this software. + However, please also note there are some hints on how to properly scan the photographs in Section 4.3, “How to use Scanned Image Extractor and Section 4.4, “Tips and Tricks for using Scanned Image Extractor. +

4. How to:

4.1. Install Scanned Imaged Extractor

+ Download the latest file for your operation system from Scanned Image Extractor Files. + If your operation system is 64bit, I reccommend you choose the respective 64bit version of Scanned Imaged Extractor. +

4.1.1. Microsoft Windows

+ The binary installation package is self-explanatory. + Download and execute it (download file ending on win32.exe or win64.exe). + Tested with Windows 7 (64bit). +

4.1.2. GNU Linux

+ For Debian-like systems (tested with Ubuntu) download the respective .DEB files. + Install the pre-requisites: + + sudo apt-get install libqt5core5a libqt5network5 + libqt5gui5 libqt5svg5 libqt5widgets5 liblbfgs0 + libopencv-core2.4 libopencv-highgui2.4 + libopencv-imgproc2.4 + . + Now install Scanned Imaged Extractor with + sudo dpkg -i scannerExtract-x.y.z.deb. + Start the program with scannedImagedExtractor. +

+ For RPM-based systems (tested with Fedora) install the following pre-requisites: + sudo dnf install opencv-core qt5-qtsvg + qt5-qtbase liblbfgs + opencv. + Now install Scanned Imaged Extractor with + rpm --install -p scannerExtract-x.y.z.rpm + Start the program with scannedImagedExtractor. +

+ Tested with Ubuntu 14.04, 15.04 and Fedora 22-3 (for all with both 32, and 64bit). +

4.1.3. Building from Source

+ You will need cmake and the third-party modules OpenCV (version 2.4 or 3), liblbfgs and Qt5. + If you use version 2 of OpenCV, then you will need to add "-DOPENCV2=1" to the cmake command line. +If, for example you want to build in ubuntu, do: + sudo apt-get install liblbfgs-dev libopencv-dev libqt5svg5-dev + qttools5-dev-tools qttools5-dev qtbase5-dev cmake . +Now build Scanned Image Extractor: +


+                mkdir build
+                cd build
+                cmake path/to/scannerExtract-X.Y.Z/scannerExtract/ -DCMAKE_BUILD_TYPE=release -DOPENCV2=1
+                make
+                (make install)

+ + +

4.2. Overview of the whole album/photograph scanning process

+ This section roughly explains how to use Scanned Image Extractor as part of a tool chain: +

  1. +Scan an album page with at least 300dpi (however, especially for older photographs, 600dpi should be enough). As document type, choose picture/photograph. +The complete scanning process of all albums/album pages will cost you most of the time. So to improve the efficiency here, refer to the following notes. +Also make sure you have a look at Section 4.4, “Tips and Tricks for using Scanned Image Extractor. +

    Note

    + Do not use the preview system of the scanner, it will only cost a lot of time. Just scan the complete scanning area. Only use it to get used to how the result looks like +

    +

    Note

    + Do test your process before you start scanning all of your albums (i.e. follow this guide for some 2-3 album pages and test if everything's like you want it to be) +

    +

    Note

    + If you have good quality photographs and want to post-process the images with a 16-bit aware tool (Gimp 2.9+, Lightroom, ...), then use 16bit scanning. +

    +

  2. + Use Scanned Image Extractor to extract the photographs of the scanned images (see Section 4.3, “How to use Scanned Image Extractor). +

  3. + Organize your photographs on the file level. E.g. create folders and rename the files appropriately. Also copy comments to the filename, which people have next to their album images, quite often. + A tool like my pivot - photo, image and video organization tool can help you here. +

  4. + Organize your photographs on the (meta) data level. Add tags to your images, post-process them by adapting colors etc. Use a free open source tool like + digiKam or a commercial tool like Lightroom for this. +

+

4.3. How to use Scanned Image Extractor

+The user interface of Scanned Image Extractor is not very sophisticated. +It consists of three main areas, one displaying the scanned image (1), +one for the preview of the current photograph (2) +and lastly, one area for the extraction settings (3), most importantly for the aspect ratio (4) and orientation (5) control. +Refer to Figure 1, “Scanned Image Extractor Screenshot” for a screenshot. +

Figure 1. Scanned Image Extractor Screenshot

Scanned Image Extractor Screenshot

+ Start by loading a scanner image (File menu). If you want to process all, just choose the first scanned image in your directory. + Now, after some computation, the detected photographs are suggested as blue boxes in the input image. + These blue boxes will be extracted to a specified directory (see settings) as digital photograph. + When your done with the current scanned image, proceed to the next one by clicking on the respective button. + The output images of the last image will then be processed automatically, there's no need to press the "save" button every time. +

+ Press the keys 1-9 and 0 to enforce a certain aspect ratio for the current target. +

+ Press the keys "a", "s", "d" or "f" for fastly changing the orientation of the current target selection. +

+ If you dislike the current detection(s) you can manipulate, delete or manually add them yourself. + Go to any edge or corner to change the size of the selected target. + If you press CTRL while dragging, this will be symmetric. + If you press SHIFT and then drag a corner of the selected rectangle, you can rotate it by dragging. + For adding a new selection, deselect all (click somewhere empty) and click at a corner of the photograph. + Keep the mouse pressed and drag the red line to another corner and release the mouse. +Now you have a new rectangle which you can resize by moving your mouse. Click to have a new target rectangle. +

4.4. Tips and Tricks for using Scanned Image Extractor

Note

+ Most albums have a page format which doesn't completely fit on the scanner. Scan one page with two iterations: align the top-left page to your scanner and then turn the page upside-down and align the former bottom-right (now top-left) corner with your scanner. This will ensure - in most cases - that every photograph is contained completely in at least one of the two scans. +

Figure 2. Scanned Image Extractor Album Placement

Scanned Image Extractor Album Placement

Note

+ I DO NOT TAKE ANY RESPONSIBILITY if you damage your scanner, so do this on yor own responsibility: The results look a lot better, if you use one hand to press the album onto the scanner. It reduces bulges in your scans. + (Das ist in Figure 2, “Scanned Image Extractor Album Placement” angedeutet) +

Note

+ If you want to scan multiple single photographs (WITHOUT album), do not place them right at the scanner edge. Leave some space to the scanner boundaries and to the other photographs. This will make the automated recognition process easier and reduce the risk of the photograph overlapping the boundary when closing the lid. + There more space in between photographs and to the boundary, the better. +

Figure 3. Scanned Image Extractor Multiple Photographs

Scanned Image Extractor Multiple Photographs

Note

+ Always try to constrain the aspect ratio with as few different aspect ratios as possible. + Otherwise skipping through the resulting image is not a nice experience. +

5. More Help

5.1. Help on certain widgets

+ If certain widgets of the application are + not quite clear, hover the mouse over it. + Information about it will be displayed in a + hint and/or in the status bar of the application. +

+ Additionally, sometimes it might be helpful to enter + the help mode. This is the button with the question mark. + Click it, then click the element which you want to + have help for. +

5.2. Donate to the Author

+ If you like the software, if you wish to say thank you + or if wish to support further development of the + software, consider making a donation to the author + (no tax deduction). + This can be done directly via the projects's sourceforge + donation page, https://sourceforge.net/p/scannedimageextractor/donate, + or by writing an email to donate at dominik-ruess.de. + Thank you. +

6. GNU General Public License

You can find version 3 of the GNU GPL here: + http://www.gnu.org/licenses/gpl.html. + A copy of the license is also contained in the program source code. +

\ No newline at end of file diff --git a/module_misc/CMakeLists.txt b/module_misc/CMakeLists.txt new file mode 100644 index 0000000..0202a17 --- /dev/null +++ b/module_misc/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required (VERSION 2.8.8) + + +set (PROJECTNAME "misc") +project (${PROJECTNAME} CXX) + +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/settings.cmake ) + + +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/qt5.cmake ) + + +find_package (versioning REQUIRED) + + +include_directories ( + . + ) + +set ( ${PROJECTNAME}_SOURCES + filenamenumbering_pre.cpp + version_module_misc.cpp + translation.cpp + ) + +set ( ${PROJECTNAME}_HEADERS + filenamenumbering_pre.h + version_module_misc.h + translation.h + ) + +set (${PROJECTNAME}_RESSOURCES + ) + +set (${PROJECTNAME}_FORMS +) + +add_library(${PROJECTNAME} STATIC + ${${PROJECTNAME}_SOURCES} + ${${PROJECTNAME}_HEADERS} + ${${PROJECTNAME}_RESSOURCES} + ${${PROJECTNAME}_FORMS} +) + +qt5_use_modules(${PROJECTNAME} Core Widgets Gui) + + +TARGET_LINK_LIBRARIES (${PROJECTNAME} + ${MY_LIBS} + ${QT_LIBRARIES} + ) + + diff --git a/module_misc/filenamenumbering_pre.cpp b/module_misc/filenamenumbering_pre.cpp new file mode 100644 index 0000000..f2a06ac --- /dev/null +++ b/module_misc/filenamenumbering_pre.cpp @@ -0,0 +1,451 @@ +/*********************************************************************** + * This file is part of module_misc. + * + * module_misc 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 + * (at your option) any later version. + * + * module_misc 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 module_misc. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include +#include +#include +#include +#include + +#include "filenamenumbering_pre.h" + +namespace MiscTools +{ + +/** + * a separator to build up a filenamestring + */ +#ifdef _WIN32 + #define SEPARATOR QString("<") +#else + #define SEPARATOR QString('/') +#endif + +FilenameNumbering_PRE::FilenameNumbering_PRE() +{ +} + +InfoList FilenameNumbering_PRE::splitFileToStringParts(const QString& filenameOrig, + const bool caseInsensitive, + const bool withoutExtension, + InfoList *stringValues) +{ + InfoList out; + if (stringValues != NULL) { + stringValues->clear(); + } + + const QFileInfo f = filenameOrig; + QString filename; + if (withoutExtension) { + filename = caseInsensitive ? f.completeBaseName().toLower() : f.completeBaseName(); + } else { + filename = caseInsensitive ? f.fileName().toLower() : f.fileName(); + } + + for (int i=0; i FilenameNumbering_PRE::getDifferentFile_Patterns(QStringList filenames, + const bool caseInsensitive, + const bool withoutExtension) +{ + QVector patterns; + for (int i=0; i > &fileNumberValues, + QVector &numbersUnique, + QVector &numberingPositions, + bool & onePatternFound, + const bool caseInsensitive, + const bool withoutExtension) +{ + const int nF = filenames.size(); + fileNumberValues.clear(); + numbersUnique.clear(); + numberingPositions.clear(); + + const QVector diffPatterns = getDifferentFile_Patterns(filenames, caseInsensitive, withoutExtension); + if (diffPatterns.size() != 1) { + onePatternFound = false; + qWarning() << "different file patterns found, please revise"; + return; + } + onePatternFound = true; + + const InfoList patterns = diffPatterns.first(); + + numberingPositions.clear(); + for (int i=0; i tmp; + for (int i=0; i sortedInd = tmp.values(); + for (int j=0; j >& tagsAndDateMap, + const QString& tag, + QVector& runningFileNumbers, + QVector > >& startAndLengthOfRunnNumbers) +{ + startAndLengthOfRunnNumbers.clear(); + runningFileNumbers.clear(); + + QMultiMap tagPositions; + QVector > filenameNumericValues; + QVector tmp1; + QString tmp2; + QVector > > startAndLengthOfAllTags; + _getTagMap(filenames, + taggedFileName, + tagsAndDateMap, + tagPositions, + tmp1, tmp2, + filenameNumericValues, + startAndLengthOfAllTags); + if (filenameNumericValues.size() != filenames.size()) { + qWarning() << "number of filenames mismatch"; + return false; + } + + // create tag number map to numerical value + // position in filename, + QVector numberingPos; + QMapIterator i(tagPositions); + int k=0; + while (i.hasNext()) { + i.next(); + const int tagNo = i.value(); + if (tagsAndDateMap[tagNo].first == tag) { + numberingPos.push_back(k); + } + k++; + } + + if (numberingPos.size() == 0) { + qWarning() << "could not determine running number"; + return false; + } + + const int n = filenames.size(); + runningFileNumbers.resize(n); + startAndLengthOfRunnNumbers.resize(n); + for (int j=0; j >& tagsAndDateMap, + QMultiMap& tagPositions, // first = tagNo, second = tagOrderPos; + QVector& datePatternsUsed, + QString& datePattern, + QVector >& filenameNumericValues, + QVector > >& tagSourceFNPositionsAndLengths) +{ + // find positions and order of given tags + datePattern=""; + tagPositions.clear(); + datePatternsUsed.clear(); + filenameNumericValues.clear(); + tagSourceFNPositionsAndLengths.clear(); + for (int i=0;i=0) { + tagPositions.insertMulti(pos, i); + pos = taggedFileName.indexOf(tagsAndDateMap[i].first, pos+1); + } + } + + // now extract fixed text between tags + // also create datePatterns/parse format for comparison + QStringList textInBetween; + datePattern = ""; + datePatternsUsed.clear(); + QMapIterator i(tagPositions); + int pos = 0; + int k=0; + while (i.hasNext()) { + i.next(); + const int tagPos = i.key(); + const int tagNo = i.value(); + if (tagsAndDateMap[tagNo].second.length() > 0) { + datePatternsUsed.push_back(k); + datePattern += QString("%1%2").arg(SEPARATOR).arg(tagsAndDateMap[tagNo].second); + } + if (tagPos != pos) { + textInBetween.push_back(taggedFileName.mid(pos, tagPos-pos)); + } + pos = tagPos + tagsAndDateMap[tagNo].first.length(); + k++; + if (!i.hasNext()) { + if (pos != taggedFileName.length()) { + textInBetween.push_back(taggedFileName.right(taggedFileName.length()-pos)); + } + } + } + + // strip all known text to obtain numerical values + const int n = filenames.size(); + const int d = tagPositions.size(); + filenameNumericValues.resize(n); + tagSourceFNPositionsAndLengths.resize(n); + for (int i=0; i0) { + currLength = pos - currLength; + tagSourceFNPositionsAndLengths[i][ind] = QPair(currPosValue, currLength); + currPosValue += textInBetween[j].length() + currLength; + ind++; + } + // make sure, just inserted space is not considered again: + pos++; + } + if (ind == d-1) { + // last part of basename was a number + tagSourceFNPositionsAndLengths[i][ind] = QPair(currPosValue, originalFilenameLength - currPosValue); + ind++; + } else if (ind != d) { + qWarning() << "error, problems with determining the positions and lengths of the " + " tag values for " << filenames[i] << " " << ind << " " << n-1; + return false; + } + + QStringList values = fn.split(SEPARATOR, QString::SkipEmptyParts); + if (values.length() != d) { + qWarning() << "mismatching number of tags and found values"; + filenameNumericValues[i].clear(); + continue; + } + for (int j=0; j < d; j++) { + bool ok; + const int val = values[j].toInt(&ok); + filenameNumericValues[i][j] = ok ? val : QVariant(values[j]); + } + } + + datePattern = datePattern.replace(SEPARATOR, " "); + return true; +} + +QVector FilenameNumbering_PRE::findMoveOrdering( + const QList >& moveExisting + ) +{ + QVector currentExisting(moveExisting.size()); + + QList > notHandled = moveExisting; + QVector backMap(notHandled.size()); + for (int i=0; i order; + int lastSize = order.size() - 1; + while (notHandled.size() > 0) { + if (lastSize == order.size()) { + qCritical() << "could not resolve movement, circular dependencies ?!"; + return QVector(); + } + + lastSize = order.size(); + + for (int i=notHandled.size()-1; i>=0; i--) { + const QString src = notHandled[i].first; + const QString target = notHandled[i].second; + // either the file does not exist or it exists but will be removed before + // current file gets moved + if (!currentExisting.contains(target) ) { + order.push_back(backMap[i]); + //added.push_back(notHandled[i].second); + //deleted.push_back(notHandled[i].first); + currentExisting.append(target); + if (currentExisting.contains(src)) { + currentExisting.remove(currentExisting.indexOf(src)); + } + notHandled.removeAt(i); + backMap.remove(i); + } + } + } + return order; +} + + +template <> +template <> +Q_OUTOFLINE_TEMPLATE bool MyFilePartsList::operator==(const MyFilePartsList &b) const +{ + if (size() != b.size()) { + return false; + } + bool same = true; + for (int i=0; i < (int)size(); i++) { + if (this->at(i).typeName() == b.at(i).typeName()) { + if (this->at(i).typeName() == QString("QString")) { + same &= this->at(i).toString() == b[i].toString(); + } + } else { + same = false; + break; + } + } + return same; +} + +} // end namespace MiscTools diff --git a/module_misc/filenamenumbering_pre.h b/module_misc/filenamenumbering_pre.h new file mode 100644 index 0000000..bf28bb9 --- /dev/null +++ b/module_misc/filenamenumbering_pre.h @@ -0,0 +1,108 @@ +/*********************************************************************** + * This file is part of module_misc. + * + * module_misc 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 + * (at your option) any later version. + * + * module_misc 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 module_misc. If not, see + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef FILENAMENUMBERING_PRE_H +#define FILENAMENUMBERING_PRE_H + +#include +#include +#include +#include + +namespace MiscTools +{ + +/** + * use this class to avoid unintended use of direct overloaded + * operator== in QList for template QVariant + */ +template +class MyFilePartsList : public QVector +{ +public: + template + Q_OUTOFLINE_TEMPLATE bool operator==(const MyFilePartsList &b) const; + +}; + +class FilenameNumberingTests; + +typedef MyFilePartsList InfoList; + +class FilenameNumbering_PRE +{ + friend class FilenameNumberingTests; + +private: + + FilenameNumbering_PRE(); +public: + + typedef QPair DT; + + static InfoList splitFileToStringParts(const QString& filename, + const bool caseInsensitive = false, + const bool withoutExtension = true, + InfoList * stringValues = NULL); + + static QVector getDifferentFile_Patterns( + QStringList filenames, + const bool caseInsensitive = false, + const bool withoutExtension = true); + + static void getUniqueNumbersAndValues(const QStringList filenames, + const bool diffSuffixSameNumbers, + QVector >& fileNumberValues, + QVector& numbersUnique, + QVector& numberingPositions, + bool &onePatternFound, + const bool caseInsensitive = false, + const bool withoutExtension = true); + + static bool getTagsBackMapAndNumbers( + const QStringList& filenames, + const QString& taggedFileName, + const QVector >& tagsAndDateMap, + const QString& tag, + QVector& runningFileNumbers, + QVector > >& startAndLengthOfRunnNumbers); + + + /** + * there might be a non direct renaming graph, try to find it + */ + static QVector findMoveOrdering( + const QList > &moveExisting + ); + +protected: + static bool _getTagMap( + const QStringList &filenames, + const QString &taggedFileName, + const QVector > &tagsAndDateMap, // first = tagNo, second = tagOrderPos; + QMultiMap &tagPositions, + QVector &datePatternsUsed, + QString &datePattern, + QVector > &filenameNumericValues, + QVector > > &tagSourceFNPositionsAndLengths); +}; + +} // namespace MiscTools + +#endif // FILENAMENUMBERING_PRE_H diff --git a/module_misc/translation.cpp b/module_misc/translation.cpp new file mode 100644 index 0000000..b31421c --- /dev/null +++ b/module_misc/translation.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#include "translation.h" + +namespace MiscTools +{ + +Translation::Translation() +{ +} + +void Translation::setDefaultLocale(const QString& locale) +{ + QString shortLocale = locale.left(2).toLower(); + if (shortLocale == "de") { + QLocale::setDefault(QLocale::German); + } else { + QLocale::setDefault(QLocale::English); + } +} + +QTranslator* Translation::getTranslator(const QString& locale, + const QStringList& projPaths, + const QString& filename) +{ + QTranslator* translator = new QTranslator(); + QString shortLocale = locale.left(2).toLower(); + bool found = false; + // first search in given paths + foreach(const QString& path, projPaths) { + if (translator->load(path + filename + locale)) { + found = true; + break; + } + } + // if not found, try to load short locale + if (!found) { + if (shortLocale == "en") { + // this is english, anyways + } else { + qDebug() << "now trying to load " << shortLocale + << "for" << filename; + // try to load short locale in the given paths + foreach(const QString& path, projPaths) { + if (translator->load(path + filename + shortLocale)) { + found = true; + break; + } + } + if (!found) { + // finally, fall back to english hardcoded + qDebug() << "could not load translation " << QString(shortLocale) + << "for" << filename; + qDebug() << "falling back to hard-coded \"en\""; + } + } + } + return translator; +} + +} // end namespace misc diff --git a/module_misc/translation.h b/module_misc/translation.h new file mode 100644 index 0000000..afae642 --- /dev/null +++ b/module_misc/translation.h @@ -0,0 +1,23 @@ +#ifndef TRANSLATION_H +#define TRANSLATION_H + +#include +#include + +namespace MiscTools +{ + +class Translation +{ + Translation(); +public: + static QTranslator* getTranslator(const QString& locale, + const QStringList& projPaths, + const QString& filename); + + static void setDefaultLocale(const QString& locale); +}; + +} // namespace MiscTools + +#endif // TRANSLATION_H diff --git a/module_misc/version_module_misc.cpp b/module_misc/version_module_misc.cpp new file mode 100644 index 0000000..9ddf0c4 --- /dev/null +++ b/module_misc/version_module_misc.cpp @@ -0,0 +1,23 @@ +/*********************************************************************** + * This file is part of module_misc. + * + * module_misc 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 + * (at your option) any later version. + * + * module_misc 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 module_misc. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "version_module_misc.h" + +VersionNumberMisc<1,2,DR_PATCH_NUMBER> version_module_misc; diff --git a/module_misc/version_module_misc.h b/module_misc/version_module_misc.h new file mode 100644 index 0000000..1b52c12 --- /dev/null +++ b/module_misc/version_module_misc.h @@ -0,0 +1,33 @@ +/*********************************************************************** + * This file is part of module_misc. + * + * module_misc 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 + * (at your option) any later version. + * + * module_misc 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 module_misc. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef VERSION_MODULE_MISC_H +#define VERSION_MODULE_MISC_H + +#include "versioning.h" +#include "patchnumber.h" + +template +struct VersionNumberMisc : public VersionNumber +{}; + +extern VersionNumberMisc<1, 2, DR_PATCH_NUMBER> version_module_misc; + +#endif // VERSION_MODULE_MISC_H diff --git a/module_versioning/versioning.h b/module_versioning/versioning.h new file mode 100644 index 0000000..069f94b --- /dev/null +++ b/module_versioning/versioning.h @@ -0,0 +1,161 @@ +/*********************************************************************** + * This file is part of module_misc. + * + * module_misc 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 + * (at your option) any later version. + * + * module_misc 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 module_misc. If not, see + * + * + * Copyright (C) 2013, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef VERSIONING_H +#define VERSIONING_H + +#include +#include +#include +#include +#include +#include +#ifdef QT_NETWORK_LIB +#include +#include +#include +#include +#include +#endif + + +// determine bits of this compiler +// http://stackoverflow.com/a/1505664 +template static int DetermineBitsHelper(); +template<> int DetermineBitsHelper<4>() { + return 32; +} +template<> int DetermineBitsHelper<8>() { + return 64; +} +// helper function just to hide clumsy syntax + static int DetermineBits() { return DetermineBitsHelper(); } + +/** + * class to allow for checking version requirements + * + * APR's Version Numbering: + * http://apr.apache.org/versioning.html + */ +template +struct VersionNumber +{ + VersionNumber() + { + checkRequirements(); + } + + template + void checkCompatibility() const + { + static_assert(requireMajor == major, "Incompatible major library version"); + static_assert(usedMinor <= minor, "Incompatible minor version: library too old"); + } + + virtual bool checkForUpdateVersion(const QString& location, + const qint32 magicNumber, + qint32& majorRemote, + qint32& minorRemote, + qint32& patchRemote, + QString& link, + QString& text, + bool& connection) const + { +#ifdef QT_NETWORK_LIB + QNetworkAccessManager* m_NetworkMngr = new QNetworkAccessManager(); + QNetworkReply *reply= m_NetworkMngr->get(QNetworkRequest(location)); + QEventLoop loop; + loop.connect(reply, SIGNAL(finished()),SLOT(quit())); + loop.exec(); + if (reply->error() == QNetworkReply::NoError) { + connection= true; + + QDataStream in(reply); + qint32 magic; + quint16 streamVersion; + in >> magic >> streamVersion; + if (magic != magicNumber) { + qCritical() << "Version file is not recognized by this application"; + connection = false; + return false; + } else if (streamVersion > in.version()) { + qCritical() << "Version file is from a more recent version of the application"; + connection = false; + return false; + } + in.setVersion(streamVersion); + in >> majorRemote >> minorRemote >> patchRemote >> link >> text; + } else { + qCritical() << "Could not establish connection " << reply->error() << ":" << reply->errorString(); + connection = false; + delete m_NetworkMngr; + return false; + } + + delete reply; + delete m_NetworkMngr; + + const bool newVersion = + major < majorRemote || minor < minorRemote || patch < patchRemote; + + return newVersion; +#else + Q_UNUSED(location); + Q_UNUSED(magicNumber); + Q_UNUSED(majorRemote); + Q_UNUSED(minorRemote); + Q_UNUSED(patchRemote); + Q_UNUSED(link); + Q_UNUSED(text); + qCritical() << QString("network library of Qt not linked against application"); + connection = false; + return false; +#endif + } + + int getVersionMajor() const + { + return major; + } + + int getVersionMinor() const + { + return minor; + } + + int getVersionPatch() const + { + return patch; + } + + virtual void checkRequirements() const + { + static_assert(true, "no requirements needed"); + } + + int getCompilerBits() + { + // appropriate function will be selected at compile time + return DetermineBits(); + } + +}; + +#endif // VERSIONING_H diff --git a/scannerExtract/CHANGELOG b/scannerExtract/CHANGELOG new file mode 100644 index 0000000..10a6982 --- /dev/null +++ b/scannerExtract/CHANGELOG @@ -0,0 +1,51 @@ +################################################################################ +2015-09-26; by Dominik Rue + +- removed a bug which prevented saving on clicking on the save button + +- disabled disabling of saving button (user can choose to overwrite) + +################################################################################ +2015-09-25; by Dominik Rue + +- removed a bug which caused an application crash on loading images + +- added successful saving information text on status bar + +- removed a bug which caused backslashes in filepath to not save files + +- removed a bug which caused an exception on exiting the program + +- removed a bug which prevented saving when non existing directory was specified + +- added "uninstall before install" which tries to uninstall old versions + +- removed some fixed paths and settings for cmake + +- added bit information (i.e. 32/64) to about dialog + + +################################################################################ +2015-08; by Dominik Rue + +- added mutex to decrease maximum memory consumption + (useful for the 32bit vresions) + +- added online documentation to docs folder + +- A new selection can now also be created by clicking twice + (used to be only by dragging) + +- faster extraction of preview in previously bloccking situations + +- made some changes to the online documentation, i.e. howto install + +- added the online documentation to the source package + +- fixed a bug which would not reload already seen 16bit images + +- fixed a bug which caused the application to crash on closing it + +################################################################################ +2015-08; by Dominik Rue +First release diff --git a/scannerExtract/CMakeLists.txt b/scannerExtract/CMakeLists.txt new file mode 100644 index 0000000..912c673 --- /dev/null +++ b/scannerExtract/CMakeLists.txt @@ -0,0 +1,243 @@ + ####################################################################### + # This file is part of Scanned Image Extract. + # + # Scanned Image Extract 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 + # (at your option) any later version. + # + # Scanned Image Extract 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 Scanned Image Extract. If not, see + # + # + # Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + ######################################################################/ + +cmake_minimum_required (VERSION 2.8) + +set (PROJECTNAME "scannedImageExtractor") +project (${PROJECTNAME} CXX) + +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/settings.cmake ) + +find_package (versioning REQUIRED) + +find_package (misc REQUIRED) + +find_package (liblbfgs REQUIRED) + +set (QT_USE_QTMAIN TRUE) +set (QT_USE_SVG TRUE) +set (QT_USE_NETWORK TRUE) +set (QT_MORE_COMPONENTS QtSvg QtNetwork) +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/qt5.cmake ) +find_package (Qt5Network REQUIRED) +find_package (Qt5Svg REQUIRED) + +if (OPENCV2) + find_package (OpenCV REQUIRED core imgproc highgui) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV2") +else() + find_package (OpenCV REQUIRED core imgproc imgcodecs) +endif() + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + +include_directories( ${OpenCV_INCLUDE_DIRS} ) + +find_package(OpenMP) +if (OPENMP_FOUND) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") +endif() + +set(CMAKE_AUTOMOC ON) + +include_directories ( + . + ${CMAKE_CURRENT_BINARY_DIR} + ) + +set ( ${PROJECTNAME}_SOURCES + mainwindow.cpp + imageboundary.cpp + main.cpp + imagescene.cpp + preloadsource.cpp + copytargets.cpp + about.cpp + version_scannerExtract.cpp + settingsdialog.cpp + extracttargets.cpp + TargetImage.cpp + sourcefile.cpp + helpdialog.cpp + ) + +set ( ${PROJECTNAME}_HEADERS + mainwindow.h + extracttargets.h + imageboundary.h + imagescene.h + settings.h + sourcefile.h + TargetImage.h + preloadsource.h + copytargets.h + about.h + version_scannerExtract.h + settingsdialog.h + helpdialog.h + + ) + +set (${PROJECTNAME}_RESSOURCES + scannerIcons.qrc + ) + +set (${PROJECTNAME}_FORMS + mainwindow.ui + about.ui + settingsdialog.ui + helpdialog.ui +) + +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/addtranslation.cmake ) + +# for this application, actually build the ressource file and include it +set(RESOURCE_NAME "translations") +set(MAPPED_DIR ${CMAKE_CURRENT_BINARY_DIR}) +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/onTheFlyResourceFile.cmake ) + +QT5_WRAP_UI (${PROJECTNAME}_FORMS_HEADERS ${${PROJECTNAME}_FORMS}) +QT5_ADD_RESOURCES (${PROJECTNAME}_RESOURCES_RCC ${${PROJECTNAME}_RESSOURCES}) + +# set exe icon +IF(WIN32) + IF( MINGW ) + # resource compilation for MinGW + ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scannerImageExtractor_ico.o + COMMAND windres.exe -I${CMAKE_CURRENT_SOURCE_DIR} -i${CMAKE_CURRENT_SOURCE_DIR}/scannerImageExtractor_ico.rc + -o ${CMAKE_CURRENT_BINARY_DIR}/scannerImageExtractor_ico.o ) + SET(${PROJECTNAME}_SOURCES ${${PROJECTNAME}_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/scannerImageExtractor_ico.o) + ELSE( MINGW ) + SET(${PROJECTNAME}_SOURCES ${${PROJECTNAME}_SOURCES} scannerImageExtractor_ico.rc) + ENDIF( MINGW ) +ENDIF(WIN32) + +add_executable (${PROJECTNAME} WIN32 + ${${PROJECTNAME}_HEADERS} + ${${PROJECTNAME}_SOURCES} + ${${PROJECTNAME}_HEADERS_MOC} + ${${PROJECTNAME}_FORMS_HEADERS} + ${${PROJECTNAME}_RESOURCES_RCC} + ${${PROJECTNAME}_TRANSLATION_FILES} + ) + +qt5_use_modules (${PROJECTNAME} Network Widgets Svg) +TARGET_LINK_LIBRARIES (${PROJECTNAME} + ${MY_LIBS} + ${QT_LIBRARIES} + ${OpenCV_LIBS} + ${LIBLBFGS_LIBRARY} + ) + +if(WIN32 OR MINGW) +TARGET_LINK_LIBRARIES (${PROJECTNAME} + Qt5::WinMain + ) +endif() + +install(TARGETS ${PROJECTNAME} + RUNTIME DESTINATION bin COMPONENT main + ) + +if (WIN32) + INSTALL(FILES + ${LIBLBFGS_LIBRARY_DLL} + ${OpenCV_DIR}/bin/libopencv_core300.dll + ${OpenCV_DIR}/bin/libopencv_imgproc300.dll + ${OpenCV_DIR}/bin/libopencv_imgcodecs300.dll + DESTINATION bin + COMPONENT main + ) +endif(WIN32) + +# add nice icon for Gnome and KDE and add to default programs for cameras +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/installDesktop.cmake ) +#set(sizes "16x16" "22x22" "24x24" "36x36" "42x42" "72x72" "96x96" "32x32" "48x48" "64x64" "128x128" "80x80") +set(sizes "128x128" "256x256") +INSTALL_DESKTOP_LOCAL(" %f" + "Scanned Image Extractor" + "" + "ico" + "${sizes}" + "Terminal=false +Type=Application +MimeType=x-content/image-dcf; +Categories=Graphics\;Photography\;GNOME\;KDE\; +X-GNOME-FullName=Scanned Image Extractor\n") + +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/installQt5.cmake ) + +set ( PACKAGE_NAME ${PROJECTNAME} ) +set ( MAIN_DISPLAY_NAME "Scanned Image Extractor") +set ( USE_COMPONENTS main ) +SET ( VERSION_MAJOR 0 ) +SET ( VERSION_MINOR 2 ) +set ( VERSION_PATCH ${CURRENT_PATCH_NUMBER}) + +IF(WIN32) + # There is a bug in NSI that does not handle full unix paths properly. Make + # sure there is at least one set of four (4) backlasshes. + set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/images\\\\logo.ico") + SET(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/images\\\\logo.png") + SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\scannedImageExtractor.exe") + SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}Scanned Image Extractor") +Endif(WIN32) + +IF(UNIX) + message("using ${CMAKE_SYSTEM_PROCESSOR}") + # http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29 + SET(CPACK_SET_DESTDIR "on") + SET(CPACK_DEBIAN_PACKAGE_NAME "scannedImageExtractor") + SET(CPACK_PACKAGING_INSTALL_PREFIX "/tmp") + if(MAKE_RPM) + set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST} + /usr/local + /usr/local/bin + /usr + /usr/share + /usr/share/applications + /usr/share/icons + /usr/share/icons/hicolor + /usr/share/icons/hicolor/256x256/apps + /usr/share/icons/hicolor/256x256 + /usr/share/icons/hicolor + /usr/share/icons/hicolor/128x128 + /usr/share/icons/hicolor/128x128/apps + /usr/share/icons/hicolor/256x256/apps + /usr/share/icons/hicolor/256x256) + SET(CPACK_GENERATOR "RPM") + SET(CPACK_RPM_PACKAGE_LICENSE "GPL v3") + SET(CPACK_RPM_PACKAGE_VENDOR "Dominik Rueß ") + SET(CPACK_RPM_PACKAGE_REQUIRES "opencv-core >= 2.4, qt5-qtsvg >= 5.0, qt5-qtbase >= 5.0, liblbfgs >= 1.0") + SET(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + else() + SET(CPACK_GENERATOR "DEB") + SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5core5a, libqt5network5, libqt5gui5, libqt5svg5, libqt5widgets5, liblbfgs0, libopencv-core2.4, libopencv-highgui2.4, libopencv-imgproc2.4") + SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") + SET(CPACK_DEBIAN_PACKAGE_SECTION "kde") + SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + SET(CPACK_PACKAGE_CONTACT "scannerExtract@dominik-ruess.de") + SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Dominik Rueß ") + endif() +ENDIF() + + +include ( ${CMAKE_CURRENT_LIST_DIR}/../CMakeModules/buildPackage.cmake ) diff --git a/scannerExtract/LICENSE b/scannerExtract/LICENSE new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/scannerExtract/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 3 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, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/scannerExtract/README b/scannerExtract/README new file mode 100644 index 0000000..b4af270 --- /dev/null +++ b/scannerExtract/README @@ -0,0 +1,81 @@ +/*********************************************************************** + * This file is part of Scanned Image Extractor. + * + * Scanned Image Extractor 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 + * (at your option) any later version. + * + * Scanned Image Extractor 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 Scanned Image Extractor. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +Homepage of Scanned Image Extractor: +http://dominik-ruess.de/scannerExtract/ + +####################################################################### +# Content: # +####################################################################### + +1. How to install binaries on different systems +2. How to compile on unix systems + +####################################################################### +# Installing Binaries: # +####################################################################### + +WINDOWS: download the binaries and install. + There are no dependencies for the installation binary + tested with Windows 7 + +Linux-DEB: + tested Ubuntu 15.04 with and Ubuntu 14.04 LTS + 1. Pre-requisites: + sudo apt-get install libqt5core5a libqt5network5 \ + libqt5gui5 libqt5svg5 libqt5widgets5 liblbfgs0 \ + libopencv-core2.4 libopencv-highgui2.4 \ + libopencv-imgproc2.4 + 2. install debian package: + sudo dpkg -i scannerExtract-x.y.z.deb + +Linux-RPM: + tested with Fedora 22 + 1. Pre-requisites, adapt to your architecture here: + sudo dnf install opencv-core.x86_64 qt5-qtsvg.x86_64 \ + qt5-qtbase.x86_64 liblbfgs-devel.x86_64 \ + opencv.x86_64 + 2. install RPM package: + rpm --install -p scannerExtract-x.y.z.rpm + +####################################################################### +# Compile on unix systems: # +####################################################################### + +Tested with Ubuntu 15.04 + +1. pre-requisites + sudo apt-get install liblbfgs-dev libopencv-dev libqt5svg5-dev \ + qttools5-dev-tools qttools5-dev qtbase5-dev cmake + +2. build (tested on Ubuntu 15.04) + - commands: + mkdir build + cd build + cmake path/to/scannerExtract-X.Y.Z/scannerExtract/ \ + -DCMAKE_BUILD_TYPE=release -DOPENCV2=1 + make + (make install) + - note: if you use OpenCV2 (e.g. Ubuntu 15.04) then add + -DOPENCV2=1 to your cmake call + +3. run + "./scannedImageExtractor" or if installed "scannedImageExtractor" + diff --git a/scannerExtract/TargetImage.cpp b/scannerExtract/TargetImage.cpp new file mode 100644 index 0000000..33d9513 --- /dev/null +++ b/scannerExtract/TargetImage.cpp @@ -0,0 +1,23 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "TargetImage.h" +int TargetImage::nextId = 0; +int TargetImage::nextCopyId = 0; diff --git a/scannerExtract/TargetImage.h b/scannerExtract/TargetImage.h new file mode 100644 index 0000000..9ddda6a --- /dev/null +++ b/scannerExtract/TargetImage.h @@ -0,0 +1,131 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef TARGETIMAGE_H +#define TARGETIMAGE_H + +#include "imageboundary.h" + +#include +#include +#include + +#ifdef __GNUC__ +#include +#endif +class BackMap +{ +public: + BackMap(const double angle, + const QPointF translation, + const QSizeF size, + const double scale) + { + const double c = qCos(angle), s = qSin(angle); + rotation[0] = c; + rotation[1] = -s; + rotation[2] = s; + rotation[3] = c; + this->translation[0] = translation.x(); + this->translation[1] = translation.y(); + this->size[0] = size.width(); + this->size[1] = size.height(); + this->scale = scale; + } + + inline void transform(const QPointF& input, float& x, float& y) + { + QPointF preTrans(input.x() - 0.5*size[0]*scale, + input.y() - 0.5*size[1]*scale); + x = rotation[0] * preTrans.x() + rotation[1] * preTrans.y() + translation[0]*scale; + y = rotation[2] * preTrans.x() + rotation[3] * preTrans.y() + translation[1]*scale; + } + +private: + + double scale; + double size[2]; + double rotation[4]; + double translation[2]; +}; + +typedef std::tr1::shared_ptr BackMapPtr; + +enum Rotation90 +{ + TargetRotation0 = 0, + TargetRotation90 = 1, + TargetRotation180 = 2, + TargetRotation270 = 3 +}; + + +struct TargetImage +{ + ImageBoundaryPtr boundary; + + QImage image; + + Rotation90 rotation; + int determinedRotation; + + TargetImage() + : boundary(new ImageBoundary) + , rotation(TargetRotation0) + , width(0) + , height(0) + , copyId(-1) + , workOnId(++nextId) + , aspect(-1.0) + {} + + TargetImage(ImageBoundaryPtr newB) + : boundary(newB) + , rotation(TargetRotation0) + , width(0) + , height(0) + , copyId(-1) + , workOnId(++nextId) + , aspect(-1.0) + {} + + ~TargetImage() + { + backmap = BackMapPtr(); + boundary = ImageBoundaryPtr(); + } + + BackMapPtr backmap; + int width; + int height; + + int copyId; + long int workOnId; + + float aspect; + + static int nextCopyId; +private: + static int nextId; +}; + +typedef std::shared_ptr TargetImagePtr; + +#endif // TARGETIMAGE_H diff --git a/scannerExtract/WARRANTY b/scannerExtract/WARRANTY new file mode 100644 index 0000000..38ea708 --- /dev/null +++ b/scannerExtract/WARRANTY @@ -0,0 +1 @@ +This software is licensed under the GPL, see source code for details. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/scannerExtract/WARRANTY_DE b/scannerExtract/WARRANTY_DE new file mode 100644 index 0000000..1e4125a --- /dev/null +++ b/scannerExtract/WARRANTY_DE @@ -0,0 +1 @@ +Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. diff --git a/scannerExtract/about.cpp b/scannerExtract/about.cpp new file mode 100644 index 0000000..bfde459 --- /dev/null +++ b/scannerExtract/about.cpp @@ -0,0 +1,81 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include +#include "about.h" +#include "ui_about.h" + +#include +#include +#include + +DialogAbout::DialogAbout(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogAbout) +{ + ui->setupUi(this); + + const int size = 128; + ui->label_image->setMargin(5); + ui->label_image->setMinimumSize(size+10, size+10); + ui->label_image->setMaximumSize(size+10, size+10); + ui->label_image->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + //ui->label_image->setMaximumSize(size, size); + ui->label_image->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + + QSvgRenderer renderer(QString(":images/logo.svg")); + QImage image(size, size, QImage::Format_ARGB32); + image.fill(0x00000000); // partly transparent red-ish background + QPainter painter(&image); + renderer.render(&painter); + + QString text; + QFile tmp(tr(":WARRANTY_EN")); + if (tmp.open(QIODevice::ReadOnly)) + { + text = tmp.readAll(); + } + ui->label_license->setText(ui->label_license->text() + text); + ui->label_license->setWordWrap(true); + + ui->label_image->setPixmap(QPixmap::fromImage(image));//.scaled(size, size, Qt::KeepAspectRatio)); + this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); +} + +DialogAbout::~DialogAbout() +{ + delete ui; +} + +void DialogAbout::on_pushButton_done_clicked() +{ + this->close(); +} + +void DialogAbout::setVersion(const int major, const int minor, const int patch, const int bits) +{ + ui->label_version->setText(tr("version %1.%2.%3 - %4bit version").arg(major).arg(minor).arg(patch).arg(bits)); +} + +QString DialogAbout::getDonateText() const +{ + return ui->label_donation->text(); +} diff --git a/scannerExtract/about.h b/scannerExtract/about.h new file mode 100644 index 0000000..c64d97b --- /dev/null +++ b/scannerExtract/about.h @@ -0,0 +1,51 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef DIALOGABOUT_SCANNER_EXTRACT_H +#define DIALOGABOUT_SCANNER_EXTRACT_H + +#include + +#include "about.h" + +namespace Ui { +class DialogAbout; +} + +class DialogAbout : public QDialog +{ + Q_OBJECT + +public: + explicit DialogAbout(QWidget *parent = 0); + ~DialogAbout(); + + void setVersion(const int, const int, const int, const int); + + QString getDonateText() const; + +private slots: + void on_pushButton_done_clicked(); + +private: + Ui::DialogAbout *ui; +}; + +#endif // DIALOGABOUT_SCANNER_EXTRACT_H diff --git a/scannerExtract/about.ui b/scannerExtract/about.ui new file mode 100644 index 0000000..d9fecf9 --- /dev/null +++ b/scannerExtract/about.ui @@ -0,0 +1,236 @@ + + + DialogAbout + + + + 0 + 0 + 628 + 562 + + + + + 0 + 0 + + + + About Scanned Image Extractor + + + + + + + + 10 + + + + + + 0 + 0 + + + + + 128 + 0 + + + + + 128 + 16777215 + + + + QFrame::Panel + + + QFrame::Raised + + + + + + 5 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + 24 + 75 + true + + + + Scanned Image Extractor + + + + + + + + 75 + true + + + + Version + + + + + + + <html><head/><body><p align="justify"><span style=" font-style:italic;">Scanned Image Extractor</span> is a programm which allows fast and efficient extraction of multiple photographs of scanned albums</p></body></html> + + + true + + + + + + + <html><head/><body><p>Copyright 2015, Dominik Rueß <a href="mailto:pivot@dominik-ruess.de"><span style=" text-decoration: underline; color:#0000ff;">scanner-extractor@dominik-ruess.de</span></a></p></body></html> + + + true + + + + + + + <html><head/><body><p>License: <span style=" font-style:italic;">The GNU General Public License (GPL), Version 3</span></p></body></html> + + + + + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + <html><head/><body><p>Bugs, feature requests or spelling errors can be reported to: <a href="https://sourceforge.net/p/scannedimageextractor/tickets/"><span style=" text-decoration: underline; color:#0000ff;">sourceforge.net/p/scannedimageextractor/tickets/ </span></a>(or email).<br/>I'm always looking forward to translations into YOUR language.</p></body></html> + + + true + + + true + + + + + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + <html><head/><body><p align="justify">If you like <span style=" font-style:italic;">Scanned Image Extractor</span> or if you wish to support the author consider donating</span>: </p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">via Sourceforge (Donation for user <span style=" font-style:italic;">domsen</span>): <a href="https://sourceforge.net/p/scannedimageextractor/donate/"><span style=" text-decoration: underline; color:#0000ff;">sourceforge.net/p/scannedimageextractor/donate/</span></a></li><li align="justify" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">personally: contact me at <a href="mailto:donate@dominik-ruess.de"><span style=" text-decoration: underline; color:#0000ff;">donate@dominik-ruess.de</span></a></li></ul></body></html> + + + true + + + true + + + + + + + Qt::Horizontal + + + + + + + Credits go to the GNOME project (i.e. the gome icon artists) for the application icon (Creative Commons Attribution-Share Alike 3.0 Unported), which consists of Gnome-image-x-generic.svg and Gnome-scanner.svg. + + + true + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Ok + + + + + + + + + + + + + + diff --git a/scannerExtract/copytargets.cpp b/scannerExtract/copytargets.cpp new file mode 100644 index 0000000..0930cfc --- /dev/null +++ b/scannerExtract/copytargets.cpp @@ -0,0 +1,238 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "copytargets.h" + +#include +#ifndef OPENCV2 +#include +#include +#include +#else +#include +#endif + +#include +#include + +#include "extracttargets.h" + +QMutex CopyTargets::memorySaveMutex; + +CopyTargets::CopyTargets(QObject *parent) + : QThread(parent) + , _stopped(false) + , _exitWritingOperationDone(false) +{ +} + +CopyTargets::~CopyTargets() +{ + _fileListMutex.lock(); + abortSaveFile(0); + while (!_exitWritingOperationDone || _filesToCopy.size() > 0) + { + _fileListMutex.unlock(); + // saving may occur on closing + qDebug() << "waiting for all writing operations to finish (still" << _filesToCopy.size() << "to write)"; + //_computationCondition.wait(&_computationRunning); + //qDebug() << "finished writing next image"; + QThread::wait(500); + _fileListMutex.lock(); + } + _filesToCopy.clear(); + _fileListMutex.unlock(); + //_computationRunning.unlock(); + _stopped = true; + _condition.wakeAll(); + + wait(); +} + +void CopyTargets::addSaveFiles(SourceFilePtr source) +{ + QMutexLocker l(&_fileListMutex); + _filesToCopy.push_back(source); + _abortSaveFile = 0; + + if (!isRunning()) { + start(QThread::LowPriority); + } else { + _condition.wakeOne(); + } + +} + +void CopyTargets::abortSaveFile(SourceFilePtr file) +{ + _abortSaveFile = file; +} + +void CopyTargets::clear() +{ + QMutexLocker l(&_fileListMutex); + _filesToCopy.clear(); +} + +#define ABORT_CURRENT_TEST(breakit) \ + if (_abortSaveFile.get() != 0 \ + && file->source.absoluteFilePath() == _abortSaveFile->source.absoluteFilePath()) \ + { \ + if (breakit) break; \ + else continue; \ + } + +void CopyTargets::run() +{ + while (!_stopped) { + SourceFilePtr file; + { + QMutexLocker l(&_fileListMutex); + if (_filesToCopy.size() == 0) { + _condition.wait(&_fileListMutex); + // continue: in the meantime it might have been stopped + // or set empty + continue; + } + file= _filesToCopy.first(); + _filesToCopy.pop_front(); + } + //QMutexLocker l(&_computationRunning); + + QMutexLocker l1(&ExtractTargets::imageMutex); + QList targets = file->targets; + QList backmaps; + for (int i=0; ibackmap); + } + l1.unlock(); + + QMutexLocker l2(&memorySaveMutex); + cv::Mat src = cv::imread(file->source.canonicalFilePath().toLocal8Bit().data(), + CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR); + QDir targetDir (QDir::rootPath()); + targetDir.mkpath(QFileInfo(_targetDir).absolutePath()); + + for (int i=0; iboundary->getCopied()) { + qDebug() << "Target " << i + << " of source " + << file->source.canonicalFilePath() + << " has already been copied in this session, skipping"; + continue; + } + if (targets[i]->copyId == -1) + { + targets[i]->copyId = ++TargetImage::nextCopyId; + } + const int tW = targets[i]->width; + const int tH = targets[i]->height; + if (tW == 0 || tH == 0) { + continue; + } + + cv::Mat mapX(tH, tW, CV_32FC1), + mapY(tH, tW, CV_32FC1); + cv::Mat out(tH, tW, src.type()); + for (int r=0; r(r); + float* mY = mapY.ptr(r); + for (int c=0; ctransform(QPointF(c, r), mX[c], mY[c]); + } + ABORT_CURRENT_TEST(true); + } + ABORT_CURRENT_TEST(true); + cv::transpose(mapX, mapX); + cv::transpose(mapY, mapY); + ABORT_CURRENT_TEST(false); + + cv::remap(src, out, mapX, mapY, CV_INTER_CUBIC); + mapX.release(); + mapY.release(); + cv::flip(out, out, 0); + QString newFileName(QString("%1%2%3_%4.%5") + .arg(_targetDir + QDir::separator()) + .arg(_prefix) + .arg(file->source.baseName()) + .arg(targets[i]->copyId, (int)FIELD_WIDTH, (int)10, QChar('0')) + .arg(file->source.suffix())); + + cv::Mat out2; + int rot = targets[i]->determinedRotation + targets[i]->rotation + 1; + + if (out.size().width ==0 || out.size().height == 0) + { + emit copyError(file, targets[i]); + } + else + { + switch(rot) { + case 1: + case 5: + case -3: + cv::transpose(out, out2); + cv::flip(out2, out2, 1); + break; + case 2: + case 6: + case -2: + cv::flip(out, out2, -1); + break; + case 3: + case -1: + cv::transpose(out, out2); + cv::flip(out2, out2, 0); + break; + default: + out2=out; + break; + } + if (cv::imwrite(newFileName.toLocal8Bit().data(), out2)) { + ABORT_CURRENT_TEST(true); + targets[i]->boundary->setCopied(true); + if (!_stopped) + { + emit copied(QFileInfo(newFileName).fileName(), + QFileInfo(newFileName).absolutePath()); + } + } else { + if (!_stopped) + { + emit copyError(file, targets[i]); + } + } + } + } + ABORT_CURRENT_TEST(false); + file->changed = false; + src.release(); + l2.unlock(); + + //l.unlock(); + + _computationCondition.wakeAll(); + } + _computationCondition.wakeAll(); +} diff --git a/scannerExtract/copytargets.h b/scannerExtract/copytargets.h new file mode 100644 index 0000000..7b5638c --- /dev/null +++ b/scannerExtract/copytargets.h @@ -0,0 +1,84 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef COPYTARGETS_H +#define COPYTARGETS_H + +#include +#include +#include +#include + +#include "sourcefile.h" + +#define TARGET_FILENAME "scanner_extracted" +#define FIELD_WIDTH 2 + +class CopyTargets : public QThread +{ + Q_OBJECT +public: + explicit CopyTargets(QObject *parent = 0); + + ~CopyTargets(); + + void addSaveFiles(SourceFilePtr); + + void abortSaveFile(SourceFilePtr); + + void setDestination(const QString targetDir) { _targetDir = targetDir;} + + static QMutex memorySaveMutex; + + void clear(); + + void setPrefix(QString prefix) { _prefix = prefix; } + + void setExitSaving() { _exitWritingOperationDone = true; } + +signals: + void copyError(SourceFilePtr source, TargetImagePtr target); + void copied(QString filename, QString targetDir); + +public slots: + +protected: + void run(); + +private: + QVector _filesToCopy; + + QString _targetDir; + + QMutex _fileListMutex; + // QMutex _computationRunning; + QWaitCondition _condition; + QWaitCondition _computationCondition; + + bool _stopped; + + QString _prefix; + + SourceFilePtr _abortSaveFile; + + bool _exitWritingOperationDone; +}; + +#endif // COPYTARGETS_H diff --git a/scannerExtract/extracttargets.cpp b/scannerExtract/extracttargets.cpp new file mode 100644 index 0000000..f852530 --- /dev/null +++ b/scannerExtract/extracttargets.cpp @@ -0,0 +1,285 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include + +#include "extracttargets.h" + + +QMutex ExtractTargets::imageMutex; +QMutex ExtractTargets::fileListMutex; + +ExtractTargets::ExtractTargets(QObject *parent) + : QThread(parent) + , _stopped(false) + , _abortCurrentStartNext(false) +{ +} + +void ExtractTargets::addTarget(TargetImagePtr target, + SourceFilePtr source, + const bool highPriority) +{ + QMutexLocker l(&fileListMutex); + + if (_current.get() != 0 + && _current->workOnId == target->workOnId) + { + // already loading -> do nothing + return; + } + + if (highPriority) { + _abortCurrentStartNext = true; + } + + QPair item(target, source); + if (highPriority) { + _targetList.push_front(item); + } + else { + _targetList.push_back(item); + } + + // find duplicates and delete (work from back) + for (int i=_targetList.size()-1; i>=0; i--) { + for (int j=i-1; j>=0; j--) { + if (_targetList[i].first->workOnId + == _targetList[j].first->workOnId) { + _targetList.erase(_targetList.begin() + i); + } + } + } + + _stopped = false; + if (!isRunning()) { + start(QThread::HighPriority); + } else { + _condition.wakeOne(); + } +} + +void ExtractTargets::stop() +{ + _stopped = true; +} + +ExtractTargets::~ExtractTargets() +{ + fileListMutex.lock(); + _targetList.clear(); + _stopped = true; + _condition.wakeAll(); + fileListMutex.unlock(); + + wait(); +} + +void ExtractTargets::run() +{ + while (!_stopped) { + _abortCurrentStartNext = false; + { + QMutexLocker l(&fileListMutex); + if (_targetList.size() == 0) { + _condition.wait(&fileListMutex); + // continue: in the meantime it might have been stopped + // or set empty + continue; + } + } + + fileListMutex.lock(); + _current = _targetList.first().first; + SourceFilePtr currentSource = _targetList.first().second; + fileListMutex.unlock(); + + imageMutex.lock(); + extract(_current, currentSource); + imageMutex.unlock(); + + if (_stopped || _abortCurrentStartNext) { + continue; + } + + fileListMutex.lock(); + _targetList.pop_front(); + fileListMutex.unlock(); + + if (!_stopped) { + emit doneTarget(_current); + } + _current = TargetImagePtr(); + } +} + +void ExtractTargets::extract(TargetImagePtr target, SourceFilePtr source) +{ + QImage out; + if (source->imageOrig.isNull() + || source->imageOrig.width() == 0 + || source->imageOrig.height() == 0) + { + target->backmap = BackMapPtr(); + target->image = QImage(); + return; + } + + const QImage& sourceImage = source->imageOrig; + + const double cropPerc = target->boundary->getCrop() < 0 ? _cropPercentage : target->boundary->getCrop(); + target->boundary->setCrop(cropPerc); + const int width = _norm(target->boundary->corners()[0] * (1-cropPerc) + -target->boundary->corners()[3] * (1-cropPerc)); + const int height = _norm(target->boundary->corners()[1] * (1-cropPerc) + -target->boundary->corners()[0] * (1-cropPerc)); + + out = QImage(width, height, QImage::Format_RGB32); + out.fill(QColor(0,0,0)); + + // check correct order, such that it does not reflect in any dimension + // (no flipping) + + double anglesSource[4]; + QPointF center(0,0); + for (int i=0;i<4;i++) { + center += target->boundary->corners()[0]; + } + center /= 4; + center = target->boundary->mapToScene(center); + for (int i=0; i<4; i++) { + QPointF curr = target->boundary->mapToScene(target->boundary->corners()[i])-center; + anglesSource[i] = qAtan2(curr.y(), curr.x()); + } + int numNeg = 0; + for (int i=0; i<4; i++) { + const double sgn1 = (anglesSource[i]-anglesSource[(i+3)%4]); + //const double sgn2 = (anglesTarget[i]-anglesTarget[(i+3)%4]); + if (sgn1 < 0) numNeg++; + } + + // either double reflected (numNeg == 2) or only one side + if (numNeg >= 2) { + QPointF corners[4]; + if (numNeg > 2) { + corners[0] = target->boundary->corners()[0]; + corners[1] = target->boundary->corners()[3]; + corners[2] = target->boundary->corners()[2]; + corners[3] = target->boundary->corners()[1]; + } else { + corners[0] = target->boundary->corners()[2]; + corners[1] = target->boundary->corners()[3]; + corners[2] = target->boundary->corners()[0]; + corners[3] = target->boundary->corners()[1]; + + } + target->boundary->setCorners(corners); + // start over again + extract(target, source); + } + else + { + // now also check the orientation, it has to be + // similar to the source. meaning roughly upright -> upright + QPointF currRot = target->boundary->mapToScene(target->boundary->corners()[2]) + -target->boundary->mapToScene(target->boundary->corners()[1]); + const double resultAngle = qAtan2( currRot.y(), + currRot.x() ); + + const int num90DegreeBins = qRound((resultAngle)/(M_PI/2.0)); + + QPointF dirX(target->boundary->corners()[3]* (1-cropPerc) + -target->boundary->corners()[0]* (1-cropPerc)), + dirY(target->boundary->corners()[0]* (1-cropPerc) + -target->boundary->corners()[1]* (1-cropPerc)); + QSizeF size(_norm(dirX), _norm(dirY)) ; + dirX /= size.width(); + dirY /= size.height(); + QPointF center(0.5*(target->boundary->mapToScene(target->boundary->corners()[0]) + + target->boundary->mapToScene(target->boundary->corners()[2]))); + + const int sourceHeight = sourceImage.height(); + const int sourceWidth = sourceImage.width(); + + target->backmap = BackMapPtr(new BackMap(resultAngle, + center, + size, + source->scale)); + +#pragma omp parallel for + for (int y=0; yboundary->corners()[1]* (1-cropPerc) + + y*dirY + x*dirX); + pos = target->boundary->mapToScene(pos); + const int xSource = qRound(pos.x()); + const int ySource = qRound(pos.y()); + if (xSource >= 0 + && xSource < sourceWidth + && ySource >= 0 + && ySource < sourceHeight) { + out.setPixel(x,y, sourceImage.pixel(xSource, ySource)); + } else { + out.setPixel(x,y,qRgb(0,0,0)); + } + } + } + } + + if (_stopped || _abortCurrentStartNext) { + target->width = 0; + target->height = 0; + target->backmap = BackMapPtr(); + target->image = QImage(); + return; + } + else + { + target->width = (double)width * source->scale; + target->height = (double)height * source->scale; + } + + + // finally, add normalizing rotation and user rotation: + out = out.transformed(QTransform().rotate( num90DegreeBins*90).rotate(target->rotation*90)); + + target->determinedRotation = num90DegreeBins; + target->image = out; + } +} + +inline double ExtractTargets::_norm(const QPointF& p) +{ + return qSqrt(p.x()*p.x() + p.y()*p.y()); +} + + +inline double ExtractTargets::_dot(const QPointF& p1, const QPointF& p2) +{ + return p1.x() * p2.x() + p1.y() * p2.y(); +} + +inline double ExtractTargets::_norm2(const QPointF& p) +{ + return p.x()*p.x() + p.y()*p.y(); +} diff --git a/scannerExtract/extracttargets.h b/scannerExtract/extracttargets.h new file mode 100644 index 0000000..75b5cbc --- /dev/null +++ b/scannerExtract/extracttargets.h @@ -0,0 +1,81 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef EXTRACTTARGETS_H +#define EXTRACTTARGETS_H + +#include +#include +#include +#include +#include + +#include "TargetImage.h" +#include "sourcefile.h" + +class ExtractTargets : public QThread +{ + Q_OBJECT +public: + explicit ExtractTargets(QObject *parent = 0); + ~ExtractTargets(); + + void addTarget(TargetImagePtr target, + SourceFilePtr source, + const bool highPriority = false); + + static QMutex imageMutex; + static QMutex fileListMutex; + + QList > getList() { return _targetList; } + + void setCrop(const float crop) { _cropPercentage = crop; } + + + +signals: + void doneTarget(const TargetImagePtr&); + +public slots: + + void stop(); + +protected: + void run(); + +private: + inline double _norm(const QPointF&); + inline double _dot(const QPointF& p1, const QPointF& p2); + inline double _norm2(const QPointF& p); + + QWaitCondition _condition; + void extract(TargetImagePtr target, SourceFilePtr source); + + QList > _targetList; + + bool _stopped; + bool _abortCurrentStartNext; + + float _cropPercentage; + + TargetImagePtr _current; +}; + +#endif // EXTRACTTARGETS_H diff --git a/scannerExtract/helpdialog.cpp b/scannerExtract/helpdialog.cpp new file mode 100644 index 0000000..ae87621 --- /dev/null +++ b/scannerExtract/helpdialog.cpp @@ -0,0 +1,16 @@ +#include "helpdialog.h" +#include "ui_helpdialog.h" + +HelpDialog::HelpDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::HelpDialog) +{ + ui->setupUi(this); + + ui->label_overview->setPixmap(QPixmap::fromImage(QImage(":/images/overview.png"))); +} + +HelpDialog::~HelpDialog() +{ + delete ui; +} diff --git a/scannerExtract/helpdialog.h b/scannerExtract/helpdialog.h new file mode 100644 index 0000000..a26d25e --- /dev/null +++ b/scannerExtract/helpdialog.h @@ -0,0 +1,22 @@ +#ifndef HELPDIALOG_H +#define HELPDIALOG_H + +#include + +namespace Ui { +class HelpDialog; +} + +class HelpDialog : public QDialog +{ + Q_OBJECT + +public: + explicit HelpDialog(QWidget *parent = 0); + ~HelpDialog(); + +private: + Ui::HelpDialog *ui; +}; + +#endif // HELPDIALOG_H diff --git a/scannerExtract/helpdialog.ui b/scannerExtract/helpdialog.ui new file mode 100644 index 0000000..38ce06d --- /dev/null +++ b/scannerExtract/helpdialog.ui @@ -0,0 +1,189 @@ + + + HelpDialog + + + + 0 + 0 + 750 + 650 + + + + Help + + + + + + + 18 + 75 + true + + + + Scanned Image Extractor Help + + + + + + + true + + + + + 0 + 0 + 730 + 561 + + + + + + + Find the more detailed online help at <a href="http://dominik-ruess.de/scannerExtract">dominik-ruess.de/scannerExtract</a> + + + true + + + + + + + This is a short introduction on how to use <i>Scanned Image Extractor</i>. Scroll down to see the complete help text. <br> +Now, here is an example of how the user interface of the program may look like: + + + true + + + + + + + + + + QFrame::Panel + + + QFrame::Raised + + + image + + + Qt::AlignCenter + + + 25 + + + + + + + First of all, you load a scanner image. It will appear in the area marked with (1). The program will suggest some photographs. These are marked with a rectangle. Once you select such a rectangle, its preview will apear in the area (2). <br>The properties of these rectangles can be changed in area (3). aspect ratio changes are located in (4) and the orientation of every rectangle/photograph can be changed in (5). + + + true + + + + + + + <b>Photograph/Rectangle Handling:</b> +<br>You can modify the shape of the output photographs/rectangles:<ul> +<li>drag corner or edge of rectangles for size changes</li> + <li>press CTRL for symmetric change</li> + <li>keep SHIFT pressed before dragging corner, this rotates the rectangle</li> + <li>add new rectangle: deselect all (click somewhere empty). Click on a photograph corner, keep mouse clicked and drag line to a second corner. Then move/resize the new rectangle and click to release.</li> + </ul> +If you process to the next scanned image, the previous photographs will be extracted <i>automatically</i>. + + + true + + + + + + + <b>Keyboard shortcuts:</b><table> + <tr><td>Keys 0-9</td><td> select aspect ratios</td></tr> + <tr><td>Keys 'a', 's', 'd' and 'f'</td><td> change orientation of current target</td></tr> + <tr><td style="padding-right:20px;">Keys CTRL+V and CTRL+B</td><td> navigate to prev. and next input image</td></tr> + <tr><td>Keys N, M and delete</td><td> navigate prev. and next target or delete target</td></tr></table> + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &OK + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + pushButton + clicked() + HelpDialog + close() + + + 320 + 456 + + + 319 + 239 + + + + + diff --git a/scannerExtract/ico/scannedImageExtractor.png b/scannerExtract/ico/scannedImageExtractor.png new file mode 100644 index 0000000..586780c Binary files /dev/null and b/scannerExtract/ico/scannedImageExtractor.png differ diff --git a/scannerExtract/ico/scannedImageExtractor128x128.png b/scannerExtract/ico/scannedImageExtractor128x128.png new file mode 100644 index 0000000..586780c Binary files /dev/null and b/scannerExtract/ico/scannedImageExtractor128x128.png differ diff --git a/scannerExtract/ico/scannedImageExtractor256x256.png b/scannerExtract/ico/scannedImageExtractor256x256.png new file mode 100644 index 0000000..4dcc0fe Binary files /dev/null and b/scannerExtract/ico/scannedImageExtractor256x256.png differ diff --git a/scannerExtract/imageboundary.cpp b/scannerExtract/imageboundary.cpp new file mode 100644 index 0000000..732585b --- /dev/null +++ b/scannerExtract/imageboundary.cpp @@ -0,0 +1,122 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "imageboundary.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TargetImage.h" + +ImageBoundary::ImageBoundary(QGraphicsItem *parent) + : QGraphicsPathItem(parent) + , _isCopied(false) + , _userHasSeenThis(false) + , _boundaryPercentage(-1.0) +{ + + QPointF corner[] = {QPointF(-100,-75), + QPointF(100,-75), + QPointF(100,75), + QPointF(-100,75)}; + setCorners(corner); + + setFlag(QGraphicsItem::ItemIsMovable, true); + setFlag(QGraphicsItem::ItemIsSelectable, true); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + + setBrush(NON_SELECTED); + +} + +QRectF ImageBoundary::boundingRect() +{ + QRectF out; + QPointF mi(1e10,1e10), ma(-1e10, -1e10); + for (int i=0; i<4; i++) + { + mi.setX(qMin(mi.x(), corners()[i].x())); + mi.setY(qMin(mi.y(), corners()[i].y())); + ma.setX(qMax(ma.x(), corners()[i].x())); + ma.setY(qMax(ma.y(), corners()[i].y())); + } + out = QRectF(mi, ma); + return out; +} + +void ImageBoundary::setCorners(const QPointF corner[]) +{ + QPainterPath path; + + path.moveTo(corner[0]); + for (int i=0; i<4; i++) { + _corners[i] = corner[i]; + if (i>0) { + path.lineTo(corner[i]); + } + } + path.lineTo(corner[0]); + + setPath(path); + +} + +const QPointF* ImageBoundary::corners() const +{ + return _corners; +} + +void ImageBoundary::setCopied(const bool copied) +{ + dirty(); + _isCopied = copied; +} + +void ImageBoundary::paint ( QPainter * painter, + const QStyleOptionGraphicsItem * option, + QWidget * widget ) +{ + QPen pen; + if ( this->isSelected()) { + setBrush(SELECTED); + pen.setStyle(Qt::DashLine); + QTime t = QTime::currentTime(); + QVector dashes; + dashes << 5 << 5; + pen.setDashPattern(dashes); + pen.setDashOffset(5*((float)t.second() + (float)t.msec()/1000.0)); + } else { + setBrush(_isCopied ? COPIED : NON_SELECTED); + } + pen.setWidth(2); + pen.setCosmetic(true); + setPen(pen); + + QStyleOptionGraphicsItem option2 (*option); + option2.state = option2.state & (~QStyle::State_Selected); + QGraphicsPathItem::paint(painter, &option2, widget); +} + diff --git a/scannerExtract/imageboundary.h b/scannerExtract/imageboundary.h new file mode 100644 index 0000000..eda9710 --- /dev/null +++ b/scannerExtract/imageboundary.h @@ -0,0 +1,85 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef IMAGEBOUNDARY_H +#define IMAGEBOUNDARY_H + +#include +#include +#include +#include +#include + +#include + +class TargetImage; + +#define SELECTED QBrush(QColor(255,0,0,50)) +#define NON_SELECTED QBrush(QColor(0,0,255,50)) +#define COPIED QBrush(QColor(0,255,0,50)) + +class ImageBoundary : public QGraphicsPathItem +{ + +public: + explicit ImageBoundary(QGraphicsItem *parent = 0); + + QRectF boundingRect(); + + void paint ( QPainter * painter, + const QStyleOptionGraphicsItem * option, + QWidget * widget = 0 ); + + void setCorners(const QPointF corner[]); + + const QPointF* corners() const; + + void setCopied(const bool copied); + + bool getCopied() const { return _isCopied; } + + bool getUserHasSeenThis() const { return _userHasSeenThis; } + void setUserHasSeenThis() { _userHasSeenThis = true; } + + void setCrop(const double perc) { _boundaryPercentage = perc; } + double getCrop() const { return _boundaryPercentage; } + + void dirty() { _isCopied = false; } + +signals: + +public slots: + +private: + int _lastSecond; + + QPointF _corners[4]; + + bool _isCopied; + + bool _userHasSeenThis; // this allows to adapt to the current aspect ratio + + double _boundaryPercentage; + +}; + +typedef std::shared_ptr ImageBoundaryPtr; + +#endif // IMAGEBOUNDARY_H diff --git a/scannerExtract/images/Document-save.svg b/scannerExtract/images/Document-save.svg new file mode 100644 index 0000000..d27b36b --- /dev/null +++ b/scannerExtract/images/Document-save.svg @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Save + + + Jakub Steiner + + + + + hdd + hard drive + save + io + store + + + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Edit-delete.svg b/scannerExtract/images/Edit-delete.svg new file mode 100644 index 0000000..0fac801 --- /dev/null +++ b/scannerExtract/images/Edit-delete.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Delete + 2005-12-28 + + + Andreas Nilsson + + + http://tango-project.org + + + delete + remove + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Gnome-image-x-generic.svg b/scannerExtract/images/Gnome-image-x-generic.svg new file mode 100644 index 0000000..0c97a75 --- /dev/null +++ b/scannerExtract/images/Gnome-image-x-generic.svg @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Generic Image + + + Lapo Calamandrei + + + http://www.gnome.org + + + Jakub Steiner, Andreas Nilsson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Gnome-image-x-generic_rot.svg b/scannerExtract/images/Gnome-image-x-generic_rot.svg new file mode 100644 index 0000000..6296fa2 --- /dev/null +++ b/scannerExtract/images/Gnome-image-x-generic_rot.svg @@ -0,0 +1,594 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Lapo Calamandrei + + + http://www.gnome.org + + + Jakub Steiner, Andreas Nilsson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scannerExtract/images/Gnome-scanner.svg b/scannerExtract/images/Gnome-scanner.svg new file mode 100644 index 0000000..9511fe9 --- /dev/null +++ b/scannerExtract/images/Gnome-scanner.svg @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + Scanner Device + + + device + input + scanner + image + raster + bitmap + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Media-seek-backward.svg b/scannerExtract/images/Media-seek-backward.svg new file mode 100644 index 0000000..9c68e7f --- /dev/null +++ b/scannerExtract/images/Media-seek-backward.svg @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Media Seek Backward + + + Lapo Calamandrei + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Media-seek-forward.svg b/scannerExtract/images/Media-seek-forward.svg new file mode 100644 index 0000000..b0f40dd --- /dev/null +++ b/scannerExtract/images/Media-seek-forward.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Media Seek Forward + + + Lapo Calamandrei + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Media-skip-backward.svg b/scannerExtract/images/Media-skip-backward.svg new file mode 100644 index 0000000..15be424 --- /dev/null +++ b/scannerExtract/images/Media-skip-backward.svg @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Media Skip Backward + + + Lapo Calamandrei + + + + + + media + player + video + sound + seek + skip + previous + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Media-skip-forward.svg b/scannerExtract/images/Media-skip-forward.svg new file mode 100644 index 0000000..3524ac4 --- /dev/null +++ b/scannerExtract/images/Media-skip-forward.svg @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Media Skip Forward + + + Lapo Calamandrei + + + + + + media + seek + skip + forward + player + music + video + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/Refresh_file.svg b/scannerExtract/images/Refresh_file.svg new file mode 100644 index 0000000..39fbb8b --- /dev/null +++ b/scannerExtract/images/Refresh_file.svg @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/View-zoom-1.svg b/scannerExtract/images/View-zoom-1.svg new file mode 100644 index 0000000..ee7ced9 --- /dev/null +++ b/scannerExtract/images/View-zoom-1.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/View-zoom-fit.svg b/scannerExtract/images/View-zoom-fit.svg new file mode 100644 index 0000000..4393bf0 --- /dev/null +++ b/scannerExtract/images/View-zoom-fit.svg @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Martin Ruskov + + + http://commons.wikimedia.org/wiki/Tango_icon + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/View-zoom-in.svg b/scannerExtract/images/View-zoom-in.svg new file mode 100644 index 0000000..f868952 --- /dev/null +++ b/scannerExtract/images/View-zoom-in.svg @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Martin Ruskov + + + http://commons.wikimedia.org/wiki/Tango_icon + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/View-zoom-out.svg b/scannerExtract/images/View-zoom-out.svg new file mode 100644 index 0000000..e628364 --- /dev/null +++ b/scannerExtract/images/View-zoom-out.svg @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Martin Ruskov + + + http://commons.wikimedia.org/wiki/Tango_icon + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scannerExtract/images/logo.svg b/scannerExtract/images/logo.svg new file mode 100644 index 0000000..dc57afd --- /dev/null +++ b/scannerExtract/images/logo.svg @@ -0,0 +1,976 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Lapo Calamandrei + + + http://www.gnome.org + + + Jakub Steiner, Andreas Nilsson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scannerExtract/images/overview.png b/scannerExtract/images/overview.png new file mode 100644 index 0000000..2cb2a77 Binary files /dev/null and b/scannerExtract/images/overview.png differ diff --git a/scannerExtract/images/rotate.png b/scannerExtract/images/rotate.png new file mode 100644 index 0000000..db7a8fd Binary files /dev/null and b/scannerExtract/images/rotate.png differ diff --git a/scannerExtract/images/sizeChange.png b/scannerExtract/images/sizeChange.png new file mode 100644 index 0000000..422f287 Binary files /dev/null and b/scannerExtract/images/sizeChange.png differ diff --git a/scannerExtract/imagescene.cpp b/scannerExtract/imagescene.cpp new file mode 100644 index 0000000..bbe20d4 --- /dev/null +++ b/scannerExtract/imagescene.cpp @@ -0,0 +1,1707 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "imagescene.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "settings.h" +// #define DEBUG_TEST + +ImageScene::ImageScene(QObject *parent) + : QGraphicsScene(parent) + , _currentState(MouseStateNotLoaded) + , _currentMouseState(MouseStateNone) + , _sizeChange(":/images/sizeChange.png") + , _rotate(":/images/rotate.png") + , _currentIndex(-1) + , _currLine(0) + , _cropPercentage(0) + , _aspectRatio(-1) + , _backgroundLoader(0) + , _isWaiting(false) + , _enforceAspectForNew(false) + , _waitBar(0) + , _numNeighbours(2) +{ + qRegisterMetaType("QFileInfoList"); + qRegisterMetaType("SourceFilePtr"); + qRegisterMetaType("TargetImagePtr"); + connect(this, SIGNAL(selectionChanged()), + this, SLOT(onSelectionChanged()), Qt::QueuedConnection); + + connect(&_copyTargetThread, SIGNAL(copied(QString,QString)), + SLOT(doneCopy(QString,QString)), Qt::QueuedConnection); + connect(&_copyTargetThread, SIGNAL(copied(QString,QString)), + SIGNAL(doneCopying(QString,QString)), Qt::QueuedConnection); + + connect(&_timer, SIGNAL(timeout()), this, SLOT(updateSelection()), Qt::QueuedConnection); + + + connect(this, SIGNAL(renewList(QFileInfoList,int)), + this, SLOT(newImageList(QFileInfoList,int)), Qt::QueuedConnection); + + /* + connect(this, SIGNAL(extractTarget(int,int)), SLOT(_extractTarget(int,int)), + Qt::QueuedConnection);*/ + + connect(&_targetExtractor, SIGNAL(doneTarget(const TargetImagePtr&)), + this, SLOT(doneLoadingTarget(const TargetImagePtr&)), Qt::BlockingQueuedConnection); + + connect(&_copyTargetThread, SIGNAL(copyError(SourceFilePtr,TargetImagePtr)), + this, SLOT(_onCopyError(SourceFilePtr,TargetImagePtr))); + _timer.setInterval(250); + _timer.start(); + +} + +ImageScene::~ImageScene() +{ + if (_backgroundLoader != 0) + { + delete _backgroundLoader; + } + disconnect(this); + saveCurrent(); + _copyTargetThread.setExitSaving(); + delete _currLine; +} + + +void ImageScene::updateSelection() +{ + // for a selection animation + if (_currentIndex >= 0 + && _currentIndex < _currentFiles.size() + && _currentFiles[_currentIndex]->targets.size() > 0) + { + for (int i=0; i<_currentFiles[_currentIndex]->targets.size(); i++) + { + _currentFiles[_currentIndex]->targets[i]->boundary->update(); + } + } + update(); +} + +void ImageScene::init() +{ + + + QListIterator i(items()); + while (i.hasNext()) + { + QGraphicsItem* item = i.next(); + item->setVisible(false); + removeItem(item); // does not perform "delete" (would destroy use of smartptr) + } + + QList v = views(); + _view = v.size() > 0 ? v[0] : NULL; + _view->setCursor(Qt::CrossCursor); + _view->viewport()->setMouseTracking(true); + + update(); + _view->resetMatrix(); + _view->resetTransform(); + _view->update(); + +} + + +void ImageScene::newImageList(const QFileInfoList& images, + const int selectedIndex) +{ + + if (!_extractMutex.tryLock()) + { + emit (renewList(images, selectedIndex)); + } + + _copyTargetThread.clear(); + if (_backgroundLoader != 0) { + disconnect(_backgroundLoader); + _backgroundLoader->setPriority(QThread::LowPriority); + _backgroundLoader->disconnect(); + _backgroundLoader->stop(); + _backgroundLoader->clear(); + _backgroundLoader->deleteLater(); + } + + _backgroundLoader = new PreloadSource(); + + connect(_backgroundLoader, SIGNAL(doneLoading(SourceFilePtr,int)), + this, SLOT(_doneLoading(SourceFilePtr,int)), Qt::QueuedConnection); + _currentFiles.clear(); + for (int i=0; isource = images[i]; + _currentFiles.push_back(tmp); + } + _currentIndex = qMax(0,selectedIndex); + _currentTarget = 0; + + + _extractMutex.unlock(); + emit reloadSettings(); // update settings for thread + + _isWaiting = false; + loadPosition(_currentIndex, false, true); +} + +void ImageScene::saveCurrent(const bool noUpdate, const bool force) +{ + if (_currentIndex>=0 + && _currentIndex < _currentFiles.size() + && _currentFiles[_currentIndex]->targets.size() > 0) { + clearSelection(); + if (!noUpdate) + { + emit updateTargetDisplay(QPixmap()); + } + if (force) + { + for (int i=0; i<_currentFiles[_currentIndex]->targets.size(); i++) + { + _currentFiles[_currentIndex]->targets[i]->boundary->setCopied(false); + } + } + _copyTargetThread.addSaveFiles(_currentFiles[_currentIndex]); + } +} + +void ImageScene::loadPosition(const int newPosition, + const bool increment, + const bool forceReload) +{ + bool positionChanged = false; + if ( (newPosition >= 0 && !increment) + || (newPosition == -2 && !increment) + || (increment)) { + const int newPos = newPosition == -2 ? _currentFiles.size() -1 : (increment ? _currentIndex + newPosition : newPosition); + if (newPos>= 0 && newPos <_currentFiles.size()) { + positionChanged = _currentIndex != newPos; + + if (positionChanged) { + _copyTargetThread.abortSaveFile(0); + saveCurrent(); + } + + _currentIndex = newPos; + } + } + + if (_currentIndex <0 || _currentIndex >= _currentFiles.size()) + { + return; + } + + if (_currentIndex >=0 && _currentIndex < _currentFiles.size()) + { + emit changed(_currentFiles[_currentIndex]->changed); + emit fileName(_currentFiles[_currentIndex]->source.fileName()); + emit filePosition(QString(tr("%1 of %2")).arg(_currentIndex + 1).arg(_currentFiles.size())); + } +#ifdef DEBUG_TEST + // work on all images in selected directory + static bool done = false; + if (!done) { + qDebug() << "changed"; + const int m = 3; + QVector w(m); + w[0] = 0.0; w[1] = 1; w[2] = 5; //3.0; w[2] = 7.0; w[3] = 15; + /* for (int i=0; isource = ->source.absoluteFilePath(); + _backgroundLoader->addLoadFiles( + _currentFiles[a], + m, + values, + false, + false); + } + /*} + } + } + }*/ + done = true; + qDebug() << "done"; + return; + } +#endif + + if ( (_isWaiting && !positionChanged) + || _currentFiles[_currentIndex]->error) + { + if (_currentFiles[_currentIndex]->error) + { + emit fileName(_currentFiles[_currentIndex]->source.fileName() + + " - ERROR LOADING SOURCE"); + _copyTargetThread.abortSaveFile(0); + if (_waitBar != 0) + { + _waitBar->setVisible(false); + delete _waitBar; + _waitBar = 0; + + _isWaiting = false; + } + clear(); + emit updateTargetDisplay(QPixmap()); + return; + } + if (_currentFiles[_currentIndex]->imageOrig.isNull()) { + QTimer::singleShot(500, this, SLOT(loadPosition())); + return; + } + } + + // do clear target display + emit setTargetWaiting(false); + emit updateTargetDisplay(QPixmap()); + + bool alreadyLoaded= false, isLoading = false; + if (positionChanged) { + + if (!_currentFiles[_currentIndex]->imageOrig.isNull()) { + alreadyLoaded = true; + } + if (_backgroundLoader->isCurrentlyLoading() == + _currentFiles[_currentIndex]->source.absoluteFilePath()) { + isLoading = true; + } + } + + if (isLoading) { + if (_waitBar == 0 || !_waitBar->isVisible()) + { + _waitBar = new QProgressBar(_view); + _waitBar->setWindowModality(Qt::ApplicationModal); + _waitBar->setMaximum(0); + _waitBar->setMinimum(0); + _waitBar->show(); + } + init(); // clear display + return; + } + + if ((!alreadyLoaded && positionChanged) + || forceReload + || _currentFiles[_currentIndex]->image.get() == NULL) { + emit fileName(_currentFiles[_currentIndex]->source.fileName()); + init(); // clear display + + bool isSaved = !_currentFiles[_currentIndex]->changed; + _backgroundLoader->addLoadFiles(_currentFiles[_currentIndex], + _currentIndex, + true, + isSaved); + + if (_waitBar == 0 || !_waitBar->isVisible()) + { + _waitBar = new QProgressBar(_view); + _waitBar->setWindowModality(Qt::ApplicationModal); + _waitBar->setMaximum(0); + _waitBar->setMinimum(0); + _waitBar->show(); + } + _isWaiting = true; + return; // done setting up threads + } + + + // start preloading for neighbours, start and end + + for (int i=_numNeighbours-1; i>=0; i--) + { + for (int j=0; j<2; j++) + { + const int ind = j==1 ? + qMax(0, _currentIndex - i -1) + : qMin(_currentFiles.size()-1, _currentIndex + i + 1); + if (_currentFiles[ind]->image.get() == NULL) + { + bool isSaved = !_currentFiles[ind]->changed; + _backgroundLoader->addLoadFiles(_currentFiles[ind], + ind, + false, + isSaved); + } + } + } + + // update current display + clear(); + _currentFiles[_currentIndex]->image->setVisible(true); + _currentFiles[_currentIndex]->image->setZValue(-100); + addItem(_currentFiles[_currentIndex]->image.get()); + _view->resetMatrix(); + _view->fitInView(_currentFiles[_currentIndex]->image.get(), + Qt::KeepAspectRatio); + + for (int i=0; i<_currentFiles[_currentIndex]->targets.size(); i++) { + _currentFiles[_currentIndex]->targets[i]->boundary->setVisible(true); + _currentFiles[_currentIndex]->targets[i]->boundary->setZValue(10+i); + addItem(_currentFiles[_currentIndex]->targets[i]->boundary.get()); + if (!_currentFiles[_currentIndex]->targets[i]->boundary->getUserHasSeenThis() + && _enforceAspectForNew) + { + _correctAspectRatio(_currentFiles[_currentIndex]->targets[i]); + } + _currentFiles[_currentIndex]->targets[i]->boundary->setUserHasSeenThis(); + qApp->processEvents(); + } + + if (_currentIndex >=0) + { + // select one item - but only if not all of them have been copied, already + if (_currentFiles[_currentIndex]->targets.size() > 0) { + int ind=-1; + for (int i=_currentFiles[_currentIndex]->targets.size()-1; i>=0; i--) + { + if (!_currentFiles[_currentIndex]->targets[i]->boundary->getCopied()) { + ind = i; + } + } + clearSelection(); + if (ind >=0) { + _currentFiles[_currentIndex]->targets[ind]->boundary->setSelected(true); + emit targetPosition(QString(tr("%1 of %2")).arg(ind + 1).arg(_currentFiles[_currentIndex]->targets.size())); + } + } + + emit changed(_currentFiles[_currentIndex]->changed); + emit fileName(_currentFiles[_currentIndex]->source.fileName()); + emit filePosition(QString(tr("%1 of %2")).arg(_currentIndex + 1).arg(_currentFiles.size())); + } + + if (_waitBar != 0) { + _waitBar->setVisible(false); + delete _waitBar; + _waitBar = 0; + } + + _currentState = MouseStateNone; + _currentMouseState = MouseStateNone; + _isWaiting = false; + _view->update(); + update(); + + _copyTargetThread.abortSaveFile(_currentFiles[_currentIndex]); + + // free old data - but only, if it has been saved, already + // the target extraction may still work in one of the old images + // so lock + + while (!ExtractTargets::fileListMutex.tryLock(50)) + { + qApp->processEvents(); + } + for (int i=0; i<_currentFiles.size(); i++) { + if (i == _currentIndex) continue; + + bool inWaitingList = false; + QListIterator> it(_targetExtractor.getList()); + while (it.hasNext()) + { + if (it.next().second->id == _currentFiles[i]->id) + { + inWaitingList = true; + break; + } + } + + bool tooFar = qAbs(i-_currentIndex) > _numNeighbours + && (!_currentFiles[i]->changed + || _currentFiles[i]->error + || (_currentFiles[i]->targets.size() > 0 + && !_currentFiles[i]->targets[0]->boundary->getUserHasSeenThis())); + if (tooFar && !inWaitingList) { + _currentFiles[i]->image = QGraphicsPixmapItemPtr(); + _currentFiles[i]->imageOrig = QImage(); + for (int j=0; j<_currentFiles[i]->targets.size(); j++) { + _currentFiles[i]->targets[j]->image = QImage(); + _currentFiles[i]->targets[j]->backmap = BackMapPtr(); + } + } + } + ExtractTargets::fileListMutex.unlock(); +} + +void ImageScene::_doneLoading(const SourceFilePtr &source, const int position) +{ +#ifdef DEBUG_TEST + return; +#endif + if (position>=0 && position <_currentFiles.size()) + { + if ( _currentFiles[position]->id == source->id) + { + _currentFiles[position]->image = QGraphicsPixmapItemPtr(new QGraphicsPixmapItem( + QPixmap::fromImage(_currentFiles[position]->imageOrig) + ) + ); + int currentId = -1; + for (int i=_currentFiles[position]->targets.size()-1; i>=0; i--) + { + _currentFiles[position]->targets[i]->boundary->setCrop(_cropPercentage); + if (_enforceAspectForNew) + { + _currentFiles[position]->targets[i]->aspect = _aspectRatio; + _correctAspectRatio(_currentFiles[position]->targets[i]); + } + if (position == _currentIndex && i == 0) + { + currentId = i; + } + else + { + _extractTarget(position, _currentFiles[position]->targets[i]); + } + } + if (currentId >= 0) + { + // insert current lastly, since we want to have it first + _currentTarget = _currentFiles[position]->targets[0]; + _extractTarget(position, _currentFiles[position]->targets[currentId], true); + } + if (position == _currentIndex) + { + loadPosition(); + } + } + } +} + +TargetImagePtr ImageScene::addBoundary(ImageBoundaryPtr newB) +{ + _currentFiles[_currentIndex]->targets.push_back(TargetImagePtr(new TargetImage(newB))); + addItem(newB.get()); + return _currentFiles[_currentIndex]->targets.last(); +} + +void ImageScene::onSelectionChanged() +{ + + if (_currentState != MouseStateNewItem + && _currentMouseState != MouseStateNewItem) { + QList items = _findSelectedTarget(); + emit numSelected(items.size()); + double rotation =-1.0, aspect = -1.0, crop = -1.0; + bool uniqueRotation = true, uniqueAspect = true, uniqueCrop = true; + + if (items.size() > 0) { + _currentTarget = items.first(); + } + else + { + _currentTarget = TargetImagePtr(); + } + + QListIterator i (items); + while (i.hasNext()) + { + TargetImagePtr target = i.next(); + if (rotation < 0) { + rotation = target->rotation; + aspect = target->aspect; + crop = target->boundary->getCrop(); + } + + if (rotation != target->rotation) { + uniqueRotation = false; + } + if (aspect != target->aspect) { + uniqueAspect = false; + } + if (crop != target->boundary->getCrop()) { + uniqueCrop = false; + } + + if (!uniqueRotation && !uniqueAspect && !uniqueCrop) { + break; + } + } + + if (items.size() > 0) + { + if (uniqueRotation) { + emit rotation90(items[0]->rotation); + } else { + emit noRotation(); + } + //if (aspect >=1) { + if (uniqueAspect) { + emit selectedAspect(items[0]->aspect); + } else { + emit noAspect(); + } + //} + if (crop > 0) { + if (uniqueCrop) { + emit newCrop(items[0]->boundary->getCrop()); + } else { + emit noCrop(); + } + } + } + _currentMouseState = MouseStateMoveItem; + _view->setCursor(Qt::OpenHandCursor); + _updateTarget(false); + } + update(); + _view->update(); +} + +void ImageScene::_updateTarget(const bool targetChanged, bool dirty) +{ + + // search for targets + QListIterator it(_findSelectedTarget()); + while (it.hasNext()) + { + TargetImagePtr currTarget = it.next(); + + if (targetChanged + || currTarget->image.width() == 0 + || currTarget->image.height() == 0 + || currTarget->image.isNull()) + { + QListIterator i2(_currentFiles[_currentIndex]->targets); + while (i2.hasNext()) + { + if (i2.next()->workOnId == currTarget->workOnId) + { + emit setTargetWaiting(true); + _extractTarget(_currentIndex, currTarget, true); + break; + } + } + } + else + { + QPixmap out; + QImage img = currTarget->image; + + QListIterator i2(_currentFiles[_currentIndex]->targets); + while (i2.hasNext()) + { + if (i2.next()->workOnId == currTarget->workOnId) + { + out = QPixmap::fromImage(img); + emit setTargetWaiting(false); + emit updateTargetDisplay(out); + break; + } + } + } + if (dirty) + { + currTarget->boundary->setCopied(false); + currTarget->boundary->dirty(); + } + } + + + if (dirty) { + _currentFiles[_currentIndex]->changed=true; + emit changed(true); + } +} + +void ImageScene::_extractTarget(const int fromImage, + const TargetImagePtr target, + const bool highPriority) +{ + if (fromImage >=0 && fromImage < _currentFiles.size()) + { + if (!target->boundary->getUserHasSeenThis() + || target->boundary->getCrop()<0) + { + target->boundary->setCrop(_cropPercentage); + } + +/* target->boundary->setFlags( + QGraphicsItem::ItemHasNoContents + | target->boundary->flags());*/ + _targetExtractor.addTarget(target, + _currentFiles[fromImage], + highPriority); + + } +} + +void ImageScene::wheelEvent(QGraphicsSceneWheelEvent *event) +{ + if (event->modifiers() & Qt::ControlModifier) { + const double numDegrees = event->delta()/8.0; + const double numSteps = numDegrees / 15.0; + double factor = qPow(1.12, numSteps); + + QPointF scenePos = _view->mapToScene( + _view->mapFromGlobal(event->screenPos()) + ); + zoom(factor); + _view->centerOn(scenePos); + event->accept(); + } else if (event->modifiers() & Qt::ShiftModifier) { + // scroll left-right + const int numPixRight = event->delta(); + if (_view->horizontalScrollBar () != 0) { + //_view->horizontalScrollBar()->scroll(numPixRight, 0); + _view->horizontalScrollBar()->setValue( + _view->horizontalScrollBar()->value() - numPixRight); + } + event->accept(); + } else { + event->ignore(); + } + + // otherwise the scrolling will be up-/down +} + +void ImageScene::doneCopy(const QString &, const QString &) +{ + bool changes = false; + if (_currentIndex >= 0 && _currentIndex <_currentFiles.size()) + { + bool changes = _currentFiles[_currentIndex]->targets.size() > 0; + for (int k=0; k<(int)_currentFiles[_currentIndex]->targets.size(); k++) + { + changes &= _currentFiles[_currentIndex]->targets[k]->boundary->getCopied(); + } + } + emit changed(!changes); + this->update(); +} + +void ImageScene::keyPressEvent ( QKeyEvent * keyEvent ) +{ + if (keyEvent->key() == Qt::Key_Plus) { + zoom(1.25); + + } else if (keyEvent->key() == Qt::Key_Minus) { + zoom(0.8); + + } else if (keyEvent->key() == Qt::Key_Delete + || keyEvent->key() == Qt::Key_Backspace) { + deleteSelection(); + + } else if (keyEvent->key() == Qt::Key_Escape) { + if (_currentState == MouseStateNewItem) { + removeItem(_currLine); + delete _currLine; + _currLine = 0; + } + else if (_currentMouseState == MouseStateNewItem) + { + deleteSelection(); + } + _currentState = MouseStateNone; + _currentMouseState = MouseStateNone; + _view->setCursor(Qt::CrossCursor); + + } /*else if (keyEvent->key() == Qt::Key_Tab) { + bool changed=false; + TargetImagePtr target = _findSelectedTarget()[0]; + if (target != 0) { + QPointF corners[4]; + for (int i=0;i<4;i++) corners[i]= target->boundary->corners()[i]; + const double l1 = _norm(corners[1]-corners[0]); + const double l2 = _norm(corners[2]-corners[1]); + corners[0] *= l1/l2; + corners[2] *= l1/l2; + corners[1] *= l2/l1; + corners[3] *= l2/l1; + target->boundary->setCorners(corners); + _updateTarget(true); + changed = true; + } + if (!changed) { + QGraphicsScene::keyPressEvent(keyEvent); + } + + } */ + else { + QGraphicsScene::keyPressEvent(keyEvent); + } +} + +QList ImageScene::_findSelectedTarget() +{ + QList out; + + if (selectedItems().size() == 0 + || _currentFiles[_currentIndex]->targets.size() ==0) + return out; + + QMap map; + QListIterator iT(_currentFiles[_currentIndex]->targets); + int ind=0; + while (iT.hasNext()) + { + TargetImagePtr t = iT.next(); + map.insert(t->boundary.get(), t); + ind++; + } + + QListIterator i(selectedItems()); + while (i.hasNext()) + { + ImageBoundary* item = dynamic_cast(i.next()); + if (item) { + out.append(map[item]); + } + } + + return out; +} + +void ImageScene::zoom(double factor) +{ + if (_view == NULL) { + return; + } + + _view->scale(factor, factor); + if (_currLine != NULL) { + const QPointF p1 = _view->mapToScene( + _view->mapFromGlobal(QPoint(0,0)) + ); + const QPointF p2 = _view->mapToScene( + _view->mapFromGlobal(QPoint(0,1)) + ); + const double width = 3.0 * _norm(p1-p2); + QPen pen = _currLine->pen(); + pen.setWidth(width); + _currLine->setPen(pen); + } +} + + +inline double ImageScene::_norm(const QPointF& p) +{ + return qSqrt(p.x()*p.x() + p.y()*p.y()); +} + + +inline double ImageScene::_dot(const QPointF& p1, const QPointF& p2) +{ + return p1.x() * p2.x() + p1.y() * p2.y(); +} + +inline double ImageScene::_norm2(const QPointF& p) +{ + return p.x()*p.x() + p.y()*p.y(); +} + +inline double ImageScene::_lineDist(const QPointF& l1, + const QPointF& l2, + const QPointF& p) +{ + return ( (l2.x() - l1.x())*(l1.y() - p.y()) + - (l1.x() - p.x())*(l2.y() - l1.y())) + / (qSqrt( (l2.x() - l1.x() ) * (l2.x() - l1.x() ) + + (l2.y() - l1.y())*(l2.y() - l1.y()) )); +} + +void ImageScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) +{ + if (_currentState == MouseStateNotLoaded) { + return; + } + + if (mouseEvent->button() != Qt::LeftButton) { + if (_currentState == MouseStateNewItem) { + _currentState = MouseStateNone; + _currentMouseState = MouseStateNone; + removeItem(_currLine); + delete _currLine; + _currLine = 0; + _view->setCursor(Qt::CrossCursor); + } + return; + } + + if (_currentState == MouseStateNone + && _currentMouseState == MouseStateReleaseItem) + { + // first corner + _view->setCursor(Qt::CrossCursor); + _currentMouseState = MouseStateNone; + clearSelection(); + } else if (_currentState == MouseStateNone + && _currentMouseState == MouseStateNone + && selectedItems().size() == 0) + { + // draw line + const QPointF currMousePoint = _view->mapToScene( + _view->mapFromGlobal(mouseEvent->screenPos()) + ); + + const QPointF p1 = _view->mapToScene( + _view->mapFromGlobal(QPoint(0,0)) + ); + const QPointF p2 = _view->mapToScene( + _view->mapFromGlobal(QPoint(0,1)) + ); + const double width = 3.0 * _norm(p1-p2); + delete _currLine; + _lastCornerPos[0] = currMousePoint; + _currLine = new QGraphicsLineItem(QLineF(currMousePoint, currMousePoint)); + QPen pen; + pen.setWidth(width); + pen.setStyle(Qt::DashDotLine); + pen.setColor(NEW_BOX_LINE_COLOR); + _currLine->setPen(pen); + addItem(_currLine); + _currentState = MouseStateNewItem; + } else if (_currentState == MouseStateMoveCorner + && _currentMouseState == MouseStateNewItem) + { + // switch to release mode, such that the next release of + // the mouse stops the process + _currentMouseState = MouseStateNewItemRelease; + } else if (_currentState == MouseStateNone + && _currentMouseState == MouseStateMoveItem) + { + _view->setCursor(Qt::ClosedHandCursor); + _currentState = MouseStateMoveItem; + QGraphicsScene::mousePressEvent(mouseEvent); + + } else if (_currentState == MouseStateNone + && _currentMouseState == MouseStateRotateItem) + { + _currentState = MouseStateRotateItem; + _lastTransformation = _currentTarget->boundary->transform(); + + _rotationCenter = QPointF(0,0); + for (int i=0; i<4; i++) { + QPointF posCorner = _view->mapToGlobal(_view->mapFromScene( + _currentTarget->boundary->mapToScene(_currentTarget->boundary->corners()[i]))); + _rotationCenter += posCorner; + } + _rotationCenter /= 4; + QPointF lastAngleDir = mouseEvent->screenPos() - _rotationCenter; + _lastAngle = qAtan2(lastAngleDir.x(), lastAngleDir.y()); + QGraphicsScene::mousePressEvent(mouseEvent); + + } else if (_currentState == MouseStateNone + && _currentMouseState == MouseStateMoveCorner) + { + _currentState = MouseStateMoveCorner; + for (int i=0; i<4; i++) { + _lastCornerPos[i] = _currentTarget->boundary->corners()[i]; + } + _lastTransformation = _currentTarget->boundary->transform(); + } else if (_currentState == MouseStateNone + && _currentMouseState == MouseStateMoveEdge) + { + _currentState = MouseStateMoveEdge; + for (int i=0; i<4; i++) { + _lastCornerPos[i] = _currentTarget->boundary->corners()[i]; + } + _lastTransformation = _currentTarget->boundary->transform(); + const double lCurr = _norm(_currentTarget->boundary->corners()[(_currentEdge+1)%4] - _currentTarget->boundary->corners()[_currentEdge]); + const double lOrth = _norm(_currentTarget->boundary->corners()[(_currentEdge+3)%4] + - _currentTarget->boundary->corners()[_currentEdge]); + _currAspectRatio = ( lCurr > lOrth ? _aspectRatio : 1.0/_aspectRatio); + } else { + QGraphicsScene::mousePressEvent(mouseEvent); + } +} + + +void ImageScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) +{ + if (_view == NULL) { + return; + } + + if (_currentState == MouseStateNone) { + bool found = false; + for (int k=0; k<(int)_currentFiles[_currentIndex]->targets.size() && !found; k++) { + if (!_currentFiles[_currentIndex]->targets[k]->boundary->isSelected()) { + continue; + } + + // check if mouse above one corner + for (int i=0; i<4; i++) { ; + QPointF posCorner = _view->mapToGlobal(_view->mapFromScene( + _currentFiles[_currentIndex]->targets[k]->boundary->mapToScene( + _currentFiles[_currentIndex]->targets[k]->boundary->corners()[i]))); + + if (QPointF(mouseEvent->screenPos() - posCorner).manhattanLength() < DISTANCE_GRAB_CORNER + && ! (mouseEvent->modifiers() & Qt::ShiftModifier)) { + if (_currentMouseState != MouseStateMoveCorner) { + QPointF center = QPointF(0,0); + for (int j=0; j<4;j++) { + center += _currentFiles[_currentIndex]->targets[k]->boundary->corners()[j]; + } + center /= 4.0; + center = _view->mapToGlobal(_view->mapFromScene( + _currentFiles[_currentIndex]->targets[k]->boundary->mapToScene(center))); + QPointF corner = _view->mapToGlobal(_view->mapFromScene( + _currentFiles[_currentIndex]->targets[k]->boundary->mapToScene( + _currentFiles[_currentIndex]->targets[k]->boundary->corners()[i]))) - center; + qreal angle = qAtan2(corner.y(), corner.x()); + QCursor tmp = _sizeChange; + const QPixmap cursorPix = tmp.pixmap().transformed(QTransform().rotateRadians(angle ),Qt::SmoothTransformation); + tmp = QCursor(cursorPix); + _view->setCursor(tmp); + _currentMouseState = MouseStateMoveCorner; + } + + _currentCorner = i; + _currentTarget = _currentFiles[_currentIndex]->targets[k]; + found = true; + break; + } + } + + // check if mouse above edge + if (!found && !(mouseEvent->modifiers() & Qt::ShiftModifier)) { + for (int i=0; i<4; i++) { + const QPointF p1 = _view->mapToGlobal( + _view->mapFromScene( + _currentFiles[_currentIndex]->targets[k]->boundary->mapToScene( + _currentFiles[_currentIndex]->targets[k]->boundary->corners()[i]))); + const QPointF p2 = _view->mapToGlobal( + _view->mapFromScene( + _currentFiles[_currentIndex]->targets[k]->boundary->mapToScene( + _currentFiles[_currentIndex]->targets[k]->boundary->corners()[(i+1)%4]))); + const QPointF diff = p1 -p2; + const double dist2 = _norm2(diff); + QPointF mP = mouseEvent->screenPos(); + if (_norm2(mP - p1) < dist2 + && _norm2(mP - p2) < dist2) + { + // = is in between both points + // now compute distance to connecting line + if (qAbs(_lineDist(p1, p2, mP)) < DISTANCE_GRAB_EDGE) { + qreal angle = qAtan2(diff.y(), diff.x()) - M_PI/2.0; + QCursor tmp = _sizeChange; + const QPixmap cursorPix = tmp.pixmap().transformed(QTransform().rotateRadians(angle ),Qt::SmoothTransformation); + tmp = QCursor(cursorPix); + _view->setCursor(tmp); + _currentMouseState = MouseStateMoveEdge; + _currentEdge = i; + _currentTarget = _currentFiles[_currentIndex]->targets[k]; + found = true; + break; + } + } + } + } + + // check if mouse above selected item + if (!found + && _currentFiles[_currentIndex]->targets[k]->boundary->isUnderMouse() + && ! (mouseEvent->modifiers() & Qt::ShiftModifier)) { + + if (_currentMouseState != MouseStateMoveItem) { + _view->setCursor(Qt::OpenHandCursor); + _currentMouseState = MouseStateMoveItem; + } + found = true; + break; + } else if ((mouseEvent->modifiers() & Qt::ShiftModifier) + && _currentFiles[_currentIndex]->targets[k]->boundary->isUnderMouse()) { + if (_currentMouseState != MouseStateRotateItem) { + _view->setCursor(_rotate); + _currentMouseState = MouseStateRotateItem; + _currentTarget = _currentFiles[_currentIndex]->targets[k]; + } + found = true; + break; + } + } + + // if not, search for other item to be able to select + if (!found) { + for (int k=0; k<(int)_currentFiles[_currentIndex]->targets.size(); k++) { + if (!_currentFiles[_currentIndex]->targets[k]->boundary->isSelected() + && _currentFiles[_currentIndex]->targets[k]->boundary->isUnderMouse() + && ! (mouseEvent->modifiers() & Qt::ShiftModifier)) + { + if (_currentMouseState != MouseStateSelectItem) { + _view->setCursor(Qt::PointingHandCursor); + _currentMouseState = MouseStateSelectItem; + } + found = true; + } + } + } + + if (found == false + && _currentMouseState != MouseStateNone) { + if (_findSelectedTarget().size() > 0 && _findSelectedTarget()[0] != 0) { + _view->setCursor(Qt::ArrowCursor); + _currentMouseState = MouseStateReleaseItem; + } else { + _view->setCursor(Qt::CrossCursor); + _currentMouseState = MouseStateNone; + } + } + + } else if (_currentState == MouseStateRotateItem) { + QPointF currAngleDir = mouseEvent->screenPos() - _rotationCenter; + double currAngle = qAtan2(currAngleDir.x(), currAngleDir.y()); + QTransform trans = _lastTransformation; + _currentTarget->boundary->setTransform(trans.rotateRadians(_lastAngle-currAngle)); + + } else if (_currentState == MouseStateMoveEdge) { + QPointF currCorners[4]; + for (int i=0;i<4; i++) { + currCorners[i] = _currentTarget->boundary->corners()[i]; + } + + + // make sure all computations are done on start basis + // this will not cause redraw as they are scheduled + // the next setTransform will cause the actual redraw + _currentTarget->boundary->setCorners(_lastCornerPos); + _currentTarget->boundary->setTransform(_lastTransformation); + + const QPointF posCorner = _currentTarget->boundary->mapFromScene( + _view->mapToScene( + _view->mapFromGlobal(mouseEvent->screenPos()) + ) + ); + + const QPointF lastToCurr = _currentTarget->boundary->corners()[_currentEdge] - + _currentTarget->boundary->corners()[(_currentEdge+3)%4]; + + + double diff = qAbs(-_lineDist(_lastCornerPos[_currentEdge], + _lastCornerPos[(_currentEdge+1)%4], + posCorner)); + + const double lengthSide = _norm(lastToCurr); + const double distOppositeMouse = qAbs(_lineDist(_lastCornerPos[(_currentEdge+3)%4], + _lastCornerPos[(_currentEdge+2)%4], + posCorner)); + + if (lengthSide > distOppositeMouse) { + diff *= -1; + } + + QPointF movement = _currentTarget->boundary->corners()[(_currentEdge+1)%4] - + _currentTarget->boundary->corners()[_currentEdge]; + movement /= _norm(movement); + const double tmp = movement.x(); + movement.setX(movement.y()); + movement.setY(tmp); + + if (_dot(movement, lastToCurr) < 0) { + movement *= -1.0; + } + + if (! (mouseEvent->modifiers() & Qt::ControlModifier)) { + diff /= 2.0; + } + + QPointF newPos[4]; + newPos[_currentEdge] = _lastCornerPos[_currentEdge] + diff * movement; + newPos[(_currentEdge+1)%4] = _lastCornerPos[(_currentEdge+1)%4] + diff * movement; + newPos[(_currentEdge+3)%4] = _lastCornerPos[(_currentEdge+3)%4] - diff * movement; + newPos[(_currentEdge+2)%4] = _lastCornerPos[(_currentEdge+2)%4] - diff * movement; + + if (mouseEvent->modifiers() & Qt::ControlModifier) { + // this means scaling around the center + QTransform trans = _lastTransformation; + _currentTarget->boundary->setTransform(trans); + _currentTarget->boundary->update(); + } else { + // really drag one corner towards somewhere + // meaning that we translate the object + QTransform trans = _lastTransformation; + _currentTarget->boundary->setTransform(trans.translate(diff*movement.x(), + diff*movement.y())); + _currentTarget->boundary->update(); + } + _currentTarget->boundary->setCorners(newPos); + + + if (_aspectRatio > 0 ) { + QPointF c[4]; for (int i=0; i<4; i++) c[i] = _currentTarget->boundary->corners()[i]; + QPointF c0[4]; for (int i=0; i<4; i++) c0[i] = c[i]; + QPointF dir = c[(_currentEdge+1)%4] - c[_currentEdge]; + const double lCurr = _norm(dir); + dir /= lCurr; + const double lOrth = _norm(c[(_currentEdge+3)%4] - c[_currentEdge]); + + const double newLength = 0.5 * lOrth * _currAspectRatio; + QPointF center = c[(_currentEdge+1)%4] + c[_currentEdge]; + center /= 2.0; + + c[(_currentEdge+1)%4] = center + dir * newLength; + c[_currentEdge] = center - dir * newLength; + center = c[(_currentEdge+2)%4] + c[(_currentEdge+3)%4]; + center /= 2.0; + c[(_currentEdge+2)%4] = center + dir * newLength; + c[(_currentEdge+3)%4] = center - dir * newLength; + _currentTarget->boundary->setCorners(c); + _currentTarget->aspect = _aspectRatio; + } + } else if (_currentState == MouseStateMoveCorner) { + // make sure all computations are done on start basis + // this will not cause redraw as they are scheduled + // the next setTransform will cause the actual redraw + _currentTarget->boundary->setCorners(_lastCornerPos); + _currentTarget->boundary->setTransform(_lastTransformation); + + QPointF posCorner = _currentTarget->boundary->mapFromScene( + _view->mapToScene( + _view->mapFromGlobal(mouseEvent->screenPos()) + ) + ); + + QPointF diff = posCorner - _lastCornerPos[_currentCorner]; + + if (_aspectRatio > 0) { + //diff = _lastTransformation.inverted().map(diff); + QPointF p = posCorner - _lastCornerPos[(_currentCorner+2)%4]; + double currAspect = p.x()/p.y(); + if (currAspect < 0) + currAspect *= -1.0; + QPointF d[8]; + + if (currAspect > 1.0) + { + // landscape: what fits better? + d[0] = QPointF (p.x(), -p.x() / _aspectRatio); + d[1] = QPointF (-p.x(), -p.x() / _aspectRatio); + d[2] = QPointF (-p.x(), p.x() / _aspectRatio); + d[3] = QPointF (p.x(), p.x() / _aspectRatio); + d[4] = QPointF (p.y() * _aspectRatio , -p.y()); + d[5] = QPointF (-p.y() * _aspectRatio , -p.y()); + d[6] = QPointF (-p.y() * _aspectRatio , p.y()); + d[7] = QPointF (p.y() * _aspectRatio , p.y()); + } + else + { + // portrait + d[0] = QPointF (p.x(), -p.x() * _aspectRatio); + d[1] = QPointF (-p.x(), -p.x() * _aspectRatio); + d[2] = QPointF (-p.x(), p.x() * _aspectRatio); + d[3] = QPointF (p.x(), p.x() * _aspectRatio); + d[4] = QPointF (-p.y() / _aspectRatio, p.y() ); + d[5] = QPointF (-p.y() / _aspectRatio, -p.y() ); + d[6] = QPointF (p.y() / _aspectRatio, -p.y() ); + d[7] = QPointF (p.y() / _aspectRatio, p.y() ); + } + + int minInd=-1; + double maxDist = 1e10; + for (int i=0; i<8; i++) + { + if (maxDist > _norm2(d[i]-p)) + { + minInd = i; + maxDist = _norm2(d[i]-p); + } + } + + diff = d[minInd] + _lastCornerPos[(_currentCorner+2)%4] - _lastCornerPos[_currentCorner]; + _currentTarget->aspect = _aspectRatio; + } + + + if (! (mouseEvent->modifiers() & Qt::ControlModifier)) { + diff /= 2; + } + + + QPointF newPos[4]; + newPos[_currentCorner] = _lastCornerPos[_currentCorner] + diff; + newPos[(_currentCorner+2)%4] = _lastCornerPos[(_currentCorner+2)%4] - diff; + newPos[(_currentCorner+3)%4].setX( newPos[(_currentCorner+2)%4].x()); + newPos[(_currentCorner+3)%4].setY( newPos[(_currentCorner)].y()); + newPos[(_currentCorner+1)%4].setX( newPos[(_currentCorner)].x()); + newPos[(_currentCorner+1)%4].setY( newPos[(_currentCorner+2)%4].y()); + + if (mouseEvent->modifiers() & Qt::ControlModifier) { + // this means scaling around the center + QTransform trans = _lastTransformation; + _currentTarget->boundary->setTransform(trans); + _currentTarget->boundary->update(); + _currentTarget->boundary->setCorners(newPos); + _correctAspectRatio(_currentTarget); + } else { + // really drag one corner towards somewhere + // meaning that we translate the object + QTransform trans = _lastTransformation; + _currentTarget->boundary->setTransform(trans.translate(diff.x(), diff.y())); + _currentTarget->boundary->update(); + _currentTarget->boundary->setCorners(newPos); + } + } else if (_currentState == MouseStateNewItem) { + const QPointF posCorner = _view->mapToScene( + _view->mapFromGlobal(mouseEvent->screenPos()) + ); + _currLine->setLine(QLineF(_lastCornerPos[0], posCorner)); + } else if (_currentState == MouseStateMoveItem) { + QGraphicsScene::mouseMoveEvent(mouseEvent); + } +} + + +void ImageScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) + { + bool update = false; + bool recompute = true; + bool bringCurrentTargetToFront = false; + + if (_currentState == MouseStateMoveItem) { + _currentState = MouseStateNone; + _view->setCursor(Qt::OpenHandCursor); + update = true; + + } + else if (_currentState == MouseStateNewItem) { + // fix line and start drawing rectangle for item + // compute line position & length + const QPointF firstPoint = _lastCornerPos[0]; + const QPointF currPoint = _view->mapToScene( + _view->mapFromGlobal(mouseEvent->screenPos()) + ); + + const double diff = _norm(_view->mapToGlobal(_view->mapFromScene(currPoint)) - + _view->mapToGlobal(_view->mapFromScene(firstPoint))); + if (diff > 5) + { + const QPointF diff = currPoint - firstPoint; + const double length = _norm(diff); + + // create new rect + emit rotation90(TargetRotation0); + ImageBoundaryPtr newBoundary (new ImageBoundary()); + _currentTarget = addBoundary(newBoundary); + _currentTarget->aspect = _aspectRatio; + newBoundary->setCrop(_cropPercentage); + newBoundary->setUserHasSeenThis(); + clearSelection(); + newBoundary->setSelected(true); + + // determine rotation and center, for transformation + // of new boundary + QPointF newPoints[4]; + const double l2 = length/2.0; + newPoints[0] = QPointF(0, l2); + newPoints[1] = QPointF(0, l2); + newPoints[2] = QPointF(0, -l2); + newPoints[3] = QPointF(0, -l2); + qreal angle = qAtan2(diff.y(), diff.x()) - M_PI/2.0; + newBoundary->setCorners(newPoints); + const QPointF center = (currPoint + firstPoint)/2.0; + newBoundary->setTransform(QTransform().translate(center.x(), center.y()).rotateRadians(angle)); + + // now prepare new state such that it moves corner + QCursor tmpCurs = _sizeChange; + const QPixmap cursorPix = tmpCurs.pixmap().transformed(QTransform().rotateRadians(angle ),Qt::SmoothTransformation); + tmpCurs = QCursor(cursorPix); + _view->setCursor(tmpCurs); + _currentCorner = 0; + _currentState = MouseStateMoveCorner; + _currentMouseState = MouseStateNewItem; + for (int i=0; i<4; i++) { + _lastCornerPos[i] = _currentTarget->boundary->corners()[i]; + } + _lastTransformation = _currentTarget->boundary->transform(); + + // remove line + removeItem(_currLine); + delete _currLine; + _currLine = 0; + } + + } else if (_currentState == MouseStateRotateItem) { + _currentState = MouseStateNone; + if (!(mouseEvent->modifiers() & Qt::ShiftModifier)) { + _view->setCursor(Qt::OpenHandCursor); + _currentMouseState = MouseStateMoveItem; + } + update = true; + bringCurrentTargetToFront = true; + } else if ( (_currentState == MouseStateMoveCorner + || _currentState == MouseStateMoveEdge) + && _currentMouseState != MouseStateNewItem ) + { + // if _currentMouseState == MouseStateNewItem + // this means we have to continue moving the rect + // until user clicks again + _currentState = MouseStateNone; + _currentMouseState = MouseStateMoveItem; + update = true; + recompute = true; + bringCurrentTargetToFront = true; + } else if (_currentState == MouseStateMoveEdge + && _currentMouseState == MouseStateNewItemRelease ) + { + _currentState = MouseStateNone; + _currentMouseState = MouseStateMoveItem; + update = true; + bringCurrentTargetToFront = true; + } + + QGraphicsScene::mouseReleaseEvent(mouseEvent); + + if (update) { + _updateTarget(recompute, true); + } + + if (bringCurrentTargetToFront) { + // more than one selection and possibly manipulation + // an item which is not displayed -> send update image of this image + QPixmap out; + if (!_currentTarget->image.isNull() + && _currentTarget.get() != 0) + { + out = QPixmap::fromImage(_currentTarget->image); + } + emit updateTargetDisplay(out); + } + } + +void ImageScene::newRotation(const Rotation90 rot) +{ + QListIterator i(_findSelectedTarget()); + while (i.hasNext()) + { + TargetImagePtr tmp = i.next(); + tmp->rotation = rot; + tmp->boundary->setCopied(false); + + } + _currGlobalRotation = rot; + _updateTarget(true); +} + +void ImageScene::newIndividualCrop(const double percentage) +{ + QListIterator i(_findSelectedTarget()); + while (i.hasNext()) + { + i.next()->boundary->setCrop(percentage/100.0); + } + _updateTarget(true); + update(); +} + + +void ImageScene::deleteSelection() +{ + if (_currentFiles.size() == 0) { + return; + } + QList list = selectedItems(); + + _currentState = MouseStateNone; + _currentMouseState = MouseStateNone; + + for (int i=0; i=0 ; i--) { + for (int j=0; j<_currentFiles[_currentIndex]->targets.size(); j++) { + if (list.at(i) == _currentFiles[_currentIndex]->targets[j]->boundary.get()) { + _currentFiles[_currentIndex]->targets.erase( + _currentFiles[_currentIndex]->targets.begin()+j); + } + } + } + clearSelection(); + _updateTarget(); + + nextTarget(0); + _view->setCursor(Qt::CrossCursor); +} + +void ImageScene::nextTarget(const int increment) +{ + if (_currentFiles.size() == 0) { + return; + } + const int numTargets = _currentFiles[_currentIndex]->targets.size(); + int pos = -1; + if (numTargets>0) { + const int num = selectedItems().size(); + if (num == 0) { + if (increment > 0) { + pos = 0; + } else { + pos = numTargets - 1; + } + _currentFiles[_currentIndex]->targets[numTargets-1]->boundary->setSelected(true); + } else { + int currPos = 0; + for (int i=0; itargets[i]->boundary.get() + == selectedItems()[0]) { + currPos = i; + clearSelection(); + break; + } + } + pos = currPos+increment < 0 ? numTargets-1 : (currPos+increment) % numTargets; + _currentTarget = _currentFiles[_currentIndex]->targets[pos]; + _currentTarget->boundary->setSelected(true); + _updateTarget(); + } + } + emit targetPosition(QString(tr("%1 of %2")).arg(pos+1).arg(_currentFiles[_currentIndex]->targets.size())); +} + +void ImageScene::newAspectRatio(const double ratio) +{ + _aspectRatio = ratio; + + QListIterator i(_findSelectedTarget()); + while (i.hasNext()) + { + _correctAspectRatio(i.next()); + } + _updateTarget(true); +} + +bool ImageScene::_correctAspectRatio(TargetImagePtr target) +{ + target->aspect = _aspectRatio; + + if (_aspectRatio <=0) { + return false; + } + + + QPointF c[4]; + for (int i=0; i<4; i++) c[i] = target->boundary->corners()[i]; + + const double width = _norm(c[0] - c[3]); + const double height = _norm(c[1] - c[0]); + + const double currAspect = width > height ? (double)width/double(height) : (double)height/double(width); + if (qAbs(_aspectRatio - currAspect) < 1e-5) { + return false; + } + + // fit with short side + if (width >= height) { + const double newHeight = 0.5 * width / _aspectRatio; + QPointF dir, center; + center = (c[0]+ c[1])/2.0; + dir = c[0]-c[1]; + dir /= _norm(dir); + c[0] = center + newHeight * dir; + c[1] = center - newHeight * dir; + + center = (c[3] + c[2])/2.0; + c[3] = center + newHeight * dir; + c[2] = center - newHeight * dir; + target->boundary->setCorners(c); + } else { + const double newWidth = 0.5 * height/ _aspectRatio; + QPointF dir, center; + center = (c[0]+ c[3])/2.0; + dir = c[0]-c[3]; + dir /= _norm(dir); + c[0] = center + newWidth * dir; + c[3] = center - newWidth * dir; + + center = (c[1] + c[2])/2.0; + c[1] = center + newWidth * dir; + c[2] = center - newWidth * dir; + target->boundary->setCorners(c); + + } + + return true; +} + +void ImageScene::zoomFit() +{ + _view->fitInView(_currentFiles[_currentIndex]->image.get(), Qt::KeepAspectRatio); +} + +void ImageScene::zoom1() +{ + if (_view == 0) { + return; + } + QPoint center (_view->width()/2, _view->height()/2); + QPointF centerScene = _currentFiles[_currentIndex]->image->mapFromParent(center.x(), center.y()); + _view->resetMatrix(); + _view->centerOn(centerScene.x(), centerScene.y()); +} + + +void ImageScene::updateMinMax(const int mi, const int ma) +{ + if ( _backgroundLoader != 0) + _backgroundLoader->updateMinMax(mi, ma); +} + +void ImageScene::_onCopyError(SourceFilePtr source, TargetImagePtr) +{ + QMessageBox::critical(_view, + tr("copy error"), + tr("Could not copy a target from scanned image '%s'' - enough disc space left ? enough RAM available ? If the images are too large, the 32bit version of this software might also be in trouble").arg(source->source.fileName())); +} + +void ImageScene::getIsFirstLast(bool& isFirst, bool& isLast) +{ + isFirst = _currentIndex <= 0; + isLast = _currentFiles.size() -1 == _currentIndex || _currentFiles.size() == 0; +} + +void ImageScene::setEnforceAspect(const bool enforce) +{ + _enforceAspectForNew = enforce; +} + +void ImageScene::setDestination(QString destination) +{ + _copyTargetThread.setDestination(destination); +} + + +void ImageScene::reloadFromNewSettings() +{ + // the target extraction may still work in one of the old images + // so lock + while (!ExtractTargets::imageMutex.tryLock(50)) + { + qApp->processEvents(); + } + + for (int i=0; i<_currentFiles.size(); i++) { + if (_currentFiles[i]->changed + && i != _currentIndex) { + qDebug() << "resetting" << _currentFiles[i]->source.absoluteFilePath(); + _currentFiles[i]->image = QGraphicsPixmapItemPtr(); + _currentFiles[i]->imageOrig = QImage(); + for (int j=0; j<_currentFiles[i]->targets.size(); j++) { + _currentFiles[i]->targets[j]->image = QImage(); + } + _currentFiles[i]->targets.clear(); + } + } + ExtractTargets::imageMutex.unlock(); + loadPosition(); +} + +void ImageScene::refreshView() +{ + QMessageBox::StandardButton reply = QMessageBox::question(_view, tr("refresh"), + tr("This will overwrite currently (and possibly saved) extracted images - continue ?"), + QMessageBox::Yes | QMessageBox::Abort); + bool save = reply == QMessageBox::Yes; + + if (save) + { + while(!ExtractTargets::imageMutex.tryLock(50)) + { + qApp->processEvents(); + } + + clear(); + if (_currentIndex >=0) { + _currentFiles[_currentIndex]->changed = true; + _currentFiles[_currentIndex]->image = QGraphicsPixmapItemPtr(); + _currentFiles[_currentIndex]->imageOrig = QImage(); + for (int j=0; j<_currentFiles[_currentIndex]->targets.size(); j++) { + _currentFiles[_currentIndex]->targets[j]->image = QImage(); + } + _currentFiles[_currentIndex]->targets.clear(); + } + _currentFiles[_currentIndex]->error = false; + ExtractTargets::imageMutex.unlock(); + loadPosition(); + } +} + +void ImageScene::selectAll() +{ + QListIterator i(items()); + while (i.hasNext()) + { + QGraphicsItem* item = i.next(); + item->setSelected(true); + } +} + +void ImageScene::clear() +{ + // overwrite clear such that it does not delete it + // otherwise memory leaks with smart pointers + init(); + +} + +void ImageScene::doneLoadingTarget(const TargetImagePtr &target) +{ + if (_currentIndex >=0 && _currentIndex < _currentFiles.size()) + { + for (int i=0; i<_currentFiles[_currentIndex]->targets.size(); i++) + { + /*QGraphicsItem::GraphicsItemFlags flags = + _currentFiles[_currentIndex] ->targets[i]->boundary->flags() & (~QGraphicsItem::ItemHasNoContents); + _currentFiles[_currentIndex]->targets[i]->boundary->setFlags(flags);*/ + if (_currentFiles[_currentIndex]->targets[i]->workOnId == target->workOnId + && _currentTarget.get() != 0 && _currentTarget->workOnId == target->workOnId) { + // the threading model does destroy the rendering -> hotfix re-add + emit updateTargetDisplay(QPixmap::fromImage(target->image)); + emit setTargetWaiting(false); + } + if (_currentFiles[_currentIndex]->targets[i]->workOnId == target->workOnId) + { + removeItem(target->boundary.get()); + addItem(target->boundary.get()); + } + } + } + update(); + _view->update(); +} + +void ImageScene::initialCropChanged(const double val) +{ + _cropPercentage = val; +} diff --git a/scannerExtract/imagescene.h b/scannerExtract/imagescene.h new file mode 100644 index 0000000..9cd13af --- /dev/null +++ b/scannerExtract/imagescene.h @@ -0,0 +1,241 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef IMAGESCENE_H +#define IMAGESCENE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "imageboundary.h" +#include "sourcefile.h" +#include "preloadsource.h" +#include "copytargets.h" +#include "extracttargets.h" + +#define DISTANCE_GRAB_CORNER 10 +#define DISTANCE_GRAB_EDGE 15 +#define NEW_BOX_LINE_COLOR QColor(255,0,0,255) + +enum MouseState +{ + MouseStateNotLoaded, + MouseStateNone, + MouseStateSelectItem, + MouseStateReleaseItem, + MouseStateNewItem, + MouseStateNewItemRelease, + MouseStateMoveItem, + MouseStateRotateItem, + MouseStateMoveCorner, + MouseStateMoveEdge, + MouseStateMoveEdgePre, +}; + +class ImageScene : public QGraphicsScene +{ + Q_OBJECT +public: + explicit ImageScene(QObject *parent = 0); + + ~ImageScene(); + + TargetImagePtr addBoundary(ImageBoundaryPtr); + + void init(); + + +signals: + void updateTargetDisplay(const QPixmap& pixmap); + void rotation90(const Rotation90 rotation); + void resetAspect(); + void fileName(const QString&); + void landscapeButton(bool landscape); + void changed(bool hasChanges); + void selectedAspect(float aspect); + void newCrop(const double cropPerc); + void noAspect(); // no unique aspect + void noCrop(); + void noRotation(); + void reloadSettings(); + void renewList(QFileInfoList,int); + void extractTarget(int, int); + void setTargetWaiting(bool); + void filePosition(QString); + void targetPosition(QString); + void numSelected(int); + void doneCopying(const QString&, const QString&); + +public slots: + + void newImageList(const QFileInfoList& images = QFileInfoList(), + const int selectedIndex = 0); + + void loadPosition(const int newPosition = -1, + const bool increment= false, + const bool forceReload = false); + + void newRotation(const Rotation90); + + void newIndividualCrop(const double percentage); + + void deleteSelection(); + + void nextTarget(const int increment); + + void newAspectRatio(const double ratio); + + + void zoom(double factor); + + void zoomFit(); + void zoom1(); + + void saveCurrent(const bool noUpdate = false, + const bool force = false); + + void updateMinMax(const int, const int); + + void getIsFirstLast(bool &isFirst, bool &isLast); + + void setEnforceAspect(const bool enforce); + + void setDestination(QString destination); + + void setPrefix(const QString prefix) { _copyTargetThread.setPrefix(prefix); } + + void setThresh(const double thresh) { if (hasLoader()) _backgroundLoader->setThresh(thresh); } + void setMaxAspect(const double maxAspect) { if (hasLoader())_backgroundLoader->setMaxAspect(maxAspect); } + void setLevels(const int levels) { if (hasLoader()) _backgroundLoader->setLevels(levels); } + void setMaxOverlap(const double maxOverlap) { if (hasLoader()) _backgroundLoader->setMaxOverlap(maxOverlap); } + void setMinArea(const double minArea) { if (hasLoader()) _backgroundLoader->setMinArea(minArea); } + void setMinAreaWithinImage(const double minArea) { if (hasLoader()) _backgroundLoader->setMinAreaWithinImage(minArea); } + void setSplitMaxOffset(const double maxOffset) { if (hasLoader()) _backgroundLoader->setSplitMaxOffset(maxOffset); } + void setSplitMinCornerDist(const double minCornerDist) { if (hasLoader()) _backgroundLoader->setSplitMinCornerDist(minCornerDist); } + void setSplitMinLengthFrac(const double minLengthFrac) { if (hasLoader()) _backgroundLoader->setSplitMinLengthFrac(minLengthFrac); } + void setMaximumHierarchyLevel(const int level) { if (hasLoader()) _backgroundLoader->setMaxHierarchyLevel(level); } + void setNumPreLoad(const int num) { _numNeighbours = num; } + void reloadFromNewSettings(); + + void doneLoadingTarget(const TargetImagePtr& target); + + void refreshView(); + + void selectAll(); + + void initialCropChanged(const double val); + + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent); + void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent); + void keyPressEvent ( QKeyEvent * keyEvent ); + void wheelEvent(QGraphicsSceneWheelEvent *event); + +private slots: + + void doneCopy(const QString&, const QString&); + + void onSelectionChanged(); + + void _doneLoading(const SourceFilePtr &, const int position); + + void _onCopyError(SourceFilePtr, TargetImagePtr); + + void updateSelection(); + + void clear(); + + void _extractTarget(const int fromImageId, + const TargetImagePtr target, + const bool highPriority = false); + +private: + QList _findSelectedTarget(); + + inline double _norm(const QPointF&); + inline double _dot(const QPointF&, const QPointF&); + inline double _norm2(const QPointF& ); + inline double _lineDist(const QPointF& l1, + const QPointF& l2, + const QPointF& p); + + + void _updateTarget(const bool changed = false, bool dirty = false); + + bool _correctAspectRatio(TargetImagePtr target); + + MouseState _currentState; + MouseState _currentMouseState; + QGraphicsView* _view; + + int _currentCorner; + int _currentEdge; + TargetImagePtr _currentTarget; + + QPixmap _sizeChange; + QPixmap _rotate; + + double _lastAngle; + QPointF _rotationCenter; + QTransform _lastTransformation; + QPointF _lastCornerPos[4]; + + QVector _currentFiles; + int _currentIndex; + + QGraphicsLineItem* _currLine; + + double _cropPercentage; + + Rotation90 _currGlobalRotation; + + double _aspectRatio; + double _currAspectRatio; + + PreloadSource* _backgroundLoader; + bool hasLoader() const { return _backgroundLoader != 0; } + + bool _isWaiting; + + CopyTargets _copyTargetThread; + + QTimer _timer; + + bool _enforceAspectForNew; + + QProgressBar* _waitBar; + + QMutex _extractMutex; + + ExtractTargets _targetExtractor; + + int _numNeighbours; +}; + +#endif // IMAGESCENE_H diff --git a/scannerExtract/main.cpp b/scannerExtract/main.cpp new file mode 100644 index 0000000..72a5a6f --- /dev/null +++ b/scannerExtract/main.cpp @@ -0,0 +1,88 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include + +#include +#include "mainwindow.h" + +#include "TargetImage.h" +#include "sourcefile.h" +#include "translation.h" + +#include + +int main(int argc, char *argv[]) +{ + qRegisterMetaType("Rotation90"); + qRegisterMetaType("SourceFile"); + + QApplication app(argc, argv); + QStringList args = app.arguments(); + + // ### load locale + QString locale = QLocale::system().name(); + for (int i=args.length()-1; i>0; i--) { + if (args[i]== "-l" || args[i] == "--locale") { + if (argc <= i+1) { + qWarning() << QString("please provide a locale, e.g.: %1 -l en").arg(args[0]); + + } else { + locale = args[i+1]; + qDebug() << "trying to load locale " << locale << "..."; + args.removeAt(i+1); + } + args.removeAt(i); + } + } + + // set locale and load translations + MiscTools::Translation::setDefaultLocale(locale); + + QStringList langPaths = QStringList() << QString(":/"); + app.installTranslator(MiscTools::Translation::getTranslator(locale, langPaths, "qt_")); + app.installTranslator(MiscTools::Translation::getTranslator(locale, langPaths, "qtbase_")); + app.installTranslator(MiscTools::Translation::getTranslator(locale, langPaths, "qt_help_")); + app.installTranslator(MiscTools::Translation::getTranslator(locale, langPaths, "trans_scannedImageExtractor_")); + + // ### setup warranty display + QFile file(QApplication::tr(":/WARRANTY_EN", "start")); + std::cout << "This is Scanned Image Extractor - version " + << version_scannerExtract.getVersionMajor() << "." + << version_scannerExtract.getVersionMinor() << "." + << version_scannerExtract.getVersionPatch() + << std::endl; + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&file); + while (!in.atEnd()) { + std::cout << in.readLine().toStdString() << std::endl; + } + std::cout << std::endl; + } else { + std::cout << "not found" << std::endl; + } + file.close(); + + MainWindow mainWindow; + mainWindow.show(); + + return app.exec(); +} diff --git a/scannerExtract/mainwindow.cpp b/scannerExtract/mainwindow.cpp new file mode 100644 index 0000000..f2fb891 --- /dev/null +++ b/scannerExtract/mainwindow.cpp @@ -0,0 +1,906 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pQPixmap.h" + +#include "imageboundary.h" +#include "TargetImage.h" + +#include "settings.h" + +MainWindow::MainWindow(QWidget *parent): + QMainWindow(parent), + ui(new Ui::MainWindow), + _dialogLock(false), + _title(tr("Scanned Image Extractor")), + _targetWait(0), + _tearDown(false) +{ + ui->setupUi(this); + qRegisterMetaType("QFileInfoList"); + qRegisterMetaType("SourceFilePtr"); + qRegisterMetaType("TargetImagePtr"); + + ui->graphicsView_Source->setScene(&_scene); + _scene.init(); + connect(&_scene, SIGNAL(doneCopying(QString,QString)), SLOT(doneCopy(QString,QString))); + + setWindowTitle(_title); + + connect(ui->actionLoad_Directory, SIGNAL(triggered()), + this, SLOT(_onLoadFile())); + connect(&_scene, SIGNAL(changed(bool)), this, SLOT(currImageHasChanges(bool)), Qt::QueuedConnection); + connect(&_scene, SIGNAL(selectedAspect(float)), this, SLOT(toggleAspect(float)), Qt::QueuedConnection); + connect(&_scene, SIGNAL(numSelected(int)), this, SLOT(numSelectionChanged(int)), Qt::QueuedConnection); + connect(this, SIGNAL(newList(QFileInfoList,int)), + &_scene, SLOT(newImageList(QFileInfoList,int)), Qt::QueuedConnection); + + statusBar()->showMessage(tr("Hover the mouse pointer over an element to get help")); + + + QSettings settings(tr(IMAGE_ORGANIZATION_ORG), tr(IMAGE_ORGANIZATION_APP)); + restoreGeometry(settings.value("mainwin_geom").toByteArray()); + ui->splitter->restoreState(settings.value("mainwin_splitter").toByteArray()); + ui->doubleSpinBox_cropInitial->setValue(settings.value("cropdistance", 2.0).toDouble()); + ui->doubleSpinBox_crop->setValue(settings.value("cropdistance", 3.0).toDouble()); + ui->lineEdit_aspectRatio->setText(settings.value("manualaspect", "4:3").toString()); + ui->graphicsView_Target->setScene(&_sceneTarget); + + connect(ui->checkBox_enforceAspect, SIGNAL(toggled(bool)), &_scene, SLOT(setEnforceAspect(bool)), Qt::QueuedConnection); + + ui->checkBox_enforceAspect->setChecked(settings.value("enforceAspectNextIm", true).toBool()); + + + connect(&_scene, SIGNAL(updateTargetDisplay(QPixmap)), + this, SLOT(_onNewTargetImage(QPixmap)), Qt::QueuedConnection); + + connect(&_scene, SIGNAL(rotation90(Rotation90)), + this, SLOT(_onRotation90(Rotation90)), Qt::QueuedConnection); + + connect(this, SIGNAL(newOrientation(Rotation90)), + &_scene, SLOT(newRotation(Rotation90)), Qt::QueuedConnection); + + connect(&_scene, SIGNAL(resetAspect()), this, SLOT(_resetAspect()), Qt::QueuedConnection); + + connect(&_scene, SIGNAL(filePosition(QString)), ui->label_imagePosition, SLOT(setText(QString)), Qt::QueuedConnection); + connect(&_scene, SIGNAL(targetPosition(QString)), ui->label_targetPosition, SLOT(setText(QString)), Qt::QueuedConnection); + + connect(ui->doubleSpinBox_crop, SIGNAL(valueChanged(double)), + &_scene, SLOT(newIndividualCrop(double)), Qt::QueuedConnection); + + connect(ui->splitter, SIGNAL(splitterMoved(int,int)), + this, SLOT(_updateTargetView(int,int)), Qt::QueuedConnection); + + connect(ui->radioButton_1_1, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_2_1, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_3_1, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_3_2, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_4_3, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_5_3, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_5_4, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_16_9, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_free, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->radioButton_manual, SIGNAL(toggled(bool)), this, SLOT(_getAspectRatio())); + connect(ui->lineEdit_aspectRatio, SIGNAL(textChanged(QString)), this, SLOT(_getAspectRatio())); +// connect(ui->lineEdit_aspectRatio, SIGNAL(textEdited(QString)), this, SLOT(_getAspectRatio())); + + connect(this, SIGNAL(newAspectRatio(double)), + &_scene, SLOT(newAspectRatio(double)), Qt::QueuedConnection); + + ui->radioButton_rot0->setChecked(true); + + ui->graphicsView_Source->setBackgroundBrush( QPalette().dark() );//QBrush(IMAGE_BACKGROUND_COLOR)); + ui->graphicsView_Target->setBackgroundBrush(QPalette().dark());//QBrush(IMAGE_BACKGROUND_COLOR)); + + //_getAspectRatio(); + + connect(&_scene, SIGNAL(fileName(const QString)), + ui->label_filename, SLOT(setText(QString)), Qt::QueuedConnection); + connect(&_scene, SIGNAL(fileName(const QString)), SLOT(newFileName(QString)), Qt::QueuedConnection); + connect(&_scene, SIGNAL(noAspect()), SLOT(noAspect()), Qt::QueuedConnection); + connect(&_scene, SIGNAL(noRotation()), SLOT(noRotation()), Qt::QueuedConnection); + connect(&_scene, SIGNAL(noCrop()), SLOT(noCrop()), Qt::QueuedConnection); + + if (QIcon::hasThemeIcon("go-first")) + ui->toolButton_firstImage->setIcon(QIcon::fromTheme("go-first")); + if (QIcon::hasThemeIcon("go-last")) + ui->toolButton_lastImage->setIcon(QIcon::fromTheme("go-last")); + if (QIcon::hasThemeIcon("go-next")) + { + ui->toolButton_nextImage->setIcon(QIcon::fromTheme("go-next")); + ui->toolButton_nextItem->setIcon(QIcon::fromTheme("go-next")); + } + if (QIcon::hasThemeIcon("go-previous")) + { + ui->toolButton_prevImage->setIcon(QIcon::fromTheme("go-previous")); + ui->toolButton_prevItem->setIcon(QIcon::fromTheme("go-previous")); + } + + if (QIcon::hasThemeIcon("zoom-in")) + ui->toolButton_zoomIn->setIcon(QIcon::fromTheme("zoom-in")); + if (QIcon::hasThemeIcon("zoom-out")) + ui->toolButton_zoomOut->setIcon(QIcon::fromTheme("zoom-out")); + if (QIcon::hasThemeIcon("zoom-original")) + ui->toolButton_zoomOriginal->setIcon(QIcon::fromTheme("zoom-original")); + if (QIcon::hasThemeIcon("zoom-fit-best")) + ui->toolButton_zoomFit->setIcon(QIcon::fromTheme("zoom-fit-best")); + + if (QIcon::hasThemeIcon("view-refresh")) + ui->toolButton_refresh->setIcon(QIcon::fromTheme("view-refresh")); + if (QIcon::hasThemeIcon("help")) + ui->toolButton_Help->setIcon(QIcon::fromTheme("help")); + + connect(ui->toolButton_refresh, SIGNAL(clicked()), &_scene, SLOT(refreshView()), Qt::QueuedConnection); + + + // check for update after two minutes + QTimer::singleShot( WAIT_FOR_DONATE_HINT_MS, this, SLOT(on_actionSupport_by_donation_triggered()) ); + QTimer::singleShot( WAIT_FOR_CHECK_FOR_UPDATE, this, SLOT(on_actionCheck_for_new_version_triggered()) ); + + connect (&_settings, SIGNAL(newValues()), this, SLOT(newValues()), Qt::QueuedConnection); + + connect (&_scene, SIGNAL(reloadSettings()), this, SLOT(loadSettings()), Qt::QueuedConnection); + connect (&_scene, SIGNAL(newCrop(double)), SLOT(onNewCrop(double)), Qt::QueuedConnection); + connect (&_scene, SIGNAL(setTargetWaiting(bool)), SLOT(setWaitTarget(bool)), Qt::QueuedConnection); + + enableButtons(); + newValues(); + _scene.newIndividualCrop(ui->doubleSpinBox_crop->value()); + + if (!settings.value("starthelp", false).toBool()) + { + QTimer::singleShot(2000, this, SLOT(on_actionOnline_Help_triggered())); + } + settings.setValue("starthelp", true); + + + new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A), this, SLOT(selectAll())); + + _getAspectRatio(); +} + +void MainWindow::_onLoadFile() +{ + QSettings settings(tr(IMAGE_ORGANIZATION_ORG), tr(IMAGE_ORGANIZATION_APP)); + + QStringList filters; + filters << "*.jpg" << "*.jpeg" << "*.tiff" << "*.tif" << "*.bmp" << "*.png" << "*.gif" << "*.pbm" << "*.pgm" << "*.ppm"; + + const QString filename = QFileDialog::getOpenFileName(this, + tr("Load Image"), + settings.value("lastDir").toString(), + tr("Images (%1)").arg(filters.join(" "))); + + if (filename.length() > 0) { + QFileInfo info(filename); + + settings.setValue("lastDir", info.absolutePath()); + + QFileInfoList otherimages; + QDir dir(info.absolutePath()); + otherimages = dir.entryInfoList(filters); + + int index = -1; + for (int i=0; i<(int)otherimages.size(); i++) { + if (otherimages.at(i).fileName() == info.fileName()) { + index = i; + } + } + + emit newList(otherimages, index); + } +} + +MainWindow::~MainWindow() +{ + _tearDown = true; + disconnect(this); + disconnect(&_scene); + disconnect(&_sceneTarget); + QSettings settings(tr(IMAGE_ORGANIZATION_ORG), tr(IMAGE_ORGANIZATION_APP)); + settings.setValue("mainwin_geom", saveGeometry()); + settings.setValue("mainwin_splitter", ui->splitter->saveState()); + settings.setValue("cropdistance", ui->doubleSpinBox_cropInitial->value()); + settings.setValue("manualaspect", ui->lineEdit_aspectRatio->text()); + settings.setValue("enforceAspectNextIm", ui->checkBox_enforceAspect->isChecked()); + + delete ui; +} + +void MainWindow::_onNewTargetImage(const QPixmap& pixmap) +{ + if (_tearDown) return; + + if (_sceneTarget.items().size() > 0) + { + for (int i=_sceneTarget.items().size()-1; i>=0; i--) { + QGraphicsItem* item = _sceneTarget.items()[i]; + _sceneTarget.removeItem(item); + delete item; + } + } + + QGraphicsPixmapItem* pixItem = new QGraphicsPixmapItem(pixmap); + _sceneTarget.addItem(pixItem); + + _updateTargetView(); +} + +void MainWindow::_updateTargetView(int, int) +{ + + if (_sceneTarget.items().size() > 0) { + + _sceneTarget.setSceneRect(_sceneTarget.items()[0]->boundingRect()); + ui->graphicsView_Target->centerOn(_sceneTarget.items()[0]); + ui->graphicsView_Target->fitInView(_sceneTarget.items()[0], + Qt::KeepAspectRatio); + ui->graphicsView_Target->scale(0.95,0.95); + ui->graphicsView_Target->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + ui->graphicsView_Target->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + } +} + +void MainWindow::_onRotation90(const Rotation90 rotation) +{ + switch (rotation) { + case TargetRotation0: + ui->radioButton_rot0->setChecked(true); + break; + case TargetRotation90: + ui->radioButton_rot90->setChecked(true); + break; + case TargetRotation180: + ui->radioButton_rot180->setChecked(true); + break; + case TargetRotation270: + ui->radioButton_rot270->setChecked(true); + break; + } +} + +void MainWindow::on_radioButton_rot0_toggled(bool isChecked) +{ + if (isChecked) emit newOrientation(TargetRotation0); +} + +void MainWindow::on_radioButton_rot90_toggled(bool isChecked) +{ + if (isChecked) emit newOrientation(TargetRotation90); +} + +void MainWindow::on_radioButton_rot180_toggled(bool isChecked) +{ + if (isChecked) emit newOrientation(TargetRotation180); +} + +void MainWindow::on_radioButton_rot270_toggled(bool isChecked) +{ + if (isChecked) emit newOrientation(TargetRotation270); +} + +void MainWindow::on_toolButton_deleteItem_clicked() +{ + _scene.deleteSelection(); +} + +void MainWindow::on_toolButton_prevItem_clicked() +{ + _scene.nextTarget(-1); +} + +void MainWindow::on_toolButton_nextItem_clicked() +{ + _scene.nextTarget(1); +} + +void MainWindow::_getAspectRatio() +{ + double aspectRatio = -1; + if (ui->radioButton_16_9->isChecked()) { + aspectRatio = 16.0/9.0; + } else if (ui->radioButton_1_1->isChecked()) { + aspectRatio = 1.000001; + } else if (ui->radioButton_2_1->isChecked()) { + aspectRatio = 2.0; + } else if (ui->radioButton_3_1->isChecked()) { + aspectRatio = 3.0/1.0; + } else if (ui->radioButton_3_2->isChecked()) { + aspectRatio = 3.0/2.0; + } else if (ui->radioButton_4_1->isChecked()) { + aspectRatio = 4.0/1.0; + } else if (ui->radioButton_4_3->isChecked()) { + aspectRatio = 4.0/3.0; + } else if (ui->radioButton_5_3->isChecked()) { + aspectRatio = 5.0/3.0; + } else if (ui->radioButton_5_4->isChecked()) { + aspectRatio = 5.0/4.0; + } else if (ui->radioButton_manual->isChecked()) { + QString ratioStr = ui->lineEdit_aspectRatio->text(); + const int pos = ratioStr.indexOf(":"); + if (pos > 0) { + const double part1 = ratioStr.left(pos).toDouble(); + const double part2 = ratioStr.right(ratioStr.length() -pos -1).toDouble(); + if (part1 > 0 && part2 > 0) { + aspectRatio = part1 / part2; + } + } + else + { + aspectRatio = ratioStr.toFloat(); + } + } + + emit newAspectRatio(aspectRatio); +} + +void MainWindow::toggleAspect(const float aspectNew) +{ + const float minDiff = 0.001; + float aspect = aspectNew; + if (aspect < 1.0 && aspect > 0) { + aspect = 1.0/aspect; + } + if (qAbs(aspect - 16.0/9.0) < minDiff){ + ui->radioButton_16_9->setChecked(true); + } else if (qAbs(aspect - 1.0) < minDiff) { + ui->radioButton_1_1->setChecked(true); + } else if (qAbs(aspect - 2.0) < minDiff) { + ui->radioButton_2_1->setChecked(true); + } else if (qAbs(aspect - 3.0) < minDiff) { + ui->radioButton_3_1->setChecked(true); + } else if (qAbs(aspect - 3.0/2.0) < minDiff) { + ui->radioButton_3_2->setChecked(true); + } else if (qAbs(aspect - 4.0) < minDiff) { + ui->radioButton_4_1->setChecked(true); + } else if (qAbs(aspect - 4.0/3.0) < minDiff) { + ui->radioButton_4_3->setChecked(true); + } else if (qAbs(aspect - 5.0/3.0) < minDiff) { + ui->radioButton_5_3->setChecked(true); + } else if (qAbs(aspect - 5.0/4.0) < minDiff) { + ui->radioButton_5_4->setChecked(true); + } else if (aspect > 0) + { + ui->radioButton_manual->setChecked(true); + ui->lineEdit_aspectRatio->setText(QString("%1").arg(aspect)); + } + else + { + ui->radioButton_free->setChecked(true); + } +} + +void MainWindow::on_toolButton_zoomIn_clicked() +{ + _scene.zoom(1.25); +} + +void MainWindow::on_toolButton_zoomOut_clicked() +{ + _scene.zoom(0.8); +} + +void MainWindow::on_toolButton_zoomFit_clicked() +{ + _scene.zoomFit(); +} + +void MainWindow::on_toolButton_zoomOriginal_clicked() +{ + _scene.zoom1(); +} + +void MainWindow::on_toolButton_firstImage_clicked() +{ + _scene.loadPosition(0); + enableButtons(); +} + +void MainWindow::on_toolButton_lastImage_clicked() +{ + + _scene.loadPosition(-2); + enableButtons(); +} + +void MainWindow::on_toolButton_nextImage_clicked() +{ + + _scene.loadPosition(1, true); + enableButtons(); +} + +void MainWindow::resizeEvent(QResizeEvent *) +{ + _updateTargetView(); +} + +void MainWindow::on_toolButton_prevImage_clicked() +{ + + _scene.loadPosition(-1, true); + enableButtons(); +} + +void MainWindow::on_toolButton_saveTargtes_clicked() +{ + bool save = true; + bool force = false; + if (ui->toolButton_saveTargtes->styleSheet().length() > 0) + { + QMessageBox::StandardButton reply = QMessageBox::question(this, tr("Already saved"), + tr("The images have already been extracted for this scan, " + " do you want to save them again?"), + QMessageBox::Yes|QMessageBox::Abort); + save = reply == QMessageBox::Yes; + force = save; + + } + if (save) + { + _scene.saveCurrent(true, force); + } +} + + +void MainWindow::_resetAspect() +{ + ui->radioButton_free->setChecked(true); +} + +void MainWindow::on_actionAbout_Qt_triggered() +{ + qApp->aboutQt(); +} + +void MainWindow::on_action_About_triggered() +{ + _about.setModal(true); + _about.setVersion(version_scannerExtract.getVersionMajor(), + version_scannerExtract.getVersionMinor(), + version_scannerExtract.getVersionPatch(), + version_scannerExtract.getCompilerBits()); + _about.show(); +} + +void MainWindow::on_actionSupport_by_donation_triggered() +{ + const QString donateText = _about.getDonateText(); + const QString donateTitle = tr("Support Scanned Image Extractor"); + + if (sender() == ui->actionSupport_by_donation) { + QMessageBox::information(this, + donateTitle, + donateText); + } else { + // if first time: save date: + // otherwise: check if one week has passed and asked for donation + QSettings settings(tr(IMAGE_ORGANIZATION_ORG), tr(IMAGE_ORGANIZATION_APP)); + const int firstTimeYear = 2000; + QDateTime firstTime = settings.value("firsttimestarteddonation", + QDateTime(QDate(firstTimeYear,1,1), + QTime::currentTime())).toDateTime(); + if (firstTime.date().year() == firstTimeYear) + { + settings.setValue("firsttimestarteddonation", QDateTime::currentDateTime()); + } else if (QDateTime::currentDateTime().addDays(DAYS_UNTIL_DONATE_HINT) > firstTime ){ + if (!lockDialog()) { + QTimer::singleShot(10000, this, SLOT(on_actionSupport_by_donation_triggered())); + return; + } + provideInfo(donateTitle, donateText, tr("donatehint")); + unlockDialog(); + settings.setValue("firsttimestarteddonation", QDateTime::currentDateTime()); + } + } +} + +void MainWindow::on_actionCheck_for_new_version_triggered() +{ + qint32 major, minor, patch; + QString link, text; + bool connection; + + QProgressDialog* bar = NULL; + if (sender() == ui->actionCheck_for_new_version) { + bar = new QProgressDialog(tr("Retrieving version data"), tr("asdf"), 0, 0, this); + bar->setCancelButton(0); + bar->show(); + } + + //QDataStream data(reply); + + const bool result = version_scannerExtract.checkForUpdateVersion(NEW_VERSION_LOCATION_SCANNER_EXTRACT, + NEW_VERSION_MAGIC_NUMBER, + major, + minor, + patch, + link, + text, + connection); + if (bar != NULL) { + bar->close(); + bar->deleteLater(); + } + + // only show once a week + QSettings settings(tr(IMAGE_ORGANIZATION_ORG), tr(IMAGE_ORGANIZATION_APP)); + settings.setValue("main_geometry", saveGeometry()); + QDate lastHint = settings.value("lastShowUpdate", QDate(1950,1,1)).toDate(); + QDate oneWeekBack = QDate::currentDate().addDays(-7); + const bool autoCheck = lastHint < oneWeekBack || sender() == ui->actionCheck_for_new_version; + + if (result && autoCheck) + { + QDialog *diag = new QDialog(this); + diag->setModal(true); + QVBoxLayout* layH = new QVBoxLayout(); + diag->setLayout(layH); + diag->layout()->addWidget(new QLabel(tr("New version of Scanned Image Extractor available: %1.%2.%3 (current: %4.%5.%6)").arg(major).arg(minor).arg(patch).arg(version_scannerExtract.getVersionMajor()).arg(version_scannerExtract.getVersionMinor()).arg(version_scannerExtract.getVersionPatch()))); + QLabel* dlLabel = new QLabel(QString(tr("Download: %2")).arg(link).arg(link)); + dlLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByMouse); + dlLabel->setOpenExternalLinks(true); + diag->layout()->addWidget(dlLabel); + diag->layout()->addWidget(new QLabel(tr("Changelog:"))); + QTextBrowser* tb = new QTextBrowser(); + tb->setText(text); + tb->setReadOnly(true); + diag->layout()->addWidget(tb); + QPushButton *okay = new QPushButton(tr("close")); + connect(okay, SIGNAL(clicked()), diag, SLOT(deleteLater())); + QHBoxLayout *lay = new QHBoxLayout(); + lay->addStretch(); + lay->addWidget(okay); + lay->addStretch(); + layH->addLayout(lay); + diag->show(); + settings.setValue("lastShowUpdate", QDate::currentDate()); + } else { + if (!connection && sender() == ui->actionCheck_for_new_version) { + QMessageBox::warning(this, tr("no connection"), tr("Was not able to connect to new version data server. Please check manually"), QMessageBox::Ok); + } else if (sender() == ui->actionCheck_for_new_version) { + QMessageBox::information(this, tr("no update necessary"), tr("There is no new version of Scanned Image Extractor!"), QMessageBox::Ok); + } + } +} + +void MainWindow::provideInfo( + const QString &headline, + const QString &text, + const QString& settingsValue, + const QString& showAgain, + const int width, + const int minWidth) +{ + QSettings settings(qApp->translate("tools", IMAGE_ORGANIZATION_ORG), qApp->translate("tools", IMAGE_ORGANIZATION_APP)); + if (!settings.value(settingsValue, true).toBool()) { + return; + } + + const int iconsize = 128; + + QDialog* dialog = new QDialog(this, Qt::Dialog); + dialog->setMinimumWidth(minWidth); + dialog->setMaximumWidth(width); + dialog->setModal(true); + dialog->setWindowTitle(headline); + QVBoxLayout* layout = new QVBoxLayout; + QHBoxLayout* messageInfo = new QHBoxLayout; + + QIcon icon; + if (QIcon::hasThemeIcon("info")) { + icon = QIcon::fromTheme("info"); + } else { + icon = QIcon(":/images/info.png"); + } + QLabel* infoIcon = new QLabel; + infoIcon->setScaledContents(false); + pQPixmap pixmap (icon.pixmap(256, + QIcon::Normal, + QIcon::On)); + infoIcon->setPixmap(pixmap->scaled(QSize(iconsize, iconsize), + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); + infoIcon->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + QLabel* info = new QLabel(text); + info->setOpenExternalLinks(true); + info->setTextFormat(Qt::RichText); + info->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); + info->setWordWrap(true); +#ifndef _WIN32 + info->setMargin(5); +#endif + info->setMaximumWidth(width-iconsize); + messageInfo->addWidget(infoIcon); + messageInfo->addWidget(info); + + QHBoxLayout* layoutCheckBox = new QHBoxLayout; + layoutCheckBox->addStretch(); + QCheckBox* showAgainBox = new QCheckBox(showAgain); + showAgainBox->setChecked(true); + showAgainBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + layoutCheckBox->addWidget(showAgainBox); + + QHBoxLayout* layoutButton = new QHBoxLayout; + layoutButton->addStretch(); + + QPushButton* okButton = new QPushButton(qApp->translate("tools", "OK")); + layoutButton->addWidget(okButton); +#ifndef _WIN32 + layoutButton->setMargin(5); +#endif + qApp->connect(okButton, SIGNAL(clicked()), dialog, SLOT(close())); + + + layout->addLayout(messageInfo); + layout->addLayout(layoutCheckBox); + layout->addLayout(layoutButton); + dialog->setLayout(layout); + + dialog->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + dialog->exec(); + + settings.setValue(settingsValue, showAgainBox->isChecked()); + + delete dialog; + dialog = 0; +} + +bool MainWindow::lockDialog() +{ + if (_dialogLock) { + return false; + } + _dialogLock = true; + return true; +} + +void MainWindow::unlockDialog() +{ + _dialogLock = false; +} + +void MainWindow::enableButtons() +{ + bool isFirst, isLast; + _scene.getIsFirstLast(isFirst, isLast); + ui->toolButton_nextImage->setEnabled(!isLast); + ui->toolButton_lastImage->setEnabled(!isLast); + ui->toolButton_firstImage->setEnabled(!isFirst); + ui->toolButton_prevImage->setEnabled(!isFirst); +} + +void MainWindow::currImageHasChanges(bool hasChanges) +{ + if (hasChanges) + { + ui->toolButton_saveTargtes->setStyleSheet(""); + ui->toolButton_saveTargtes->setEnabled(true); + } + else + { + ui->toolButton_saveTargtes->setStyleSheet("background-color:#AA88EE55;"); + //ui->toolButton_saveTargtes->setEnabled(false); + } +} + +void MainWindow::newFileName(const QString filename) +{ + setWindowTitle(_title + " - " + filename); + enableButtons(); +} + +void MainWindow::on_action_Settings_triggered() +{ + _settings.show(); +} + +void MainWindow::loadSettings() +{ + _scene.setDestination(_settings.getTargetDir()); + _scene.setPrefix(_settings.getPrefix()); + + _scene.setThresh(_settings.getThresh()); + _scene.setMaxAspect(_settings.getMaxAspect()); + _scene.setLevels(_settings.getLevels() ); + _scene.setMaxOverlap(_settings.getMinArea()); + _scene.setMinArea(_settings.getMinArea()); + _scene.setMinAreaWithinImage(_settings.getMinAreaWithinImage()); + _scene.setSplitMaxOffset(_settings.getSplitMaxoffsetFrac()); + _scene.setSplitMinCornerDist(_settings.getSplitMinCornerDist()); + _scene.setSplitMinLengthFrac(_settings.getSplitMinLengthFrac()); + _scene.setMaximumHierarchyLevel(_settings.getMaxHierarchyLevel()); + _scene.setNumPreLoad(_settings.getNumPreLoad()); +} + +void MainWindow::newValues() +{ + loadSettings(); + _scene.reloadFromNewSettings(); +} + + +void MainWindow::onNewCrop(const double crop) +{ + ui->doubleSpinBox_crop->setValue(crop*100.0); +} + + +void MainWindow::noRotation() +{ + QListIterator i(ui->groupBox_orientation->children()); + while (i.hasNext()) + { + QObject* item = i.next(); + QRadioButton* b = dynamic_cast( item ); + if (b > 0 && b->isChecked()) { + b->setAutoExclusive(false); + b->setChecked(false); + b->setAutoExclusive(true); + } + } +} + +void MainWindow::noAspect() +{ + QListIterator i(ui->groupBox_aspect->children()); + while (i.hasNext()) + { + QRadioButton* b = dynamic_cast( i.next()); + if (b > 0 && b->isChecked()) { + b->setAutoExclusive(false); + b->setChecked(false); + b->setAutoExclusive(true); + } + } +} + +void MainWindow::noCrop() +{ + ui->doubleSpinBox_crop->setValue(0); +} + +void MainWindow::setWaitTarget(const bool wait) +{ + if (wait) { + if (_targetWait == 0) { + _targetWait = new QProgressBar(ui->graphicsView_Target); + _targetWait->setMaximum(0); + _targetWait->setMinimum(0); + _targetWait->show(); + } + } + else + { + if (_targetWait != 0) { + _targetWait->setVisible(false); + delete _targetWait; + _targetWait = 0; + } + } +} + + + +void MainWindow::on_actionAbout_liblbfgs_triggered() +{ + QMessageBox::information(this, + tr("liblbfgs"), + tr("liblbfgs is an optimization/energy minimization library which implements the" + " Limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm (L-BFGS)." + "Copyright (c) 2002-2014 by Naoaki Okazaki - MIT license"), + QMessageBox::Ok); + + +} + +void MainWindow::on_doubleSpinBox_cropInitial_valueChanged(const double val) +{ + _scene.initialCropChanged(val/100.0); +} + +void MainWindow::numSelectionChanged(const int num) +{ + ui->doubleSpinBox_crop->setEnabled(num > 0); + ui->doubleSpinBox_cropInitial->setEnabled(num == 0); +} + + +void MainWindow::doneCopy(const QString& filename, + const QString& targetLocation) +{ + statusBar()->showMessage(QString(tr("finished copying '%1' to '%2'")).arg(filename).arg(targetLocation), + 5000); +} + +void MainWindow::on_actionOnline_Help_triggered() +{ + _helpDialog.show(); + /* + QMessageBox::information(this, + tr("Help"),getHelpText(), + QMessageBox::Ok);*/ +} + +QString MainWindow::getHelpText() +{ + + return tr("Find the online help at dominik-ruess.de/scannerExtract" + "

" + "Workflow:
    " + "
  1. load a scanned image
  2. " + "
  3. the system will suggest photographs, you can now:
      " + "
    1. accept the suggestion(s)
    2. " + "
    3. manipulate suggestions:
      • drag corner or edge of rectangles
      • " + "
      • press CTRL for symmetric change
      • " + "
      • keep SHIFT pressed before dragging corner, this rotates the rectangle
    4. " + "
    5. add new rectangle: deselect all (click somewhere empty). Click on a photograph corner, keep mouse clicked and drag line to a second corner. Then move/resize the new rectangle and click to release.
    6. " + "
  4. " + "
  5. the rectangles will be saved automatically when you go to the next scanned image
" + "Keyboard shortcuts:
" + "" + "" + "" + "
Keys 0-9 select aspect ratios
Keys 'a', 's', 'd' and 'f' change orientation of current target
Keys CTRL+V and CTRL+B navigate to prev. and next input image
Keys N, M and delete navigate prev. and next target or delete target
"); +} + +void MainWindow::showStartupHelp() +{ + provideInfo(tr("Startup Hint"), getHelpText(), tr("startupHelp")); +} + +void MainWindow::on_toolButton_Help_clicked() +{ + QWhatsThis::enterWhatsThisMode(); +} + +void MainWindow::on_actionAbout_Open_CV_triggered() +{ + QMessageBox::information(this, + tr("About OpenCV"), + tr("OpenCV a powerful and free (BSD-License) computer vision library." + " Scanned Image Extractor can use version 2 or 3 of OpenCV." + " Copyright (c) 2015 by itseez"), + QMessageBox::Ok); +} diff --git a/scannerExtract/mainwindow.h b/scannerExtract/mainwindow.h new file mode 100644 index 0000000..340b444 --- /dev/null +++ b/scannerExtract/mainwindow.h @@ -0,0 +1,191 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +#include "imagescene.h" +#include "about.h" +#include +#include "settingsdialog.h" +#include "helpdialog.h" + +#define IMAGE_BACKGROUND_COLOR QColor(220,220,220) + +#define WAIT_FOR_DONATE_HINT_MS 30000 +//2*60*1000 +#define WAIT_FOR_CHECK_FOR_UPDATE 1*60*1000 +#define DAYS_UNTIL_DONATE_HINT -5 + +#define NEW_VERSION_LOCATION_SCANNER_EXTRACT "http://dominik-ruess.de/scannerExtract/currentVersion" +#define NEW_VERSION_MAGIC_NUMBER 29384730 + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +signals: + void newOrientation(const Rotation90 rot); + + void newAspectRatio(const double ratio); + + void newList(QFileInfoList, int); + +private slots: + void _onLoadFile(); + + void _onNewTargetImage(const QPixmap& pixmap); + + void _onRotation90(const Rotation90 rotation); + + void on_radioButton_rot0_toggled(bool isChecked); + + void on_radioButton_rot90_toggled(bool isChecked); + + void on_radioButton_rot180_toggled(bool isChecked); + + void on_radioButton_rot270_toggled(bool isChecked); + + void on_toolButton_deleteItem_clicked(); + + void on_toolButton_prevItem_clicked(); + + void on_toolButton_nextItem_clicked(); + + void _updateTargetView(int x=0, int y=0); + + void _getAspectRatio(); + + void on_toolButton_zoomIn_clicked(); + + void on_toolButton_zoomOut_clicked(); + + void on_toolButton_zoomFit_clicked(); + + void on_toolButton_zoomOriginal_clicked(); + + void on_toolButton_firstImage_clicked(); + + void on_toolButton_lastImage_clicked(); + + void on_toolButton_nextImage_clicked(); + + void on_toolButton_prevImage_clicked(); + + void on_toolButton_saveTargtes_clicked(); + + void _resetAspect(); + + void on_actionAbout_Qt_triggered(); + + void on_action_About_triggered(); + + void on_actionSupport_by_donation_triggered(); + + void on_actionCheck_for_new_version_triggered(); + + void provideInfo(const QString& headline, + const QString& text, + const QString& settingsValue, + const QString& showAgain = qApp->translate("tools", "Show hint in future"), + const int width = 800, + const int minWidth = 600); + + bool lockDialog(); + + void unlockDialog(); + + void resizeEvent(QResizeEvent *); + + void currImageHasChanges(bool hasChanges); + + void newFileName(const QString); + + void enableButtons(); + + void toggleAspect(const float aspect); + + void loadSettings(); + void newValues(); + + void onNewCrop(const double crop); + + void on_action_Settings_triggered(); + + void selectAll() { _scene.selectAll(); } + + void noRotation(); + void noAspect(); + void noCrop(); + + void setWaitTarget(const bool wait); + + void on_actionAbout_liblbfgs_triggered(); + + void on_doubleSpinBox_cropInitial_valueChanged(const double val); + + void numSelectionChanged(const int num); + + void on_actionOnline_Help_triggered(); + + QString getHelpText(); + + void showStartupHelp(); + + void on_toolButton_Help_clicked(); + + void on_actionAbout_Open_CV_triggered(); + + void doneCopy(const QString &filename, const QString &targetLocation); +private: + Ui::MainWindow *ui; + + ImageScene _scene; + + QGraphicsScene _sceneTarget; + + DialogAbout _about; + + bool _dialogLock; + + QString _title; + + SettingsDialog _settings; + + QProgressBar* _targetWait; + + bool _tearDown; + + HelpDialog _helpDialog; +}; + +#endif // MAINWINDOW_H diff --git a/scannerExtract/mainwindow.ui b/scannerExtract/mainwindow.ui new file mode 100644 index 0000000..37497dc --- /dev/null +++ b/scannerExtract/mainwindow.ui @@ -0,0 +1,1214 @@ + + + MainWindow + + + + 0 + 0 + 1167 + 667 + + + + MainWindow + + + + + 6 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Scanned Image:</span></p></body></html> + + + + + + + + + + + + + + + + The input image view. Zoom in/out (also use mousewheel). Create new output image by start ing to drag. Manipulate output images by dragging on their borders or corners (with SHIFT+drag it is rotating). + + + The input image view. Zoom in/out (also use mousewheel). Create new output image by start ing to drag. Manipulate output images by dragging on their borders or corners (with SHIFT+drag it is rotating). + + + The input image view. Zoom in/out (also use mousewheel). Create new output image by start ing to drag. Manipulate output images by dragging on their borders or corners (with SHIFT+drag it is rotating). + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Zoom in + + + Zoom in + + + Zoom in + + + + + + + + :/images/View-zoom-in.svg:/images/View-zoom-in.svg + + + + 32 + 32 + + + + + + + + Zoom out + + + Zoom out + + + Zoom out + + + - + + + + :/images/View-zoom-out.svg:/images/View-zoom-out.svg + + + + 32 + 32 + + + + + + + + Zoom to scale 1:1 + + + Zoom to scale 1:1 + + + Zoom to scale 1:1 + + + 1:1 + + + + :/images/View-zoom-1.svg:/images/View-zoom-1.svg + + + + 32 + 32 + + + + + + + + Zoom fit + + + Zoom fit + + + Zoom fit + + + fit + + + + :/images/View-zoom-fit.svg:/images/View-zoom-fit.svg + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Go to first file in the current directory + + + Go to first file in the current directory + + + Go to first file in the current directory + + + |< + + + + :/images/Media-skip-backward.svg:/images/Media-skip-backward.svg + + + + 32 + 32 + + + + + + + + Go to previous file in the current directory + + + Go to previous file in the current directory + + + Go to previous file in the current directory + + + < + + + + :/images/Media-seek-backward.svg:/images/Media-seek-backward.svg + + + + 32 + 32 + + + + Ctrl+V + + + + + + + + + + + + + + Go to next file in the current directory (CTRL+B) + + + Go to next file in the current directory (CTRL+B) + + + Go to next file in the current directory (CTRL+B) + + + > + + + + :/images/Media-seek-forward.svg:/images/Media-seek-forward.svg + + + + 32 + 32 + + + + Ctrl+B + + + + + + + Go to last file in the current directory + + + Go to last file in the current directory + + + Go to last file in the current directory + + + >| + + + + :/images/Media-skip-forward.svg:/images/Media-skip-forward.svg + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Save all output images for current input image (green=has already been saved) + + + Save all output images for current input image (green=has already been saved) + + + Save all output images for current input image (green=has already been saved) + + + save + + + + :/images/Document-save.svg:/images/Document-save.svg + + + + 32 + 32 + + + + Ctrl+S + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + :/images/Refresh_file.svg:/images/Refresh_file.svg + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + Set aspect options for extracted images + + + Aspect Ratio + + + + 3 + + + 0 + + + 1 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Set aspect of output images to 1:1 (1) + + + Set aspect of output images to 1:1 (1) + + + Set aspect of output images to 1:1 (1) + + + 1:1 + + + 1 + + + + + + + Set aspect of output images to 5:4 (8) + + + Set aspect of output images to 5:4 (8) + + + Set aspect of output images to 5:4 (8) + + + 5:4 + + + 8 + + + + + + + Set aspect of output images to 3:2 (2) + + + Set aspect of output images to 3:2 (2) + + + Set aspect of output images to 3:2 (2) + + + 3:2 + + + 2 + + + true + + + + + + + Set aspect of output images to 2:1 (4) + + + Set aspect of output images to 2:1 (4) + + + Set aspect of output images to 2:1 (4) + + + 2:1 + + + 4 + + + + + + + Set aspect of output images to 4:1 (6) + + + Set aspect of output images to 4:1 (6) + + + Set aspect of output images to 4:1 (6) + + + 4:1 + + + 6 + + + + + + + Set aspect of output images to 5:3 (7) + + + Set aspect of output images to 5:3 (7) + + + Set aspect of output images to 5:3 (7) + + + 5:3 + + + 7 + + + + + + + Set aspect of output images to manual (0) + + + Set aspect of output images to manual (0) + + + Set aspect of output images to manual (0) + + + Manual + + + 0 + + + + + + + Set aspect of output images to 4:3 (3) + + + Set aspect of output images to 4:3 (3) + + + Set aspect of output images to 4:3 (3) + + + 4:3 + + + 3 + + + + + + + + 0 + 0 + + + + + + + + Set aspect of output images to 16:9 (9) + + + Set aspect of output images to 16:9 (9) + + + Set aspect of output images to 16:9 (9) + + + 16:9 + + + 9 + + + + + + + Set aspect of output images to 3:1 (5) + + + Set aspect of output images to 3:1 (5) + + + Set aspect of output images to 3:1 (5) + + + 3:1 + + + 5 + + + + + + + Set aspect of output images to free or unconstrained (CTRL+-) + + + Set aspect of output images to free or unconstrained (CTRL+-) + + + Set aspect of output images to free or unconstrained (CTRL+-) + + + Free + + + Ctrl+- + + + false + + + + + + + enforce this ratio in next unprocessed image + + + + + + + + + + Orientation of Output + + + false + + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + the output orientation change is none (A) + + + the output orientation change is none (A) + + + the output orientation change is none (A) + + + + + + A + + + + + + + the output orientation change is 180° (upside down) - (KEY D) + + + the output orientation change is 180° (upside down) - (KEY D) + + + the output orientation change is 180° (upside down) - (KEY D) + + + 180° + + + D + + + + + + + the output orientation change is 90° (rotate right) - (KEY S) + + + the output orientation change is 90° (rotate right) - (KEY S) + + + the output orientation change is 90° (rotate right) - (KEY S) + + + 90° + + + S + + + + + + + the output orientation change is 180° (rotate left) - (KEY F) + + + the output orientation change is 180° (rotate left) - (KEY F) + + + the output orientation change is 180° (rotate left) - (KEY F) + + + 270° + + + F + + + + + + + + + + Misc + + + + 0 + + + 0 + + + 3 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + detected images will be cropped by this size + + + detected images will be cropped by this size + + + detected images will be cropped by this size + + + 1 + + + 99.000000000000000 + + + 1.000000000000000 + + + 1.000000000000000 + + + + + + + This crop is applied to all new targets. Individual target crops can be adapted by selecting it and change "current" + + + This crop is applied to all new targets. Individual target crops can be adapted by selecting it and change "current" + + + This crop is applied to all new targets. Individual target crops can be adapted by selecting it and change "current" + + + 1 + + + 99.000000000000000 + + + 2.000000000000000 + + + + + + + Crop border (%), initial: + + + + + + + current: + + + + + + + + 75 + true + + + + After clicking on this button, click on any element to get some short help about it + + + After clicking on this button, click on any element to get some short help about it + + + After clicking on this button, click on any element to get some short help about it + + + ? + + + + 32 + 32 + + + + false + + + + + + + + + + Qt::Horizontal + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Selected Output Image (Preview):</span></p></body></html> + + + + + + + This is the preview area for the currently selected output image + + + This is the preview area for the currently selected output image + + + This is the preview area for the currently selected output image + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Go to previous output image within the current input + + + Go to previous output image within the current input + + + Go to previous output image within the current input + + + &prev. Item + + + + :/images/Media-seek-backward.svg:/images/Media-seek-backward.svg + + + + 32 + 32 + + + + N + + + + + + + + + + + + + + Go to next output image within the current input (M) + + + Go to next output image within the current input (M) + + + Go to next output image within the current input (M) + + + &next Item + + + + :/images/Media-seek-forward.svg:/images/Media-seek-forward.svg + + + + 32 + 32 + + + + M + + + + + + + remove the current output image (will not be saved to hard drive) + + + remove the current output image (will not be saved to hard drive) + + + remove the current output image (will not be saved to hard drive) + + + &delete Item + + + + :/images/Edit-delete.svg:/images/Edit-delete.svg + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + 0 + 0 + 1167 + 25 + + + + + &File + + + + + + + + + + Help + + + + + + + + + + + + + + + + + + &Load File + + + Load an input image, which usually is a scanned image from an album + + + Load an input image, which usually is a scanned image from an album + + + Ctrl+L + + + + + Set &Target Directory + + + Set Output Directory + + + Set Output Directory + + + Set the directory where the extracted files will be written to + + + Set the directory where the extracted files will be written to + + + Ctrl+T + + + + + &Exit + + + Close the program + + + Close the program + + + + + &About + + + + + About &Qt + + + + + &Help + + + F1 + + + + + Support by donation + + + + + Check for new version + + + + + &Settings + + + + + About liblbfgs + + + + + About Open&CV + + + + + + + + diff --git a/scannerExtract/pQPixmap.h b/scannerExtract/pQPixmap.h new file mode 100644 index 0000000..ff1d6ba --- /dev/null +++ b/scannerExtract/pQPixmap.h @@ -0,0 +1,60 @@ +#ifndef PQPIXMAP_H +#define PQPIXMAP_H + +/** + * @brief pQPixmap a smart pointer to a QPixmap to avoid much data on the stack + * The smart pointer always has an object (!) + */ +class pQPixmap : public std::shared_ptr +{ +public: + /** + * @brief pQPixmap enforce a creation of an empty QPixmap + */ + pQPixmap() + : std::shared_ptr(new QPixmap()) + { + } + + /** + * @brief pPixmap load from file + * @param filename the file + */ + pQPixmap(const QString& filename) + : std::shared_ptr(new QPixmap(filename)) + {} + + /** + * @brief pQPixmap create this as reference to another pQPixmap + * @param other the other smart pointer to the QPixmap + */ + pQPixmap(const pQPixmap& other) + : std::shared_ptr() + { + this->reset(); + std::shared_ptr::operator =( other); + if (other.get() == 0) { + std::shared_ptr::operator =( std::make_shared(QPixmap())); + } + } + + /** + * @brief pQPixmap obtain ownership of a QPixmap pointer + * @param other the pointer to an QPixmap -> must not be deleted somewhere else + */ + pQPixmap(QPixmap* other) + : std::shared_ptr(other) + { + } + + /** + * @brief pQPixmap a smart pointer to an image given an actual QPixmap object + * @param image the object to be referenced to + */ + pQPixmap(const QPixmap& image) + : std::shared_ptr(new QPixmap(image)) + { + } +}; + +#endif // PQPIXMAP_H diff --git a/scannerExtract/preloadsource.cpp b/scannerExtract/preloadsource.cpp new file mode 100644 index 0000000..2504639 --- /dev/null +++ b/scannerExtract/preloadsource.cpp @@ -0,0 +1,1965 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "preloadsource.h" + +#include + +#include +#include +#include +#include + +#include +#ifndef OPENCV2 +#include +#include +#include +#else +#include +#endif +#include + +//#define DEBUG +//#define DEBUG_TEST +#include "copytargets.h" + +#define CvPt2QtPt(p) QPointF(p.x, p.y) + +QMutex PreloadSource::preloadMutex; +QWaitCondition PreloadSource::waitFinished; + +#ifdef DEBUG_TEST +static int tmpVal2 = 1; +#endif +#ifdef DEBUG +static int tmpVal =0; +#endif + +#define ABORT_COMPUTATION(s) \ + if (_abortAndLoadNext || _stopped) return s; + +PreloadSource::PreloadSource(QObject *parent) + : QThread(parent) + , _stopped(false) + , _abortAndLoadNext(false) + , _qImageFmt(QImage::Format_ARGB32) +{ + //setEnergyWeights(5,1,1,5); +} + + +PreloadSource::~PreloadSource() +{ + _fileListMutex.lock(); + _filesToLoad.clear(); + _stopped = true; + _condition.wakeOne(); + _fileListMutex.unlock(); + + wait(); +} + +void PreloadSource::addLoadFiles(const SourceFilePtr& file, + const int position, + const bool highPriority, + const bool onlyLoadImages) +{ + QMutexLocker l(&_fileListMutex); + if (_current && _current->id == file->id) { + return; + } + if (highPriority) { + _abortAndLoadNext = true; + } + _filesToLoad.push_front(QPair (file, onlyLoadImages ? -position-1 : position)); // negative position: onlyLoadImages + + // now remove duplicates (from back) + for (int i=_filesToLoad.size()-1; i>= 0 ; i--) { + for (int j=i-1; j >=0; j--) { + if (_filesToLoad[i].first->source.fileName() == _filesToLoad[j].first->source.fileName()) { + _filesToLoad.erase(_filesToLoad.begin() + i); + break; + } + } + } + + _stopped = false; + if (!isRunning()) { + if (highPriority) { + start(QThread::HighPriority); + } + else + { + start(QThread::LowPriority); + } + } else { + if (highPriority) { + setPriority(QThread::HighPriority); + } + else + { + setPriority(QThread::LowPriority); + } + _condition.wakeOne(); + } +} + +void PreloadSource::clear() +{ + { + QMutexLocker l(&_fileListMutex); + _filesToLoad.clear(); + } + if (!isRunning()) { + start(QThread::LowPriority); + } else { + _condition.wakeOne(); + } + //waitFinished.wait(&preloadMutex); +} + +inline double PreloadSource::polyArea(const QVector& p) const +{ + //https://en.wikipedia.org/wiki/Polygon#Area_and_centroid + const int n = p.size(); + double area = 0.0; + for (int i=0; i &p, + const int from, + const int to) const +{ + //https://en.wikipedia.org/wiki/Polygon#Area_and_centroid + const int n = p.size(); + const int localTo = to < 0 ? n : qMin(n, to); + double area = 0.0; + if (from < to) { + for (int i=from; i pts, + const cv::Mat& image, + double& sumValues, + long int& numPixels) +{ + // assume single channel image + sumValues = 0; + numPixels = 0; + + IplImage tmp = image; + assert(image.type() == CV_8U); + + for (int i=0; i<4; i++) + { + + CvLineIterator iterator; + const int count = cvInitLineIterator( &tmp, pts[i], pts[(i+1)%4], &iterator, 4); + + for( int j = 0; j < count; j++ ){ + sumValues += iterator.ptr[0]; + CV_NEXT_LINE_POINT(iterator); + } + /* for float images: + cv::Point2f diff = pts[(i+1)%4] - pts[i]; + const int count= cv::norm(diff); + for (int j=0; j=0 && p.y >=0 + && p.x < image.size().width + && p.y < image.size().height) + { + sumValues += image.at(p.y, p.x); + } + } */ + numPixels += cv::norm(pts[i] - pts[(i+1)%4]); + } +} + +void PreloadSource::getSumOfRectangleSamplingF(const QVector pts, + const cv::Mat& image, + double& sumValues, + long int& numPixels) +{ + // assume single channel image + sumValues = 0; + numPixels = 0; + + assert(image.type() == CV_32F); + + for (int i=0; i<4; i++) + { + + // for float images: + cv::Point2f diff = pts[(i+1)%4] - pts[i]; + const int count= cv::norm(diff); + for (int j=0; j=0 && p.y >=0 + && p.x < image.size().width + && p.y < image.size().height) + { + const float val = image.at(p.y, p.x); + sumValues += val*0 == 0? val : 0; + } + } + numPixels += cv::norm(pts[i] - pts[(i+1)%4]); + } +} + +struct QPairFirstComparer +{ + template + bool operator()(const QPair & a, const QPair & b) const + { + return a.first > b.first; + } +}; + +void PreloadSource::preSelectFast(const cv::Mat& image, + const std::vector >& contours, + const std::vector& hierarchy, + const QVector& rects, + const QVector >& points, + QVector& valid) const +{ + const float imageArea = image.rows * image.cols; + int num =0; +#pragma omp parallel for + for (unsigned int i=0; i< contours.size(); i++) + { + if (!valid[i]) + continue; + + int level = 0; + int parent = hierarchy[i][3]; + while (parent >= 0) + { + level++; + parent = hierarchy[parent][3]; + if (level > _maxHierarchyLevel) { + break; + } + } + if (rects[i].size.area() / (double) imageArea < _minArea + /*|| ratio > _maxAspect do not check aspect since we may want to split this rectangle + which might result in a better aspect */ + //a < _minAreaWithinImage + || level > _maxHierarchyLevel) + { +#pragma omp critical + valid[i] = false; + num++; + } + } +} + +#ifdef DEBUG +static int extractNum = 0; +#endif + +inline float extractRectangleValueSum(const cv::Mat& image, + const cv::RotatedRect rect) +{ + if (rect.size.area() <20) { + return 0; + } + cv::Mat M, rotated, cropped; + float angle = rect.angle; + cv::Size rect_size = rect.size; + + // thanks to http://felix.abecassis.me/2011/10/opencv-rotation-deskewing/ + if (rect.angle < -45.) { + angle += 90.0; + qSwap(rect_size.width, rect_size.height); + } + M = getRotationMatrix2D(rect.center, angle, 1.0); + + // perform the affine transformation + cv::warpAffine(image, rotated, M, image.size(), cv::INTER_LINEAR); + + // crop the resulting image + cv::getRectSubPix(rotated, rect_size, rect.center, cropped); + const float out = cv::sum(cropped)[0]; +#ifdef DEBUG + cv::imwrite(QString("test_extract%1_e%2.png").arg(extractNum++).arg(out/(float)rect.size.area()).toLocal8Bit().toStdString(), cropped); +#endif + return out; +} + +void PreloadSource::bestRectangles(const cv::Mat& imageOrig, + const cv::Mat& boundaries, + const cv::Vec3i &thresholds, + const std::vector >& contours, + const std::vector& hierarchy, + const QVector& rects, + const QVector >& points, + QVector& energies, + QVector &out) +{ + _minFrameEnergy = 0.75; + _maxAreaFractionEnergy = 0.5; + _e1 = 0.1; + _e2 = 5.0; + _e3 = 1; + _e4 = 10; + +#ifdef DEBUG + cv::Mat bdCopy; + boundaries.copyTo(bdCopy); + cv::cvtColor(bdCopy, bdCopy, CV_GRAY2BGR); +#endif + const int imSize = 500; + cv::Mat smallImage; + // downsample very small, so it is feasible to extract whole rectangles + + // there's usually a light peak from the scanner background + // hence compute energy better = higher difference from background + // this will be done later, however, he we prepare the corresponding image + + float scale; + if (imageOrig.size().width < imageOrig.size().height) + { + scale = (float) imageOrig.size().height / (float) imSize; + cv::resize(imageOrig, smallImage, cv::Size(int(float(imageOrig.size().width)/scale), + imSize)); + } + else + { + scale = (float) imageOrig.size().width / (float) imSize; + cv::resize(imageOrig, smallImage, cv::Size(imSize, + int(float(imageOrig.size().height)/scale))); + } + + cv::Mat diffFromScannerBackground, + difference = cv::Mat::zeros(smallImage.size(), CV_8U) * 255.0, + differenceDark = cv::Mat::zeros(smallImage.size(), CV_8U) * 255.0, + tmp, backgroundEgdes; + + std::vector channels(3); + cv::split(smallImage, channels); + for (int i=0; i<3; i++) { + diffFromScannerBackground = cv::Mat::ones(smallImage.size(), CV_8U) * thresholds[i]; + // bright scanner background + cv::threshold(channels[i], tmp, thresholds[i], 0, cv::THRESH_TRUNC); + cv::absdiff(diffFromScannerBackground, tmp, diffFromScannerBackground); + difference = cv::max(difference, diffFromScannerBackground); + + + // black scanner background + diffFromScannerBackground = cv::Mat::ones(smallImage.size(), CV_8U) * 15; //thresholds[_histPositions][i]; + cv::absdiff(diffFromScannerBackground, channels[i], diffFromScannerBackground); + differenceDark = cv::max(differenceDark, diffFromScannerBackground); + } + + // * don't use the black values for now - many images seem dark and that would exclude quite some of them + // difference = cv::min(differenceDark, difference); + + cv::medianBlur(difference, difference, 3); + const int threshTo = 255; + difference = difference * (threshTo / 50); + + const int s = 3; + cv::Mat kernel = cv::getStructuringElement(0, cv::Size(s,s)); + cv::Canny(difference, backgroundEgdes, 150, 300); + const int w = backgroundEgdes.size().width-1, h = backgroundEgdes.size().height-1; + cv::line(backgroundEgdes, cv::Point2i(0,0), cv::Point2i(w,0), cv::Scalar(255,2555,255,255)); + cv::line(backgroundEgdes, cv::Point2i(0,0), cv::Point2i(0,h), cv::Scalar(255,2555,255,255)); + cv::line(backgroundEgdes, cv::Point2i(w,0), cv::Point2i(w,h), cv::Scalar(255,2555,255,255)); + cv::line(backgroundEgdes, cv::Point2i(0,h), cv::Point2i(w,h), cv::Scalar(255,2555,255,255)); + cv::dilate(backgroundEgdes, backgroundEgdes, kernel); + cv::GaussianBlur(backgroundEgdes, backgroundEgdes, cv::Size(0,0), 3.5); + + cv::threshold(difference, difference, 127, 255, cv::THRESH_BINARY); + + +#ifdef DEBUG_TEST + cv::imwrite(QString("test_smallCanny%1.png").arg(tmpVal2).toLocal8Bit().toStdString(), backgroundEgdes); + cv::imwrite(QString("test_smallImDiff%1.png").arg(tmpVal2++).toLocal8Bit().toStdString(), difference); +#endif +#ifdef DEBUG + cv::imwrite(QString("test_smallIm%1.png").arg(tmpVal).toLocal8Bit().toStdString(), smallImage); +#endif + + int n = contours.size(); + QVector selected(n); // 0 not considered, 1 selected, -1 disregarded + for(int i=0; i< n; i++) + { + selected[i] = out[i] ? 0 : -1; + } + energies.resize(n); + +#define INVALIDATE(i) \ + out[i] = false; \ + selected[i] = -1; + + QVector > energiesAndIdexes(n); // for sorting with backmap + + const double imageArea = imageOrig.rows * imageOrig.cols; + + // compute energy +#pragma omp parallel for + for (int i=0; i rects[i].size.height ? + (double)rects[i].size.width / (double)rects[i].size.height : + (double)rects[i].size.height / (double)rects[i].size.width; + + // rectangle is too much outside of the image? + QPolygonF pIm, pRect; + const float x = imageOrig.size().width, y = imageOrig.size().height; + pRect << CvPt2QtPt(points[i][0]) << CvPt2QtPt(points[i][1]) + << CvPt2QtPt(points[i][2]) << CvPt2QtPt(points[i][3]); + pIm << CvPt2QtPt(cv::Point2f(0,0)) << CvPt2QtPt(cv::Point2f(x,0)) + << CvPt2QtPt(cv::Point2f(x,y)) << CvPt2QtPt(cv::Point2f(0,y)); + QPolygonF intersected = pRect.intersected(pIm); + const double withinImageArea = polyArea(intersected); + const double a = withinImageArea / rects[i].size.area(); + + int level = 0; + int parent = hierarchy[i][3]; + while (parent >= 0) + { + level++; + parent = hierarchy[parent][3]; + } + + // all together + min Area + if (rects[i].size.area() / (double) imageArea > _minArea + && rects[i].size.area() / (double) imageArea < _maxArea + && ratio <= _maxAspect + && out[i] + && a > _minAreaWithinImage + && level <= _maxHierarchyLevel) + { + + const cv::RotatedRect& r = rects[i]; + const cv::RotatedRect rectSmall(cv::Point2f(float(r.center.x)/scale, + float(r.center.y)/scale), + cv::Size2f(float(r.size.width)/scale, + float(r.size.height)/scale), + r.angle); + const double frameEnergy = extractRectangleValueSum(difference, rectSmall) + / double((double)threshTo * (double)rectSmall.size.area()); + + if (frameEnergy > _minFrameEnergy) + { + double sumValues, backgroundSum; + long int numPixels, backgroundNum; + getSumOfRectangleSampling(points[i], boundaries, sumValues, numPixels); + getSumOfRectangleSampling(points[i], backgroundEgdes, backgroundSum, backgroundNum); +#ifdef DEBUG + QVector pts(4); + rectSmall.points(pts.data()); + for (int k=0; k<4; k++) { + cv::line(bdCopy, points[i][k], points[i][(k+1)%4], cv::Scalar(0,0,255)); + cv::line(smallImage, pts[k], pts[(k+1)%4], cv::Scalar(0,0,255)); + } +#endif + // best area is around half of the image + // energy: 1. sampling values along the field + // 2. area (highest value is half the image) + // 3. aspect - 7:5 (between 3:2 and 4:3) + // 4. monotony inside rect (used above the reject background rectangles) + + const double areaEnergy = (imageArea*_maxAreaFractionEnergy - qAbs(double(imageArea*_maxAreaFractionEnergy - rects[i].size.area()))) / (imageArea*_maxAreaFractionEnergy); + const double borderEnergy = sumValues / (double)numPixels / 255.0; + const double borderEnergyBackground = backgroundSum / (double)backgroundNum / 255.0; + const double aspectEnergy = (7.0/5.0 - qAbs(7.0/5.0 - ratio)) * 5.0 / 7.0; + energy = _e1 * areaEnergy * areaEnergy + + _e2 * qPow(borderEnergy, 2.0) + + _e2 * qPow(borderEnergyBackground, 2.0) + + _e3 * aspectEnergy * aspectEnergy + + _e4 * frameEnergy * frameEnergy; + + /* + double tmp = areaEnergy, tmp2 = aspectEnergy, pow =2.0; + energy = _e1 * qPow(0.2*qRound(tmp*5.0), pow) + + _e2 * qPow(qMin(borderEnergy, frameEnergy ), pow) + + _e4 * qPow(0.2*qRound(tmp2*5.0), pow);*/ + + found = true; + } + } + } +#pragma omp critical + if (found) { + energiesAndIdexes[i] = QPair(energy, i); + energies[i] = energy; + } + else + { + energiesAndIdexes[i] = QPair(0, i); + INVALIDATE(i); + } + } + } + // Ordering ascending + qSort(energiesAndIdexes.begin(), energiesAndIdexes.end(), QPairFirstComparer()); + + // now choose: best first, then disable all parents and kids. search next + int choice = 0; + while (choice >= 0 && !_stopped && !_abortAndLoadNext) + { + choice = -1; + // search next best rectangle + for (int i=0; i=0) + { + INVALIDATE(parent); + parent = hierarchy[parent][3]; + } + + // now stack kids and work through + QList kids; + if (hierarchy[choice][2]>=0) + { + kids.append(hierarchy[choice][2]); + } + while (kids.length()>0) + { + const int current = kids.first(); + kids.pop_front(); // remove that element + if (current < 0)// || selected[current] <0) + { + continue; + } + + INVALIDATE(current); + + // append first of that current kid + kids.append(hierarchy[current][2]); + + // append next neighbour of that current kid + kids.append(hierarchy[current][0]); + } + } + +#ifdef DEBUG + cv::imwrite(QString("test_rectsSampling%1.png").arg(tmpVal).toLocal8Bit().toStdString(), bdCopy); + cv::imwrite(QString("test_rectsSamplingSmall%1.png").arg(tmpVal).toLocal8Bit().toStdString(), smallImage); +#endif +} + +inline QVector computeContourLength(const std::vector& contour) +{ + const int m = contour.size(); + // compute sum of contour lengths + QVector length(m+1); + for (int j=1; j >& contours, + QVector& rects, + std::vector& hierarchy, + QVector >& points, + QVector& valid) +{ + + // ok here it seems there is a possibility such that two rectangles are merged into one + // now add these two sub-rectangles/contours and make sure hierarchy is just correct + // (however the "inside" relation won't be correct) + + // hierarchy[i]: next(0), prev(1), firstKid(2), parent(3) + + const int l= contours.size(); + std::vector< cv::Point > c1, c2; + c1.insert(c1.end(), contours[i].begin(), contours[i].begin() + (i1==(int)contours[i].size()-1? i1: i1+1)); + c1.insert(c1.end(), contours[i].begin() + i2, contours[i].end()); //(i2==0? i2 : i2-1), contours[i].end() ); + + c2.insert(c2.end(), + contours[i].begin() + i1, //(i1==0?i1:i1-1), + contours[i].begin() + (i2==(int)contours[i].size()-1? i2: i2+1)); + contours.push_back(c1); + contours.push_back(c2); + + rects.push_back(minAreaRect (c1)); + rects.push_back(minAreaRect (c2)); + + valid.push_back(true); + valid.push_back(true); + + points.resize(l+2); + points[l].resize(4); + points[l+1].resize(4); + rects[l].points(points[l].data()); + rects[l+1].points(points[+1l].data()); + + hierarchy.push_back(cv::Vec4i(l+1, -1, -1, i)); + if (hierarchy[i][2] >= 0) + { + const int kid = hierarchy[i][2]; + hierarchy[kid][1] = l+1; + + hierarchy.push_back(cv::Vec4i(kid, l, -1, i)); + } + else + { + hierarchy.push_back(cv::Vec4i(-1, l, -1, i)); + } + hierarchy[i][2] = l; +} + +void PreloadSource::rectangleOverlap(std::vector >& contours, + QVector& rects, + std::vector& hierarchy, + QVector >& points, + QVector > &sumOfContourLengths, + QVector& valid) const +{ + + // find rectangles which (slightly) overlap at two respective corners + // also look for single large convexity defects + const int n = contours.size(); + for (int i=0; i defects; + std::vector hull; + + cv::convexHull(contours[i], hull); + + if (hull.size() < 4) + { + continue; + } + + cv::convexityDefects(contours[i], hull, defects); + + if (defects.size() > 1) + { + // find best defect pair, which means closest distance to each other + // and long enough contour length in between + const double rectLength = 2*rects[i].size.width + 2*rects[i].size.height; + const int m = contours[i].size(); + + // now compare defects, but only if contour in between is long enough + for (unsigned int j=0; j < defects.size(); j++) + { + if (sumOfContourLengths[i].size() < (int)contours[i].size()) { + sumOfContourLengths[i] = computeContourLength(contours[i]); + } + const QVector& length = sumOfContourLengths[i]; + + // getMaxDefect position + const double maxDist = qMin(rects[i].size.width, + rects[i].size.height)/2.0; + const int bestN = 5; + QVector maxDistFound (bestN, 0); + QVector > bestPairs(bestN); + /** + * compare to closest point on rectangle. if it is only (say half) + * the length away (-> to the opposite side) then add splitted + */ + //const double minLengthInBetween = 40.0; + //const double maxAreaPerLength = 5.0; + const int ind = defects[j][2]; + for (unsigned int j=0; j rectLength * _splitMinLengthFrac) + { + // energy consists of length fraction and distance to rectangle fraction + // so defects with rather equal lengths towards both circles + // and a high defect values are preferred + const double distL1P1 = distancePointLine(points[i][0], points[i][1], contours[i][i1]); + const double distL1P2 = distancePointLine(points[i][2], points[i][3], contours[i][i1]); + const double distL2P1 = distancePointLine(points[i][1], points[i][2], contours[i][i1]); + const double distL2P2 = distancePointLine(points[i][0], points[i][3], contours[i][i1]); + double minRectDist = qMin(distL1P1, qMin(distL1P2, qMin(distL2P1, distL2P2))); + + // try to distribute around the rectangle + const double energy = (shortestDist - length.last() / (double)bestN) + + 4 * minRectDist * rectLength; + int choice = bestN; + for (int k=bestN-1; k>=0; k--) { + if (energy < maxDistFound[k] ) + { + break; + } + choice = k; + } + if (choice < bestN) { + bestPairs[choice] = QPair(i1, i2); + maxDistFound[choice] = energy; + } + } + } + for (int k=0; k 0) { + addSubRectangles(i, bestPairs[k].first, bestPairs[k].second, contours, rects, hierarchy, points, valid); + } + } + + /** + * the following seems to work ok, however it is somewhat limited + * since it is only tried to compare to neighboring defects + */ + // compare to other defects + for (unsigned int k=j+1; k < defects.size(); k++) + { + const int i1 = qMin(defects[j][2], defects[k][2]); + const int i2 = qMax(defects[j][2], defects[k][2]); + double shortestDist = qMin(length[i2] - length[i1], + length[i1] + (length[m] - length[i1])); + if (shortestDist > rectLength * _splitMinLengthFrac + && cv::norm(contours[i][i1] - contours[i][i2]) < maxDist) + { + // now save this + // found best defect pair + // now test how close that pair is and if it is rather on the diagonal of the bounding rect + const double diagLength = qSqrt(rects[i].size.width * rects[i].size.width + + rects[i].size.height * rects[i].size.height); + const double distD1P1 = distancePointLine(points[i][0], points[i][2], contours[i][i1]); + const double distD1P2 = distancePointLine(points[i][0], points[i][2], contours[i][i2]); + const double distD2P1 = distancePointLine(points[i][1], points[i][3], contours[i][i1]); + const double distD2P2 = distancePointLine(points[i][1], points[i][3], contours[i][i2]); + + const double sumDiagDist = qMin( distD1P1 + distD1P2, distD2P1 + distD2P2); + + if (sumDiagDist < _splitMaxOffsetFrac * diagLength) + { + // also make sure this is far enough away from corner + double distanceCorner = 1e10; + for (int l=0; l<4; l++) + { + distanceCorner = qMin(distanceCorner, cv::norm(points[i][l])); + } + if (distanceCorner > _splitMinCornerDist * diagLength) { + addSubRectangles(i, i1, i2, contours, rects, hierarchy, points, valid); + } + } + } + } + } + } + } +} + +/* +void PreloadSource::computeContourLengths(const std::vector >& contours, + const QVector& valid, + QVector >& sumOfContourLengths) +{ + const int n = contours.size(); + sumOfContourLengths.resize(n); +#pragma omp parallel for + for (int i=0; i length(m+1); + for (int j=1; j >& sumOfContourLengths, + const QVector & valid, + std::vector >& contours) +{ + /* + *I did remove this since there's quite some danger correct images might get removed, as well + */ + const int n = contours.size(); +#pragma omp parallel for + for (int i=0; i valid(m, true); + + // compute all distances + for (int j=1; j= minLengthInBetween) { + // now compute area of this part polygon. + // if it is very small, then add this pair to removal. + // sample both directions + const double areaPerLength1 = + polyAreaCV(contours[i], j, k ) / cLength1; + if (areaPerLength1 < maxAreaPerLength) + { + // prevent computing this, again + for (int v=j+1; v= minLengthInBetween) + { + const double areaPerLength2 = + polyAreaCV(contours[i], k, j ) / cLength2; + if (areaPerLength2 < maxAreaPerLength) + { + // prevent computing this, again + for (int v=k+1; v=0; j--) { + if (!valid[j]) { + contours[i].erase(contours[i].begin() + j); + } + } + } + } + /**/ +} + +double PreloadSource::distancePointLine(const cv::Point2f& LP1, + const cv::Point2f& LP2, + const cv::Point2f& p) const +{ + const double dY = LP2.y - LP1.y; + const double dX = LP2.x - LP1.y; + const double ret = qAbs ( dY * p.x - dX * p.y + LP2.x * LP1.y - LP2.y * LP1.x) / qSqrt(dY * dY + dX * dX); + return ret; +} + + +cv::Mat PreloadSource::loadAndShrink(const QString& filename) +{ + cv::Mat image = cv::imread(filename.toLocal8Bit().data(), + CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR); + + if (image.channels() == 1) { + cv::cvtColor(image, image, CV_GRAY2BGR); + } + if (image.channels() == 4) { + cv::cvtColor(image, image, CV_BGRA2BGR); + } + + if (image.depth() == CV_16S + || image.depth() == CV_16U) + { + qDebug() << "found 16bit image"; + cv::normalize(image,image,0,255,cv::NORM_MINMAX); + image.convertTo(image, CV_8U); + } + return image; +} + +void PreloadSource::newTargets(SourceFilePtr &source, cv::Mat& alreadyLoaded, bool& locked) +{ + source->targets.clear(); + _imSize = 2000; + + // prevent two big chunks of memory at the same time -> see copytargets + + if (alreadyLoaded.empty()) + { + alreadyLoaded = loadAndShrink(source->source.absoluteFilePath()); + } + + cv::Mat image = alreadyLoaded; + + if (image.size().width == 0 + || image.size().height == 0 + || image.empty()) + { + source->error = true; + return; + } + + float scale; + cv::Mat im; + if (image.size().width < image.size().height) + { + scale = (float) image.size().height / (float) _imSize; + cv::resize(image, im, cv::Size(int(float(image.size().width)/scale), + _imSize)); + } + else + { + scale = (float) image.size().width / (float) _imSize; + cv::resize(image, im, cv::Size(_imSize, + int(float(image.size().height)/scale))); + } + CopyTargets::memorySaveMutex.unlock(); + locked = false; + ABORT_COMPUTATION(); + + int bestThresh; + std::vector thresholds = getThresholds(image, bestThresh); + std::vector rectDetection = extractRectangles(thresholds, image); + cv::cvtColor(im, image, cv::COLOR_BGR2GRAY); + + cv::medianBlur(image, image, 5); + + image.convertTo(image, CV_32F); + + if (image.cols == 0) { + return; + } + cv::Mat overallMask, out; + const int levels = _levels; + + overallMask = cv::Mat::zeros(image.rows, image.cols, image.type()); + + for (int i=0; i < levels; i++) + { + ABORT_COMPUTATION() + cv::pyrDown(image, image); + cv::Mat mu, mu2, sigma; + cv::blur(image, mu, cv::Size(3,3)); + cv::Mat tmp(image.rows, image.cols, image.type()); + + cv::multiply(image, image, tmp); + cv::blur(tmp, mu2, cv::Size(3,3)); + cv::multiply(mu, mu, tmp); + cv::sqrt(mu2 - tmp, sigma); + + cv::resize(sigma, tmp, cv::Size(overallMask.cols, overallMask.rows)); + overallMask += tmp; + } + image.release(); + + // remove NaN and INF + for(int row = 0; row < overallMask.rows; ++row) { + float* p = overallMask.ptr(row); + for(int col = 0; col < overallMask.cols; col++) { + if (p[col] * 0.0f != 0.0f) { + p[col] = 0.0f; + } + } + } + + ABORT_COMPUTATION() + + + const int s = 5; + cv::Mat kernel = cv::getStructuringElement(0, cv::Size(s,s)); + cv::morphologyEx(overallMask, overallMask, cv::MORPH_OPEN, kernel); + cv::erode(overallMask, overallMask, kernel); + + cv::threshold(overallMask, out, _threshold*levels, 1, CV_THRESH_BINARY); + out.convertTo(out, CV_8U); + ABORT_COMPUTATION() + +#ifdef DEBUG + // save mask + QString fn = source->source.baseName() + "_mask.png"; + cv::imwrite(fn.toLocal8Bit().toStdString(), overallMask); +#endif + + std::vector > contours; + std::vector hierarchy; + + cv::findContours( out, contours, hierarchy, + CV_RETR_TREE , //CV_RETR_LIST, + CV_CHAIN_APPROX_TC89_KCOS //CV_CHAIN_APPROX_NONE + ); + ABORT_COMPUTATION() + + if (rectDetection.size() > 0) + { + const int start = contours.size() ; + contours.resize(start + rectDetection.size()); + hierarchy.resize(start + rectDetection.size()); + cv::Vec4i hi; + hi[0] = hi[1] = hi[2] = hi[3] = -1; + for (unsigned int i=0; i< rectDetection.size(); i++) + { + ABORT_COMPUTATION() + hierarchy[i+start] = hi; + contours[i+start].resize(4); + std::vector pts(4); + rectDetection[i].size.width /= scale; + rectDetection[i].size.height /= scale; + rectDetection[i].center.x /= scale; + rectDetection[i].center.y /= scale; + + rectDetection[i].points(pts.data()); + for (int j=0; j<4; j++) { + contours[i+start][j] = pts[j]; + } + } + } + + // compute needed data + QVector rects(contours.size()); + QVector > points(contours.size()); + QVector keep(contours.size()); + keep.fill(true); + QVector energies; + + for (int j=0; j< (int)contours.size(); j++) { + rects[j] = minAreaRect (contours[j]); + points[j].resize(4); + rects[j].points(points[j].data()); + } + ABORT_COMPUTATION() + + PreloadSource::preSelectFast(overallMask, contours, hierarchy, rects, points, keep); + ABORT_COMPUTATION() + +#ifdef DEBUG + /// Draw contours + /// + cv::RNG rng(12345); + cv::Mat drawing = cv::Mat::zeros( overallMask.size(), CV_8UC3 ); + for( unsigned int i = 0; i< contours.size(); i++ ) + { + if (hierarchy[i][3] <0) { + cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); + cv::drawContours( drawing, contours, i, color, 2, 8, hierarchy, _maxHierarchyLevel); + } + } + + fn = source->source.baseName() + "_conts.png"; + cv::imwrite(fn.toLocal8Bit().toStdString(), drawing); +#endif + + QVector > sumOfContourLengths(contours.size()); + //computeContourLengths(contours, sumOfContourLengths); + + //removeFilaments(sumOfContourLengths, keep, contours); + + // detect overlapping rectangles and split others, as well + rectangleOverlap(contours, rects, hierarchy, points, sumOfContourLengths, keep); + ABORT_COMPUTATION() + + // select best rectangle based on hierachy structure + //cv::GaussianBlur(overallMask, overallMask, cv::Size(0,0), 3.5); + + + // do it again, find contours seems to destroy out + // cv::threshold(overallMask, out, _threshold*levels, 255, CV_THRESH_BINARY); + out = overallMask * int(_threshold * float(levels)); + cv::GaussianBlur(out, out, cv::Size(0,0), 5.0); + out.convertTo(out, CV_8U); + +#ifdef DEBUG + fn = source->source.baseName() + "_blur.png"; + cv::imwrite(fn.toLocal8Bit().toStdString(), out); +#endif + ABORT_COMPUTATION() + + + bestRectangles(im, + out, + thresholds[bestThresh>=0? bestThresh : 0], + contours, + hierarchy, + rects, + points, + energies, + keep); + + ABORT_COMPUTATION() + +#ifdef DEBUG + /// Draw contours + /// + drawing = cv::Mat::zeros( overallMask.size(), CV_8UC3 ); + for( unsigned int i = 0; i< contours.size(); i++ ) + { + if (hierarchy[i][3] <0) { + cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); + cv::drawContours( drawing, contours, i, color, 2, 8, hierarchy, _maxHierarchyLevel); + } + } + + fn = source->source.baseName() + "_conts_noFilaments.png"; + cv::imwrite(fn.toLocal8Bit().toStdString(), drawing); +#endif + + // now extract rectangles and remove remaining overlaps + // sort by energy. this means a rectangle cannot lose and the winner loses itself. + QVector > backmap(contours.size()); + for (unsigned int i=0; i(energies[i], i); + } + qSort(backmap.begin(), backmap.end(), QPairFirstComparer()); + +#ifdef DEBUG_TEST + cv::Mat visualize; + im.copyTo(visualize); +#endif + + cv::GaussianBlur(overallMask, overallMask, cv::Size(0,0), 5.0); + + for (int j=0; j< (int)contours.size(); j++) { + ABORT_COMPUTATION() + const int ind1 = backmap[j].second; + cv::RotatedRect& rect = rects[ind1]; + if (keep[ind1]) { + // find overlapping rectangles - disregard the one with less energy + QPolygonF p; + p << CvPt2QtPt(points[ind1][0]) << CvPt2QtPt(points[ind1][1]) + << CvPt2QtPt(points[ind1][2]) << CvPt2QtPt(points[ind1][3]); + for (int i=j+1; i<(int)contours.size(); i++) + { + const int ind2 = backmap[i].second; + if (keep[ind2]) + { + QPolygonF p2; + p2 << CvPt2QtPt(points[ind2][0]) << CvPt2QtPt(points[ind2][1]) + << CvPt2QtPt(points[ind2][2]) << CvPt2QtPt(points[ind2][3]); + const QPolygonF intersected = p.intersected(p2); + const double area = polyArea(intersected); + const double a1 = area / (rects[ind1].size.area()); + const double a2 = area / (rects[ind2].size.area()); + if (a1 > _maxOverlap || a2 > _maxOverlap) + { + keep[ind2] = false; + } + } + } + +#ifdef DEBUG_TEST + rect.points(points[ind1].data()); + for (int i=0; i<4; i++) { + cv::line(visualize, points[ind1][i], points[ind1][(i+1)%4], cv::Scalar(0,0,255), 3); + } +#endif + // optimize rectangle + optimizeRectangle(overallMask, rect); + rect.points(points[ind1].data()); +#ifdef DEBUG_TEST + for (int i=0; i<4; i++) { + cv::line(visualize, points[ind1][i], points[ind1][(i+1)%4], cv::Scalar(0,255,255), 2); + } +#endif + + const float scaleNew = scale / source->scale; + QVector corners(4); + corners[0] = QPointF(scaleNew*rect.size.width/2.0, scaleNew*rect.size.height/2.0); + corners[1] = QPointF(scaleNew*rect.size.width/2.0, -scaleNew*rect.size.height/2.0); + corners[2] = QPointF(-scaleNew*rect.size.width/2.0, -scaleNew*rect.size.height/2.0); + corners[3] = QPointF(-scaleNew*rect.size.width/2.0, scaleNew*rect.size.height/2.0); + TargetImagePtr target(new TargetImage); + target->boundary->setCorners(corners.data()); + target->boundary->setTransform(target->boundary->transform().translate(scaleNew*rect.center.x, scaleNew*rect.center.y).rotate(rect.angle)); + + source->targets.push_back(target); + } + } + +#ifdef DEBUG_TEST + QString fn2 = QString("%1_%2_%3_%4_" + source->source.baseName() + "_prodBorder_results.png").arg(_e1).arg(_e2).arg(_e3).arg(_e4); + cv::imwrite(fn2.toLocal8Bit().toStdString(), visualize); +#endif +} + +void PreloadSource::updateMinMax(const int mi, const int ma) +{ + _min = mi; + _max = ma; +} + +void PreloadSource::stop() +{ + _stopped = true; +} + +QString PreloadSource::isCurrentlyLoading() const +{ + return _currentFilename; +} + +inline bool PreloadSource::testAbort(SourceFilePtr sourceFile) +{ + + if (_stopped || _abortAndLoadNext) { + sourceFile->imageOrig = QImage(); + sourceFile->image.reset(); + preloadMutex.unlock(); + waitFinished.wakeAll(); + _currentFilename = ""; + return true; + } + return false; +} + +#define TEST_ABORT(s) \ + if (testAbort(s)) { \ + if (locked) CopyTargets::memorySaveMutex.unlock(); \ + locked = false; \ + continue; \ + } + +void PreloadSource::run() +{ + while (!_stopped) { + _abortAndLoadNext = false; + SourceFilePtr sourceFile; + int id; + { + QMutexLocker l(&_fileListMutex); + if (_filesToLoad.size() == 0) { + waitFinished.wakeOne(); + _condition.wait(&_fileListMutex); + // continue: in the meantime it might have been stopped + // or set empty + continue; + } + sourceFile = _filesToLoad.first().first; + + _current = sourceFile; + id = _filesToLoad.first().second; + + _filesToLoad.pop_front(); + } + + + preloadMutex.lock(); + _currentFilename = sourceFile->source.absoluteFilePath(); + qDebug() << "starting to load: " << _currentFilename; + + QImage tmpIm = QImage(sourceFile->source.absoluteFilePath()); + + CopyTargets::memorySaveMutex.lock(); + bool locked = true; + sourceFile->error = false; + sourceFile->imageOrig = tmpIm.convertToFormat(_qImageFmt); + TEST_ABORT(sourceFile); + + cv::Mat loadedData; + if (!sourceFile->imageOrig.isNull() || sourceFile->imageOrig.width() == 0) + { + // try to load a 16 bit image with opencv + loadedData = loadAndShrink(sourceFile->source.absoluteFilePath()); + + if (loadedData.empty()) + { + sourceFile->error = true; + } + else + { + // QImage has different rgb ordering + cv::Mat tmp; + cv::cvtColor(loadedData, tmp, CV_BGR2RGB); + + sourceFile->imageOrig = QImage(tmp.data, + tmp.size().width, + tmp.size().height, + tmp.step[0], + QImage::Format_RGB888).convertToFormat(_qImageFmt); + } + } + TEST_ABORT(sourceFile); + + if (!sourceFile->error) + { + // scale down original image + const int maxExtent = 2000; + sourceFile->scale = 1.0; + if (sourceFile->imageOrig.width() > maxExtent + && sourceFile->imageOrig.width() >= sourceFile->imageOrig.height()) + { + sourceFile->scale = (double) sourceFile->imageOrig.width() / (double)maxExtent; + sourceFile->imageOrig = sourceFile->imageOrig.scaled(QSize(maxExtent, maxExtent), Qt::KeepAspectRatio); + } + else if (sourceFile->imageOrig.height() > maxExtent + && sourceFile->imageOrig.width() < sourceFile->imageOrig.height()) + { + sourceFile->scale = (double) sourceFile->imageOrig.height() / (double)maxExtent; + sourceFile->imageOrig = sourceFile->imageOrig.scaled(QSize(maxExtent, maxExtent), Qt::KeepAspectRatio); + } + TEST_ABORT(sourceFile); + + if (id >= 0) + { + newTargets(sourceFile, loadedData, locked); // if id < 0 then it means only load images + } + } + if (locked) CopyTargets::memorySaveMutex.unlock(); + locked = false; + TEST_ABORT(sourceFile); + + // remove from list - since we will have it commited in a couple of lines +#ifndef TEST_DEBUG + if (!_stopped) + { + emit doneLoading(sourceFile, id < 0 ? -id -1 : id); + } +#else + sourceFile->image = QGraphicsPixmapItemPtr(); + sourceFile->imageOrig = QImage(); + for (int i=0; itargets[i]->image = QImage(); + } + sourceFile->targets.clear(); +#endif + _currentFilename = ""; + preloadMutex.unlock(); + waitFinished.wakeAll(); + } +} + + +/** + * advanced extracting here + */ + +inline cv::Point2f lineIntersection(const cv::Vec2f& l1, + const cv::Vec2f& l2) +{ + const float& theta1 = l1[1]; + const float& rho1 = l1[0]; + const float& theta2 = l2[1]; + const float& rho2 = l2[0]; + const float c1 = qCos(theta1); + const float c2 = qCos(theta2); + const float s1 = qSin(theta1); + const float s2 = qSin(theta2); + + /* cross product l1 x l2 = intersection point (homogeneous) + [r1*s2 - r2*s1], + [c1*r2 - c2*r1], + [c1*s2 - c2*s1]] */ + + cv::Point2f out; + const float third = c1*s2 - c2*s1; + + out.x = (rho1*s2 - rho2*s1)/third; + out.y = (c1*rho2 - c2*rho1)/third; + return out; +} + +inline std::vector rectanglePoints(const cv::Vec2f& l1, + const cv::Vec2f& l2, + const cv::Vec2f& l3, + const cv::Vec2f& l4) +{ + std::vector out(4); + out[0] = lineIntersection(l1, l2); + out[1] = lineIntersection(l2, l3); + out[2] = lineIntersection(l3, l4); + out[3] = lineIntersection(l4, l1); + return out; +} + +std::vector lineValues(const cv::Mat& image, + const cv::Point2f p1, + const cv::Point2f p2) +{ + assert(image.type() == CV_32F); + cv::Point2f diff = p2 - p1; + const int count= cv::norm(diff); + std::vector out(count); + for (int i=0; i((int)p.y, (int)p.x); + } + return out; + /* + const IplImage tmp = image; + CvLineIterator iterator; + const int count = cvInitLineIterator( &tmp, p1, p2, &iterator, connectivity); + std::vector out(count); + for( int i = 0; i < count; i++ ){ + out[i] = iterator.ptr[0]; + CV_NEXT_LINE_POINT(iterator); + } + return out;*/ +} + +inline float dot(const cv::Vec2f& v1, const cv::Vec2f v2) +{ + return v1[0]*v2[0] + v1[1]*v2[1]; +} + + +std::vector PreloadSource::extractRectangles(const std::vector &thresholds, + const cv::Mat& image) +{ + _rectAngularThresh = M_PI * 2.0/180.0; + _rectMinLineDistFrac = 0.3; + _maxArea = 0.75; + const float minLineDist = qMin(image.size().width, image.size().height) * _rectMinLineDistFrac; + + std::vector lines = extractLines(thresholds, image); + + if (lines.size() >= 150) + { + const int n= lines.size(); + std::vector lines2; + lines2.reserve(n/150); + for (unsigned int i=0; i image.size().height ? + image.size().width/2000 + : image.size().height/2000 ; + _rectMinDist = qMax(_rectMinDist, 2.0f); + + // add the boundary lines, since images at the boundary + // will usually have no lines detected at that boundary + lines.reserve(lines.size() + 4); + lines.push_back(cv::Vec2f(0, 0.5 * M_PI)); + lines.push_back(cv::Vec2f(0, 2.0)); + lines.push_back(cv::Vec2f(image.size().width, 0.0)); + lines.push_back(cv::Vec2f(image.size().height, 0.5 * M_PI)); + const int n = lines.size(); + + QList > parallelLines; + QList averageAngle; +#pragma omp parallel for + for (int i=0; i minLineDist) + { +#pragma omp critical + { + parallelLines.append(QPair(i,j)); + averageAngle.append(0.5 * (theta1 + theta2)); + } + } + } + } + + /* + * look for pairs of parallel lines which meet the rectangle criteria + */ + const float imageArea = image.size().width * image.size().height; + std::vector out; + std::vector > points; + + QList >::const_iterator it1(parallelLines.begin()); + QList::const_iterator avgAngle1(averageAngle.begin()); + while (it1 != parallelLines.end() && !_stopped && !_abortAndLoadNext) + { + const QPair parallelLines1 = *it1; it1++; + const float angle1 = *avgAngle1; avgAngle1++; + + QList >::const_iterator it2(it1); + QList::const_iterator avgAngle2 (avgAngle1); + + while(it2 != parallelLines.end()) + { + const QPair parallelLines2 = *it2; it2++; + const float angle2 = *avgAngle2; avgAngle2++; + + // 90 degree + const float angularDist = qAbs(qAbs(angle1 - angle2) - 0.5 * M_PI); + if (angularDist < _rectAngularThresh) + { + // it is close to a rectangle + // estimate enclosing rectangle points + std::vector pts = rectanglePoints( + lines[parallelLines1.first], + lines[parallelLines2.first], + lines[parallelLines1.second], + lines[parallelLines2.second]); + const cv::RotatedRect rect = cv::minAreaRect(pts); + const float aspect = rect.size.width > rect.size.height ? + rect.size.width / rect.size.height + : rect.size.height / rect.size.width; + assert(aspect >= 1.0); + const float relArea = rect.size.area() / imageArea; + if (aspect > _maxAspect || relArea < _minArea || relArea > _maxArea) + { + continue; + } + + out.push_back(rect); + points.push_back(pts); + } + } + } + +#ifdef DEBUG + cv::Mat im; + image.copyTo(im); + for (unsigned int i=0; i pts(4); + out[i].points(pts.data()); + cv::Scalar colorScalar = cv::Scalar( (i*7)%256, 128+ (i*19)%256, 220 + (i*11 )%256); + for( int j = 0; j < 4; j++ ) + cv::line( im, pts[j], pts[(j+1)%4], colorScalar, 1, 8 ); + } + cv::imwrite(QString("test_lines_rects%1.png").arg(tmpVal++).toLocal8Bit().toStdString(), im); +#endif + + return out; +} + +std::vector PreloadSource::getThresholds(const cv::Mat& image, + int& bestThresInd) +{ + // the last one is a threshold from lower + _histPositions = 3; + _histWindowWidth = 20; + _histMinPercentage = 0.1; + _minColorHeight = 180; + + + // Calculate histogram + std::vector hist(3); + int histSize = 256; // bin size + float range[] = { 0, 255 }; + const float *ranges[] = { range }; + + std::vector channels(3); + cv::split(image, channels); + + std::vector out; + std::vector peakheights; + + for (int pos = 0; pos <_histPositions; pos++) + { + cv::Vec3i threshs; + peakheights.push_back(0); + for (auto i=0; i<3; i++) + { + cv::calcHist( &channels[i], 1, 0, cv::Mat(), hist[i], 1, &histSize, ranges, true, false ); + + cv::normalize(hist[i], hist[i], 0, histSize, cv::NORM_MINMAX, -1, cv::Mat() ); + //cv::normalize(); + + threshs[i] = findHistPeak(hist[i], + true, + _histWindowWidth, + _histMinPercentage, + pos); + if (threshs[i] == -1) + { + threshs[i] = 0; + continue; + } + peakheights[pos] += hist[i].at(threshs[i]); + } + out.push_back(threshs); + } + + // determine thresh with highest count + float best=0; + bestThresInd = -1; + for (unsigned int i=0; i best + && out[i][0] > _minColorHeight + && out[i][1] > _minColorHeight + && out[i][2] > _minColorHeight) + { + best = peakheights[i]; + bestThresInd = i; + } + } + + // find from black threshold + cv::Vec3i thresh; + for (auto i=0; i<3; i++) + { + cv::calcHist( &channels[i], 1, 0, cv::Mat(), hist[i], 1, &histSize, ranges, true, false ); + + cv::normalize(hist[i], hist[i], 0, histSize, cv::NORM_MINMAX, -1, cv::Mat() ); + + thresh[i] = findHistPeak(hist[i], + false, + _histWindowWidth, + _histMinPercentage); + if (thresh[i] == -1) + { + thresh[i] = 0; + continue; + } + } + out.push_back(thresh); + return out; +} + +std::vector PreloadSource::extractLines(const std::vector& thresholds, + const cv::Mat& image) +{ + // copy to settings + _imSize = 500; + _histSigma = 15; + _cannyTr1 = 150; + _cannyTr2 = 300; + _medianBlurMask = 15; + _houghRho = 1; + _houghAngle = 180; + _houghFactor = 0.25; + + float scale; + cv::Mat im; + if (image.size().width < image.size().height) + { + scale = (float) image.size().height / (float) _imSize; + cv::resize(image, im, cv::Size(int(float(image.size().width)/scale), + _imSize)); + } + else + { + scale = (float) image.size().width / (float) _imSize; + cv::resize(image, im, cv::Size(_imSize, + int(float(image.size().height)/scale))); + } + + std::vector channels(3); + cv::split(im, channels); + + // first canny step + cv::Mat canny; + cv::cvtColor(im, canny, cv::COLOR_BGR2GRAY); + cv::Canny(canny, canny, _cannyTr1, _cannyTr2); + + /* + * here, different thresholds are tried (meaning that these thresholds are assumed + * as white scanner background) -> more canny steps + */ + + cv::Mat mask = cv::Mat::zeros(im.size(), CV_8U); + for (int pos = 0; pos <_histPositions; pos++) + { + // threshold over different histogram peaks (aka pos) + for (auto i=0; i<3; i++) + { + + cv::Mat dst(im.size(), CV_8U); + cv::threshold(channels[i], dst, thresholds[pos][i] - _histSigma, 1, cv::THRESH_BINARY_INV); + mask = cv::max(mask, dst); + dst.release(); + } + + cv::medianBlur(mask, mask, _medianBlurMask); + // apply threshold + std::vector newChannels(3); + for (int i=0; i<3; i++) + { + cv::multiply(mask, channels[i], newChannels[i]); + } + + cv::Mat tmp; + cv::merge(newChannels, tmp); + cv::cvtColor(tmp, tmp, cv::COLOR_BGR2GRAY); + cv::Mat cannyTmp; + cv::Canny(tmp, cannyTmp, _cannyTr1, _cannyTr2); + canny = cv::max(canny, cannyTmp); + } + + /* + * now black scanner background + */ + { + mask = cv::Mat::zeros(im.size(), CV_8U); + for (auto i=0; i<3; i++) + { + cv::Mat dst; + cv::threshold(channels[i], dst, thresholds[_histPositions][i] + _histSigma, 255, cv::THRESH_BINARY_INV); + // + mask = cv::max(mask, dst); + dst.release(); + } + + cv::medianBlur(mask, mask, _medianBlurMask); + // apply threshold + std::vector newChannels(3); + for (int i=0; i<3; i++) + { + newChannels[i] = cv::max(mask, channels[i]); + } + cv::Mat tmp; + cv::merge(newChannels, tmp); + cv::cvtColor(tmp, tmp, cv::COLOR_BGR2GRAY); + cv::Mat cannyTmp; + cv::Canny(tmp, cannyTmp, _cannyTr1, _cannyTr2); + canny = cv::max(canny, cannyTmp ); + } + + /* continue with hough transform */ + //cv::medianBlur(canny, canny, 3); //_medianBlurMaskOverall); +#ifdef DEBUG + cv::imwrite(QString("test_canny%1.png").arg(tmpVal).toLocal8Bit().toStdString(), canny); +#endif + + std::vector lines; + cv::HoughLines(canny, lines, _houghRho, M_PI / float(_houghAngle), int(_houghFactor*_imSize)); + + for (unsigned int i=0; i=0 && i< n; (fromRight? i-- : i++)) + { + bool higher = true; + for (int j=1; j(i) < hist.at(qMin(i+j, n-1)) + || hist.at(i) < hist.at(qMax(i-j, 0)) + || hist.at(i) < 256.0f * minPercentage) + { + higher = false; + break; + } + } + if (higher) + { + // retrieve pos'th peak + if (found == position) + { + return i; + } + found ++; + } + } + return -1; +} + + + +inline cv::RotatedRect rectFromData(const lbfgsfloatval_t *x) +{ + cv::RotatedRect rectangle; + rectangle.angle = x[0]; + rectangle.center.x = x[1]; + rectangle.center.y = x[2]; + rectangle.size.width = x[3]; + rectangle.size.height = x[4]; + return rectangle; +} + +cv::Mat PreloadSource::_currentImageForRectOpt; + +lbfgsfloatval_t PreloadSource::evaluate( + void *instance, + const lbfgsfloatval_t *x, + lbfgsfloatval_t *g, + const int n, + const lbfgsfloatval_t stepOrig + ) +{ + const cv::Mat& image = _currentImageForRectOpt; + cv::RotatedRect rectangle = rectFromData(x); + lbfgsfloatval_t fx = 0.0; + QVector pts(4); + double sumValues; + long int numPixels; + + const lbfgsfloatval_t step = stepOrig <= 1e-10 ? 1.0 : stepOrig; + + rectangle.points(pts.data()); + getSumOfRectangleSamplingF(pts, image, sumValues, numPixels); + fx = -(lbfgsfloatval_t) ( sumValues / (double) numPixels); + + // compute gradient + for (int i=0; i + + +#define MAX_AREA_OVERLAP 0.3 + +class PreloadSource : public QThread +{ + Q_OBJECT +public: + explicit PreloadSource(QObject *parent = 0); + + ~PreloadSource(); + + static QMutex preloadMutex; + static QWaitCondition waitFinished; + + void addLoadFiles(const SourceFilePtr& file, + const int position, + const bool highPriority=false, + const bool onlyLoadImages = false); + + void clear(); + + void newTargets(SourceFilePtr& source, cv::Mat &alreadyLoaded, bool &locked); + QString isCurrentlyLoading() const; + + void updateMinMax(const int, const int); + + void setThresh(const double thresh) { _threshold = thresh; } + void setMaxAspect(const double maxAspect) { _maxAspect = maxAspect; } + void setLevels(const int levels) { _levels = levels; } + void setMaxOverlap(const double maxOverlap) { _maxOverlap = maxOverlap; } + void setMinArea(const double minArea) { _minArea = minArea; } + void setMinAreaWithinImage(const double minArea) { _minAreaWithinImage = minArea; } + void setSplitMaxOffset(const double maxOffset) { _splitMaxOffsetFrac = maxOffset; } + void setSplitMinCornerDist(const double minCornerDist) { _splitMinCornerDist = minCornerDist; } + void setSplitMinLengthFrac(const double minLengthFrac) { _splitMinLengthFrac = minLengthFrac; } + void setMaxHierarchyLevel(const int level) { _maxHierarchyLevel = level; } + + void setEnergyWeights(const float e1, // border energy + const float e2, // area energy + const float e3, // aspect energy + const float e4) // frame content energy + { _e1 =e1; _e2 = e2; _e3 = e3; _e4 = e4; } +signals: + + void doneLoading(const SourceFilePtr&, const int position); + +public slots: + + void stop(); + +protected: + void run(); + +private: + void getSumOfRectangleSampling(const QVector pts, + const cv::Mat &image, + double &sumValues, + long &numPixels); + + static void getSumOfRectangleSamplingF(const QVector pts, + const cv::Mat &image, + double &sumValues, + long &numPixels); + + std::vector getThresholds(const cv::Mat &image, int &bestThresInd); + + void bestRectangles(const cv::Mat& imageOrig, + const cv::Mat &boundaries, + const cv::Vec3i &thresholds, + const std::vector >& contours, + const std::vector& hierarchy, + const QVector& rects, + const QVector >& points, QVector &energies, + QVector& out); // max aspect ratio is x + + void rectangleOverlap(std::vector > &contours, + QVector &rects, + std::vector& hierarchy, + QVector > &points, + QVector > &sumOfContourLengths, + QVector &valid) const; + + void computeContourLengths(const std::vector > &contours, + const QVector& valid, + QVector >& sumOfContourLengths); + + double distancePointLine(const cv::Point2f& LP1, + const cv::Point2f& LP2, + const cv::Point2f& p) const ; + + void removeFilaments(QVector > &sumOfContourLengths, + const QVector &valid, + std::vector >& contours ); + + double polyArea(const QVector& p) const; + + double polyAreaCV(const std::vector& p, + const int from = 0, + const int to = -1) const; + + std::vector extractRectangles(const std::vector& thresholds, + const cv::Mat& image); + + std::vector extractLines(const std::vector &thresholds, + const cv::Mat& image); + + /** + * @brief findHistPeak find position'th peak from left or right + * @param hist + * @param fromRight + * @param windowWidth + * @param minPercentage + * @param position + * @return + */ + int findHistPeak(const cv::Mat& hist, + const bool fromRight, + const int windowWidth = 10, + const float minPercentage = 0.3, + const int position = 0) const; + + void preSelectFast(const cv::Mat &image, + const std::vector >& contours, + const std::vector& hierarchy, + const QVector& rects, + const QVector >& points, + QVector& valid) const; + + void optimizeRectangle(const cv::Mat& edgeMask, + cv::RotatedRect& rectangle); + + bool testAbort(SourceFilePtr sourceFile); + + static lbfgsfloatval_t evaluate( + void *instance, + const lbfgsfloatval_t *x, + lbfgsfloatval_t *g, + const int n, + const lbfgsfloatval_t step + ); + cv::Mat loadAndShrink(const QString& filename); + + QVector > _filesToLoad; + SourceFilePtr _current; + + QMutex _fileListMutex; + QWaitCondition _condition; + + bool _stopped; + bool _abortAndLoadNext; + + int _min; + int _max; + + double _threshold; + double _maxAspect; + int _levels; + float _maxOverlap; + float _minArea; + float _maxArea; + float _minAreaWithinImage; + float _splitMaxOffsetFrac; + float _splitMinCornerDist; + float _splitMinLengthFrac; + int _maxHierarchyLevel; + + QString _currentFilename; + + int _imSize; + int _histPositions; + int _histWindowWidth; + float _histMinPercentage; + int _histSigma; + int _cannyTr1; + int _cannyTr2; + int _medianBlurMask; + int _houghRho; + int _houghAngle; + float _houghFactor; + float _rectAngularThresh; + float _rectMinLineDistFrac; + float _rectMinDist; + float _minFrameEnergy; + double _maxAreaFractionEnergy; + float _e1; + float _e2; + float _e3; + float _e4; + int _maxRectOptimizeIterations; + int _minColorHeight; + + static cv::Mat _currentImageForRectOpt; + + const QImage::Format _qImageFmt; +}; + +#endif // PRELOADSOURCE_H diff --git a/scannerExtract/scannerIcons.qrc b/scannerExtract/scannerIcons.qrc new file mode 100644 index 0000000..999cbca --- /dev/null +++ b/scannerExtract/scannerIcons.qrc @@ -0,0 +1,24 @@ + + + images/sizeChange.png + images/rotate.png + images/Media-seek-backward.svg + images/Media-seek-forward.svg + images/Media-skip-backward.svg + images/Media-skip-forward.svg + images/View-zoom-1.svg + images/View-zoom-fit.svg + images/View-zoom-in.svg + images/View-zoom-out.svg + images/Document-save.svg + images/Edit-delete.svg + images/Gnome-scanner.svg + images/Gnome-image-x-generic.svg + images/logo.svg + WARRANTY + images/Gnome-image-x-generic_rot.svg + images/Refresh_file.svg + WARRANTY_DE + images/overview.png + + diff --git a/scannerExtract/scannerImageExtractor_ico.rc b/scannerExtract/scannerImageExtractor_ico.rc new file mode 100644 index 0000000..ad3f900 --- /dev/null +++ b/scannerExtract/scannerImageExtractor_ico.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "images/logo.ico" \ No newline at end of file diff --git a/scannerExtract/settings.h b/scannerExtract/settings.h new file mode 100644 index 0000000..923314b --- /dev/null +++ b/scannerExtract/settings.h @@ -0,0 +1,7 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#define IMAGE_ORGANIZATION_ORG "Dominik Rueß" +#define IMAGE_ORGANIZATION_APP "scannerExtract" + +#endif // SETTINGS_H diff --git a/scannerExtract/settingsdialog.cpp b/scannerExtract/settingsdialog.cpp new file mode 100644 index 0000000..09d9eea --- /dev/null +++ b/scannerExtract/settingsdialog.cpp @@ -0,0 +1,128 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "settingsdialog.h" + +#include +#include +#include + +SettingsDialog::SettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsDialog) +{ + ui->setupUi(this); + + ui->tabWidget->removeTab(1); + load(); + + connect(ui->toolButton_folder, SIGNAL(clicked()), this, SLOT(setTargetDir())); + + connect(ui->buttonBox, SIGNAL(accepted()), SLOT(accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), SLOT(rejected())); +} + +void SettingsDialog::load() +{ + QSettings settings(tr(IMAGE_ORGANIZATION_ORG), tr(IMAGE_ORGANIZATION_APP)); + + + QString home = QDir::homePath() + "/" + tr("Pictures") + "/" + tr("ScannedImageExtractor") + "/"; + ui->lineEdit_location->setText(settings.value("targetdir", home).toString()); + ui->lineEdit_prefix->setText(settings.value("prefix", "fromScanner_").toString()); + + ui->doubleSpinBox_thres->setValue(settings.value("thresh", 5.0).toDouble()); + ui->doubleSpinBox_maxAspect->setValue(settings.value("max aspect", 2.1).toDouble()); + + ui->spinBox_levels->setValue(settings.value("levels", 3).toInt()); + ui->spinBox_maxOverlap->setValue(settings.value("maxOverlap", 30).toInt()); + ui->spinBox_minArea->setValue(settings.value("minArea", 10.0).toInt()); + ui->spinBox_minAreaWithinImage->setValue(settings.value("minAreaWithinImage", 90).toInt()); + ui->spinBox_splitMaxOffsetFrac->setValue(settings.value("splitMaxOffsetFromDiag", 20).toInt()); + ui->spinBox_splitMinCornerDist->setValue(settings.value("splitMinCornerDist", 30).toInt()); + ui->spinBox_splitMinLengthFrac->setValue(settings.value("splitMinLengthFrac", 35).toInt()); + ui->spinBox_maxHierarchyLevel->setValue(settings.value("maxHierarchyLevel", 15).toInt()); + ui->spinBox_preload->setValue(settings.value("preload", 10).toInt()); +} + +void SettingsDialog::save() +{ + + QSettings settings(tr(IMAGE_ORGANIZATION_ORG), tr(IMAGE_ORGANIZATION_APP)); + + QString dir = ui->lineEdit_location->text(); + dir.replace("\\", "/"); + if (dir.right(1) != "/") + { + dir = dir + "/"; + } + ui->lineEdit_location->setText(dir); + settings.setValue("targetdir", dir); + settings.setValue("prefix", ui->lineEdit_prefix->text()); + + settings.setValue("thresh", ui->doubleSpinBox_thres->value()); + settings.setValue("max aspect", ui->doubleSpinBox_maxAspect->value()); + + settings.setValue("levels", ui->spinBox_levels->value()); + settings.setValue("maxOverlap", ui->spinBox_maxOverlap->value()); + settings.setValue("minArea", ui->spinBox_minArea->value()); + settings.setValue("minAreaWithinImage", ui->spinBox_minAreaWithinImage->value()); + settings.setValue("splitMaxOffsetFromDiag", ui->spinBox_splitMaxOffsetFrac->value()); + settings.setValue("splitMinCornerDist", ui->spinBox_splitMinCornerDist->value()); + settings.setValue("splitMinLengthFrac", ui->spinBox_splitMinLengthFrac->value()); + settings.setValue("maxHierarchyLevel", ui->spinBox_maxHierarchyLevel->value()); + + settings.setValue("preload", ui->spinBox_preload->value()); +} + +SettingsDialog::~SettingsDialog() +{ + delete ui; +} + +void SettingsDialog::accepted() +{ + // save and close + save(); + emit newValues(); + close(); +} + +void SettingsDialog::rejected() +{ + // reset and close + load(); + close(); +} + + +void SettingsDialog::setTargetDir() +{ + QString location = ui->lineEdit_location->text(); + location = QFileDialog::getExistingDirectory(this, + tr("Select Output directory"), + location); + + if (location.length() == 0) { + return; + } + + ui->lineEdit_location->setText(QDir(location).canonicalPath() ); +} diff --git a/scannerExtract/settingsdialog.h b/scannerExtract/settingsdialog.h new file mode 100644 index 0000000..a7a1b6c --- /dev/null +++ b/scannerExtract/settingsdialog.h @@ -0,0 +1,74 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include + +#include "settings.h" +#include "ui_settingsdialog.h" + +namespace Ui { +class SettingsDialog; +} + +class SettingsDialog : public QDialog +{ + Q_OBJECT + +signals: + void newValues(); + +public: + explicit SettingsDialog(QWidget *parent = 0); + ~SettingsDialog(); + + double getThresh() const { return ui->doubleSpinBox_thres->value(); } + double getMaxAspect() const { return ui->doubleSpinBox_maxAspect->value(); } + + QString getTargetDir() const { return ui->lineEdit_location->text(); } + QString getPrefix() const { return ui->lineEdit_prefix->text(); } + + int getLevels() const { return ui->spinBox_levels->value(); } + double getMaxOverlap() const { return (double)ui->spinBox_maxOverlap->value() / 100.0; } + double getMinArea() const { return (double)ui->spinBox_minArea->value() / 100.0 ; } + double getMinAreaWithinImage() const { return (double)ui->spinBox_minAreaWithinImage->value() / 100.0 ; } + double getSplitMaxoffsetFrac() const { return (double)ui->spinBox_splitMaxOffsetFrac->value() / 100.0 ; } + double getSplitMinCornerDist() const { return (double)ui->spinBox_splitMinCornerDist->value() / 100.0 ; } + double getSplitMinLengthFrac() const { return (double)ui->spinBox_splitMinLengthFrac->value() / 100.0 ; } + double getMaxHierarchyLevel() const { return ui->spinBox_maxHierarchyLevel->value(); } + int getNumPreLoad() const { return ui->spinBox_preload->value(); } + +private slots: + void setTargetDir(); + + void save(); + void load(); + + void accepted(); + + void rejected(); + +private: + Ui::SettingsDialog *ui; +}; + +#endif // SETTINGSDIALOG_H diff --git a/scannerExtract/settingsdialog.ui b/scannerExtract/settingsdialog.ui new file mode 100644 index 0000000..aa326d5 --- /dev/null +++ b/scannerExtract/settingsdialog.ui @@ -0,0 +1,439 @@ + + + SettingsDialog + + + + 0 + 0 + 565 + 583 + + + + Scanner Extract Settings + + + + + + true + + + 0 + + + + Generic Settings + + + + + + Generic Settings + + + + + + + + + pre-load so many images: + + + + + + + image write prefix: + + + + + + + + + + select folder + + + select folder + + + select folder + + + ... + + + + + + + write to folder: + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + Image Extraction Settings (simple) + + + + + + + 50 + true + false + + + + Subframe requirements + + + false + + + + + + + margin-left:10px; + + + minimum subframe area x%, of original image area: + + + + + + + + + + margin-left:10px + + + <html><head/><body><p>minimum subframe area x%, which needs to be within<br/>original image:</p></body></html> + + + false + + + + + + + + + + margin-left:10px + + + maximum aspect ratio: + + + + + + + 1 + + + 1.000000000000000 + + + + + + + margin-left:10px + + + <html><head/><body><p>if x% of the subframe is contained in another, <br/>choose the larger (area wise):</p></body></html> + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Advanced + + + + + + Automated Image Extraction settings (ADVANCED) + + + + + + + + + 1 + + + + + + + 1 + + + 0.100000000000000 + + + + + + + margin-left:10px; + + + <html><head/><body><p>Maximum displacement from diagonal of the <br/>convexity defect candidates (% of diagonal):</p></body></html> + + + + + + + margin-left:10px + + + <html><head/><body><p>number of levels (the more the stable but also the less <br/>close images may be placed to each other):</p></body></html> + + + + + + + + true + + + + Rectangle splitting (for diagonally overlapping subframes) + + + + + + + + + + margin-left:10px; + + + <html><head/><body><p>overlapping minimum distance from enclosing <br/>rectangle corner (% of diagonal):</p></body></html> + + + + + + + + + + margin-left:10px; + + + <html><head/><body><p>sub contour of needs to be longer than x% of the <br/>diagonal length of the enclosing rectangle:</p></body></html> + + + + + + + + true + + + + Pre-Processing + + + + + + + margin-left:10px + + + threshold for edge image (x times the number of levels): + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + true + + + + Contours + + + + + + + margin-left:10px + + + Maximum contour hierarchy level + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + true + + + + margin-right:10px + + + Note: Any changes will only apply to unvisited images or if reloaded + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/scannerExtract/sourcefile.cpp b/scannerExtract/sourcefile.cpp new file mode 100644 index 0000000..d6856c8 --- /dev/null +++ b/scannerExtract/sourcefile.cpp @@ -0,0 +1,23 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "sourcefile.h" + +int SourceFile::nextId = 0; diff --git a/scannerExtract/sourcefile.h b/scannerExtract/sourcefile.h new file mode 100644 index 0000000..b029481 --- /dev/null +++ b/scannerExtract/sourcefile.h @@ -0,0 +1,57 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef SOURCEFILE_H +#define SOURCEFILE_H + +#include +#include + +#include "TargetImage.h" + + +typedef std::tr1::shared_ptr QGraphicsPixmapItemPtr; + +struct SourceFile +{ + QFileInfo source; + QList targets; + QGraphicsPixmapItemPtr image; + QImage imageOrig; + int id; + + bool error; + bool changed; + SourceFile() + : id(++nextId) + , error(false) + , changed(true) + { + } + + double scale; +private: + static int nextId; + +}; + +typedef std::shared_ptr SourceFilePtr; + +#endif // SOURCEFILE_H diff --git a/scannerExtract/trans_scannedImageExtractor_de.ts b/scannerExtract/trans_scannedImageExtractor_de.ts new file mode 100644 index 0000000..1bb0df7 --- /dev/null +++ b/scannerExtract/trans_scannedImageExtractor_de.ts @@ -0,0 +1,1139 @@ + + + + + DialogAbout + + Dialog + Über Scanned Image Extractor + + + + About Scanned Image Extractor + +Über Scanned Image Extractor + + + + Scanned Image Extractor + + + + + Version + + + + + <html><head/><body><p align="justify"><span style=" font-style:italic;">Scanned Image Extractor</span> is a programm which allows fast and efficient extraction of multiple photographs of scanned albums</p></body></html> + <html><head/><body><p align="justify"><span style=" font-style:italic;">Scanned Image Extractor</span> ist ein Programm zur schnellen Extraktion von Fotografien aus Scannerbildern (z.B. von Alben)</p></body></html> + + + + <html><head/><body><p>Copyright 2015, Dominik Rueß <a href="mailto:pivot@dominik-ruess.de"><span style=" text-decoration: underline; color:#0000ff;">scanner-extractor@dominik-ruess.de</span></a></p></body></html> + + + + + <html><head/><body><p>License: <span style=" font-style:italic;">The GNU General Public License (GPL), Version 3</span></p></body></html> + <html><head/><body><p>Lizenz: <span style=" font-style:italic;">The GNU General Public License (GPL), Version 3</span></p></body></html> + + + + <html><head/><body><p>Bugs, feature requests or spelling errors can be reported to: <a href="https://sourceforge.net/p/scannedimageextractor/tickets/"><span style=" text-decoration: underline; color:#0000ff;">sourceforge.net/p/scannedimageextractor/tickets/ </span></a>(or email).<br/>I'm always looking forward to translations into YOUR language.</p></body></html> + <html><head/><body><p>Bugs, feature requests or spelling errors can be reported to: <a href="https://sourceforge.net/p/scannedimageextractor/tickets/"><span style=" text-decoration: underline; color:#0000ff;">https://sourceforge.net/p/scannedimageextractor/tickets/ </span></a>(or email).<br/>I'm always looking forward to translations into YOUR language.</p></body></html> + <html><head/><body><p>Fehler, Verbesserungsvorschläge und sonstige Probleme bitte bei <a href="https://sourceforge.net/p/scannedimageextractor/tickets/"><span style=" text-decoration: underline; color:#0000ff;">sourceforge.net/p/scannedimageextractor/tickets/ </span></a>eintragen (oder per email).<br/>I'm always looking forward to translations into YOUR language.</p></body></html> + + + + <html><head/><body><p align="justify">If you like <span style=" font-style:italic;">Scanned Image Extractor</span> or if you wish to support the author consider donating</span>: </p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">via Sourceforge (Donation for user <span style=" font-style:italic;">domsen</span>): <a href="https://sourceforge.net/p/scannedimageextractor/donate/"><span style=" text-decoration: underline; color:#0000ff;">sourceforge.net/p/scannedimageextractor/donate/</span></a></li><li align="justify" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">personally: contact me at <a href="mailto:donate@dominik-ruess.de"><span style=" text-decoration: underline; color:#0000ff;">donate@dominik-ruess.de</span></a></li></ul></body></html> + <html><head/><body><p align="justify">Wenn sie <span style=" font-style:italic;">Scanned Image Extractor</span> mögen oder Sie den Autor dieses Programms unterstützen wollen, überlegen Sie zu spenden</span>: </p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">via Sourceforge: <a href="https://sourceforge.net/p/scannedimageextractor/donate/"><span style=" text-decoration: underline; color:#0000ff;">sourceforge.net/p/scannedimageextractor/donate/</span></a></li><li align="justify" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">kontaktieren Sie mich per E-Mail <a href="mailto:donate@dominik-ruess.de"><span style=" text-decoration: underline; color:#0000ff;">donate@dominik-ruess.de</span></a></li></ul></body></html> + + + <html><head/><body><p align="justify">If you like <span style=" font-style:italic;">Scanned Image Extractor</span> or if you wish to support the author consider donating</span>: </p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">via Sourceforge (Donation for user <span style=" font-style:italic;">domsen</span>): <a href="https://sourceforge.net/p/scannedimageextractor/donate/"><span style=" text-decoration: underline; color:#0000ff;">https://sourceforge.net/p/scannedimageextractor/donate/</span></a></li><li align="justify" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">personally: contact me at <a href="mailto:donate@dominik-ruess.de"><span style=" text-decoration: underline; color:#0000ff;">donate@dominik-ruess.de</span></a></li></ul></body></html> + <html><head/><body><p align="justify">Wenn sie <span style=" font-style:italic;">Scanned Image Extractor</span> mögen oder Sie den Autor dieses Programms unterstützen wollen, überlegen Sie zu spenden</span>: </p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">via Sourceforge: <a href="https://sourceforge.net/p/scannedimageextractor/donate/"><span style=" text-decoration: underline; color:#0000ff;">https://sourceforge.net/p/scannedimageextractor/donate/</span></a></li><li align="justify" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">kontaktieren Sie mich per E-Mail <a href="mailto:donate@dominik-ruess.de"><span style=" text-decoration: underline; color:#0000ff;">donate@dominik-ruess.de</span></a></li></ul></body></html> + + + + Credits go to the GNOME project (i.e. the gome icon artists) for the application icon (Creative Commons Attribution-Share Alike 3.0 Unported), which consists of Gnome-image-x-generic.svg and Gnome-scanner.svg. + Vielen Dank an das GNOME project (insb. an die "gnome-icon artists") für das Anwendungssymbol (Creative Commons Attribution-Share Alike 3.0 Unported), einer Kombination aus Gnome-image-x-generic.svg und Gnome-scanner.svg. + + + + &Ok + + + + + :WARRANTY_EN + :WARRANTY_DE + + + + version %1.%2.%3 - %4bit version + Version %1.%2.%3 - %4Bit-Version + + + version %1.%2.%3 + Version %1.%2.%3 + + + + HelpDialog + + Dialog + Hilfe + + + + Help + Hilfe + + + + Scanned Image Extractor Help + Scanned Image Extractor Hilfe + + + + Find the more detailed online help at <a href="http://dominik-ruess.de/scannerExtract">dominik-ruess.de/scannerExtract</a> + Detailllierte Hilfe finden Sie unter <a href="http://dominik-ruess.de/scannerExtract">dominik-ruess.de/scannerExtract</a> + + + + This is a short introduction on how to use <i>Scanned Image Extractor</i>. Scroll down to see the complete help text. <br> +Now, here is an example of how the user interface of the program may look like: + Dies ist eine kurze Einleitung über die Benutzung von <i>Scanned Image Extractor</i>. Scrollen Sie weiter nach unten, um den Text vollständig zu sehen.<br>Hier sehen Sie ein Beispiel, wie die Oberfläche des Programms aussehen könnte: + + + + image + + + + + First of all, you load a scanner image. It will appear in the area marked with (1). The program will suggest some photographs. These are marked with a rectangle. Once you select such a rectangle, its preview will apear in the area (2). <br>The properties of these rectangles can be changed in area (3). aspect ratio changes are located in (4) and the orientation of every rectangle/photograph can be changed in (5). + Als erstes laden Sie ein Scannerbild. Es wird in dem mit (1) markierten Bereich erscheinen. Das Programm wird Ihnen Fotografien vorschlagen. Diese sind mit einem Rechteck gekenntzeichnet. Sobald Sie eines der Rechtecke markieren, wird dessen Vorschau in (2) erscheinen.<br>Die Eigenschaften der Rechtecke können im Bereich (3) geändert werden: Die Seitenverhältniseinstellungen sind in (4) und die Ausrichtung der Bilder können in (5) gesteuert werden. + + + + <b>Photograph/Rectangle Handling:</b> +<br>You can modify the shape of the output photographs/rectangles:<ul> +<li>drag corner or edge of rectangles for size changes</li> + <li>press CTRL for symmetric change</li> + <li>keep SHIFT pressed before dragging corner, this rotates the rectangle</li> + <li>add new rectangle: deselect all (click somewhere empty). Click on a photograph corner, keep mouse clicked and drag line to a second corner. Then move/resize the new rectangle and click to release.</li> + </ul> +If you process to the next scanned image, the previous photographs will be extracted <i>automatically</i>. + <b>Photograph/Rectangle Handling:</b> +<br>You can modify the shape of the output photographs/rectangles:<ul> +<li>drag corner or edge of rectangles for size changes</li> + <li>press CTRL for symmetric change</li> + <li>keep SHIFT pressed before dragging corner, this rotates the rectangle</li> + <li>add new rectangle: deselect all (click somewhere empty). Click on a photograph corner, keep mouse clicked and drag line to a second corner. Then move/resize the new rectangle and click to release.</li> + </ul> + <b>Fotografie-/Rechteck-Manipulation:</b> +<br>Sie können die Form und Lage des Ausgangsbildes beeinflussen: +<ul><li>ziehen Sie die Ecken oder Seiten des ausgewählten Rechtecks</li><li>halten Sie STRG gedrückt für symmetrische Änderung</li><li>rotieren, halten sie dafür die Umschalttaste gedrückt, bevor Sie die Ecken ziehen</li><li>neue Rechtecke hinzufügen: wählen Sie alle ab (irgendwo ins Leere klicken). Klicken Sie auf eine Ecke einer Fotografie, halten Sie die Maus gedrückt und ziehen Sie die rote Linie zu einer zweiten Ecke. Dann das Rechteck ziehen/bewegen und klicken zum fertigstellen.</li></ul> +Sobald Sie auf das nächste Scannerbild wechseln, werden die Ausgaben des vorherigen Bildes <i>automatisch</i> im Hintergrund extrahiert. + + + + <b>Keyboard shortcuts:</b><table> + <tr><td>Keys 0-9</td><td> select aspect ratios</td></tr> + <tr><td>Keys 'a', 's', 'd' and 'f'</td><td> change orientation of current target</td></tr> + <tr><td style="padding-right:20px;">Keys CTRL+V and CTRL+B</td><td> navigate to prev. and next input image</td></tr> + <tr><td>Keys N, M and delete</td><td> navigate prev. and next target or delete target</td></tr></table> + <b>Tastaturkürzel:</b><br><table><tr><td>Tasten 0-9</td><td> Seitenverhältnis auswählen</td></tr><tr><td>Tasten 'a', 's', 'd' und 'f'</td><td> Die Ausrichtung für die Auswahl anpassen</td></tr><tr><td style="padding-right:20px;">Tasten STRG+V und STRG+B</td><td>zum vorherigen und nächsten Scannerbild</td></tr><tr><td>Tasten N, M und Entfernen</td><td>das vorherige/nächste Rechteck oder akt. löschen</td></tr></table> + + + + &OK + + + + + ImageScene + + + + + + %1 of %2 + %1 von %2 + + + + copy error + Kopier-Fehler + + + + Could not copy a target from scanned image '%s'' - enough disc space left ? enough RAM available ? If the images are too large, the 32bit version of this software might also be in trouble + Konnte eine Fotografie nicht kopieren, vom dem Scannerbild '%s' - haben Sie genügend Speicherplatz? Auch kann die 32bit Version dieser Software Probleme bei sehr großen Eingangsbildern bekommen + + + Could not copy last target - enough disc space left ? + Konnte letztes Ziel nicht kopieren - genügend Speicherplatz vorhanden ? + + + + refresh + Neu laden + + + + This will overwrite currently (and possibly saved) extracted images - continue ? + Diese Aktion wird die aktuellen Zielbilder überschreiben. Fortsetzen ? + + + + MainWindow + + + MainWindow + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Scanned Image:</span></p></body></html> + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Scanner-Bild:</span></p></body></html> + + + + + + The input image view. Zoom in/out (also use mousewheel). Create new output image by start ing to drag. Manipulate output images by dragging on their borders or corners (with SHIFT+drag it is rotating). + Die Ansicht des Eingangs-Bildes (Scanner-Bild). Zoomen Sie herein und raus (auch mit dem Mausrad). Erstellen Sie ein neues Ausgangs-/Zielbild indem Sie an einer Bildecke beginnen zu klicken und zu ziehen. Sie können Zielbilder manipulieren, indem sie die Auswahl ziehen oder an den Ecken bzw. Kanten mit der Maus ziehen. (Umschalttase über eine Ecke gedrückt halten, um zu rotieren). + + + + + + Zoom in + Hereinzoomen + + + + + + + + + + + + Zoom out + Herauszoomen + + + + - + + + + + + + Zoom to scale 1:1 + 1:1 zoom + + + + + 1:1 + + + + + + + Zoom fit + Zoom einpassen + + + + fit + einpassen + + + + + + Go to first file in the current directory + Zum ersten Bild im aktuellen Verzeichnis + + + + |< + + + + + + + Go to previous file in the current directory + Zum vorherigen Bild im aktuellen Verzeichnis gehen + + + + < + + + + + Ctrl+V + + + + + + + Go to next file in the current directory (CTRL+B) + Zum nächsten Bild im aktuellen Verzeichnis gehen + + + + > + + + + + Ctrl+B + + + + + + + Go to last file in the current directory + Zum letzten Bild im aktuellen Verzeichnis + + + + >| + + + + + + + Save all output images for current input image (green=has already been saved) + Alle Ziel-/Ausgangsbilder des aktuellen Eingangsbildes speichern (grün heißt, es wurde gespeichert) + + + + save + Speichern + + + + Ctrl+S + + + + + ... + + + + + Set aspect options for extracted images + Seitenverhältnis-Einstellungen für die Ausgangsbilder + + + + Aspect Ratio + Seitenverhältnis + + + + + + Set aspect of output images to 1:1 (1) + Seitenverhältnis des Ausgangsbildes auf 1:1 setzen + + + + 1 + + + + + + + Set aspect of output images to 5:4 (8) + Seitenverhältnis des Ausgangsbildes auf 5:4 setzen + + + + 5:4 + + + + + 8 + + + + + + + Set aspect of output images to 3:2 (2) + Seitenverhältnis des Ausgangsbildes auf 3:2 setzen + + + + 3:2 + + + + + 2 + + + + + + + Set aspect of output images to 2:1 (4) + Seitenverhältnis des Ausgangsbildes auf 2:1 setzen + + + + 2:1 + + + + + 4 + + + + + + + Set aspect of output images to 4:1 (6) + Seitenverhältnis des Ausgangsbildes auf 4:1 setzen + + + + 4:1 + + + + + 6 + + + + + + + Set aspect of output images to 5:3 (7) + Seitenverhältnis des Ausgangsbildes auf 5:3 setzen + + + + 5:3 + + + + + 7 + + + + + + + Set aspect of output images to manual (0) + Seitenverhältnis des Ausgangsbildes auf manuelle Eingabe setzen + + + + Manual + Manuelle Eingabe + + + + 0 + + + + + + + Set aspect of output images to 4:3 (3) + Seitenverhältnis des Ausgangsbildes auf 4:3 setzen + + + + 4:3 + + + + + 3 + + + + + + + Set aspect of output images to 16:9 (9) + Seitenverhältnis des Ausgangsbildes auf 16:9 setzen + + + + 16:9 + + + + + 9 + + + + + + + Set aspect of output images to 3:1 (5) + Seitenverhältnis des Ausgangsbildes auf 3:1 setzen + + + + 3:1 + + + + + 5 + + + + + + + Set aspect of output images to free or unconstrained (CTRL+-) + Seitenverhältnis des Ausgangsbildes auf nicht einschränken (CTRL+-) + + + + Free + Frei + + + + Ctrl+- + + + + + enforce this ratio in next unprocessed image + Seitenverhältnis im nächsten unbearbeiteten Bild wie oben + + + + Orientation of Output + Ausrichtung der Ausgangsbildes + + + + + + the output orientation change is none (A) + Ausrichtungsanpassung: keine + + + + 0° + + + + + A + + + + + + + the output orientation change is 180° (upside down) - (KEY D) + Ausrichtungsanpassung: 180° - (Taste D) + + + + 180° + + + + + D + + + + + + + the output orientation change is 90° (rotate right) - (KEY S) + Ausrichtungsanpassung: 90° - (Taste S) + + + + 90° + + + + + S + + + + + + + the output orientation change is 180° (rotate left) - (KEY F) + Ausrichtungsanpassung: 270° - (Taste F) + + + + 270° + + + + + F + + + + + Misc + Allgemein + + + + + + detected images will be cropped by this size + detected images will be shrinked by this size + Ausgangsbilder werden um diesen Betrag ausgeschnitten + + + + + + This crop is applied to all new targets. Individual target crops can be adapted by selecting it and change "current" + Dieser Zuschnitt wird allen neuen Fotografien zugewiesen. Verwenden Sie "aktuell", um den Zuschnitt für ausgewählte Fotografien individuell anzupassen + + + + Crop border (%), initial: + Rand abschneiden (%), Standard-Wert: + + + + current: + aktuell: + + + + + + After clicking on this button, click on any element to get some short help about it + Wenn Sie auf diesen Button klicken, klicken Sie auf ein beliebiges Elemen, um Hilfe dafür zu erhalten + + + + ? + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Selected Output Image (Preview):</span></p></body></html> + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Ausgewähltes Ausgangsbild (Vorschau):</span></p></body></html> + + + + + + This is the preview area for the currently selected output image + Das ist die Vorschau für das aktuelle gewählte Ausgangsbild + + + + + + Go to previous output image within the current input + Zum vorherigen Ausgangsbild + + + + &prev. Item + &vorheriges Ausgangsbild + + + + N + + + + + + + Go to next output image within the current input (M) + Zum nächsten Ausgangsbild + + + + &next Item + &nächstes Ausgangsbild + + + + M + + + + + + + remove the current output image (will not be saved to hard drive) + Das aktuelle Ausgangsbild entfernen (wird nicht auf der Festplatte gespeichert) + + + + &delete Item + Ausgangsbild &löschen + + + + &File + &Datei + + + + Help + Hilfe + + + + &Load File + Datei &laden + + + + + Load an input image, which usually is a scanned image from an album + Ein Eingangsbild laden - normalerweise ein eingescanntes Album-Abbild (oder mehrere Einzelbilder) + + + + Ctrl+L + + + + + Set &Target Directory + Das &Ausgangs-/Zielverzeichnis setzen + + + + + Set Output Directory + Das Ausgangs-/Zielverzeichnis setzen + + + + + Set the directory where the extracted files will be written to + Das Ausgangs-/Zielverzeichnis setzen (dort werden die extrahierten Bilder gespeichert) + + + + Ctrl+T + + + + + &Exit + + + + + + Close the program + Das Programm schließen + + + + &About + &Über Scanned Image Extractor + + + + About &Qt + Über &Qt + + + + &Help + Online &help + &Hilfe + + + + F1 + + + + + Support by donation + Unterstützung durch Spenden + + + + Check for new version + Auf eine neue Version prüfen + + + + &Settings + &Einstellungen + + + + About liblbfgs + Über liblbfgs + + + + About Open&CV + Über Open&CV + + + + Scanned Image Extractor + + + + + Hover the mouse pointer over an element to get help + Halten Sie den Mauszeiger über ein Element, um einen Hilfetext zu erhalten + + + + Load Image + Bild Laden + + + + Images (%1) + Bilder (%1) + + + + Already saved + Bereits gespeichert + + + + The images have already been extracted for this scan, do you want to save them again? + Die Ausgangs-Bilder wurden bereits gespeichert - wollen Sie sie nochmal speichern? + + + + Support Scanned Image Extractor + Support Scanned Imaged Extract + Unterstützen Sie Scanned Image Extractor + + + + donatehint + + + + + Retrieving version data + Hole Versionsinformation + + + + asdf + + + + + New version of <i>Scanned Image Extractor</i> available: <b>%1.%2.%3</b> (current: %4.%5.%6) + New version of <i>Scanned Imaged Extractor</i> available: <b>%1.%2.%3</b> (current: %4.%5.%6) + Neue Version von <i>Scanned Image Extractor</i> verfügbar: <b>%1.%2.%3</b> (aktuell: %4.%5.%6) + + + + Download: <a href="%1">%2</a> + + + + + <b>Changelog:</b> + <b>Änderungshistorie:</b> + + + + close + schließen + + + + no connection + keine Verbindung + + + + Was not able to connect to new version data server. Please check manually + Konnte keine Verbindung zu den Versionsdaten aufbauen. Bitte prüfen Sie manuell nach updates + + + + no update necessary + Kein Update nötig - Sie haben die aktuelle Version + + + + There is no new version of Scanned Image Extractor! + Es gibt keine neuere Version von <i>Scanned Image Extractor</i>! + + + + liblbfgs + + + + + <a href="http://www.chokkan.org/software/liblbfgs/">liblbfgs</a> is an optimization/energy minimization library which implements the Limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm (L-BFGS).Copyright (c) 2002-2014 by Naoaki Okazaki - <a href="http://opensource.org/licenses/mit-license.php">MIT license</a> + <a href="http://www.chokkan.org/software/liblbfgs/">liblbfgs</a> ist eine Optimierungs-/Energie-Minimierungs-Bibliothek, welche den Limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm (L-BFGS) implementiert.Copyright (c) 2002-2014 by Naoaki Okazaki - <a href="http://opensource.org/licenses/mit-license.php">MIT license</a> + + + + finished copying '%1' to '%2' + '%1' in '%2' erfolgreich gespeichert + + + + Find the online help at <a href="http://dominik-ruess.de/scannerExtract">dominik-ruess.de/scannerExtract</a><br><br><b>Workflow:</b><ol><li>load a scanned image</li><li>the system will suggest photographs, you can now:<ol><li>accept the suggestion(s)</li><li>manipulate suggestions: <ul><li>drag corner or edge of rectangles</li><li>press CTRL for symmetric change</li><li>keep SHIFT pressed before dragging corner, this rotates the rectangle</li></ul></li><li>add new rectangle: deselect all (click somewhere empty). Click on a photograph corner, keep mouse clicked and drag line to a second corner. Then move/resize the new rectangle and click to release.</li></ol></li><li>the rectangles will be saved automatically when you go to the next scanned image</li></ol><b>Keyboard shortcuts:</b><br><table><tr><td>Keys 0-9</td><td> select aspect ratios</td></tr><tr><td>Keys 'a', 's', 'd' and 'f'</td><td> change orientation of current target</td></tr><tr><td>Keys CTRL+V and CTRL+B</td><td> navigate to prev. and next input image</td></tr><tr><td>Keys N, M and delete</td><td> navigate prev. and next target or delete target</td></tr></table> + Find the online help at <a href="http://dominik-ruess.de/scannerExtract">dominik-ruess.de/scannerExtract</a><br><br><b>Workflow:</b><ol><li>load a scanned image</li><li>the system will suggest photographs, you can now:<ol><li>accept the suggestion(s)</li><li>manipulate suggestions: <ul><li>drag corner or edge of rectangles</li><li>press CTRL for symmetric change</li><li>keep SHIFT pressed before dragging corner, this rotates the rectangle</li></ul></li><li>add new rectangle: click on an image corner, keep mouse clicked and drag line to a second corner. then move the new rectangle and click to release.</li></ol></li><li>the rectangles will be saved automatically when you go to the next scanned image</li></ol><b>Keyboard shortcuts:</b><br><table><tr><td>Keys 0-9</td><td> select aspect ratios</td></tr><tr><td>Keys 'a', 's', 'd' and 'f'</td><td> change orientation of current target</td></tr><tr><td>Keys CTRL+V and CTRL+B</td><td> navigate to prev. and next input image</td></tr><tr><td>Keys N, M and delete</td><td> navigate prev. and next target or delete target</td></tr></table> + Finden Sie ausführliche Online-Hilfe unter <a href="http://dominik-ruess.de/scannerExtract">dominik-ruess.de/scannerExtract</a><br><br><b>Arbeitsablauf:</b><ol><li>Laden Sie ein Scannerbild</li><li>Das System wird nun Fotografien vorschlagen, nun können Sie:<ol><li>diese akzeptieren</li><li>diese manipulieren: <ul><li>ziehen Sie die Ecken oder Seiten des ausgewählten Rechtecks</li><li>halten Sie STRG gedrückt für symmetrische Änderung</li><li>rotieren, halten sie dafür die Umschalttaste gedrückt, bevor Sie die Ecken ziehen</li></ul></li><li>neue Rechtecke hinzufügen: wählen Sie alle ab (irgendwo ins Leere klicken). Klicken Sie auf eine Ecke einer Fotografie, halten Sie die Maus gedrückt und ziehen Sie die rote Linie zu einer zweiten Ecke. Dann das Rechteck ziehen/bewegen und klicken zum fertigstellen.</li></ol></li><li>Rechtecke werden automatisch gespeichert, sobald Sie zum nächsten Scannerbild gehen</li></ol><b>Tastaturkürzel:</b><br><table><tr><td>Tasten 0-9</td><td> Seitenverhältnis auswählen</td></tr><tr><td>Tasten 'a', 's', 'd' und 'f'</td><td> Die Ausrichtung für die Auswahl anpassen</td></tr><tr><td>Tasten STRG+V und STRG+B</td><td>zum vorherigen und nächsten Scannerbild</td></tr><tr><td>Tasten N, M und Entfernen</td><td>das vorherige/nächste Rechteck oder akt. löschen</td></tr></table> + + + + Startup Hint + Starthinweis + + + + startupHelp + + + + + About OpenCV + Über OpenCV + + + + <a href="http://opencv.org">OpenCV</a> a powerful and free (BSD-License) computer vision library. Scanned Image Extractor can use version 2 or 3 of OpenCV. Copyright (c) 2015 by <a href="http://itseez.com/">itseez</a> + <a href="http://opencv.org">OpenCV</a> a powerful and free (BSD-License) computer vision library. Scanned Image Extractor can use Version 2 or 3 of OpenCV.Copyright (c) 2015 by <a href="http://itseez.com/">itseez</a> + <a href="http://opencv.org">OpenCV</a> ist eine mächtige und freie (BSD-Lizenz) Computer Vision Bibliothek. Scanned Image Extractor kann Version 2 oder 3 von OpenCV benutzen. Copyright (c) 2015 by <a href="http://itseez.com/">itseez</a> + + + + QApplication + + + :/WARRANTY_EN + start + :/WARRANTY_DE + + + + SettingsDialog + + + Scanner Extract Settings + Scanner-Extract-Einstellungen + + + + + Generic Settings + Allgemeine Einstellungen + + + + image write prefix: + Präfix für Ausgangsbilder: + + + + write to folder: + Speichere in Ordner: + + + + + + select folder + Wählen Sie den Ordner aus + + + + pre-load so many images: + Anzahl Bilder vorausladen: + + + + ... + + + + + Image Extraction Settings (simple) + Bildextraktions-Einstellungen + + + + Subframe requirements + Ausgangsbild + + + + minimum subframe area x%, of original image area: + Minimale Ausgangsbild-Fläche in x%, des Eingangsbildes: + + + + <html><head/><body><p>minimum subframe area x%, which needs to be within<br/>original image:</p></body></html> + <html><head/><body><p>Minimale Ausgangsbild-Fläche in x%, die innerhalb des <br/>Original-Bildes liegen soll:</p></body></html> + + + + maximum aspect ratio: + Maximales Seitenverhältnis: + + + + <html><head/><body><p>if x% of the subframe is contained in another, <br/>choose the larger (area wise):</p></body></html> + <html><head/><body><p>Wenn x% eines Ausgangsbildes in einem anderen enthalten sind<br/>wähle dann nur eines von beiden:</p></body></html> + + + + Advanced + + + + + Automated Image Extraction settings (ADVANCED) + + + + + + + margin-left:10px; + + + + + <html><head/><body><p>Maximum displacement from diagonal of the <br/>convexity defect candidates (% of diagonal):</p></body></html> + + + + + <html><head/><body><p>number of levels (the more the stable but also the less <br/>close images may be placed to each other):</p></body></html> + + + + + Rectangle splitting (for diagonally overlapping subframes) + + + + + <html><head/><body><p>overlapping minimum distance from enclosing <br/>rectangle corner (% of diagonal):</p></body></html> + + + + + <html><head/><body><p>sub contour of needs to be longer than x% of the <br/>diagonal length of the enclosing rectangle:</p></body></html> + + + + + Pre-Processing + + + + + threshold for edge image (x times the number of levels): + + + + + Contours + + + + + Maximum contour hierarchy level + + + + + Note: Any changes will only apply to unvisited images or if reloaded + Hinweis: Alle Änderungen werden nur auf die noch nicht gesichteten Bilder angwendet + + + + Pictures + Bilder + + + + ScannedImageExtractor + + + + + Select Output directory + Wählen Sie das Ziel-/Ausgangsverzeichnis + + + + tools + + + OK + + + + + Show hint in future + Den Hinweis in Zukunft nochmal zeigen + + + diff --git a/scannerExtract/translations b/scannerExtract/translations new file mode 100644 index 0000000..c3cc643 --- /dev/null +++ b/scannerExtract/translations @@ -0,0 +1,9 @@ + + + /home/ruess/Projekte/trunk/buildtest/trans_scannedImageExtractor_de.qm + /usr/share/qt5/translations/qt_de.qm + /usr/share/qt5/translations/qtbase_de.qm + /usr/share/qt5/translations/qt_help_de.qm + /usr/share/qt5/translations/qtbase_de.qm + + diff --git a/scannerExtract/version_scannerExtract.cpp b/scannerExtract/version_scannerExtract.cpp new file mode 100644 index 0000000..5710c78 --- /dev/null +++ b/scannerExtract/version_scannerExtract.cpp @@ -0,0 +1,23 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#include "version_scannerExtract.h" + +VersionNumberScannerExtract<0,2,DR_PATCH_NUMBER> version_scannerExtract; diff --git a/scannerExtract/version_scannerExtract.h b/scannerExtract/version_scannerExtract.h new file mode 100644 index 0000000..25c7338 --- /dev/null +++ b/scannerExtract/version_scannerExtract.h @@ -0,0 +1,38 @@ +/*********************************************************************** + * This file is part of Scanned Image Extract. + * + * Scanned Image Extract 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 + * (at your option) any later version. + * + * Scanned Image Extract 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 Scanned Image Extract. If not, see + * + * + * Copyright (C) 2015, Dominik Rueß; info@dominik-ruess.de + **********************************************************************/ + +#ifndef VERSION_SCANNER_EXTRACT_H +#define VERSION_SCANNER_EXTRACT_H + +#include "versioning.h" +#include "patchnumber.h" + + +template +struct VersionNumberScannerExtract : public VersionNumber +{ + void checkRequirements() const + { + } +}; + +extern VersionNumberScannerExtract<0, 2, DR_PATCH_NUMBER> version_scannerExtract; + +#endif // VERSION_SCANNER_EXTRACT_H