├── Exercises ├── ITKIntroduction │ ├── CMakeLists.txt │ └── exercise1 │ │ ├── build.sh │ │ ├── CMakeLists.txt │ │ ├── BasicImageFilteringITK.cxx │ │ ├── BasicImageFilteringITKAnswer1.cxx │ │ └── BasicImageFilteringITKAnswer2.cxx ├── OpenCVIntroduction │ ├── CMakeLists.txt │ ├── exercise1 │ │ ├── CMakeLists.txt │ │ ├── BasicFilteringOpenCV.cxx │ │ └── BasicFilteringOpenCVAnswer.cxx │ └── exercise2 │ │ ├── CMakeLists.txt │ │ ├── BasicVideoFilteringOpenCV.cxx │ │ └── BasicVideoFilteringOpenCVAnswer.cxx ├── CMakeLists.txt ├── ITKOpenCVBridge │ ├── CMakeLists.txt │ ├── exercise1 │ │ ├── CMakeLists.txt │ │ ├── BasicFilteringITKOpenCVBridgeAnswer.cxx │ │ └── BasicFilteringITKOpenCVBridge.cxx │ └── exercise2 │ │ ├── CMakeLists.txt │ │ ├── BasicVideoFilteringITKOpenCVBridge.cxx │ │ └── BasicVideoFilteringITKOpenCVBridgeAnswer.cxx └── ITKVideoPipeline │ ├── CMakeLists.txt │ ├── exercise1 │ ├── CMakeLists.txt │ ├── ITKVideoSingleFrameFilters.cxx │ └── ITKVideoSingleFrameFiltersAnswer.cxx │ └── exercise2 │ ├── CMakeLists.txt │ ├── ITKVideoMultiFrameFilters.cxx │ ├── ITKVideoMultiFrameFiltersAnswer.cxx │ └── ITKVideoMultiFrameFiltersAnswer2.cxx ├── Documents ├── Art │ ├── Tux.png │ ├── asus.jpg │ ├── hart.png │ ├── ibanez.png │ ├── itkLogo.png │ ├── leotta.png │ ├── perera.png │ ├── reynolds.png │ ├── OpenCVITKex1.png │ ├── OpenCVLogo.png │ ├── mandrilgray.png │ ├── OpenCVex1-GUI.png │ ├── KitwareFocusAreas.png │ ├── OpenCVITKex1-ans.png │ ├── OpenCVex1-ans-GUI.png │ ├── OpenCVex2-ans-GUI.png │ ├── blackeubuntulogo.png │ ├── OpenCVex2-ans-save.png │ ├── Screenshot-Nautilus.jpg │ ├── Screenshot-Terminal.jpg │ ├── Screenshot-CMakeGUI-01.png │ ├── Screenshot-CMakeGUI-02.png │ ├── Screenshot-CMakeGUI-03.png │ ├── Screenshot-CMakeGUI-04.png │ ├── Screenshot-CMakeGUI-05.png │ ├── Screenshot-ITKDoxygen-01.png │ ├── Screenshot-OpenTerminal.jpg │ ├── Screenshot-mandrillgray-01.png │ ├── Screenshot-VirtualBox-OSE-01.png │ ├── Screenshot-VirtualBox-OSE-02.png │ ├── Screenshot-mandrillgrayCanny-01.png │ ├── Screenshot-mandrillgrayMean-01.png │ ├── Screenshot-mandrillgrayMedian-01.png │ └── Screenshot-OpenCV-ITK-VirtualBox-01.png ├── CMakeLists.txt └── Tutorial │ ├── SoftwarePreparation2.tex │ ├── CMakeLists.txt │ ├── SoftwarePreparation1.tex │ ├── SoftwareEnvironment.tex │ ├── SoftwarePreparation.tex │ ├── ITKOpenCVBridgeTutorial.tex │ ├── ITKOverview.tex │ ├── ITKVideoFilters.tex │ ├── ITKOpenCVBridge.tex │ ├── OpenCVIntroduction.tex │ └── ITKIntroduction.tex ├── CMakeLists.txt └── README /Exercises/ITKIntroduction/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(exercise1) 3 | -------------------------------------------------------------------------------- /Exercises/OpenCVIntroduction/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(exercise1) 2 | add_subdirectory(exercise2) 3 | -------------------------------------------------------------------------------- /Documents/Art/Tux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Tux.png -------------------------------------------------------------------------------- /Documents/Art/asus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/asus.jpg -------------------------------------------------------------------------------- /Documents/Art/hart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/hart.png -------------------------------------------------------------------------------- /Documents/Art/ibanez.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/ibanez.png -------------------------------------------------------------------------------- /Documents/Art/itkLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/itkLogo.png -------------------------------------------------------------------------------- /Documents/Art/leotta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/leotta.png -------------------------------------------------------------------------------- /Documents/Art/perera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/perera.png -------------------------------------------------------------------------------- /Documents/Art/reynolds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/reynolds.png -------------------------------------------------------------------------------- /Documents/Art/OpenCVITKex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/OpenCVITKex1.png -------------------------------------------------------------------------------- /Documents/Art/OpenCVLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/OpenCVLogo.png -------------------------------------------------------------------------------- /Documents/Art/mandrilgray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/mandrilgray.png -------------------------------------------------------------------------------- /Documents/Art/OpenCVex1-GUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/OpenCVex1-GUI.png -------------------------------------------------------------------------------- /Documents/Art/KitwareFocusAreas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/KitwareFocusAreas.png -------------------------------------------------------------------------------- /Documents/Art/OpenCVITKex1-ans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/OpenCVITKex1-ans.png -------------------------------------------------------------------------------- /Documents/Art/OpenCVex1-ans-GUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/OpenCVex1-ans-GUI.png -------------------------------------------------------------------------------- /Documents/Art/OpenCVex2-ans-GUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/OpenCVex2-ans-GUI.png -------------------------------------------------------------------------------- /Documents/Art/blackeubuntulogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/blackeubuntulogo.png -------------------------------------------------------------------------------- /Documents/Art/OpenCVex2-ans-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/OpenCVex2-ans-save.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-Nautilus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-Nautilus.jpg -------------------------------------------------------------------------------- /Documents/Art/Screenshot-Terminal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-Terminal.jpg -------------------------------------------------------------------------------- /Documents/Art/Screenshot-CMakeGUI-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-CMakeGUI-01.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-CMakeGUI-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-CMakeGUI-02.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-CMakeGUI-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-CMakeGUI-03.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-CMakeGUI-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-CMakeGUI-04.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-CMakeGUI-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-CMakeGUI-05.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-ITKDoxygen-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-ITKDoxygen-01.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-OpenTerminal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-OpenTerminal.jpg -------------------------------------------------------------------------------- /Documents/Art/Screenshot-mandrillgray-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-mandrillgray-01.png -------------------------------------------------------------------------------- /Exercises/ITKIntroduction/exercise1/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /home/tutorial/bin/ITK-OpenCV-Bridge-Tutorial/Exercises/ITKIntroduction/exercise1 3 | make 4 | gnome-terminal 5 | -------------------------------------------------------------------------------- /Documents/Art/Screenshot-VirtualBox-OSE-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-VirtualBox-OSE-01.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-VirtualBox-OSE-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-VirtualBox-OSE-02.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-mandrillgrayCanny-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-mandrillgrayCanny-01.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-mandrillgrayMean-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-mandrillgrayMean-01.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-mandrillgrayMedian-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-mandrillgrayMedian-01.png -------------------------------------------------------------------------------- /Documents/Art/Screenshot-OpenCV-ITK-VirtualBox-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightSoftwareConsortium/ITK-OpenCV-Bridge-Tutorial/HEAD/Documents/Art/Screenshot-OpenCV-ITK-VirtualBox-01.png -------------------------------------------------------------------------------- /Exercises/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Here we will add the hands-on exercises 3 | # 4 | add_subdirectory( ITKIntroduction ) 5 | add_subdirectory( OpenCVIntroduction ) 6 | add_subdirectory( ITKOpenCVBridge ) 7 | add_subdirectory( ITKVideoPipeline ) 8 | -------------------------------------------------------------------------------- /Exercises/ITKOpenCVBridge/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(ITK REQUIRED ) 2 | if(ITK_FOUND) 3 | include(${ITK_USE_FILE}) 4 | endif() 5 | 6 | find_package(OpenCV REQUIRED) 7 | if(OpenCV_FOUND) 8 | include_directories(${OpenCV_INCLUDE_DIRS}) 9 | endif() 10 | 11 | add_subdirectory(exercise1) 12 | add_subdirectory(exercise2) 13 | -------------------------------------------------------------------------------- /Exercises/ITKVideoPipeline/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(ITK REQUIRED ) 2 | if(ITK_FOUND) 3 | include(${ITK_USE_FILE}) 4 | endif() 5 | 6 | find_package(OpenCV REQUIRED) 7 | if(OpenCV_FOUND) 8 | include_directories(${OpenCV_INCLUDE_DIRS}) 9 | endif() 10 | 11 | add_subdirectory(exercise1) 12 | add_subdirectory(exercise2) 13 | -------------------------------------------------------------------------------- /Documents/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(LATEX) 2 | 3 | if(NOT PDFLATEX_COMPILER) 4 | message("pdflatex compiler was not found. Please pass to advanced mode and provide its full path" FATAL_ERROR) 5 | endif() 6 | 7 | file(GLOB_RECURSE PNG_FILES "*.png") 8 | file(GLOB_RECURSE JPG_FILES "*.jpg") 9 | 10 | add_subdirectory(Tutorial) 11 | 12 | -------------------------------------------------------------------------------- /Exercises/OpenCVIntroduction/exercise1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( BasicFilteringOpenCV ) 2 | 3 | find_package( OpenCV REQUIRED ) 4 | 5 | add_executable( BasicFilteringOpenCV BasicFilteringOpenCV.cxx ) 6 | target_link_libraries( BasicFilteringOpenCV ${OpenCV_LIBS} ) 7 | 8 | add_executable( BasicFilteringOpenCVAnswer BasicFilteringOpenCVAnswer.cxx ) 9 | target_link_libraries( BasicFilteringOpenCVAnswer ${OpenCV_LIBS} ) 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8 FATAL_ERROR) 2 | 3 | project(ITK-OpenCV-Bridge) 4 | 5 | set(CMAKE_MODULE_PATH ${ITK-OpenCV-Bridge_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH}) 6 | 7 | 8 | file(GLOB_RECURSE CXX_FILES "*.cxx") 9 | 10 | 11 | add_subdirectory(Exercises) 12 | 13 | 14 | option(BUILD_PRESENTATION "Build the PDF Presentation." ON) 15 | 16 | if(BUILD_PRESENTATION) 17 | add_subdirectory(Documents) 18 | endif() 19 | -------------------------------------------------------------------------------- /Exercises/OpenCVIntroduction/exercise2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( BasicVideoFilteringOpenCV ) 2 | 3 | find_package( OpenCV REQUIRED ) 4 | 5 | add_executable( BasicVideoFilteringOpenCV BasicVideoFilteringOpenCV.cxx ) 6 | target_link_libraries( BasicVideoFilteringOpenCV ${OpenCV_LIBS} ) 7 | 8 | add_executable( BasicVideoFilteringOpenCVAnswer BasicVideoFilteringOpenCVAnswer.cxx ) 9 | target_link_libraries( BasicVideoFilteringOpenCVAnswer ${OpenCV_LIBS} ) 10 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This presentation is copyrighted by the Insight Software Consortium 2 | and it is publicly distributed under the: 3 | 4 | Creative Commons by Attribution License 3.0 5 | http://creativecommons.org/licenses/by/3.0/ 6 | 7 | 8 | This tutorial introduces the software bridge between ITK and OpenCV. 9 | The goal is to illustrate how ITK image analysis functionalities can 10 | be used from OpenCV applications. 11 | 12 | Source code examples are distributed under the Apache 2.0 License. 13 | -------------------------------------------------------------------------------- /Exercises/ITKOpenCVBridge/exercise1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # BasicFilteringITKOpenCVBridge 3 | add_executable(BasicFilteringITKOpenCVBridge 4 | BasicFilteringITKOpenCVBridge.cxx ) 5 | target_link_libraries(BasicFilteringITKOpenCVBridge 6 | ${ITK_LIBRARIES} ${OpenCV_LIBS}) 7 | 8 | # BasicFilteringITKOpenCVBridgeAnswer 9 | add_executable(BasicFilteringITKOpenCVBridgeAnswer 10 | BasicFilteringITKOpenCVBridgeAnswer.cxx ) 11 | target_link_libraries(BasicFilteringITKOpenCVBridgeAnswer 12 | ${ITK_LIBRARIES} ${OpenCV_LIBS}) 13 | -------------------------------------------------------------------------------- /Exercises/ITKVideoPipeline/exercise1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Make sure that we prefix the executable names with the exerciser number. 3 | # 4 | 5 | # ITKVideoPipeline 6 | add_executable(ITKVideoSingleFrameFilters 7 | ITKVideoSingleFrameFilters.cxx ) 8 | target_link_libraries(ITKVideoSingleFrameFilters ${ITK_LIBRARIES} ${OpenCV_LIBS}) 9 | 10 | # ITKVideoPipeline 11 | add_executable(ITKVideoSingleFrameFiltersAnswer 12 | ITKVideoSingleFrameFiltersAnswer.cxx ) 13 | target_link_libraries(ITKVideoSingleFrameFiltersAnswer ${ITK_LIBRARIES} ${OpenCV_LIBS}) 14 | -------------------------------------------------------------------------------- /Exercises/ITKOpenCVBridge/exercise2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # BasicVideoFilteringITKOpenCVBridge 3 | add_executable(BasicVideoFilteringITKOpenCVBridge 4 | BasicVideoFilteringITKOpenCVBridge.cxx ) 5 | target_link_libraries(BasicVideoFilteringITKOpenCVBridge 6 | ${ITK_LIBRARIES} ${OpenCV_LIBS}) 7 | 8 | # BasicVideoFilteringITKOpenCVBridgeAnswer 9 | add_executable(BasicVideoFilteringITKOpenCVBridgeAnswer 10 | BasicVideoFilteringITKOpenCVBridgeAnswer.cxx ) 11 | target_link_libraries(BasicVideoFilteringITKOpenCVBridgeAnswer 12 | ${ITK_LIBRARIES} ${OpenCV_LIBS}) 13 | -------------------------------------------------------------------------------- /Exercises/ITKVideoPipeline/exercise2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Make sure that we prefix the executable names with the exerciser number. 3 | # 4 | 5 | # ITKVideoPipeline 6 | add_executable(ITKVideoMultiFrameFilters 7 | ITKVideoMultiFrameFilters.cxx ) 8 | target_link_libraries(ITKVideoMultiFrameFilters ${ITK_LIBRARIES} ${OpenCV_LIBS}) 9 | 10 | # ITKVideoPipeline 11 | add_executable(ITKVideoMultiFrameFiltersAnswer 12 | ITKVideoMultiFrameFiltersAnswer.cxx ) 13 | target_link_libraries(ITKVideoMultiFrameFiltersAnswer ${ITK_LIBRARIES} ${OpenCV_LIBS}) 14 | 15 | # ITKVideoPipelineAnswer2 16 | add_executable(ITKVideoMultiFrameFiltersAnswer2 17 | ITKVideoMultiFrameFiltersAnswer2.cxx ) 18 | target_link_libraries(ITKVideoMultiFrameFiltersAnswer2 ${ITK_LIBRARIES} ${OpenCV_LIBS}) 19 | -------------------------------------------------------------------------------- /Exercises/ITKIntroduction/exercise1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.4) 2 | if(COMMAND CMAKE_POLICY) 3 | cmake_policy(SET CMP0003 NEW) 4 | endif(COMMAND CMAKE_POLICY) 5 | 6 | project(ITKBasicImageFiltering) 7 | 8 | find_package(ITK REQUIRED) 9 | if(ITK_FOUND) 10 | include(${ITK_USE_FILE}) 11 | endif() 12 | 13 | find_package(OpenCV REQUIRED) 14 | if(OpenCV_FOUND) 15 | include_directories(${OpenCV_INCLUDE_DIRS}) 16 | endif() 17 | 18 | add_executable(BasicImageFilteringITK BasicImageFilteringITK.cxx ) 19 | target_link_libraries(BasicImageFilteringITK ${ITK_LIBRARIES}) 20 | 21 | add_executable(BasicImageFilteringITKAnswer1 BasicImageFilteringITKAnswer1.cxx ) 22 | target_link_libraries(BasicImageFilteringITKAnswer1 ${ITK_LIBRARIES}) 23 | 24 | add_executable(BasicImageFilteringITKAnswer2 BasicImageFilteringITKAnswer2.cxx ) 25 | target_link_libraries(BasicImageFilteringITKAnswer2 ${ITK_LIBRARIES}) 26 | -------------------------------------------------------------------------------- /Documents/Tutorial/SoftwarePreparation2.tex: -------------------------------------------------------------------------------- 1 | \section{Virtual Machines Preparation} 2 | 3 | \centeredlargetext{white}{black}{ 4 | Virtual Machines Preparation II 5 | } 6 | 7 | \begin{frame} 8 | \frametitle{Booting the Virtual Machine} 9 | \begin{itemize} 10 | \item Click on the ``OpenCV-ITK'' icon on the left, to select it. 11 | \item Click on the Green Arrow at the top ``Show''. 12 | \item The VM will start to boot and you will see the warning: 13 | \end{itemize} 14 | \begin{center} 15 | \includegraphics[width=0.4\paperwidth]{Screenshot-VirtualBox-OSE-02.png} 16 | \end{center} 17 | \begin{itemize} 18 | \item Click ``OK'' 19 | \end{itemize} 20 | \end{frame} 21 | 22 | \begin{frame} 23 | \frametitle{Booting the Virtual Machine} 24 | \begin{itemize} 25 | \item The boot sequence should continue and you shold see: 26 | \end{itemize} 27 | \begin{center} 28 | \includegraphics[width=0.7\paperwidth]{Screenshot-OpenCV-ITK-VirtualBox-01.png} 29 | \end{center} 30 | \end{frame} 31 | 32 | \centeredlargetext{white}{black}{ 33 | Your Virtual Machine\\ is Ready ! 34 | } 35 | 36 | \begin{frame} 37 | \frametitle{Additional Copies} 38 | \begin{itemize} 39 | \item The same source trees are available in the DVD / USB key 40 | \item Outside of the VirtualBox image 41 | \end{itemize} 42 | \end{frame} 43 | 44 | -------------------------------------------------------------------------------- /Exercises/OpenCVIntroduction/exercise1/BasicFilteringOpenCV.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | 26 | int main ( int argc, char **argv ) 27 | { 28 | if( argc < 2 ) 29 | { 30 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"< 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | 26 | int main ( int argc, char **argv ) 27 | { 28 | if( argc < 2 ) 29 | { 30 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"< 20 | #include 21 | #include 22 | 23 | int main( int argc, char * argv [] ) 24 | { 25 | if( argc < 5 ) 26 | { 27 | std::cerr << "Usage: " << std::endl; 28 | std::cerr << argv[0] << " inputImageFile outputImageFile radiusX radiusY" << std::endl; 29 | return EXIT_FAILURE; 30 | } 31 | 32 | typedef unsigned char InputPixelType; 33 | typedef unsigned char OutputPixelType; 34 | 35 | const unsigned int Dimension = 2; 36 | 37 | typedef itk::Image< InputPixelType, Dimension > InputImageType; 38 | typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 39 | 40 | typedef itk::ImageFileReader< InputImageType > ReaderType; 41 | typedef itk::ImageFileWriter< OutputImageType > WriterType; 42 | 43 | ReaderType::Pointer reader = ReaderType::New(); 44 | WriterType::Pointer writer = WriterType::New(); 45 | 46 | reader->SetFileName( argv[1] ); 47 | writer->SetFileName( argv[2] ); 48 | 49 | typedef itk::MedianImageFilter< InputImageType, OutputImageType > FilterType; 50 | 51 | FilterType::Pointer filter = FilterType::New(); 52 | 53 | InputImageType::SizeType indexRadius; 54 | 55 | indexRadius[0] = atoi( argv[3] ); // radius along x 56 | indexRadius[1] = atoi( argv[4] ); // radius along y 57 | 58 | filter->SetRadius( indexRadius ); 59 | 60 | filter->SetInput( reader->GetOutput() ); 61 | writer->SetInput( filter->GetOutput() ); 62 | 63 | try 64 | { 65 | writer->Update(); 66 | } 67 | catch( itk::ExceptionObject & excp ) 68 | { 69 | std::cerr << excp << std::endl; 70 | return EXIT_FAILURE; 71 | } 72 | 73 | return EXIT_SUCCESS; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /Exercises/ITKIntroduction/exercise1/BasicImageFilteringITKAnswer1.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int main( int argc, char * argv [] ) 24 | { 25 | if( argc < 5 ) 26 | { 27 | std::cerr << "Usage: " << std::endl; 28 | std::cerr << argv[0] << " inputImageFile outputImageFile radiusX radiusY" << std::endl; 29 | return EXIT_FAILURE; 30 | } 31 | 32 | typedef unsigned char InputPixelType; 33 | typedef unsigned char OutputPixelType; 34 | 35 | const unsigned int Dimension = 2; 36 | 37 | typedef itk::Image< InputPixelType, Dimension > InputImageType; 38 | typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 39 | 40 | typedef itk::ImageFileReader< InputImageType > ReaderType; 41 | typedef itk::ImageFileWriter< OutputImageType > WriterType; 42 | 43 | ReaderType::Pointer reader = ReaderType::New(); 44 | WriterType::Pointer writer = WriterType::New(); 45 | 46 | reader->SetFileName( argv[1] ); 47 | writer->SetFileName( argv[2] ); 48 | 49 | typedef itk::MeanImageFilter< InputImageType, OutputImageType > FilterType; 50 | 51 | FilterType::Pointer filter = FilterType::New(); 52 | 53 | InputImageType::SizeType indexRadius; 54 | 55 | indexRadius[0] = atoi( argv[3] ); // radius along x 56 | indexRadius[1] = atoi( argv[4] ); // radius along y 57 | 58 | filter->SetRadius( indexRadius ); 59 | 60 | filter->SetInput( reader->GetOutput() ); 61 | writer->SetInput( filter->GetOutput() ); 62 | 63 | try 64 | { 65 | writer->Update(); 66 | } 67 | catch( itk::ExceptionObject & excp ) 68 | { 69 | std::cerr << excp << std::endl; 70 | return EXIT_FAILURE; 71 | } 72 | 73 | return EXIT_SUCCESS; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /Exercises/ITKVideoPipeline/exercise1/ITKVideoSingleFrameFilters.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | int main ( int argc, char **argv ) 29 | { 30 | if( argc < 3 ) 31 | { 32 | std::cout << "Usage: " << argv[0] << "input_image output_image" << std::endl; 33 | return EXIT_FAILURE; 34 | } 35 | 36 | const unsigned int Dimension = 2; 37 | typedef unsigned char PixelType; 38 | typedef itk::Image< PixelType, Dimension > FrameType; 39 | typedef itk::VideoStream< FrameType > VideoType; 40 | 41 | typedef itk::VideoFileReader< VideoType > ReaderType; 42 | typedef itk::VideoFileWriter< VideoType > WriterType; 43 | typedef itk::MedianImageFilter< FrameType, FrameType > ImageFilterType; 44 | typedef itk::ImageFilterToVideoFilterWrapper< ImageFilterType > 45 | VideoFilterType; 46 | 47 | ReaderType::Pointer reader = ReaderType::New(); 48 | WriterType::Pointer writer = WriterType::New(); 49 | ImageFilterType::Pointer imageFilter = ImageFilterType::New(); 50 | VideoFilterType::Pointer videoFilter = VideoFilterType::New(); 51 | 52 | itk::ObjectFactoryBase::RegisterFactory( itk::OpenCVVideoIOFactory::New() ); 53 | reader->SetFileName( argv[1] ); 54 | writer->SetFileName( argv[2] ); 55 | 56 | FrameType::SizeType neighborhoodRadius; 57 | neighborhoodRadius[0] = 10; 58 | neighborhoodRadius[1] = 10; 59 | imageFilter->SetRadius( neighborhoodRadius ); 60 | videoFilter->SetImageFilter( imageFilter ); 61 | 62 | videoFilter->SetInput( reader->GetOutput() ); 63 | writer->SetInput( videoFilter->GetOutput() ); 64 | 65 | try 66 | { 67 | writer->Update(); 68 | } 69 | catch( itk::ExceptionObject & excp ) 70 | { 71 | std::cerr << excp << std::endl; 72 | return EXIT_FAILURE; 73 | } 74 | 75 | return EXIT_SUCCESS; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /Exercises/ITKOpenCVBridge/exercise1/BasicFilteringITKOpenCVBridgeAnswer.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | int main ( int argc, char **argv ) 28 | { 29 | if( argc < 2 ) 30 | { 31 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"< InputImageType; 41 | typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 42 | typedef itk::OpenCVImageBridge BridgeType; 43 | typedef itk::CurvatureFlowImageFilter< InputImageType, OutputImageType > 44 | FilterType; 45 | 46 | InputImageType::Pointer itkImage = 47 | BridgeType::CVMatToITKImage< InputImageType >( inputImage ); 48 | 49 | FilterType::Pointer filter = FilterType::New(); 50 | filter->SetTimeStep( 0.5 ); 51 | filter->SetNumberOfIterations( 20 ); 52 | 53 | filter->SetInput( itkImage ); 54 | try 55 | { 56 | filter->Update(); 57 | } 58 | catch( itk::ExceptionObject & excp ) 59 | { 60 | std::cerr << excp << std::endl; 61 | return EXIT_FAILURE; 62 | } 63 | 64 | cv::Mat resultImage = 65 | BridgeType::ITKImageToCVMat< OutputImageType >( filter->GetOutput() ); 66 | 67 | if(argc < 3) 68 | { 69 | std::string windowName = "Exercise 1: Basic Filtering in OpenCV & ITK"; 70 | cv::namedWindow( windowName, CV_WINDOW_FREERATIO); 71 | cvResizeWindow( windowName.c_str(), resultImage.cols, resultImage.rows+50 ); 72 | cv::Mat scaled; 73 | resultImage.convertTo(scaled, CV_8UC1 ); 74 | cv::imshow( windowName, scaled ); 75 | cv::waitKey(); 76 | } 77 | else 78 | { 79 | cv::imwrite( argv[2], resultImage ); 80 | } 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /Exercises/ITKOpenCVBridge/exercise1/BasicFilteringITKOpenCVBridge.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | int main ( int argc, char **argv ) 28 | { 29 | if( argc < 2 ) 30 | { 31 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"< InputImageType; 41 | typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 42 | typedef itk::OpenCVImageBridge BridgeType; 43 | typedef itk::MedianImageFilter< InputImageType, OutputImageType > 44 | FilterType; 45 | 46 | InputImageType::Pointer itkImage = 47 | BridgeType::CVMatToITKImage< InputImageType >( inputImage ); 48 | 49 | FilterType::Pointer filter = FilterType::New(); 50 | InputImageType::SizeType neighborhoodRadius; 51 | neighborhoodRadius[0] = 9; 52 | neighborhoodRadius[1] = 9; 53 | filter->SetRadius( neighborhoodRadius ); 54 | 55 | filter->SetInput( itkImage ); 56 | try 57 | { 58 | filter->Update(); 59 | } 60 | catch( itk::ExceptionObject & excp ) 61 | { 62 | std::cerr << excp << std::endl; 63 | return EXIT_FAILURE; 64 | } 65 | 66 | cv::Mat resultImage = 67 | BridgeType::ITKImageToCVMat< OutputImageType >( filter->GetOutput() ); 68 | 69 | if(argc < 3) 70 | { 71 | std::string windowName = "Exercise 1: Basic Filtering in OpenCV & ITK"; 72 | cv::namedWindow( windowName, CV_WINDOW_FREERATIO); 73 | cvResizeWindow( windowName.c_str(), resultImage.cols, resultImage.rows+50 ); 74 | cv::Mat scaled; 75 | resultImage.convertTo( scaled, CV_8UC1 ); 76 | cv::imshow( windowName, scaled ); 77 | cv::waitKey(); 78 | } 79 | else 80 | { 81 | cv::imwrite( argv[2], resultImage ); 82 | } 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /Exercises/ITKIntroduction/exercise1/BasicImageFilteringITKAnswer2.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | int main( int argc, char * argv [] ) 26 | { 27 | if( argc < 6 ) 28 | { 29 | std::cerr << "Usage: " << std::endl; 30 | std::cerr << argv[0] << " inputImageFile outputImageFile variance lowerThreshold upperThreshold" << std::endl; 31 | return EXIT_FAILURE; 32 | } 33 | 34 | typedef unsigned char InputPixelType; 35 | typedef float RealPixelType; 36 | typedef unsigned char OutputPixelType; 37 | 38 | typedef itk::Image< InputPixelType, 2 > InputImageType; 39 | typedef itk::Image< RealPixelType, 2 > RealImageType; 40 | typedef itk::Image< OutputPixelType, 2 > OutputImageType; 41 | 42 | typedef itk::ImageFileReader< InputImageType > ReaderType; 43 | typedef itk::ImageFileWriter< OutputImageType > WriterType; 44 | 45 | ReaderType::Pointer reader = ReaderType::New(); 46 | WriterType::Pointer writer = WriterType::New(); 47 | 48 | reader->SetFileName( argv[1] ); 49 | writer->SetFileName( argv[2] ); 50 | 51 | 52 | typedef itk::CastImageFilter< 53 | InputImageType, RealImageType > CastFilterType; 54 | 55 | CastFilterType::Pointer caster = CastFilterType::New(); 56 | 57 | 58 | typedef itk::CannyEdgeDetectionImageFilter< 59 | RealImageType, RealImageType > FilterType; 60 | 61 | FilterType::Pointer canny = FilterType::New(); 62 | 63 | 64 | typedef itk::RescaleIntensityImageFilter< 65 | RealImageType, OutputImageType > RescaleFilterType; 66 | 67 | RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); 68 | 69 | 70 | caster->SetInput( reader->GetOutput() ); 71 | canny->SetInput( caster->GetOutput() ); 72 | rescaler->SetInput( canny->GetOutput() ); 73 | writer->SetInput( rescaler->GetOutput() ); 74 | 75 | 76 | canny->SetVariance( atof( argv[3] ) ); 77 | canny->SetLowerThreshold( atof( argv[4] ) ); 78 | canny->SetUpperThreshold( atof( argv[5] ) ); 79 | 80 | 81 | try 82 | { 83 | writer->Update(); 84 | } 85 | catch( itk::ExceptionObject & excp ) 86 | { 87 | std::cerr << excp << std::endl; 88 | return EXIT_FAILURE; 89 | } 90 | 91 | return EXIT_SUCCESS; 92 | } 93 | -------------------------------------------------------------------------------- /Exercises/OpenCVIntroduction/exercise2/BasicVideoFilteringOpenCV.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | 26 | // Process a single frame of video and return the resulting frame 27 | cv::Mat processFrame( const cv::Mat& inputImage ) 28 | { 29 | // ADD FRAME PROCESSING CODE HERE 30 | return inputImage; 31 | } 32 | 33 | 34 | // Iterate through a video, process each frame, and display the result in a GUI. 35 | void processAndDisplayVideo(cv::VideoCapture& vidCap) 36 | { 37 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 38 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 39 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 40 | 41 | std::string windowName = "Exercise 2: Basic Video Filtering in OpenCV"; 42 | cv::namedWindow( windowName, CV_WINDOW_FREERATIO); 43 | cvResizeWindow( windowName.c_str(), width, height+50 ); 44 | 45 | unsigned delay = 1000 / frameRate; 46 | 47 | cv::Mat frame; 48 | while( vidCap.read(frame) ) 49 | { 50 | cv::Mat outputFrame = processFrame( frame ); 51 | cv::imshow( windowName, outputFrame ); 52 | 53 | if( cv::waitKey(delay) >= 0 ) 54 | { 55 | break; 56 | } 57 | } 58 | } 59 | 60 | 61 | // Iterate through a video, process each frame, and save the processed video. 62 | void processAndSaveVideo(cv::VideoCapture& vidCap, const std::string& filename) 63 | { 64 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 65 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 66 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 67 | 68 | int fourcc = CV_FOURCC('D','I','V','X'); 69 | cv::VideoWriter vidWrite( filename, fourcc, frameRate, 70 | cvSize(width, height) ); 71 | cv::Mat frame; 72 | while( vidCap.read(frame) ) 73 | { 74 | cv::Mat outputFrame = processFrame( frame ); 75 | vidWrite << outputFrame; 76 | } 77 | } 78 | 79 | 80 | int main ( int argc, char **argv ) 81 | { 82 | if( argc < 2 ) 83 | { 84 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"< 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | 26 | // Process a single frame of video and return the resulting frame 27 | cv::Mat processFrame( const cv::Mat& inputImage ) 28 | { 29 | cv::Mat grayImage, edgeImage, resultImage; 30 | cv::cvtColor(inputImage, grayImage, CV_BGR2GRAY); 31 | cv::Canny( grayImage, edgeImage, 128, 255 ); 32 | cv::cvtColor(edgeImage, resultImage, CV_GRAY2BGR); 33 | 34 | return resultImage; 35 | } 36 | 37 | 38 | // Iterate through a video, process each frame, and display the result in a GUI. 39 | void processAndDisplayVideo(cv::VideoCapture& vidCap) 40 | { 41 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 42 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 43 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 44 | 45 | std::string windowName = "Exercise 2: Basic Video Filtering in OpenCV"; 46 | cv::namedWindow( windowName, CV_WINDOW_FREERATIO); 47 | cvResizeWindow( windowName.c_str(), width, height+50 ); 48 | 49 | unsigned delay = 1000 / frameRate; 50 | 51 | cv::Mat frame; 52 | while( vidCap.read(frame) ) 53 | { 54 | cv::Mat outputFrame = processFrame( frame ); 55 | cv::imshow( windowName, outputFrame ); 56 | 57 | if( cv::waitKey(delay) >= 0 ) 58 | { 59 | break; 60 | } 61 | } 62 | } 63 | 64 | 65 | // Iterate through a video, process each frame, and save the processed video. 66 | void processAndSaveVideo(cv::VideoCapture& vidCap, const std::string& filename) 67 | { 68 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 69 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 70 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 71 | 72 | int fourcc = CV_FOURCC('D','I','V','X'); 73 | cv::VideoWriter vidWrite( filename, fourcc, frameRate, 74 | cvSize(width, height) ); 75 | cv::Mat frame; 76 | while( vidCap.read(frame) ) 77 | { 78 | cv::Mat outputFrame = processFrame( frame ); 79 | vidWrite << outputFrame; 80 | } 81 | } 82 | 83 | 84 | int main ( int argc, char **argv ) 85 | { 86 | if( argc < 2 ) 87 | { 88 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"< 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | int main ( int argc, char **argv ) 30 | { 31 | if( argc < 3 ) 32 | { 33 | std::cout << "Usage: " << argv[0] << "input_image output_image" << std::endl; 34 | return EXIT_FAILURE; 35 | } 36 | 37 | const unsigned int Dimension = 2; 38 | typedef unsigned char IOPixelType; 39 | typedef float RealPixelType; 40 | typedef itk::Image< IOPixelType, Dimension > IOFrameType; 41 | typedef itk::Image< RealPixelType, Dimension > RealFrameType; 42 | typedef itk::VideoStream< IOFrameType > IOVideoType; 43 | typedef itk::VideoStream< RealFrameType > RealVideoType; 44 | 45 | typedef itk::VideoFileReader< IOVideoType > ReaderType; 46 | typedef itk::VideoFileWriter< IOVideoType > WriterType; 47 | typedef itk::CastImageFilter< RealFrameType, IOFrameType > 48 | CastImageFilterType; 49 | typedef itk::ImageFilterToVideoFilterWrapper< CastImageFilterType > 50 | CastVideoFilterType; 51 | typedef itk::CurvatureFlowImageFilter< IOFrameType, RealFrameType > 52 | ImageFilterType; 53 | typedef itk::ImageFilterToVideoFilterWrapper< ImageFilterType > 54 | VideoFilterType; 55 | 56 | ReaderType::Pointer reader = ReaderType::New(); 57 | WriterType::Pointer writer = WriterType::New(); 58 | ImageFilterType::Pointer imageFilter = ImageFilterType::New(); 59 | VideoFilterType::Pointer videoFilter = VideoFilterType::New(); 60 | CastImageFilterType::Pointer imageCaster = CastImageFilterType::New(); 61 | CastVideoFilterType::Pointer videoCaster = CastVideoFilterType::New(); 62 | 63 | 64 | itk::ObjectFactoryBase::RegisterFactory( itk::OpenCVVideoIOFactory::New() ); 65 | reader->SetFileName( argv[1] ); 66 | writer->SetFileName( argv[2] ); 67 | 68 | videoCaster->SetImageFilter( imageCaster ); 69 | 70 | imageFilter->SetTimeStep( 0.5 ); 71 | imageFilter->SetNumberOfIterations( 20 ); 72 | videoFilter->SetImageFilter( imageFilter ); 73 | 74 | videoFilter->SetInput( reader->GetOutput() ); 75 | videoCaster->SetInput( videoFilter->GetOutput() ); 76 | writer->SetInput( videoCaster->GetOutput() ); 77 | 78 | try 79 | { 80 | writer->Update(); 81 | } 82 | catch( itk::ExceptionObject & excp ) 83 | { 84 | std::cerr << excp << std::endl; 85 | return EXIT_FAILURE; 86 | } 87 | 88 | return EXIT_SUCCESS; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /Exercises/ITKVideoPipeline/exercise1/ITKVideoSingleFrameFiltersAnswer.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | int main ( int argc, char **argv ) 30 | { 31 | if( argc < 3 ) 32 | { 33 | std::cout << "Usage: " << argv[0] << "input_image output_image" << std::endl; 34 | return EXIT_FAILURE; 35 | } 36 | 37 | const unsigned int Dimension = 2; 38 | typedef unsigned char IOPixelType; 39 | typedef float RealPixelType; 40 | typedef itk::Image< IOPixelType, Dimension > IOFrameType; 41 | typedef itk::Image< RealPixelType, Dimension > RealFrameType; 42 | typedef itk::VideoStream< IOFrameType > IOVideoType; 43 | typedef itk::VideoStream< RealFrameType > RealVideoType; 44 | 45 | typedef itk::VideoFileReader< IOVideoType > ReaderType; 46 | typedef itk::VideoFileWriter< IOVideoType > WriterType; 47 | typedef itk::CastImageFilter< RealFrameType, IOFrameType > 48 | CastImageFilterType; 49 | typedef itk::ImageFilterToVideoFilterWrapper< CastImageFilterType > 50 | CastVideoFilterType; 51 | typedef itk::CurvatureFlowImageFilter< IOFrameType, RealFrameType > 52 | ImageFilterType; 53 | typedef itk::ImageFilterToVideoFilterWrapper< ImageFilterType > 54 | VideoFilterType; 55 | 56 | ReaderType::Pointer reader = ReaderType::New(); 57 | WriterType::Pointer writer = WriterType::New(); 58 | ImageFilterType::Pointer imageFilter = ImageFilterType::New(); 59 | VideoFilterType::Pointer videoFilter = VideoFilterType::New(); 60 | CastImageFilterType::Pointer imageCaster = CastImageFilterType::New(); 61 | CastVideoFilterType::Pointer videoCaster = CastVideoFilterType::New(); 62 | 63 | 64 | itk::ObjectFactoryBase::RegisterFactory( itk::OpenCVVideoIOFactory::New() ); 65 | reader->SetFileName( argv[1] ); 66 | writer->SetFileName( argv[2] ); 67 | 68 | videoCaster->SetImageFilter( imageCaster ); 69 | 70 | imageFilter->SetTimeStep( 0.5 ); 71 | imageFilter->SetNumberOfIterations( 20 ); 72 | videoFilter->SetImageFilter( imageFilter ); 73 | 74 | videoFilter->SetInput( reader->GetOutput() ); 75 | videoCaster->SetInput( videoFilter->GetOutput() ); 76 | writer->SetInput( videoCaster->GetOutput() ); 77 | 78 | try 79 | { 80 | writer->Update(); 81 | } 82 | catch( itk::ExceptionObject & excp ) 83 | { 84 | std::cerr << excp << std::endl; 85 | return EXIT_FAILURE; 86 | } 87 | 88 | return EXIT_SUCCESS; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /Exercises/ITKVideoPipeline/exercise2/ITKVideoMultiFrameFiltersAnswer.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | int main ( int argc, char **argv ) 31 | { 32 | if( argc < 3 ) 33 | { 34 | std::cout << "Usage: " << argv[0] << "input_image output_image" << std::endl; 35 | return EXIT_FAILURE; 36 | } 37 | 38 | const unsigned int Dimension = 2; 39 | typedef unsigned char IOPixelType; 40 | typedef float RealPixelType; 41 | typedef itk::Image< IOPixelType, Dimension > IOFrameType; 42 | typedef itk::Image< RealPixelType, Dimension > RealFrameType; 43 | typedef itk::VideoStream< IOFrameType > IOVideoType; 44 | typedef itk::VideoStream< RealFrameType > RealVideoType; 45 | 46 | typedef itk::VideoFileReader< IOVideoType > ReaderType; 47 | typedef itk::VideoFileWriter< IOVideoType > WriterType; 48 | typedef itk::CastImageFilter< RealFrameType, IOFrameType > 49 | CastImageFilterType; 50 | typedef itk::ImageFilterToVideoFilterWrapper< CastImageFilterType > 51 | CastVideoFilterType; 52 | typedef itk::CurvatureFlowImageFilter< IOFrameType, RealFrameType > 53 | ImageFilterType; 54 | typedef itk::ImageFilterToVideoFilterWrapper< ImageFilterType > 55 | VideoFilterType; 56 | 57 | typedef itk::FrameDifferenceVideoFilter< IOVideoType, IOVideoType > 58 | FrameDifferenceFilterType; 59 | 60 | ReaderType::Pointer reader = ReaderType::New(); 61 | WriterType::Pointer writer = WriterType::New(); 62 | ImageFilterType::Pointer imageFilter = ImageFilterType::New(); 63 | VideoFilterType::Pointer videoFilter = VideoFilterType::New(); 64 | CastImageFilterType::Pointer imageCaster = CastImageFilterType::New(); 65 | CastVideoFilterType::Pointer videoCaster = CastVideoFilterType::New(); 66 | FrameDifferenceFilterType::Pointer frameDifferenceFilter = 67 | FrameDifferenceFilterType::New(); 68 | 69 | itk::ObjectFactoryBase::RegisterFactory( itk::OpenCVVideoIOFactory::New() ); 70 | reader->SetFileName( argv[1] ); 71 | writer->SetFileName( argv[2] ); 72 | 73 | frameDifferenceFilter->SetFrameOffset(1); 74 | 75 | videoCaster->SetImageFilter( imageCaster ); 76 | 77 | imageFilter->SetTimeStep( 0.5 ); 78 | imageFilter->SetNumberOfIterations( 20 ); 79 | videoFilter->SetImageFilter( imageFilter ); 80 | 81 | videoFilter->SetInput( reader->GetOutput() ); 82 | videoCaster->SetInput( videoFilter->GetOutput() ); 83 | frameDifferenceFilter->SetInput( videoCaster->GetOutput() ); 84 | writer->SetInput( frameDifferenceFilter->GetOutput() ); 85 | 86 | try 87 | { 88 | writer->Update(); 89 | } 90 | catch( itk::ExceptionObject & excp ) 91 | { 92 | std::cerr << excp << std::endl; 93 | return EXIT_FAILURE; 94 | } 95 | 96 | return EXIT_SUCCESS; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /Exercises/ITKOpenCVBridge/exercise2/BasicVideoFilteringITKOpenCVBridge.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | // Process a single frame of video and return the resulting frame 28 | cv::Mat processFrame( const cv::Mat& inputImage ) 29 | { 30 | const unsigned int Dimension = 2; 31 | typedef unsigned char InputPixelType; 32 | typedef unsigned char OutputPixelType; 33 | typedef itk::Image< InputPixelType, Dimension > InputImageType; 34 | typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 35 | typedef itk::OpenCVImageBridge BridgeType; 36 | typedef itk::MedianImageFilter< InputImageType, OutputImageType > 37 | FilterType; 38 | 39 | FilterType::Pointer filter = FilterType::New(); 40 | InputImageType::SizeType neighborhoodRadius; 41 | neighborhoodRadius[0] = 9; 42 | neighborhoodRadius[1] = 9; 43 | filter->SetRadius( neighborhoodRadius ); 44 | 45 | InputImageType::Pointer itkFrame = 46 | BridgeType::CVMatToITKImage< InputImageType >( inputImage ); 47 | 48 | filter->SetInput(itkFrame); 49 | try 50 | { 51 | filter->Update(); 52 | } 53 | catch( itk::ExceptionObject & excp ) 54 | { 55 | std::cerr << excp << std::endl; 56 | } 57 | 58 | return BridgeType::ITKImageToCVMat( filter->GetOutput(), 59 | true ); 60 | } 61 | 62 | // Iterate through a video, process each frame, and display the result in a GUI. 63 | void processAndDisplayVideo(cv::VideoCapture& vidCap) 64 | { 65 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 66 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 67 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 68 | 69 | std::string windowName = "Exercise 2: Basic Video Filtering in OpenCV"; 70 | cv::namedWindow( windowName, CV_WINDOW_FREERATIO); 71 | cvResizeWindow( windowName.c_str(), width, height+50 ); 72 | 73 | unsigned delay = 1000 / frameRate; 74 | 75 | cv::Mat frame; 76 | while( vidCap.read(frame) ) 77 | { 78 | cv::Mat outputFrame = processFrame( frame ); 79 | cv::imshow( windowName, outputFrame ); 80 | 81 | if( cv::waitKey(delay) >= 0 ) 82 | { 83 | break; 84 | } 85 | } 86 | } 87 | 88 | // Iterate through a video, process each frame, and save the processed video. 89 | void processAndSaveVideo(cv::VideoCapture& vidCap, const std::string& filename) 90 | { 91 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 92 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 93 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 94 | 95 | int fourcc = CV_FOURCC('D','I','V','X'); 96 | 97 | cv::VideoWriter writer( filename, fourcc, frameRate, 98 | cv::Size(width, height) ); 99 | 100 | cv::Mat frame; 101 | while( vidCap.read(frame) ) 102 | { 103 | cv::Mat outputFrame = processFrame( frame ); 104 | writer << outputFrame; 105 | } 106 | } 107 | 108 | int main ( int argc, char **argv ) 109 | { 110 | if( argc < 2 ) 111 | { 112 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"< 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | int main ( int argc, char **argv ) 32 | { 33 | if( argc < 3 ) 34 | { 35 | std::cout << "Usage: " << argv[0] << "input_image output_image" << std::endl; 36 | return EXIT_FAILURE; 37 | } 38 | 39 | const unsigned int Dimension = 2; 40 | typedef unsigned char IOPixelType; 41 | typedef float RealPixelType; 42 | typedef itk::Image< IOPixelType, Dimension > IOFrameType; 43 | typedef itk::Image< RealPixelType, Dimension > RealFrameType; 44 | typedef itk::VideoStream< IOFrameType > IOVideoType; 45 | typedef itk::VideoStream< RealFrameType > RealVideoType; 46 | 47 | typedef itk::VideoFileReader< IOVideoType > ReaderType; 48 | typedef itk::VideoFileWriter< IOVideoType > WriterType; 49 | typedef itk::CastImageFilter< RealFrameType, IOFrameType > 50 | CastImageFilterType; 51 | typedef itk::ImageFilterToVideoFilterWrapper< CastImageFilterType > 52 | CastVideoFilterType; 53 | typedef itk::CurvatureFlowImageFilter< IOFrameType, RealFrameType > 54 | ImageFilterType; 55 | typedef itk::ImageFilterToVideoFilterWrapper< ImageFilterType > 56 | VideoFilterType; 57 | typedef itk::ThresholdImageFilter< IOFrameType > 58 | ThresholdImageFilterType; 59 | typedef itk::ImageFilterToVideoFilterWrapper< ThresholdImageFilterType > 60 | ThresholdVideoFilterType; 61 | 62 | typedef itk::FrameDifferenceVideoFilter< IOVideoType, IOVideoType > 63 | FrameDifferenceFilterType; 64 | 65 | ReaderType::Pointer reader = ReaderType::New(); 66 | WriterType::Pointer writer = WriterType::New(); 67 | ImageFilterType::Pointer imageFilter = ImageFilterType::New(); 68 | VideoFilterType::Pointer videoFilter = VideoFilterType::New(); 69 | CastImageFilterType::Pointer imageCaster = CastImageFilterType::New(); 70 | CastVideoFilterType::Pointer videoCaster = CastVideoFilterType::New(); 71 | ThresholdImageFilterType::Pointer imageThresh = ThresholdImageFilterType::New(); 72 | ThresholdVideoFilterType::Pointer videoThresh = ThresholdVideoFilterType::New(); 73 | FrameDifferenceFilterType::Pointer frameDifferenceFilter = 74 | FrameDifferenceFilterType::New(); 75 | 76 | itk::ObjectFactoryBase::RegisterFactory( itk::OpenCVVideoIOFactory::New() ); 77 | reader->SetFileName( argv[1] ); 78 | writer->SetFileName( argv[2] ); 79 | 80 | frameDifferenceFilter->SetFrameOffset(1); 81 | 82 | videoCaster->SetImageFilter( imageCaster ); 83 | 84 | imageThresh->ThresholdBelow( 128 ); 85 | videoThresh->SetImageFilter( imageThresh ); 86 | 87 | imageFilter->SetTimeStep( 0.5 ); 88 | imageFilter->SetNumberOfIterations( 20 ); 89 | videoFilter->SetImageFilter( imageFilter ); 90 | 91 | videoFilter->SetInput( reader->GetOutput() ); 92 | videoCaster->SetInput( videoFilter->GetOutput() ); 93 | frameDifferenceFilter->SetInput( videoCaster->GetOutput() ); 94 | videoThresh->SetInput( frameDifferenceFilter->GetOutput() ); 95 | writer->SetInput( videoThresh->GetOutput() ); 96 | 97 | try 98 | { 99 | writer->Update(); 100 | } 101 | catch( itk::ExceptionObject & excp ) 102 | { 103 | std::cerr << excp << std::endl; 104 | return EXIT_FAILURE; 105 | } 106 | 107 | return EXIT_SUCCESS; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /Exercises/ITKOpenCVBridge/exercise2/BasicVideoFilteringITKOpenCVBridgeAnswer.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | // Process a single frame of video and return the resulting frame 30 | cv::Mat processFrame( const cv::Mat& inputImage ) 31 | { 32 | typedef unsigned char InputPixelType; 33 | typedef float RealPixelType; 34 | typedef unsigned char OutputPixelType; 35 | typedef itk::Image< InputPixelType, 2 > InputImageType; 36 | typedef itk::Image< RealPixelType, 2 > RealImageType; 37 | typedef itk::Image< OutputPixelType, 2 > OutputImageType; 38 | typedef itk::OpenCVImageBridge BridgeType; 39 | typedef itk::CastImageFilter< InputImageType, RealImageType > 40 | CastFilterType; 41 | typedef itk::CannyEdgeDetectionImageFilter< RealImageType, RealImageType > 42 | FilterType; 43 | typedef itk::RescaleIntensityImageFilter< RealImageType, OutputImageType > 44 | RescaleFilterType; 45 | 46 | CastFilterType::Pointer caster = CastFilterType::New(); 47 | FilterType::Pointer canny = FilterType::New(); 48 | RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); 49 | 50 | InputImageType::Pointer itkFrame = 51 | itk::OpenCVImageBridge::CVMatToITKImage< InputImageType >( inputImage ); 52 | caster->SetInput( itkFrame ); 53 | canny->SetInput( caster->GetOutput() ); 54 | rescaler->SetInput( canny->GetOutput() ); 55 | 56 | canny->SetVariance( 6 ); 57 | canny->SetLowerThreshold( 1 ); 58 | canny->SetUpperThreshold( 8 ); 59 | 60 | try 61 | { 62 | rescaler->Update(); 63 | } 64 | catch( itk::ExceptionObject & excp ) 65 | { 66 | std::cerr << excp << std::endl; 67 | } 68 | 69 | cv::Mat frameOut = 70 | BridgeType::ITKImageToCVMat< OutputImageType >(rescaler->GetOutput(),true); 71 | 72 | frameOut.convertTo( frameOut, CV_8U ); 73 | 74 | return frameOut; 75 | } 76 | 77 | // Iterate through a video, process each frame, and display the result in a GUI. 78 | void processAndDisplayVideo(cv::VideoCapture& vidCap) 79 | { 80 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 81 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 82 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 83 | 84 | std::string windowName = "Exercise 2: Basic Video Filtering in OpenCV"; 85 | cv::namedWindow( windowName, CV_WINDOW_FREERATIO); 86 | cvResizeWindow( windowName.c_str(), width, height+50 ); 87 | 88 | unsigned delay = 1000 / frameRate; 89 | 90 | cv::Mat frame; 91 | while( vidCap.read(frame) ) 92 | { 93 | cv::Mat outputFrame = processFrame( frame ); 94 | cv::imshow( windowName, outputFrame ); 95 | 96 | if( cv::waitKey(delay) >= 0 ) 97 | { 98 | break; 99 | } 100 | } 101 | } 102 | 103 | // Iterate through a video, process each frame, and save the processed video. 104 | void processAndSaveVideo(cv::VideoCapture& vidCap, const std::string& filename) 105 | { 106 | double frameRate = vidCap.get( CV_CAP_PROP_FPS ); 107 | int width = vidCap.get( CV_CAP_PROP_FRAME_WIDTH ); 108 | int height = vidCap.get( CV_CAP_PROP_FRAME_HEIGHT ); 109 | 110 | int fourcc = CV_FOURCC('D','I','V','X'); 111 | 112 | cv::VideoWriter writer( filename, fourcc, frameRate, 113 | cv::Size(width, height) ); 114 | 115 | cv::Mat frame; 116 | while( vidCap.read(frame) ) 117 | { 118 | cv::Mat outputFrame = processFrame( frame ); 119 | writer << outputFrame; 120 | } 121 | } 122 | 123 | int main ( int argc, char **argv ) 124 | { 125 | if( argc < 2 ) 126 | { 127 | std::cout << "Usage: "<< argv[0] <<" input_image output_image"<