├── .gitignore ├── CMakeLists.txt ├── License.txt ├── README.md ├── Resources ├── Icons │ └── SlicerOpenCV.png └── qSlicerOpenCVModule.qrc ├── SlicerOpenCV.png ├── SlicerOpenCV ├── CMakeLists.txt ├── Logic │ ├── CMakeLists.txt │ ├── vtkSlicerOpenCVLogic.cxx │ └── vtkSlicerOpenCVLogic.h ├── Testing │ ├── CMakeLists.txt │ ├── Cxx │ │ ├── CMakeLists.txt │ │ └── vtkSlicerOpenCVLogicTest1.cxx │ └── Python │ │ ├── CMakeLists.txt │ │ └── SlicerOpenCVSelfTest.py ├── qSlicerOpenCVModule.cxx └── qSlicerOpenCVModule.h ├── SuperBuild.cmake └── SuperBuild ├── External_ITKVideoBridgeOpenCV.cmake └── External_OpenCV.cmake /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/qt,vim,python 3 | 4 | ### Qt ### 5 | 6 | # QtCreator 7 | 8 | *.autosave 9 | 10 | #QtCtreator CMake 11 | CMakeLists.txt.user 12 | 13 | 14 | 15 | ### Vim ### 16 | # swap 17 | [._]*.s[a-w][a-z] 18 | [._]s[a-w][a-z] 19 | # session 20 | Session.vim 21 | # temporary 22 | .netrwhist 23 | *~ 24 | 25 | 26 | ### Python ### 27 | # Byte-compiled / optimized / DLL files 28 | __pycache__/ 29 | *.py[cod] 30 | *$py.class 31 | 32 | # C extensions 33 | *.so 34 | 35 | # Distribution / packaging 36 | .Python 37 | env/ 38 | build/ 39 | develop-eggs/ 40 | dist/ 41 | downloads/ 42 | eggs/ 43 | .eggs/ 44 | lib/ 45 | lib64/ 46 | parts/ 47 | sdist/ 48 | var/ 49 | *.egg-info/ 50 | .installed.cfg 51 | *.egg 52 | 53 | # Installer logs 54 | pip-log.txt 55 | pip-delete-this-directory.txt 56 | 57 | # Unit test / coverage reports 58 | htmlcov/ 59 | .tox/ 60 | .coverage 61 | .coverage.* 62 | .cache 63 | nosetests.xml 64 | coverage.xml 65 | *,cover 66 | .hypothesis/ 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # IPython Notebook 72 | .ipynb_checkpoints 73 | 74 | # pyenv 75 | .python-version 76 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.1) 2 | 3 | project(SlicerOpenCV) 4 | 5 | #----------------------------------------------------------------------------- 6 | # Extension meta-information 7 | set(EXTENSION_HOMEPAGE "https://slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/SlicerOpenCV") 8 | set(EXTENSION_CATEGORY "Libraries") 9 | set(EXTENSION_CONTRIBUTORS "Nicole Aucoin (BWH), Andrey Fedorov (BWH), Jean-Christophe Fillion-Robin (Kitware)") 10 | set(EXTENSION_DESCRIPTION "This extension provides a wrapper around OpenCV libraries") 11 | set(EXTENSION_ICONURL "https://raw.githubusercontent.com/SBU-BMI/SlicerOpenCV/master/SlicerOpenCV.png") 12 | set(EXTENSION_SCREENSHOTURLS "") 13 | set(EXTENSION_BUILD_SUBDIRECTORY inner-build) 14 | 15 | set(SUPERBUILD_TOPLEVEL_PROJECT inner) 16 | 17 | #----------------------------------------------------------------------------- 18 | # Extension dependencies 19 | find_package(Slicer REQUIRED) 20 | include(${Slicer_USE_FILE}) 21 | mark_as_superbuild(Slicer_DIR) 22 | 23 | find_package(Git REQUIRED) 24 | mark_as_superbuild(GIT_EXECUTABLE) 25 | 26 | #----------------------------------------------------------------------------- 27 | # SuperBuild setup 28 | option(${EXTENSION_NAME}_SUPERBUILD "Build ${EXTENSION_NAME} and the projects it depends on." ON) 29 | mark_as_advanced(${EXTENSION_NAME}_SUPERBUILD) 30 | if(${EXTENSION_NAME}_SUPERBUILD) 31 | include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake") 32 | return() 33 | endif() 34 | 35 | #----------------------------------------------------------------------------- 36 | # Extension modules 37 | # Slicer wrapper around the library 38 | add_subdirectory(SlicerOpenCV) 39 | ## NEXT_MODULE 40 | 41 | #----------------------------------------------------------------------------- 42 | set(SlicerOpenCV_CUSTOM_CONFIG " 43 | set(OpenCV_DIR \"${OpenCV_DIR}\") 44 | if(NOT SlicerOpenCV_FIND_QUIETLY) 45 | message(STATUS \"OpenCV_DIR set to \${OpenCV_DIR}\") 46 | endif() 47 | ") 48 | 49 | #----------------------------------------------------------------------------- 50 | set(EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS) 51 | list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${OpenCV_BUILD_DIR};OpenCVPython;python;/") 52 | list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${OpenCV_BUILD_DIR};OpenCV;libs;/") 53 | if(ITKVideoBridgeOpenCV_DIR) 54 | list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${ITKVideoBridgeOpenCV_DIR};ITKVideoBridgeOpenCV;RuntimeLibraries;/") 55 | endif() 56 | set(${EXTENSION_NAME}_CPACK_INSTALL_CMAKE_PROJECTS "${EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS}" CACHE STRING "List of external projects to install" FORCE) 57 | 58 | #----------------------------------------------------------------------------- 59 | list(APPEND CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR};${EXTENSION_NAME};ALL;/") 60 | list(APPEND CPACK_INSTALL_CMAKE_PROJECTS "${${EXTENSION_NAME}_CPACK_INSTALL_CMAKE_PROJECTS}") 61 | include(${Slicer_EXTENSION_GENERATE_CONFIG}) 62 | include(${Slicer_EXTENSION_CPACK}) 63 | 64 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | 2 | For more information, please see: 3 | 4 | http://www.slicer.org 5 | 6 | The 3D Slicer license below is a BSD style license, with extensions 7 | to cover contributions and other issues specific to 3D Slicer. 8 | 9 | 10 | 3D Slicer Contribution and Software License Agreement ("Agreement") 11 | Version 1.0 (December 20, 2005) 12 | 13 | This Agreement covers contributions to and downloads from the 3D 14 | Slicer project ("Slicer") maintained by The Brigham and Women's 15 | Hospital, Inc. ("Brigham"). Part A of this Agreement applies to 16 | contributions of software and/or data to Slicer (including making 17 | revisions of or additions to code and/or data already in Slicer). Part 18 | B of this Agreement applies to downloads of software and/or data from 19 | Slicer. Part C of this Agreement applies to all transactions with 20 | Slicer. If you distribute Software (as defined below) downloaded from 21 | Slicer, all of the paragraphs of Part B of this Agreement must be 22 | included with and apply to such Software. 23 | 24 | Your contribution of software and/or data to Slicer (including prior 25 | to the date of the first publication of this Agreement, each a 26 | "Contribution") and/or downloading, copying, modifying, displaying, 27 | distributing or use of any software and/or data from Slicer 28 | (collectively, the "Software") constitutes acceptance of all of the 29 | terms and conditions of this Agreement. If you do not agree to such 30 | terms and conditions, you have no right to contribute your 31 | Contribution, or to download, copy, modify, display, distribute or use 32 | the Software. 33 | 34 | PART A. CONTRIBUTION AGREEMENT - License to Brigham with Right to 35 | Sublicense ("Contribution Agreement"). 36 | 37 | 1. As used in this Contribution Agreement, "you" means the individual 38 | contributing the Contribution to Slicer and the institution or 39 | entity which employs or is otherwise affiliated with such 40 | individual in connection with such Contribution. 41 | 42 | 2. This Contribution Agreement applies to all Contributions made to 43 | Slicer, including without limitation Contributions made prior to 44 | the date of first publication of this Agreement. If at any time you 45 | make a Contribution to Slicer, you represent that (i) you are 46 | legally authorized and entitled to make such Contribution and to 47 | grant all licenses granted in this Contribution Agreement with 48 | respect to such Contribution; (ii) if your Contribution includes 49 | any patient data, all such data is de-identified in accordance with 50 | U.S. confidentiality and security laws and requirements, including 51 | but not limited to the Health Insurance Portability and 52 | Accountability Act (HIPAA) and its regulations, and your disclosure 53 | of such data for the purposes contemplated by this Agreement is 54 | properly authorized and in compliance with all applicable laws and 55 | regulations; and (iii) you have preserved in the Contribution all 56 | applicable attributions, copyright notices and licenses for any 57 | third party software or data included in the Contribution. 58 | 59 | 3. Except for the licenses granted in this Agreement, you reserve all 60 | right, title and interest in your Contribution. 61 | 62 | 4. You hereby grant to Brigham, with the right to sublicense, a 63 | perpetual, worldwide, non-exclusive, no charge, royalty-free, 64 | irrevocable license to use, reproduce, make derivative works of, 65 | display and distribute the Contribution. If your Contribution is 66 | protected by patent, you hereby grant to Brigham, with the right to 67 | sublicense, a perpetual, worldwide, non-exclusive, no-charge, 68 | royalty-free, irrevocable license under your interest in patent 69 | rights covering the Contribution, to make, have made, use, sell and 70 | otherwise transfer your Contribution, alone or in combination with 71 | any other code. 72 | 73 | 5. You acknowledge and agree that Brigham may incorporate your 74 | Contribution into Slicer and may make Slicer available to members 75 | of the public on an open source basis under terms substantially in 76 | accordance with the Software License set forth in Part B of this 77 | Agreement. You further acknowledge and agree that Brigham shall 78 | have no liability arising in connection with claims resulting from 79 | your breach of any of the terms of this Agreement. 80 | 81 | 6. YOU WARRANT THAT TO THE BEST OF YOUR KNOWLEDGE YOUR CONTRIBUTION 82 | DOES NOT CONTAIN ANY CODE THAT REQURES OR PRESCRIBES AN "OPEN 83 | SOURCE LICENSE" FOR DERIVATIVE WORKS (by way of non-limiting 84 | example, the GNU General Public License or other so-called 85 | "reciprocal" license that requires any derived work to be licensed 86 | under the GNU General Public License or other "open source 87 | license"). 88 | 89 | PART B. DOWNLOADING AGREEMENT - License from Brigham with Right to 90 | Sublicense ("Software License"). 91 | 92 | 1. As used in this Software License, "you" means the individual 93 | downloading and/or using, reproducing, modifying, displaying and/or 94 | distributing the Software and the institution or entity which 95 | employs or is otherwise affiliated with such individual in 96 | connection therewith. The Brigham and Women?s Hospital, 97 | Inc. ("Brigham") hereby grants you, with right to sublicense, with 98 | respect to Brigham's rights in the software, and data, if any, 99 | which is the subject of this Software License (collectively, the 100 | "Software"), a royalty-free, non-exclusive license to use, 101 | reproduce, make derivative works of, display and distribute the 102 | Software, provided that: 103 | 104 | (a) you accept and adhere to all of the terms and conditions of this 105 | Software License; 106 | 107 | (b) in connection with any copy of or sublicense of all or any portion 108 | of the Software, all of the terms and conditions in this Software 109 | License shall appear in and shall apply to such copy and such 110 | sublicense, including without limitation all source and executable 111 | forms and on any user documentation, prefaced with the following 112 | words: "All or portions of this licensed product (such portions are 113 | the "Software") have been obtained under license from The Brigham and 114 | Women's Hospital, Inc. and are subject to the following terms and 115 | conditions:" 116 | 117 | (c) you preserve and maintain all applicable attributions, copyright 118 | notices and licenses included in or applicable to the Software; 119 | 120 | (d) modified versions of the Software must be clearly identified and 121 | marked as such, and must not be misrepresented as being the original 122 | Software; and 123 | 124 | (e) you consider making, but are under no obligation to make, the 125 | source code of any of your modifications to the Software freely 126 | available to others on an open source basis. 127 | 128 | 2. The license granted in this Software License includes without 129 | limitation the right to (i) incorporate the Software into 130 | proprietary programs (subject to any restrictions applicable to 131 | such programs), (ii) add your own copyright statement to your 132 | modifications of the Software, and (iii) provide additional or 133 | different license terms and conditions in your sublicenses of 134 | modifications of the Software; provided that in each case your use, 135 | reproduction or distribution of such modifications otherwise 136 | complies with the conditions stated in this Software License. 137 | 138 | 3. This Software License does not grant any rights with respect to 139 | third party software, except those rights that Brigham has been 140 | authorized by a third party to grant to you, and accordingly you 141 | are solely responsible for (i) obtaining any permissions from third 142 | parties that you need to use, reproduce, make derivative works of, 143 | display and distribute the Software, and (ii) informing your 144 | sublicensees, including without limitation your end-users, of their 145 | obligations to secure any such required permissions. 146 | 147 | 4. The Software has been designed for research purposes only and has 148 | not been reviewed or approved by the Food and Drug Administration 149 | or by any other agency. YOU ACKNOWLEDGE AND AGREE THAT CLINICAL 150 | APPLICATIONS ARE NEITHER RECOMMENDED NOR ADVISED. Any 151 | commercialization of the Software is at the sole risk of the party 152 | or parties engaged in such commercialization. You further agree to 153 | use, reproduce, make derivative works of, display and distribute 154 | the Software in compliance with all applicable governmental laws, 155 | regulations and orders, including without limitation those relating 156 | to export and import control. 157 | 158 | 5. The Software is provided "AS IS" and neither Brigham nor any 159 | contributor to the software (each a "Contributor") shall have any 160 | obligation to provide maintenance, support, updates, enhancements 161 | or modifications thereto. BRIGHAM AND ALL CONTRIBUTORS SPECIFICALLY 162 | DISCLAIM ALL EXPRESS AND IMPLIED WARRANTIES OF ANY KIND INCLUDING, 163 | BUT NOT LIMITED TO, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR 164 | A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 165 | BRIGHAM OR ANY CONTRIBUTOR BE LIABLE TO ANY PARTY FOR DIRECT, 166 | INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES 167 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY ARISING IN ANY WAY 168 | RELATED TO THE SOFTWARE, EVEN IF BRIGHAM OR ANY CONTRIBUTOR HAS 169 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. TO THE MAXIMUM 170 | EXTENT NOT PROHIBITED BY LAW OR REGULATION, YOU FURTHER ASSUME ALL 171 | LIABILITY FOR YOUR USE, REPRODUCTION, MAKING OF DERIVATIVE WORKS, 172 | DISPLAY, LICENSE OR DISTRIBUTION OF THE SOFTWARE AND AGREE TO 173 | INDEMNIFY AND HOLD HARMLESS BRIGHAM AND ALL CONTRIBUTORS FROM AND 174 | AGAINST ANY AND ALL CLAIMS, SUITS, ACTIONS, DEMANDS AND JUDGMENTS 175 | ARISING THEREFROM. 176 | 177 | 6. None of the names, logos or trademarks of Brigham or any of 178 | Brigham's affiliates or any of the Contributors, or any funding 179 | agency, may be used to endorse or promote products produced in 180 | whole or in part by operation of the Software or derived from or 181 | based on the Software without specific prior written permission 182 | from the applicable party. 183 | 184 | 7. Any use, reproduction or distribution of the Software which is not 185 | in accordance with this Software License shall automatically revoke 186 | all rights granted to you under this Software License and render 187 | Paragraphs 1 and 2 of this Software License null and void. 188 | 189 | 8. This Software License does not grant any rights in or to any 190 | intellectual property owned by Brigham or any Contributor except 191 | those rights expressly granted hereunder. 192 | 193 | PART C. MISCELLANEOUS 194 | 195 | This Agreement shall be governed by and construed in accordance with 196 | the laws of The Commonwealth of Massachusetts without regard to 197 | principles of conflicts of law. This Agreement shall supercede and 198 | replace any license terms that you may have agreed to previously with 199 | respect to Slicer. 200 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SlicerOpenCV 2 | 3 | This is an extension that adds OpenCV (https://opencv.org/) to 3D Slicer (https://slicer.org). 4 | 5 | See this Slicer labs page for details on what features will be provided by the 6 | extension, design decisions and such: 7 | 8 | Planning and development page: https://wiki.slicer.org/slicerWiki/index.php/Documentation/Labs/OpenCV 9 | 10 | Extension documentation page: https://wiki.slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/SlicerOpenCV 11 | 12 | # Contact 13 | 14 | Questions regarding this extension should be posted on 3D Slicer forum: https://discourse.slicer.org 15 | 16 | # Acknowledgments 17 | 18 | This work was supported in part by an administrative supplement to the NIH NCI 19 | projects: 20 | 21 | * U24 CA180918 Quantitative Image Informatics for Cancer Research 22 | (QIICR), http://qiicr.org, PIs Ron Kikinis and Andrey Fedorov, Brigham and 23 | Women's Hospital 24 | * U24 CA180924 Tools to Analyze Morphology and Spatially Mapped Molecular Data, 25 | PI Joel Saltz, SUNY Stony Brook 26 | -------------------------------------------------------------------------------- /Resources/Icons/SlicerOpenCV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Slicer/SlicerOpenCV/01e6b4d041664d4a9c2c0a07141609cc63bea8fb/Resources/Icons/SlicerOpenCV.png -------------------------------------------------------------------------------- /Resources/qSlicerOpenCVModule.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Icons/SlicerOpenCV.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /SlicerOpenCV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Slicer/SlicerOpenCV/01e6b4d041664d4a9c2c0a07141609cc63bea8fb/SlicerOpenCV.png -------------------------------------------------------------------------------- /SlicerOpenCV/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #----------------------------------------------------------------------------- 3 | set(MODULE_NAME OpenCV) 4 | set(MODULE_TITLE ${MODULE_NAME}) 5 | 6 | string(TOUPPER ${MODULE_NAME} MODULE_NAME_UPPER) 7 | 8 | #----------------------------------------------------------------------------- 9 | add_subdirectory(Logic) 10 | # add_subdirectory(Widgets) 11 | 12 | #----------------------------------------------------------------------------- 13 | set(MODULE_EXPORT_DIRECTIVE "Q_SLICER_QTMODULES_${MODULE_NAME_UPPER}_EXPORT") 14 | 15 | # Current_{source,binary} and Slicer_{Libs,Base} already included 16 | set(MODULE_INCLUDE_DIRECTORIES 17 | ${CMAKE_CURRENT_SOURCE_DIR}/Logic 18 | ${CMAKE_CURRENT_BINARY_DIR}/Logic 19 | ) 20 | 21 | set(MODULE_SRCS 22 | qSlicer${MODULE_NAME}Module.cxx 23 | qSlicer${MODULE_NAME}Module.h 24 | ) 25 | 26 | set(MODULE_MOC_SRCS 27 | qSlicer${MODULE_NAME}Module.h 28 | ) 29 | 30 | set(MODULE_UI_SRCS 31 | ) 32 | 33 | set(MODULE_TARGET_LIBRARIES 34 | vtkSlicer${MODULE_NAME}ModuleLogic 35 | ) 36 | 37 | set(TARGET_LINK_LIBRARIES 38 | ) 39 | 40 | set(MODULE_RESOURCES 41 | ) 42 | 43 | #----------------------------------------------------------------------------- 44 | slicerMacroBuildLoadableModule( 45 | NAME ${MODULE_NAME} 46 | TITLE ${MODULE_TITLE} 47 | EXPORT_DIRECTIVE ${MODULE_EXPORT_DIRECTIVE} 48 | INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES} 49 | SRCS ${MODULE_SRCS} 50 | MOC_SRCS ${MODULE_MOC_SRCS} 51 | UI_SRCS ${MODULE_UI_SRCS} 52 | TARGET_LIBRARIES ${MODULE_TARGET_LIBRARIES} 53 | RESOURCES ${MODULE_RESOURCES} 54 | WITH_GENERIC_TESTS 55 | ) 56 | 57 | #----------------------------------------------------------------------------- 58 | if(BUILD_TESTING) 59 | add_subdirectory(Testing) 60 | endif() 61 | -------------------------------------------------------------------------------- /SlicerOpenCV/Logic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(vtkSlicer${MODULE_NAME}ModuleLogic) 2 | 3 | set(KIT ${PROJECT_NAME}) 4 | 5 | #----------------------------------------------------------------------------- 6 | find_package(ITK COMPONENTS ITKVideoBridgeOpenCV REQUIRED) 7 | include(${ITK_USE_FILE}) 8 | 9 | #----------------------------------------------------------------------------- 10 | find_package(OpenCV 4.1 REQUIRED) 11 | message(STATUS "OpenCV library status:") 12 | message(STATUS " version: ${OpenCV_VERSION}") 13 | message(STATUS " libraries: ${OpenCV_LIBS}") 14 | 15 | #----------------------------------------------------------------------------- 16 | set(${KIT}_EXPORT_DIRECTIVE "VTK_SLICER_${MODULE_NAME_UPPER}_MODULE_LOGIC_EXPORT") 17 | 18 | set(${KIT}_INCLUDE_DIRECTORIES 19 | ) 20 | 21 | set(${KIT}_SRCS 22 | vtkSlicer${MODULE_NAME}Logic.cxx 23 | vtkSlicer${MODULE_NAME}Logic.h 24 | ) 25 | 26 | 27 | set(${KIT}_TARGET_LIBRARIES 28 | ${VTK_LIBRARIES} 29 | ${OpenCV_LIBS} 30 | ${ITK_LIBRARIES} 31 | ) 32 | 33 | #----------------------------------------------------------------------------- 34 | SlicerMacroBuildModuleLogic( 35 | NAME ${KIT} 36 | EXPORT_DIRECTIVE ${${KIT}_EXPORT_DIRECTIVE} 37 | INCLUDE_DIRECTORIES ${${KIT}_INCLUDE_DIRECTORIES} 38 | SRCS ${${KIT}_SRCS} 39 | TARGET_LIBRARIES ${${KIT}_TARGET_LIBRARIES} 40 | ) 41 | -------------------------------------------------------------------------------- /SlicerOpenCV/Logic/vtkSlicerOpenCVLogic.cxx: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | ==============================================================================*/ 17 | 18 | // OpenCV Logic includes 19 | #include "vtkSlicerOpenCVLogic.h" 20 | 21 | // MRML includes 22 | #include 23 | 24 | // VTK includes 25 | #include 26 | #include 27 | #include 28 | 29 | // ITK includes 30 | #include 31 | 32 | //---------------------------------------------------------------------------- 33 | vtkStandardNewMacro(vtkSlicerOpenCVLogic); 34 | 35 | //---------------------------------------------------------------------------- 36 | vtkSlicerOpenCVLogic::vtkSlicerOpenCVLogic() 37 | { 38 | // register the OpenCV ITK IO factory 39 | itk::ObjectFactoryBase::RegisterFactory( itk::OpenCVVideoIOFactory::New() ); 40 | 41 | } 42 | 43 | //---------------------------------------------------------------------------- 44 | vtkSlicerOpenCVLogic::~vtkSlicerOpenCVLogic() 45 | { 46 | } 47 | 48 | //---------------------------------------------------------------------------- 49 | void vtkSlicerOpenCVLogic::PrintSelf(ostream& os, vtkIndent indent) 50 | { 51 | this->Superclass::PrintSelf(os, indent); 52 | } 53 | 54 | //--------------------------------------------------------------------------- 55 | void vtkSlicerOpenCVLogic::SetMRMLSceneInternal(vtkMRMLScene * newScene) 56 | { 57 | vtkNew events; 58 | events->InsertNextValue(vtkMRMLScene::NodeAddedEvent); 59 | events->InsertNextValue(vtkMRMLScene::NodeRemovedEvent); 60 | events->InsertNextValue(vtkMRMLScene::EndBatchProcessEvent); 61 | this->SetAndObserveMRMLSceneEventsInternal(newScene, events.GetPointer()); 62 | } 63 | 64 | //----------------------------------------------------------------------------- 65 | void vtkSlicerOpenCVLogic::RegisterNodes() 66 | { 67 | assert(this->GetMRMLScene() != 0); 68 | } 69 | 70 | //--------------------------------------------------------------------------- 71 | void vtkSlicerOpenCVLogic::UpdateFromMRMLScene() 72 | { 73 | assert(this->GetMRMLScene() != 0); 74 | } 75 | 76 | //--------------------------------------------------------------------------- 77 | void vtkSlicerOpenCVLogic 78 | ::OnMRMLSceneNodeAdded(vtkMRMLNode* vtkNotUsed(node)) 79 | { 80 | } 81 | 82 | //--------------------------------------------------------------------------- 83 | void vtkSlicerOpenCVLogic 84 | ::OnMRMLSceneNodeRemoved(vtkMRMLNode* vtkNotUsed(node)) 85 | { 86 | } 87 | -------------------------------------------------------------------------------- /SlicerOpenCV/Logic/vtkSlicerOpenCVLogic.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | ==============================================================================*/ 17 | 18 | // .NAME vtkSlicerOpenCVLogic - slicer logic class for OpenCV library 19 | // .SECTION Description 20 | // This class manages the logic associated with reading, saving, 21 | // and changing properties of the OpenCV library 22 | 23 | 24 | #ifndef __vtkSlicerOpenCVLogic_h 25 | #define __vtkSlicerOpenCVLogic_h 26 | 27 | // Slicer includes 28 | #include "vtkSlicerModuleLogic.h" 29 | 30 | // MRML includes 31 | 32 | // STD includes 33 | #include 34 | 35 | #include "vtkSlicerOpenCVModuleLogicExport.h" 36 | 37 | 38 | /// \ingroup Slicer_QtModules_ExtensionTemplate 39 | class VTK_SLICER_OPENCV_MODULE_LOGIC_EXPORT vtkSlicerOpenCVLogic : 40 | public vtkSlicerModuleLogic 41 | { 42 | public: 43 | 44 | static vtkSlicerOpenCVLogic *New(); 45 | vtkTypeMacro(vtkSlicerOpenCVLogic, vtkSlicerModuleLogic); 46 | void PrintSelf(ostream& os, vtkIndent indent); 47 | 48 | protected: 49 | vtkSlicerOpenCVLogic(); 50 | virtual ~vtkSlicerOpenCVLogic(); 51 | 52 | virtual void SetMRMLSceneInternal(vtkMRMLScene* newScene); 53 | /// Register MRML Node classes to Scene. Gets called automatically when the MRMLScene is attached to this logic class. 54 | virtual void RegisterNodes(); 55 | virtual void UpdateFromMRMLScene(); 56 | virtual void OnMRMLSceneNodeAdded(vtkMRMLNode* node); 57 | virtual void OnMRMLSceneNodeRemoved(vtkMRMLNode* node); 58 | 59 | private: 60 | 61 | vtkSlicerOpenCVLogic(const vtkSlicerOpenCVLogic&); // Not implemented 62 | void operator=(const vtkSlicerOpenCVLogic&); // Not implemented 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /SlicerOpenCV/Testing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Cxx) 2 | if(Slicer_USE_PYTHONQT) 3 | # add_subdirectory(Python) 4 | endif() 5 | -------------------------------------------------------------------------------- /SlicerOpenCV/Testing/Cxx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(KIT qSlicer${MODULE_NAME}Module) 2 | 3 | #----------------------------------------------------------------------------- 4 | find_package(ITK COMPONENTS ITKVideoBridgeOpenCV REQUIRED) 5 | include(${ITK_USE_FILE}) 6 | 7 | #----------------------------------------------------------------------------- 8 | set(KIT_TEST_SRCS 9 | #qSlicer${MODULE_NAME}ModuleTest.cxx 10 | vtkSlicerOpenCVLogicTest1.cxx 11 | ) 12 | 13 | #----------------------------------------------------------------------------- 14 | slicerMacroConfigureModuleCxxTestDriver( 15 | NAME ${KIT} 16 | SOURCES ${KIT_TEST_SRCS} 17 | TARGET_LIBRARIES ${ITK_LIBRARIES} 18 | WITH_VTK_DEBUG_LEAKS_CHECK 19 | ) 20 | 21 | #----------------------------------------------------------------------------- 22 | #simple_test(qSlicer${MODULE_NAME}ModuleTest) 23 | 24 | simple_test(vtkSlicerOpenCVLogicTest1) 25 | -------------------------------------------------------------------------------- /SlicerOpenCV/Testing/Cxx/vtkSlicerOpenCVLogicTest1.cxx: -------------------------------------------------------------------------------- 1 | // MRML includes 2 | #include "vtkMRMLScene.h" 3 | 4 | // SlicerOpenCV includes 5 | #include "vtkSlicerOpenCVLogic.h" 6 | 7 | // VTK includes 8 | #include 9 | #include 10 | #include 11 | 12 | // ITK includes 13 | #include 14 | 15 | int vtkSlicerOpenCVLogicTest1(int, char * []) 16 | { 17 | vtkSmartPointer scene = vtkSmartPointer::New(); 18 | 19 | vtkNew logic1; 20 | logic1->SetMRMLScene(scene); 21 | 22 | vtkIndent indent; 23 | logic1->PrintSelf(std::cout, indent); 24 | 25 | // check that the OpenCV ITK IO factory was registered 26 | std::list< itk::ObjectFactoryBase * > factories; 27 | factories = itk::ObjectFactoryBase::GetRegisteredFactories(); 28 | bool factoryFound = false; 29 | for (std::list::iterator it = factories.begin(); 30 | it != factories.end(); 31 | it++) 32 | { 33 | itk::ObjectFactoryBase *factory = *it; 34 | if (factory->GetNameOfClass()) 35 | { 36 | if (!strcmp(factory->GetNameOfClass(), "OpenCVVideoIOFactory")) 37 | { 38 | factoryFound = true; 39 | std::cout << "Factory found: " << factory->GetNameOfClass() << std::endl; 40 | } 41 | } 42 | } 43 | if (!factoryFound) 44 | { 45 | std::cerr << "The OpenCV video IO factory was not registered with ITK!" 46 | << std::endl; 47 | return EXIT_FAILURE; 48 | } 49 | return EXIT_SUCCESS; 50 | } 51 | -------------------------------------------------------------------------------- /SlicerOpenCV/Testing/Python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(SlicerMacroBuildScriptedModule) 2 | set(SLICEROPENCV_PYTHON_RESOURCES 3 | ) 4 | 5 | # Test calculating a histogram of an image from midas 6 | slicerMacroBuildScriptedModule( 7 | NAME SlicerOpenCVSelfTest 8 | SCRIPTS SlicerOpenCVSelfTest.py 9 | RESOURCES ${SLICEROPENCV_PYTHON_RESOURCES} 10 | ) 11 | # on Windows, the build directory test doesn't work 12 | if (NOT WIN32) 13 | MESSAGE(STATUS "Adding unit test for python wrapping") 14 | slicer_add_python_unittest(SCRIPT SlicerOpenCVSelfTest.py) 15 | endif() 16 | -------------------------------------------------------------------------------- /SlicerOpenCV/Testing/Python/SlicerOpenCVSelfTest.py: -------------------------------------------------------------------------------- 1 | import os 2 | import unittest 3 | import vtk, qt, ctk, slicer 4 | from slicer.ScriptedLoadableModule import * 5 | import logging 6 | import numpy as np 7 | 8 | print 'Current SlicerOpenCVSelfTest.py path = ' 9 | scriptPath = os.path.dirname(os.path.abspath(__file__)) 10 | print scriptPath 11 | 12 | 13 | # load the python wrapped OpenCV module 14 | try: 15 | print 'Trying to import cv2' 16 | # the module is in the python path 17 | import cv2 18 | print 'Imported!' 19 | except ImportError: 20 | print 'Trying to import from file' 21 | # for the build directory, load from the file 22 | import imp, platform 23 | if platform.system() == 'Windows': 24 | cv2File = 'cv2.pyd' 25 | cv2Path = '../../../../OpenCV-build/lib/Release/' + cv2File 26 | else: 27 | cv2File = 'cv2.so' 28 | cv2Path = '../../../../OpenCV-build/lib/' + cv2File 29 | cv2Path = os.path.abspath(os.path.join(scriptPath, cv2Path)) 30 | # in the build directory, this path should exist, but in the installed extension 31 | # it should be in the python path, so only use the short file name 32 | if not os.path.isfile(cv2Path): 33 | print 'Full path not found: ',cv2Path 34 | cv2Path = cv2File 35 | print 'Loading cv2 from ',cv2Path 36 | cv2 = imp.load_dynamic('cv2', cv2File) 37 | 38 | # 39 | # SlicerOpenCVSelfTest 40 | # 41 | 42 | class SlicerOpenCVSelfTest(ScriptedLoadableModule): 43 | """Uses ScriptedLoadableModule base class, available at: 44 | https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py 45 | """ 46 | 47 | def __init__(self, parent): 48 | ScriptedLoadableModule.__init__(self, parent) 49 | self.parent.title = "SlicerOpenCVSelfTest" 50 | self.parent.categories = ["Testing.TestCases"] 51 | self.parent.dependencies = ["SlicerOpenCV"] 52 | self.parent.contributors = ["Nicole Aucoin (BWH)"] 53 | self.parent.helpText = """ 54 | This is an example of how to use OpenCV from python. 55 | It performs a simple histogram on the input vector volume and optionally captures a screenshot. 56 | """ 57 | self.parent.acknowledgementText = """ 58 | This file was originally developed by Nicole Aucoin, BWH. 59 | """ 60 | 61 | # 62 | # SlicerOpenCVSelfTestWidget 63 | # 64 | 65 | class SlicerOpenCVSelfTestWidget(ScriptedLoadableModuleWidget): 66 | """Uses ScriptedLoadableModuleWidget base class, available at: 67 | https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py 68 | """ 69 | 70 | def setup(self): 71 | ScriptedLoadableModuleWidget.setup(self) 72 | 73 | # Instantiate and connect widgets ... 74 | 75 | # 76 | # Parameters Area 77 | # 78 | parametersCollapsibleButton = ctk.ctkCollapsibleButton() 79 | parametersCollapsibleButton.text = "Parameters" 80 | self.layout.addWidget(parametersCollapsibleButton) 81 | 82 | # Layout within the dummy collapsible button 83 | parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton) 84 | 85 | # 86 | # input volume selector 87 | # 88 | self.inputSelector = slicer.qMRMLNodeComboBox() 89 | self.inputSelector.nodeTypes = ["vtkMRMLVectorVolumeNode"] 90 | self.inputSelector.selectNodeUponCreation = True 91 | self.inputSelector.addEnabled = False 92 | self.inputSelector.removeEnabled = False 93 | self.inputSelector.noneEnabled = False 94 | self.inputSelector.showHidden = False 95 | self.inputSelector.showChildNodeTypes = False 96 | self.inputSelector.setMRMLScene( slicer.mrmlScene ) 97 | self.inputSelector.setToolTip( "Pick the input to the histogram." ) 98 | parametersFormLayout.addRow("Input Volume: ", self.inputSelector) 99 | 100 | # 101 | # check box to trigger taking screen shots for later use in tutorials 102 | # 103 | self.enableScreenshotsFlagCheckBox = qt.QCheckBox() 104 | self.enableScreenshotsFlagCheckBox.checked = 0 105 | self.enableScreenshotsFlagCheckBox.setToolTip("If checked, take screen shots for tutorials. Use Save Data to write them to disk.") 106 | parametersFormLayout.addRow("Enable Screenshots", self.enableScreenshotsFlagCheckBox) 107 | 108 | # 109 | # Apply Button 110 | # 111 | self.applyButton = qt.QPushButton("Apply") 112 | self.applyButton.toolTip = "Run the algorithm." 113 | self.applyButton.enabled = False 114 | parametersFormLayout.addRow(self.applyButton) 115 | 116 | # connections 117 | self.applyButton.connect('clicked(bool)', self.onApplyButton) 118 | self.inputSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onSelect) 119 | 120 | # Add vertical spacer 121 | self.layout.addStretch(1) 122 | 123 | # Refresh Apply button state 124 | self.onSelect() 125 | 126 | def cleanup(self): 127 | pass 128 | 129 | def onSelect(self): 130 | self.applyButton.enabled = self.inputSelector.currentNode() and self.outputSelector.currentNode() 131 | 132 | def onApplyButton(self): 133 | logic = SlicerOpenCVSelfTestLogic() 134 | enableScreenshotsFlag = self.enableScreenshotsFlagCheckBox.checked 135 | logic.run(self.inputSelector.currentNode(), enableScreenshotsFlag) 136 | 137 | # 138 | # SlicerOpenCVSelfTestLogic 139 | # 140 | 141 | class SlicerOpenCVSelfTestLogic(ScriptedLoadableModuleLogic): 142 | """This class should implement all the actual 143 | computation done by your module. The interface 144 | should be such that other python code can import 145 | this class and make use of the functionality without 146 | requiring an instance of the Widget. 147 | Uses ScriptedLoadableModuleLogic base class, available at: 148 | https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py 149 | """ 150 | 151 | def takeScreenshot(self,name,description,type=-1): 152 | # show the message even if not taking a screen shot 153 | slicer.util.delayDisplay('Take screenshot: '+description+'.\nResult is available in the Annotations module.', 3000) 154 | 155 | lm = slicer.app.layoutManager() 156 | # switch on the type to get the requested window 157 | widget = 0 158 | if type == slicer.qMRMLScreenShotDialog.FullLayout: 159 | # full layout 160 | widget = lm.viewport() 161 | elif type == slicer.qMRMLScreenShotDialog.ThreeD: 162 | # just the 3D window 163 | widget = lm.threeDWidget(0).threeDView() 164 | elif type == slicer.qMRMLScreenShotDialog.Red: 165 | # red slice window 166 | widget = lm.sliceWidget("Red") 167 | elif type == slicer.qMRMLScreenShotDialog.Yellow: 168 | # yellow slice window 169 | widget = lm.sliceWidget("Yellow") 170 | elif type == slicer.qMRMLScreenShotDialog.Green: 171 | # green slice window 172 | widget = lm.sliceWidget("Green") 173 | else: 174 | # default to using the full window 175 | widget = slicer.util.mainWindow() 176 | # reset the type so that the node is set correctly 177 | type = slicer.qMRMLScreenShotDialog.FullLayout 178 | 179 | # grab and convert to vtk image data 180 | qpixMap = qt.QPixmap().grabWidget(widget) 181 | qimage = qpixMap.toImage() 182 | imageData = vtk.vtkImageData() 183 | slicer.qMRMLUtils().qImageToVtkImageData(qimage,imageData) 184 | 185 | annotationLogic = slicer.modules.annotations.logic() 186 | annotationLogic.CreateSnapShot(name, description, type, 1, imageData) 187 | 188 | def hist_curve(self, im): 189 | h = np.zeros((300,256,3)) 190 | if len(im.shape) == 2: 191 | color = [(255,255,255)] 192 | elif im.shape[2] == 3: 193 | color = [ (255,0,0),(0,255,0),(0,0,255) ] 194 | for ch, col in enumerate(color): 195 | hist_item = cv2.calcHist([im],[ch],None,[256],[0,256]) 196 | cv2.normalize(hist_item,hist_item,0,255,cv2.NORM_MINMAX) 197 | hist=np.int32(np.around(hist_item)) 198 | pts = np.int32(np.column_stack((self.bins,hist))) 199 | cv2.polylines(h,[pts],False,col) 200 | y=np.flipud(h) 201 | return y 202 | 203 | def hist_lines(self, im): 204 | h = np.zeros((300,256,3)) 205 | if len(im.shape)!=2: 206 | print("hist_lines applicable only for grayscale images") 207 | #print("so converting image to grayscale for representation" 208 | im = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) 209 | hist_item = cv2.calcHist([im],[0],None,[256],[0,256]) 210 | cv2.normalize(hist_item,hist_item,0,255,cv2.NORM_MINMAX) 211 | hist=np.int32(np.around(hist_item)) 212 | for x,y in enumerate(hist): 213 | cv2.line(h,(x,0),(x,y),(255,255,255)) 214 | y = np.flipud(h) 215 | return y 216 | 217 | def run(self, inputVolume, enableScreenshots=0): 218 | """ 219 | Do a histogram of an input image. 220 | Based on OpenCV-source/samples/python/hist.py 221 | """ 222 | 223 | logging.info('Processing started') 224 | 225 | id = inputVolume.GetID() 226 | # get the file name to re-read with OpenCV 227 | fname = inputVolume.GetStorageNode().GetFileName() 228 | logging.info('File name = %s' % fname) 229 | im = cv2.imread(fname) 230 | 231 | if im is None: 232 | print('Failed to load image file:', fname) 233 | return False 234 | 235 | if enableScreenshots: 236 | self.takeScreenshot('SlicerOpenCVSelfTestTest-Start','OpenCVHistogramScreenshot',-1) 237 | 238 | # Compute the histogram using the OpenCV hist function 239 | self.bins = np.arange(256).reshape(256,1) 240 | 241 | gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) 242 | 243 | 244 | # Histogram plotting 245 | 246 | cv2.imshow('image',im) 247 | 248 | slicer.util.delayDisplay('Showing histogram for color image in curve mode', 1000) 249 | curve = self.hist_curve(im) 250 | cv2.imshow('histogram',curve) 251 | cv2.imshow('image',im) 252 | 253 | slicer.util.delayDisplay('Showing histogram in bin mode', 1000) 254 | lines = self.hist_lines(im) 255 | cv2.imshow('histogram',lines) 256 | cv2.imshow('image',gray) 257 | 258 | slicer.util.delayDisplay('Showing equalized histogram (always in bin mode)', 1000) 259 | equ = cv2.equalizeHist(gray) 260 | lines = self.hist_lines(equ) 261 | cv2.imshow('histogram',lines) 262 | cv2.imshow('image',equ) 263 | 264 | slicer.util.delayDisplay('Showing histogram for color image in curve mode', 1000) 265 | curve = self.hist_curve(gray) 266 | cv2.imshow('histogram',curve) 267 | cv2.imshow('image',gray) 268 | 269 | slicer.util.delayDisplay('Showing histogram for a normalized image in curve mode', 1000) 270 | norm = cv2.normalize(gray, gray, alpha = 0,beta = 255,norm_type = cv2.NORM_MINMAX) 271 | lines = self.hist_lines(norm) 272 | cv2.imshow('histogram',lines) 273 | cv2.imshow('image',norm) 274 | 275 | slicer.util.delayDisplay('Done showing histogram options', 1000) 276 | cv2.destroyAllWindows() 277 | 278 | # Capture screenshot 279 | if enableScreenshots: 280 | self.takeScreenshot('SlicerOpenCVSelfTestTest-End','HistogramScreenshot',-1) 281 | 282 | logging.info('Processing completed') 283 | 284 | return True 285 | 286 | 287 | class SlicerOpenCVSelfTestTest(ScriptedLoadableModuleTest): 288 | """ 289 | This is the test case for your scripted module. 290 | Uses ScriptedLoadableModuleTest base class, available at: 291 | https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py 292 | """ 293 | 294 | def setUp(self): 295 | """ Do whatever is needed to reset the state - typically a scene clear will be enough. 296 | """ 297 | slicer.mrmlScene.Clear(0) 298 | 299 | def runTest(self): 300 | """Run as few or as many tests as needed here. 301 | """ 302 | self.setUp() 303 | self.test_SlicerOpenCVSelfTest1() 304 | 305 | def test_SlicerOpenCVSelfTest1(self): 306 | 307 | self.delayDisplay("Starting the test") 308 | # 309 | # first, get some data 310 | # 311 | import urllib 312 | downloads = ( 313 | ('http://slicer.kitware.com/midas3/download/item/253131', 'TCGA-XJ-A9DX-01Z-00-DX1_appMag_40_29_38-256x256-180.png', slicer.util.loadVolume), 314 | ) 315 | 316 | for url,name,loader in downloads: 317 | filePath = slicer.app.temporaryPath + '/' + name 318 | if not os.path.exists(filePath) or os.stat(filePath).st_size == 0: 319 | logging.info('Requesting download %s from %s...\n' % (name, url)) 320 | urllib.urlretrieve(url, filePath) 321 | if loader: 322 | logging.info('Loading %s...' % (name,)) 323 | properties = {'singleFile' : 0} 324 | loader(filePath, properties) 325 | self.delayDisplay('Finished with download and loading') 326 | 327 | volumeNode = slicer.util.getNode(pattern="TCGA-XJ-A9DX-01Z-00-DX1_appMag_40_29_38-256x256-180") 328 | logic = SlicerOpenCVSelfTestLogic() 329 | 330 | logic.run(volumeNode) 331 | 332 | self.delayDisplay('Test passed!') 333 | -------------------------------------------------------------------------------- /SlicerOpenCV/qSlicerOpenCVModule.cxx: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | ==============================================================================*/ 17 | 18 | // Core includes 19 | #include 20 | #include 21 | #include 22 | 23 | // Qt includes 24 | #include 25 | #include 26 | 27 | // SlicerOpenCV Logic includes 28 | #include 29 | 30 | // SlicerOpenCV includes 31 | #include "qSlicerOpenCVModule.h" 32 | 33 | // ITK includes 34 | 35 | //----------------------------------------------------------------------------- 36 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) 37 | #include 38 | Q_EXPORT_PLUGIN2(qSlicerOpenCVModule, qSlicerOpenCVModule); 39 | #endif 40 | 41 | //----------------------------------------------------------------------------- 42 | /// \ingroup Slicer_QtModules_ExtensionTemplate 43 | class qSlicerOpenCVModulePrivate 44 | { 45 | public: 46 | qSlicerOpenCVModulePrivate(); 47 | }; 48 | 49 | //----------------------------------------------------------------------------- 50 | // qSlicerOpenCVModulePrivate methods 51 | 52 | //----------------------------------------------------------------------------- 53 | qSlicerOpenCVModulePrivate::qSlicerOpenCVModulePrivate() 54 | { 55 | } 56 | 57 | //----------------------------------------------------------------------------- 58 | // qSlicerOpenCVModule methods 59 | 60 | //----------------------------------------------------------------------------- 61 | qSlicerOpenCVModule::qSlicerOpenCVModule(QObject* _parent) 62 | : Superclass(_parent) 63 | , d_ptr(new qSlicerOpenCVModulePrivate) 64 | { 65 | } 66 | 67 | //----------------------------------------------------------------------------- 68 | qSlicerOpenCVModule::~qSlicerOpenCVModule() 69 | { 70 | } 71 | 72 | //----------------------------------------------------------------------------- 73 | QString qSlicerOpenCVModule::helpText() const 74 | { 75 | return "This is a loadable module that provides access to OpenCV"; 76 | } 77 | 78 | //----------------------------------------------------------------------------- 79 | QString qSlicerOpenCVModule::acknowledgementText() const 80 | { 81 | return "This work was supported by a supplement to the Quantitative Image Informatics project via the NIH-National Cancer Institute Grant U24 CA180918-03 as well as U24 CA180924 Tools to Analyze Morphology and Spatially Mapped Molecular Data with Stony Brook University."; 82 | } 83 | 84 | //----------------------------------------------------------------------------- 85 | QStringList qSlicerOpenCVModule::contributors() const 86 | { 87 | QStringList moduleContributors; 88 | moduleContributors << QString("Nicole Aucoin (BWH)"); 89 | moduleContributors << QString("Andrey Fedorov (BWH)"); 90 | moduleContributors << QString("Jean-Christophe Fillion-Robin (Kitware)"); 91 | return moduleContributors; 92 | } 93 | 94 | //----------------------------------------------------------------------------- 95 | QIcon qSlicerOpenCVModule::icon() const 96 | { 97 | return QIcon(":/Icons/SlicerOpenCV.png"); 98 | } 99 | 100 | //----------------------------------------------------------------------------- 101 | QStringList qSlicerOpenCVModule::categories() const 102 | { 103 | return QStringList() << "Libraries"; 104 | } 105 | 106 | //----------------------------------------------------------------------------- 107 | QStringList qSlicerOpenCVModule::dependencies() const 108 | { 109 | return QStringList(); 110 | } 111 | 112 | //----------------------------------------------------------------------------- 113 | void qSlicerOpenCVModule::setup() 114 | { 115 | this->Superclass::setup(); 116 | 117 | qSlicerExtensionsManagerModel* model = qSlicerApplication::application()->extensionsManagerModel(); 118 | QString settingsPath = model->extensionsSettingsFilePath(); 119 | QSettings settings(settingsPath, QSettings::IniFormat); 120 | if (settings.status() != QSettings::NoError) 121 | { 122 | qWarning() << (QString("Failed to open extensions settings file %1. Python access to OpenCV will not be available.").arg(settingsPath)); 123 | return; 124 | } 125 | 126 | // Determine this extensions root install path 127 | QString path = model->extensionInstallPath("SlicerOpenCV"); 128 | 129 | // Check if path already exists 130 | QStringList pythonPaths = qSlicerExtensionsManagerModel::readArrayValues(settings, "PYTHONPATH", "path"); 131 | for (QStringList::const_iterator iter = pythonPaths.constBegin(); iter != pythonPaths.constEnd(); ++iter) 132 | { 133 | if (*iter == path) 134 | { 135 | // Found, no need to continue 136 | return; 137 | } 138 | } 139 | pythonPaths << path; 140 | qSlicerExtensionsManagerModel::writeArrayValues(settings, pythonPaths, "PYTHONPATH", "path"); 141 | 142 | // Add the path to this running instances path list 143 | qSlicerApplication::application()->corePythonManager()->appendPythonPath(path); 144 | } 145 | 146 | //----------------------------------------------------------------------------- 147 | qSlicerAbstractModuleRepresentation* qSlicerOpenCVModule 148 | ::createWidgetRepresentation() 149 | { 150 | return NULL; 151 | } 152 | 153 | //----------------------------------------------------------------------------- 154 | vtkMRMLAbstractLogic* qSlicerOpenCVModule::createLogic() 155 | { 156 | return vtkSlicerOpenCVLogic::New(); 157 | } 158 | 159 | //----------------------------------------------------------------------------- 160 | bool qSlicerOpenCVModule::isHidden()const 161 | { 162 | return true; 163 | } 164 | -------------------------------------------------------------------------------- /SlicerOpenCV/qSlicerOpenCVModule.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | ==============================================================================*/ 17 | 18 | #ifndef __qSlicerOpenCVModule_h 19 | #define __qSlicerOpenCVModule_h 20 | 21 | // SlicerQt includes 22 | #include "qSlicerLoadableModule.h" 23 | 24 | #include "qSlicerOpenCVModuleExport.h" 25 | 26 | class qSlicerOpenCVModulePrivate; 27 | 28 | /// \ingroup Slicer_QtModules_ExtensionTemplate 29 | class Q_SLICER_QTMODULES_OPENCV_EXPORT 30 | qSlicerOpenCVModule 31 | : public qSlicerLoadableModule 32 | { 33 | Q_OBJECT 34 | #ifdef Slicer_HAVE_QT5 35 | Q_PLUGIN_METADATA(IID "org.slicer.modules.loadable.qSlicerLoadableModule/1.0"); 36 | #endif 37 | Q_INTERFACES(qSlicerLoadableModule); 38 | 39 | public: 40 | 41 | typedef qSlicerLoadableModule Superclass; 42 | explicit qSlicerOpenCVModule(QObject *parent=0); 43 | virtual ~qSlicerOpenCVModule(); 44 | 45 | qSlicerGetTitleMacro(QTMODULE_TITLE); 46 | 47 | virtual QString helpText()const; 48 | virtual QString acknowledgementText()const; 49 | virtual QStringList contributors()const; 50 | 51 | /// This module is hidden as it doesn't provide a GUI but it can still be 52 | /// accessed programatically. 53 | virtual bool isHidden()const; 54 | 55 | virtual QIcon icon()const; 56 | 57 | virtual QStringList categories()const; 58 | virtual QStringList dependencies() const; 59 | 60 | protected: 61 | 62 | /// Initialize the module. Register the volumes reader/writer 63 | virtual void setup(); 64 | 65 | /// Create and return the widget representation associated to this module 66 | virtual qSlicerAbstractModuleRepresentation * createWidgetRepresentation(); 67 | 68 | /// Create and return the logic associated to this module 69 | virtual vtkMRMLAbstractLogic* createLogic(); 70 | 71 | protected: 72 | QScopedPointer d_ptr; 73 | 74 | private: 75 | Q_DECLARE_PRIVATE(qSlicerOpenCVModule); 76 | Q_DISABLE_COPY(qSlicerOpenCVModule); 77 | 78 | }; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /SuperBuild.cmake: -------------------------------------------------------------------------------- 1 | 2 | #----------------------------------------------------------------------------- 3 | # Give option to only build for a specific instruction set 4 | #----------------------------------------------------------------------------- 5 | set(Slicer_CUDA_GENERATION "" CACHE STRING "Build CUDA device code only for specific GPU architecture. Leave empty to build for all architectures.") 6 | set_property(CACHE Slicer_CUDA_GENERATION PROPERTY STRINGS "" "Fermi" "Kepler" "Maxwell" "Pascal" "Volta") 7 | 8 | #----------------------------------------------------------------------------- 9 | # External project common settings 10 | #----------------------------------------------------------------------------- 11 | 12 | set(ep_common_c_flags "${CMAKE_C_FLAGS_INIT} ${ADDITIONAL_C_FLAGS}") 13 | set(ep_common_cxx_flags "${CMAKE_CXX_FLAGS_INIT} ${ADDITIONAL_CXX_FLAGS}") 14 | 15 | #----------------------------------------------------------------------------- 16 | # Top-level "external" project 17 | #----------------------------------------------------------------------------- 18 | 19 | # Extension dependencies 20 | foreach(dep ${EXTENSION_DEPENDS}) 21 | mark_as_superbuild(${dep}_DIR) 22 | endforeach() 23 | 24 | # Ensure call to "find_package(OpenCV)" made in any projects 25 | # look for static libraries 26 | set(OpenCV_STATIC 1) 27 | mark_as_superbuild(VARS OpenCV_STATIC ALL_PROJECTS) 28 | 29 | # Project dependencies 30 | set(proj ${SUPERBUILD_TOPLEVEL_PROJECT}) 31 | 32 | set(${proj}_DEPENDS 33 | ITKVideoBridgeOpenCV 34 | ) 35 | 36 | ExternalProject_Include_Dependencies(${proj} 37 | PROJECT_VAR proj 38 | SUPERBUILD_VAR ${EXTENSION_NAME}_SUPERBUILD 39 | ) 40 | 41 | ExternalProject_Add(${proj} 42 | ${${proj}_EP_ARGS} 43 | DOWNLOAD_COMMAND "" 44 | INSTALL_COMMAND "" 45 | SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} 46 | BINARY_DIR ${EXTENSION_BUILD_SUBDIRECTORY} 47 | BUILD_ALWAYS 1 48 | CMAKE_CACHE_ARGS 49 | -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} 50 | -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags} 51 | -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} 52 | -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags} 53 | -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 54 | -DCMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} 55 | -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} 56 | -DMIDAS_PACKAGE_EMAIL:STRING=${MIDAS_PACKAGE_EMAIL} 57 | -DMIDAS_PACKAGE_API_KEY:STRING=${MIDAS_PACKAGE_API_KEY} 58 | -D${EXTENSION_NAME}_SUPERBUILD:BOOL=OFF 59 | -DEXTENSION_SUPERBUILD_BINARY_DIR:PATH=${${EXTENSION_NAME}_BINARY_DIR} 60 | DEPENDS 61 | ${${proj}_DEPENDS} 62 | ) 63 | 64 | ExternalProject_AlwaysConfigure(${proj}) 65 | -------------------------------------------------------------------------------- /SuperBuild/External_ITKVideoBridgeOpenCV.cmake: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------------- 2 | # Build the ITK OpenCV bridge, pointing it to Slicer's ITK and this build 3 | # of OpenCV 4 | 5 | set(proj ITKVideoBridgeOpenCV) 6 | 7 | # Dependencies 8 | set(${proj}_DEPENDENCIES OpenCV) 9 | ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES) 10 | 11 | set(ITK_SOURCE_DIR ${ITK_DIR}/../ITK) 12 | set(${proj}_SOURCE_DIR ${ITK_SOURCE_DIR}/Modules/Video/BridgeOpenCV) 13 | ExternalProject_Message(${proj} "ITK_SOURCE_DIR:${ITK_SOURCE_DIR}") 14 | ExternalProject_Message(${proj} "${proj}_SOURCE_DIR:${${proj}_SOURCE_DIR}") 15 | 16 | # don't allow using the system ITK, use the Slicer one 17 | set(${proj}_BINARY_DIR ${CMAKE_BINARY_DIR}/${proj}-build) 18 | 19 | ExternalProject_Add(${proj} 20 | ${${proj}_EP_ARGS} 21 | # build from Slicer's ITK into the extension's ITK build dir 22 | DOWNLOAD_COMMAND "" 23 | SOURCE_DIR ${${proj}_SOURCE_DIR} 24 | BINARY_DIR ${${proj}_BINARY_DIR} 25 | INSTALL_COMMAND "" 26 | CMAKE_CACHE_ARGS 27 | -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} 28 | -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags} 29 | -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} 30 | -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags} 31 | -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} 32 | -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} 33 | -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} 34 | # to find ITKConfig.cmake 35 | -DITK_DIR:PATH=${ITK_DIR} 36 | -DBUILD_TESTING:BOOL=OFF 37 | -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CMAKE_BINARY_DIR}/${Slicer_THIRDPARTY_BIN_DIR} 38 | -DCMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CMAKE_BINARY_DIR}/${Slicer_THIRDPARTY_LIB_DIR} 39 | -DITK_INSTALL_RUNTIME_DIR:STRING=${Slicer_INSTALL_THIRDPARTY_LIB_DIR} 40 | -DITK_INSTALL_LIBRARY_DIR:STRING=${Slicer_INSTALL_THIRDPARTY_LIB_DIR} 41 | -DCMAKE_MACOSX_RPATH:BOOL=0 42 | # to find OpenCVConfig.cmake 43 | -DOpenCV_DIR:PATH=${OpenCV_DIR} 44 | DEPENDS ${${proj}_DEPENDENCIES} 45 | ) 46 | 47 | set(${proj}_DIR ${${proj}_BINARY_DIR}) 48 | mark_as_superbuild(VARS ${proj}_DIR:PATH) 49 | 50 | ExternalProject_Message(${proj} "${proj}_DIR:${${proj}_DIR}") 51 | -------------------------------------------------------------------------------- /SuperBuild/External_OpenCV.cmake: -------------------------------------------------------------------------------- 1 | set(proj OpenCV) 2 | 3 | # Set dependency list 4 | set(${proj}_DEPENDENCIES "") 5 | 6 | # Include dependent projects if any 7 | ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES) 8 | 9 | if(${SUPERBUILD_TOPLEVEL_PROJECT}_USE_SYSTEM_${proj}) 10 | unset(OpenCV_DIR CACHE) 11 | find_package(OpenCV 4.5 REQUIRED) 12 | if(NOT OPENCV_ARUCO_FOUND) 13 | message(FATAL_ERROR System OpenCV not built with contrib modules) 14 | endif() 15 | set(OpenCV_INCLUDE_DIR ${OpenCV_INCLUDE_DIRS}) 16 | set(OpenCV_LIBRARY ${OpenCV_LIBRARIES}) 17 | endif() 18 | 19 | # Sanity checks 20 | if(DEFINED OpenCV_DIR AND NOT EXISTS ${OpenCV_DIR}) 21 | message(FATAL_ERROR "OpenCV_DIR variable is defined but corresponds to nonexistent directory") 22 | endif() 23 | 24 | if(NOT DEFINED OpenCV_DIR AND NOT ${SUPERBUILD_TOPLEVEL_PROJECT}_USE_SYSTEM_${proj}) 25 | 26 | # OpenCV_contrib 27 | ExternalProject_SetIfNotDefined( 28 | ${SUPERBUILD_TOPLEVEL_PROJECT}_OpenCV_contrib_GIT_REPOSITORY 29 | "https://github.com/Slicer/opencv_contrib.git" 30 | QUIET 31 | ) 32 | 33 | ExternalProject_SetIfNotDefined( 34 | ${SUPERBUILD_TOPLEVEL_PROJECT}_OpenCV_contrib_GIT_TAG 35 | "49e8f123ca08e76891856a1ecce491b62d08ba20" # slicer-4.5.5-2021.12.25-49e8f123 36 | QUIET 37 | ) 38 | 39 | set(OpenCV_contrib_SOURCE_DIR ${CMAKE_BINARY_DIR}/OpenCV_contrib) 40 | ExternalProject_Message(${proj} "OpenCV_contrib_SOURCE_DIR:${OpenCV_contrib_SOURCE_DIR}") 41 | ExternalProject_Add(OpenCV_contrib-source 42 | GIT_REPOSITORY "${${SUPERBUILD_TOPLEVEL_PROJECT}_OpenCV_contrib_GIT_REPOSITORY}" 43 | GIT_TAG "${${SUPERBUILD_TOPLEVEL_PROJECT}_OpenCV_contrib_GIT_TAG}" 44 | DOWNLOAD_DIR ${CMAKE_BINARY_DIR} 45 | SOURCE_DIR ${OpenCV_contrib_SOURCE_DIR} 46 | BUILD_IN_SOURCE 1 47 | CONFIGURE_COMMAND "" 48 | BUILD_COMMAND "" 49 | INSTALL_COMMAND "" 50 | ) 51 | list(APPEND ${proj}_DEPENDENCIES 52 | OpenCV_contrib-source 53 | ) 54 | 55 | # OpenCV 56 | ExternalProject_SetIfNotDefined( 57 | ${SUPERBUILD_TOPLEVEL_PROJECT}_${proj}_GIT_REPOSITORY 58 | https://github.com/Slicer/opencv.git 59 | QUIET 60 | ) 61 | 62 | ExternalProject_SetIfNotDefined( 63 | ${SUPERBUILD_TOPLEVEL_PROJECT}_${proj}_GIT_TAG 64 | "498d4690b2331a813357d628d6a4549925033ce2" # slicer-4.5.5-2021.12.25-dad26339a9 65 | QUIET 66 | ) 67 | 68 | set(${proj}_SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}) 69 | set(${proj}_INSTALL_DIR ${CMAKE_BINARY_DIR}/${proj}-install) 70 | 71 | if(APPLE) 72 | # Workaround for OpenCV 3.2+ and OSX clang compiler issues 73 | list(APPEND ADDITIONAL_OPENCV_ARGS -DBUILD_PROTOBUF:BOOL=OFF) 74 | endif() 75 | 76 | option(SlicerOpenCV_USE_CUDA "Enable or disable the building of CUDA modules" OFF) 77 | 78 | ExternalProject_Add(${proj} 79 | ${${proj}_EP_ARGS} 80 | GIT_REPOSITORY "${${SUPERBUILD_TOPLEVEL_PROJECT}_${proj}_GIT_REPOSITORY}" 81 | GIT_TAG "${${SUPERBUILD_TOPLEVEL_PROJECT}_${proj}_GIT_TAG}" 82 | SOURCE_DIR ${${proj}_SOURCE_DIR} 83 | BINARY_DIR ${proj}-build 84 | INSTALL_DIR ${${proj}_INSTALL_DIR} 85 | CMAKE_CACHE_ARGS 86 | # Compiler settings 87 | -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} 88 | -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags} 89 | -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} 90 | -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags} 91 | -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} 92 | -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} 93 | -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} 94 | 95 | # Options 96 | -DBUILD_WITH_STATIC_CRT:BOOL=OFF # Uses runtime compatible with ITK. See issue #26 97 | -DOPENCV_MANGLE_PREFIX:STRING=slicer_opencv_ 98 | -DBUILD_SHARED_LIBS:BOOL=ON 99 | -DBUILD_DOCS:BOOL=OFF 100 | -DBUILD_EXAMPLES:BOOL=OFF 101 | -DBUILD_PERF_TESTS:BOOL=OFF 102 | -DBUILD_TESTING:BOOL=OFF 103 | -DBUILD_TESTS:BOOL=OFF 104 | -DBUILD_WITH_DEBUG_INFO:BOOL=OFF 105 | -DOPENCV_BIN_INSTALL_PATH:PATH=${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR} 106 | 107 | # Enable modules 108 | -DBUILD_opencv_core:BOOL=ON 109 | -DBUILD_opencv_highgui:BOOL=ON 110 | -DBUILD_opencv_imgcodecs:BOOL=ON 111 | -DBUILD_opencv_imgproc:BOOL=ON 112 | -DBUILD_opencv_ml:BOOL=ON 113 | -DBUILD_opencv_objdetect:BOOL=ON 114 | -DBUILD_opencv_photo:BOOL=ON 115 | -DBUILD_opencv_video:BOOL=ON 116 | -DBUILD_opencv_videoio:BOOL=ON 117 | # Enable modules required by the fact ITK calls 'find_package(OpenCV)' without specifying components. 118 | -DBUILD_opencv_calib3d:BOOL=ON 119 | -DBUILD_opencv_features2d:BOOL=ON 120 | -DBUILD_opencv_flann:BOOL=ON 121 | -DBUILD_opencv_shape:BOOL=ON 122 | -DBUILD_opencv_stitching:BOOL=ON 123 | -DBUILD_opencv_superres:BOOL=ON 124 | -DBUILD_opencv_videostab:BOOL=ON 125 | 126 | # Disable unused modules 127 | -DBUILD_opencv_apps:BOOL=OFF 128 | -DBUILD_opencv_ts:BOOL=OFF 129 | -DBUILD_opencv_world:BOOL=OFF 130 | 131 | # Features 132 | -DWITH_IPP:BOOL=OFF 133 | -DWITH_EIGEN:BOOL=OFF 134 | -DWITH_OPENCL:BOOL=OFF # Initially disabled because of build errors on MacOSX 10.6 (See #17) 135 | -DCUDA_GENERATION:STRING=${Slicer_CUDA_GENERATION} 136 | -DWITH_CUDA:BOOL=${SlicerOpenCV_USE_CUDA} 137 | -DBUILD_JAVA:BOOL=OFF 138 | -DWITH_GTK:BOOL=OFF 139 | -DWITH_GTK_2_X:BOOL=OFF 140 | -DWITH_QT:BOOL=OFF 141 | -DWITH_WIN32UI:BOOL=OFF 142 | 143 | # Options: Python 144 | -DOPENCV_SKIP_PYTHON_LOADER:BOOL=ON 145 | -DINSTALL_PYTHON_EXAMPLES:BOOL=OFF 146 | -DOPENCV_PYTHON_EXTRA_DEFINITIONS:STRING=CV_RELEASE_PYTHON # Specific to Slicer/opencv fork 147 | 148 | # Dependencies: Python 149 | # - Options expected by the OpenCV custom CMake function "find_python()" 150 | # implemented in "cmake/OpenCVDetectPython.cmake" 151 | -DPYTHON3_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} 152 | -DPYTHON3_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} 153 | -DPYTHON3_LIBRARY:FILEPATH=${PYTHON_LIBRARY} 154 | 155 | # Dependencies: VTK 156 | -DVTK_DIR:PATH=${VTK_DIR} 157 | 158 | # Dependencies: ZLIB 159 | -DBUILD_ZLIB:BOOL=OFF 160 | -DZLIB_ROOT:PATH=${ZLIB_ROOT} 161 | -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR} 162 | -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARY} 163 | -DCMAKE_POLICY_DEFAULT_CMP0074:STRING=NEW # Explicitly set to NEW to ensure ZLIB_ROOT is not ignored. 164 | 165 | # Dependencies: Media I/O 166 | -DBUILD_JPEG:BOOL=ON 167 | -DBUILD_OPENEXR:BOOL=ON 168 | -DBUILD_PNG:BOOL=ON 169 | -DBUILD_TIFF:BOOL=ON 170 | -DBUILD_WEBP:BOOL=ON 171 | 172 | # Dependencies: Media I/O: ZLIB 173 | #-DZLIB_ROOT:PATH=${ZLIB_ROOT} 174 | #-DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR} 175 | #-DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARY} 176 | #-DCMAKE_POLICY_DEFAULT_CMP0074:STRING=NEW # Explicitly set to NEW to ensure ZLIB_ROOT is not ignored. 177 | -DBUILD_ZLIB:BOOL=ON # See https://github.com/Slicer/SlicerOpenCV/issues/71 178 | 179 | # Dependencies: OpenCV_contrib 180 | -DOPENCV_EXTRA_MODULES_PATH:PATH=${OpenCV_contrib_SOURCE_DIR}/modules 181 | 182 | # Options: OpenCV_contrib 183 | -DBUILD_opencv_cnn_3dobj:BOOL=OFF # Require Caffe, Glog & Protobuf 184 | -DBUILD_opencv_hdf:BOOL=OFF # Require HDF5 185 | -DBUILD_opencv_julia:BOOL=OFF # Require JlCxx 186 | -DBUILD_opencv_ovis:BOOL=OFF # Require OGRE 187 | -DBUILD_opencv_sfm:BOOL=OFF # Require Ceres, Gflags & Glog 188 | -DBUILD_opencv_wechat_qrcode:BOOL=OFF # Require Iconv. See https://github.com/Slicer/SlicerOpenCV/issues/72 189 | -DWITH_TESSERACT:BOOL=OFF # text module 190 | 191 | # Install directories 192 | -DCMAKE_INSTALL_PREFIX:PATH= 193 | -DCMAKE_INSTALL_LIBDIR:STRING=${Slicer_INSTALL_THIRDPARTY_LIB_DIR} # Skip default initialization by GNUInstallDirs CMake module 194 | -DPYTHON3_PACKAGES_PATH:PATH=${Slicer_INSTALL_ROOT}${Slicer_BUNDLE_EXTENSIONS_LOCATION}${PYTHON_SITE_PACKAGES_SUBDIR} 195 | 196 | ${ADDITIONAL_OPENCV_ARGS} 197 | DEPENDS 198 | ${${proj}_DEPENDENCIES} 199 | ) 200 | 201 | 202 | set(OpenCV_DIR ${${proj}_INSTALL_DIR}) 203 | if(UNIX) 204 | set(OpenCV_DIR ${${proj}_INSTALL_DIR}/${Slicer_INSTALL_THIRDPARTY_LIB_DIR}/cmake/opencv4/) 205 | endif() 206 | 207 | ExternalProject_GenerateProjectDescription_Step(${proj}) 208 | else() 209 | # The project is provided using OpenCV_DIR, nevertheless since other projects 210 | # may depend on OpenCV, let's add an 'empty' one 211 | ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES}) 212 | endif() 213 | 214 | ExternalProject_Message(${proj} "OpenCV_DIR:${OpenCV_DIR}") 215 | mark_as_superbuild(OpenCV_DIR:PATH) 216 | 217 | # Set the python wrapped library path for the extension cmake file 218 | set(${proj}_PYTHON_LIB_DIR ${CMAKE_BINARY_DIR}/${proj}-build/lib) 219 | ExternalProject_Message(${proj} "OpenCV_PYTHON_LIB_DIR = ${${proj}_PYTHON_LIB_DIR}") 220 | mark_as_superbuild(${proj}_PYTHON_LIB_DIR:PATH) 221 | 222 | # Set this build directory for the upper level cmake file 223 | set(${proj}_BUILD_DIR ${CMAKE_BINARY_DIR}/${proj}-build) 224 | ExternalProject_Message(${proj} "OpenCV_BUILD_DIR = ${${proj}_BUILD_DIR}") 225 | mark_as_superbuild(${proj}_BUILD_DIR) 226 | --------------------------------------------------------------------------------