From 7f26decf1de9414314d6b8a76615f695de11db4d Mon Sep 17 00:00:00 2001
From: Paul Mercea <p.mercea@dkfz-heidelberg.de>
Date: Wed, 17 Feb 2016 14:23:18 +0100
Subject: [PATCH] Migrated OpenCV includes and code for use with OpenCV 3.1.0

---
 Modules/CameraCalibration/mitkTransform.h                    |  3 ++-
 .../Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp       |  2 +-
 .../Commands/mitkGrabCutOpenCVImageFilter.h                  |  2 +-
 .../Testing/mitkBasicCombinationOpenCVImageFilterTest.cpp    |  7 ++++---
 .../Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp    |  8 ++++----
 .../Testing/mitkCropOpenCVImageFilterTest.cpp                |  8 ++++----
 .../Testing/mitkGrabCutOpenCVImageFilterTest.cpp             |  9 ++++-----
 Modules/OpenCVVideoSupport/mitkImageToOpenCVImageFilter.cpp  |  2 +-
 Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.cpp         |  3 ++-
 Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.h           |  2 +-
 Modules/ToFHardware/mitkToFOpenCVImageGrabber.cpp            | 12 ++++++------
 Modules/US/USFilters/mitkUSImageVideoSource.cpp              |  3 ---
 Modules/US/USFilters/mitkUSImageVideoSource.h                |  2 +-
 13 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/Modules/CameraCalibration/mitkTransform.h b/Modules/CameraCalibration/mitkTransform.h
index 43c5ac9..a299865 100644
--- a/Modules/CameraCalibration/mitkTransform.h
+++ b/Modules/CameraCalibration/mitkTransform.h
@@ -17,7 +17,8 @@ See LICENSE.txt or http://www.mitk.org for details.
 #define MITKTRANSFORM_H
 
 #include <itkObject.h>
-#include <cv.h>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/calib3d.hpp>
 #include <mitkCommon.h>
 #include <mitkNumericTypes.h>
 #include <mitkNavigationData.h>
diff --git a/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp b/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp
index ade3c3d..271a7b0 100644
--- a/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp
+++ b/Modules/OpenCVVideoSupport/Commands/mitkConvertGrayscaleOpenCVImageFilter.cpp
@@ -16,7 +16,7 @@ See LICENSE.txt or http://www.mitk.org for details.
 
 #include "mitkConvertGrayscaleOpenCVImageFilter.h"
 
-#include "cv.h"
+#include <opencv2/imgproc.hpp>
 
 namespace mitk {
 
diff --git a/Modules/OpenCVVideoSupport/Commands/mitkGrabCutOpenCVImageFilter.h b/Modules/OpenCVVideoSupport/Commands/mitkGrabCutOpenCVImageFilter.h
index 1bea4c0..81327e0 100644
--- a/Modules/OpenCVVideoSupport/Commands/mitkGrabCutOpenCVImageFilter.h
+++ b/Modules/OpenCVVideoSupport/Commands/mitkGrabCutOpenCVImageFilter.h
@@ -26,7 +26,7 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "itkMutexLock.h"
 
 // opencv headers
-#include "cv.h"
+#include <opencv2/imgproc.hpp>
 
 namespace itk {
 template<unsigned int T> class Index;
diff --git a/Modules/OpenCVVideoSupport/Testing/mitkBasicCombinationOpenCVImageFilterTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkBasicCombinationOpenCVImageFilterTest.cpp
index e7853b4..f9d5ead 100644
--- a/Modules/OpenCVVideoSupport/Testing/mitkBasicCombinationOpenCVImageFilterTest.cpp
+++ b/Modules/OpenCVVideoSupport/Testing/mitkBasicCombinationOpenCVImageFilterTest.cpp
@@ -19,8 +19,9 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "mitkCropOpenCVImageFilter.h"
 #include <mitkTestingMacros.h>
 
-#include <highgui.h>
-#include <cv.h>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/imgcodecs.hpp>
+
 
 static bool ImagesAreEqualInGray(const cv::Mat& img1, const cv::Mat& img2)
 {
@@ -36,7 +37,7 @@ static bool ImagesAreEqualInGray(const cv::Mat& img1, const cv::Mat& img2)
 
 static void ConvertTestLoadedImage(std::string mitkImagePath)
 {
-  cv::Mat image = cvLoadImage(mitkImagePath.c_str());
+  cv::Mat image = cv::imread(mitkImagePath.c_str());
   cv::Mat compareImg = image.clone();
 
 
diff --git a/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp
index f98f7c4..c50de23 100644
--- a/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp
+++ b/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp
@@ -17,13 +17,13 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "mitkConvertGrayscaleOpenCVImageFilter.h"
 #include <mitkTestingMacros.h>
 
-#include <highgui.h>
-#include <cv.h>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/imgcodecs.hpp>
 
 static void ConvertTestLoadedImage(std::string mitkImagePath, std::string mitkGrayscaleImagePath)
 {
-  cv::Mat image = cvLoadImage(mitkImagePath.c_str());
-  cv::Mat compareImg = cvLoadImage(mitkGrayscaleImagePath.c_str());
+  cv::Mat image = cv::imread(mitkImagePath.c_str());
+  cv::Mat compareImg = cv::imread(mitkGrayscaleImagePath.c_str());
 
   // directly convert the image for comparison
   cv::Mat comparisonImg;
diff --git a/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp
index 6650c73..1338c70 100644
--- a/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp
+++ b/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp
@@ -17,8 +17,8 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "mitkCropOpenCVImageFilter.h"
 #include <mitkTestingMacros.h>
 
-#include <highgui.h>
-#include <cv.h>
+#include <opencv2/imgproc.hpp>
+#include <opencv2/imgcodecs.hpp>
 
 static bool ImagesAreEqualInGray(const cv::Mat& img1, const cv::Mat& img2)
 {
@@ -33,8 +33,8 @@ static bool ImagesAreEqualInGray(const cv::Mat& img1, const cv::Mat& img2)
 
 static void CropTestLoadedImage(std::string mitkImagePath, std::string mitkCroppedImagePath)
 {
-  cv::Mat image = cvLoadImage(mitkImagePath.c_str());
-  cv::Mat croppedImage = cvLoadImage(mitkCroppedImagePath.c_str());
+  cv::Mat image = cv::imread(mitkImagePath.c_str());
+  cv::Mat croppedImage = cv::imread(mitkCroppedImagePath.c_str());
 
   MITK_INFO << mitkImagePath.c_str();
   MITK_INFO << mitkCroppedImagePath.c_str();
diff --git a/Modules/OpenCVVideoSupport/Testing/mitkGrabCutOpenCVImageFilterTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkGrabCutOpenCVImageFilterTest.cpp
index 5329d25..d297089 100644
--- a/Modules/OpenCVVideoSupport/Testing/mitkGrabCutOpenCVImageFilterTest.cpp
+++ b/Modules/OpenCVVideoSupport/Testing/mitkGrabCutOpenCVImageFilterTest.cpp
@@ -20,17 +20,16 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "itkIndex.h"
 #include <itksys/SystemTools.hxx>
 
-#include <highgui.h>
-#include <cv.h>
+#include <opencv2/imgcodecs.hpp>
 
 #include "mitkOpenCVToMitkImageFilter.h"
 
 static void GrabCutTestLoadedImage(std::string imagePath, std::string maskPath, std::string resultMaskPath)
 {
   // load test images
-  cv::Mat image = cvLoadImage(imagePath.c_str());
-  cv::Mat maskImage = cvLoadImage(maskPath.c_str());
-  cv::Mat resultMaskImage = cvLoadImage(resultMaskPath.c_str());
+  cv::Mat image = cv::imread(imagePath.c_str());
+  cv::Mat maskImage = cv::imread(maskPath.c_str());
+  cv::Mat resultMaskImage = cv::imread(resultMaskPath.c_str());
 
   // make sure that the loaded mask is a gray scale image
   cv::Mat maskImageGray;
diff --git a/Modules/OpenCVVideoSupport/mitkImageToOpenCVImageFilter.cpp b/Modules/OpenCVVideoSupport/mitkImageToOpenCVImageFilter.cpp
index 72f8166..b540d83 100644
--- a/Modules/OpenCVVideoSupport/mitkImageToOpenCVImageFilter.cpp
+++ b/Modules/OpenCVVideoSupport/mitkImageToOpenCVImageFilter.cpp
@@ -86,7 +86,7 @@ namespace mitk{
     if( img )
     {
       // do not copy data, then release just the header
-      mat = cv::Mat ( img, false );
+      mat = cv::cvarrToMat( img, false );
       cvReleaseImageHeader( &img );
     }
 
diff --git a/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.cpp b/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.cpp
index da4f03f..363d7bb 100644
--- a/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.cpp
+++ b/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.cpp
@@ -18,6 +18,7 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include <iostream>
 #include <algorithm>
 
+
 mitk::OpenCVVideoSource::OpenCVVideoSource()
 : m_VideoCapture(nullptr),
   m_CurrentImage(nullptr),
@@ -95,7 +96,7 @@ cv::Mat mitk::OpenCVVideoSource::GetImage()
 {
   if(m_CurrentImage)
   {
-    cv::Mat copy( m_CurrentImage, false );
+    cv::Mat copy = cv::cvarrToMat( m_CurrentImage, false );
     return copy.clone();
   }
   return cv::Mat();
diff --git a/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.h b/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.h
index 7f6a7a6..8f1b6dc 100644
--- a/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.h
+++ b/Modules/OpenCVVideoSupport/mitkOpenCVVideoSource.h
@@ -23,7 +23,7 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "mitkUndistortCameraImage.h"
 
 // HighGui camera interface: a convenient way for grabbing from a video capture (on windows VfW is used)
-#include "highgui.h"
+#include <opencv2/highgui.hpp>
 
 // For Providing ITK Image Interface
 #include "itkRGBPixel.h"
diff --git a/Modules/ToFHardware/mitkToFOpenCVImageGrabber.cpp b/Modules/ToFHardware/mitkToFOpenCVImageGrabber.cpp
index 8fb4394..5bdf468 100644
--- a/Modules/ToFHardware/mitkToFOpenCVImageGrabber.cpp
+++ b/Modules/ToFHardware/mitkToFOpenCVImageGrabber.cpp
@@ -78,7 +78,7 @@ namespace mitk
         ImageReadAccessor currentAmplAcc(currentMITKAmplitudeImage, currentMITKAmplitudeImage->GetSliceData(0, 0, 0));
         float* amplitudeFloatData = (float*) currentAmplAcc.GetData();
         memcpy(m_CurrentOpenCVAmplitudeImage->imageData,(unsigned char*)amplitudeFloatData,numOfPixel*sizeof(float));
-        cv::Mat image(m_CurrentOpenCVAmplitudeImage);
+        cv::Mat image = cv::cvarrToMat(m_CurrentOpenCVAmplitudeImage);
         return image;
       }
       else if (m_ImageType==2)
@@ -86,7 +86,7 @@ namespace mitk
         ImageReadAccessor currentIntenAcc(currentMITKIntensityImage, currentMITKIntensityImage->GetSliceData(0, 0, 0));
         float* intensityFloatData = (float*) currentIntenAcc.GetData();
         memcpy(m_CurrentOpenCVIntensityImage->imageData,(unsigned char*)intensityFloatData,numOfPixel*sizeof(float));
-        cv::Mat image(m_CurrentOpenCVIntensityImage);
+        cv::Mat image = cv::cvarrToMat(m_CurrentOpenCVIntensityImage);
         return image;
       }
       else
@@ -94,7 +94,7 @@ namespace mitk
         ImageReadAccessor currentDistAcc(currentMITKDistanceImage, currentMITKDistanceImage->GetSliceData(0, 0, 0));
         float* distanceFloatData = (float*) currentDistAcc.GetData();
         memcpy(m_CurrentOpenCVDistanceImage->imageData,(unsigned char*)distanceFloatData,numOfPixel*sizeof(float));
-        cv::Mat image(m_CurrentOpenCVDistanceImage);
+        cv::Mat image = cv::cvarrToMat(m_CurrentOpenCVDistanceImage);
         return image;
       }
     }
@@ -103,19 +103,19 @@ namespace mitk
       if (m_ImageType==1)
       {
         this->MapScalars(currentMITKAmplitudeImage, m_CurrentOpenCVAmplitudeImage);
-        cv::Mat image(m_CurrentOpenCVAmplitudeImage);
+        cv::Mat image = cv::cvarrToMat(m_CurrentOpenCVAmplitudeImage);
         return image;
       }
       else if (m_ImageType==2)
       {
         this->MapScalars(currentMITKIntensityImage, m_CurrentOpenCVIntensityImage);
-        cv::Mat image(m_CurrentOpenCVIntensityImage);
+        cv::Mat image = cv::cvarrToMat(m_CurrentOpenCVIntensityImage);
         return image;
       }
       else
       {
         this->MapScalars(currentMITKDistanceImage, m_CurrentOpenCVDistanceImage);
-        cv::Mat image(m_CurrentOpenCVDistanceImage);
+        cv::Mat image = cv::cvarrToMat(m_CurrentOpenCVDistanceImage);
         return image;
       }
     }
diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.cpp b/Modules/US/USFilters/mitkUSImageVideoSource.cpp
index 41f592a..934a0d6 100644
--- a/Modules/US/USFilters/mitkUSImageVideoSource.cpp
+++ b/Modules/US/USFilters/mitkUSImageVideoSource.cpp
@@ -18,9 +18,6 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "mitkUSImageVideoSource.h"
 #include "mitkImage.h"
 
-//OpenCV HEADER
-#include <cv.h>
-#include <highgui.h>
 
 //Other
 #include <stdio.h>
diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.h b/Modules/US/USFilters/mitkUSImageVideoSource.h
index 525dcf3..3ce02f8 100644
--- a/Modules/US/USFilters/mitkUSImageVideoSource.h
+++ b/Modules/US/USFilters/mitkUSImageVideoSource.h
@@ -27,7 +27,7 @@ See LICENSE.txt or http://www.mitk.org for details.
 #include "mitkBasicCombinationOpenCVImageFilter.h"
 
 // OpenCV
-#include <highgui.h>
+#include <opencv2/videoio.hpp>
 
 namespace mitk {
   /**
-- 
1.9.5.msysgit.1

