diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ca2d9..7a479b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,8 +164,13 @@ endif() find_package(OpenCV REQUIRED) # Find Qt6 -find_package(Qt6 REQUIRED COMPONENTS Core Charts Gui Widgets OpenGL) +find_package(Qt6 COMPONENTS Core Charts Gui Widgets OpenGL) +if(Qt6_FOUND) qt_standard_project_setup() +add_compile_definitions(BUILD_GUI) +else() +message(WARNING "Qt6 not found, disabling the GUI.") +endif() message(STATUS "Found CMAKE_INSTALL_BINDIR: ${CMAKE_INSTALL_BINDIR}") message(STATUS "Found CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}") @@ -180,8 +185,10 @@ set(CMAKE_AUTOUIC ON) # Enable automatic UIC # Add subdirectories for each project add_subdirectory(cvutil) -add_subdirectory(PluginManager) -add_subdirectory(RoiManager) +if (Qt6_FOUND) + add_subdirectory(PluginManager) + add_subdirectory(RoiManager) +endif() # Install OpenCV and Qt6 runtime shared libraries if (CMAKE_SYSTEM_NAME STREQUAL "Windows") @@ -189,9 +196,11 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") install(FILES $ CONFIGURATIONS Debug Release DESTINATION bin) endforeach() - foreach(qt_lib Qt6::Core Qt6::Widgets Qt6::Gui Qt6::Charts Qt6::OpenGL Qt6::OpenGLWidgets) - install(FILES $ CONFIGURATIONS Debug Release DESTINATION bin) - endforeach() + if(Qt6_FOUND) + foreach(qt_lib Qt6::Core Qt6::Widgets Qt6::Gui Qt6::Charts Qt6::OpenGL Qt6::OpenGLWidgets) + install(FILES $ CONFIGURATIONS Debug Release DESTINATION bin) + endforeach() + endif() if(MSVC) # Configurable path for MSVC LLVM bin directory @@ -260,16 +269,16 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} ) - - set_target_properties(PluginManager PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} - ) - - set_target_properties(RoiManager PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} - ) + if (Qt6_FOUND) + set_target_properties(PluginManager PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} + ) + set_target_properties(RoiManager PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} + ) + endif() # foreach(opencv_lib ${OpenCV_LIBS}) # install(FILES $ CONFIGURATIONS Debug Release DESTINATION lib/cvutil COMPONENT runtime) @@ -296,22 +305,24 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") endforeach() # Install PDB files for Qt6 libraries - foreach(qt_lib Qt6::Core Qt6::Widgets Qt6::Gui Qt6::Charts Qt6::OpenGL Qt6::OpenGLWidgets) - get_target_property(pdb_path ${qt_lib} IMPORTED_PDB_LOCATION_DEBUG) - if (NOT pdb_path) - get_target_property(pdb_path ${qt_lib} IMPORTED_LOCATION_DEBUG) - if(pdb_path) - string(REPLACE ".dll" ".pdb" pdb_path ${pdb_path}) + if (Qt6_FOUND) + foreach(qt_lib Qt6::Core Qt6::Widgets Qt6::Gui Qt6::Charts Qt6::OpenGL Qt6::OpenGLWidgets) + get_target_property(pdb_path ${qt_lib} IMPORTED_PDB_LOCATION_DEBUG) + if (NOT pdb_path) + get_target_property(pdb_path ${qt_lib} IMPORTED_LOCATION_DEBUG) + if(pdb_path) + string(REPLACE ".dll" ".pdb" pdb_path ${pdb_path}) + endif() endif() - endif() - if(pdb_path AND EXISTS ${pdb_path}) - install(FILES ${pdb_path} CONFIGURATIONS Debug DESTINATION bin) - endif() - endforeach() + if(pdb_path AND EXISTS ${pdb_path}) + install(FILES ${pdb_path} CONFIGURATIONS Debug DESTINATION bin) + endif() + endforeach() + endif() endif() # Install Qt6 support plugins -if (CMAKE_SYSTEM_NAME STREQUAL "Windows") +if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND Qt6_FOUND) foreach(qt_plugin Qt6::QWindowsIntegrationPlugin) install(FILES $ CONFIGURATIONS Debug Release DESTINATION bin/platforms) # Copy pdb files for the plugins diff --git a/README.md b/README.md index b3c6de0..2db6852 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +# Information about this fork + +Modified source code to remove dependencies on Qt6. + +TODO: +- Better replace QString +- Port RoiManager (uses QtGraphicsRectItem for calculations) + # Computer Vision UTILity toolkit (CVUTIL) cvutil is a C++ computer vision library that extends the functionality of OpenCV. The library contains some functions that are frequently used computer vision developers for convenience. The library uses multi-threading, vectorization routines available in Intel's AVX 2.0 to execute algorithms in the library. The optimizaion can be disabled optionally. diff --git a/RoiManager/CMakeLists.txt b/RoiManager/CMakeLists.txt index 4efa2ba..89fe08c 100644 --- a/RoiManager/CMakeLists.txt +++ b/RoiManager/CMakeLists.txt @@ -45,13 +45,18 @@ target_link_libraries(RoiManager PRIVATE cvutil_compiler_flags ${OpenCV_LIBS} - Qt6::Core - Qt6::Widgets - Qt6::Charts - Qt6::Gui - Qt6::OpenGL ) +if (Qt6_FOUND) + target_link_libraries(RoiManager + PRIVATE + Qt6::Core + Qt6::Widgets + Qt6::Charts + Qt6::Gui + Qt6::OpenGL + ) + # Link mimalloc for Release builds only if(USE_MIMALLOC) if(TARGET mimalloc) diff --git a/RoiManager/include/RoiManager.h b/RoiManager/include/RoiManager.h index 333980a..17000d2 100644 --- a/RoiManager/include/RoiManager.h +++ b/RoiManager/include/RoiManager.h @@ -33,7 +33,9 @@ along with cvutil; see the file COPYING. If not, see // To disable warnings from external headers. #pragma warning(push, 0) +#ifdef BUILD_GUI #include +#endif #include #include diff --git a/cvutil/CMakeLists.txt b/cvutil/CMakeLists.txt index 077ea84..5d6fafd 100644 --- a/cvutil/CMakeLists.txt +++ b/cvutil/CMakeLists.txt @@ -14,19 +14,9 @@ set(SOURCES cvutil_bwskel.cpp cvutil_bwthin.cpp cvutil_core.cpp - cvutil_figure.cpp cvutil_linesim.cpp cvutil_videowriter.cpp - main.cpp cvutil_matlab_interface.cpp - MainWindow/BatchProcessor.cpp - MainWindow/FeatureExtractorThread.cpp - MainWindow/GraphicsScene.cpp - MainWindow/InteractiveExtractorThread.cpp - MainWindow/logger.cpp - MainWindow/MainWindow.cpp - MainWindow/helper_functions.cpp - MainWindow/MaterialStyle.cpp Profiler.cpp resources.qrc ) @@ -37,29 +27,49 @@ set(HEADERS cvutil_bwskel.h cvutil_bwthin.h cvutil_core.h - cvutil_figure.h cvutil_linesim.h cvutil_templates.h cvutil_matlab_interface.h cvutil_types.h cvutil_videowriter.h - demo.h - figure.h - main.h - MainWindow/BatchProcessor.h - MainWindow/FeatureExtractorThread.h - MainWindow/GraphicsScene.h - MainWindow/InteractiveExtractorThread.h - MainWindow/logger.h - MainWindow/MainWindow.h - MainWindow/helper_functions.h - MainWindow/MaterialStyle.h profiler.h resource.h stdproto.h video.h ) +if(Qt6_FOUND) + list( + APPEND SOURCES + main.cpp + cvutil_figure.cpp + MainWindow/BatchProcessor.cpp + MainWindow/FeatureExtractorThread.cpp + MainWindow/GraphicsScene.cpp + MainWindow/InteractiveExtractorThread.cpp + MainWindow/logger.cpp + MainWindow/MainWindow.cpp + MainWindow/helper_functions.cpp + MainWindow/MaterialStyle.cpp + ) + + list( + APPEND HEADERS + cvutil_figure.h + demo.h + figure.h + main.h + MainWindow/BatchProcessor.h + MainWindow/FeatureExtractorThread.h + MainWindow/GraphicsScene.h + MainWindow/InteractiveExtractorThread.h + MainWindow/logger.h + MainWindow/MainWindow.h + MainWindow/helper_functions.h + MainWindow/MaterialStyle.h + ) +endif() + # Include the resource file only if it's WIN32 and MSVC if(WIN32) list(APPEND SOURCES cvutil.rc) @@ -111,15 +121,21 @@ target_link_libraries(cvutil PRIVATE cvutil_compiler_flags ${OpenCV_LIBS} - Qt6::Core - Qt6::Widgets - Qt6::Charts - Qt6::Gui - Qt6::OpenGL - PluginManager # These are handled at the solution level, no need to add subdirectories here - RoiManager ) +if(Qt6_FOUND) + target_link_libraries(cvutil + PRIVATE + Qt6::Core + Qt6::Widgets + Qt6::Charts + Qt6::Gui + Qt6::OpenGL + PluginManager # These are handled at the solution level, no need to add subdirectories here + RoiManager + ) +endif() + # Link mimalloc for Release builds only if(USE_MIMALLOC) if(TARGET mimalloc) diff --git a/cvutil/cvutil.h b/cvutil/cvutil.h index 723ad67..bb00948 100644 --- a/cvutil/cvutil.h +++ b/cvutil/cvutil.h @@ -53,6 +53,8 @@ along with cvutil; see the file COPYING. If not, see #include "cvutil_matlab_interface.h" #include "video.h" #include "cvutil_templates.h" +#ifdef BUILD_GUI #include "figure.h" +#endif #endif diff --git a/cvutil/cvutil_core.cpp b/cvutil/cvutil_core.cpp index 27aec53..585fdf1 100644 --- a/cvutil/cvutil_core.cpp +++ b/cvutil/cvutil_core.cpp @@ -33,8 +33,10 @@ along with cvutil; see the file COPYING. If not, see #include "cvutil_bwskel.h" #include "cvutil_types.h" +#ifdef BUILD_GUI #include "MainWindow/MainWindow.h" #include "MainWindow/MaterialStyle.h" +#endif using namespace std; using namespace cv; @@ -311,6 +313,7 @@ vector> cvutil::getConnectedComponents(Mat img, Mat& lab, int size, return result; } +#ifdef BUILD_GUI void onMouse(int event, int _x, int _y, int flags, void *data) { if (event != EVENT_LBUTTONUP && //event != EVENT_MOUSEMOVE && @@ -441,6 +444,7 @@ void onMouse(int event, int _x, int _y, int flags, void *data) m.release(); } +#endif void cvutil::printheader(Mat m) { @@ -454,6 +458,7 @@ void cvutil::printheader(Mat m) cout << m << endl; } +#ifdef BUILD_GUI // Similar to imshow() in opencv, but has // * An onMouse event Handler. // * We do not have to call namedWindow() before calling @@ -502,6 +507,7 @@ void cvutil::window(cv::String winname, Mat m) setMouseCallback(winname, onMouse, static_cast(wd)); waitKey(0); } +#endif Mat cvutil::bwthin(Mat input) { @@ -775,7 +781,7 @@ void cvutil::init(int &argc, char *argv[], bool useOpt, bool useGUI) { // Enable the OpenCV to use hardware acceleration. setUseOptimized(useOpt); - +#ifdef BUILD_GUI // Initialize Qt sub-system. if (useGUI) { @@ -787,6 +793,7 @@ void cvutil::init(int &argc, char *argv[], bool useOpt, bool useGUI) GlobalValues::app = nullptr; GlobalValues::coreapp = new QCoreApplication(argc, argv); } +#endif //QApplication::setStyle(new MaterialStyle()); @@ -888,6 +895,7 @@ Mat cvutil::getImageFromComponents(Size sz, vector> components) return result; } +#ifdef BUILD_GUI Ptr cvutil::getImageProcessorWindow(QIcon appico) { static MainWindow *result = nullptr; @@ -902,20 +910,25 @@ Ptr cvutil::getImageProcessorWindow(QIcon appico) return result; } } +#endif Mat cvutil::imread(QString& filename, int flags) { +#ifdef BUILD_GUI QFile file(filename); if (!file.open(QFile::ReadOnly)) return Mat(); QByteArray arr = file.readAll(); file.close(); - return imdecode(vector(arr.begin(), arr.end()), flags); +#else + return imread(filename, flags); +#endif } bool cvutil::imwrite(QString filename, Mat img, const std::vector & params) { +#ifdef BUILD_GUI if (filename.length() == 0) { qCritical() << "Cannot save the image."; @@ -959,6 +972,9 @@ bool cvutil::imwrite(QString filename, Mat img, const std::vector & params) file.write(arr); file.close(); +#else + bool result = imwrite(filename, img, params); +#endif return result; } diff --git a/cvutil/cvutil_core.h b/cvutil/cvutil_core.h index 481393f..ce83463 100644 --- a/cvutil/cvutil_core.h +++ b/cvutil/cvutil_core.h @@ -33,6 +33,10 @@ along with cvutil; see the file COPYING. If not, see #include "cvutil.h" +#ifndef BUILD_GUI +typedef cv::String QString; +#endif + namespace cvutil { CVUTILAPI cv::Mat getSingleChannel(cv::Mat m); diff --git a/cvutil/cvutil_matlab_interface.h b/cvutil/cvutil_matlab_interface.h index 8aadcdd..d1dddc1 100644 --- a/cvutil/cvutil_matlab_interface.h +++ b/cvutil/cvutil_matlab_interface.h @@ -32,7 +32,9 @@ along with cvutil; see the file COPYING. If not, see #define MATLAB_INTERFACE_H #include "cvutil.h" +#ifdef BUILD_GUI #include "figure.h" +#endif #define bwconncomp getConnectedComponents diff --git a/cvutil/cvutil_types.h b/cvutil/cvutil_types.h index 5e284d3..4746b34 100644 --- a/cvutil/cvutil_types.h +++ b/cvutil/cvutil_types.h @@ -60,9 +60,11 @@ namespace cvutil static clock_t start; static clock_t stop; +#ifdef BUILD_GUI // Qt specific static QCoreApplication *coreapp; static QApplication *app; +#endif //static bool cswitch; diff --git a/cvutil/figure.h b/cvutil/figure.h index 7297641..0f9551e 100644 --- a/cvutil/figure.h +++ b/cvutil/figure.h @@ -32,9 +32,11 @@ along with cvutil; see the file COPYING. If not, see #define FIGURE_H #include "cvutil.h" +#ifdef BUILD_GUI #include #include #include +#endif using namespace cvutil; diff --git a/cvutil/stdproto.h b/cvutil/stdproto.h index a368448..9569658 100644 --- a/cvutil/stdproto.h +++ b/cvutil/stdproto.h @@ -82,8 +82,10 @@ along with cvutil; see the file COPYING. If not, see //#include // UI facilities +#ifdef BUILD_GUI #include #include +#endif #ifdef _MSC_VER #if (defined _WINDLL && defined CVUTIL_SOURCE) diff --git a/cvutilConfig.cmake.in b/cvutilConfig.cmake.in index b9ef545..b8af044 100644 --- a/cvutilConfig.cmake.in +++ b/cvutilConfig.cmake.in @@ -3,7 +3,7 @@ include(CMakeFindDependencyMacro) find_dependency(OpenCV REQUIRED) -find_dependency(Qt6 REQUIRED COMPONENTS Core Widgets Charts Gui OpenGL) +find_package(Qt6 COMPONENTS Core Widgets Charts Gui OpenGL) include("${CMAKE_CURRENT_LIST_DIR}/cvutilTargets.cmake")