mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 21:20:18 +08:00
Merge pull request #6813 from mshabunin:gdcm-cmake-search
This commit is contained in:
commit
b6f21a6cac
@ -191,6 +191,7 @@ OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF
|
||||
OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
|
||||
OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
|
||||
OCV_OPTION(WITH_PNG "Include PNG support" ON)
|
||||
OCV_OPTION(WITH_GDCM "Include DICOM support" OFF)
|
||||
OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
|
||||
OCV_OPTION(WITH_GIGEAPI "Include Smartek GigE support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
|
||||
OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
|
||||
@ -1008,6 +1009,7 @@ if(WITH_PNG)
|
||||
else()
|
||||
status(" PNG:" "NO")
|
||||
endif()
|
||||
|
||||
if(WITH_TIFF)
|
||||
if(TIFF_VERSION_STRING AND TIFF_FOUND)
|
||||
status(" TIFF:" "${TIFF_LIBRARY} (ver ${TIFF_VERSION} - ${TIFF_VERSION_STRING})")
|
||||
@ -1034,6 +1036,12 @@ else()
|
||||
status(" GDAL:" "NO")
|
||||
endif()
|
||||
|
||||
if(WITH_GDCM)
|
||||
status(" GDCM:" GDCM_FOUND THEN "YES (ver ${GDCM_VERSION})" ELSE "NO")
|
||||
else()
|
||||
status(" GDCM:" "NO")
|
||||
endif()
|
||||
|
||||
# ========================== VIDEO IO ==========================
|
||||
status("")
|
||||
status(" Video I/O:")
|
||||
|
@ -212,3 +212,15 @@ if(WITH_GDAL)
|
||||
ocv_include_directories(${GDAL_INCLUDE_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WITH_GDCM)
|
||||
find_package(GDCM)
|
||||
if(NOT GDCM_FOUND)
|
||||
set(HAVE_GDCM NO)
|
||||
ocv_clear_vars(GDCM_VERSION GDCM_LIBRARIES)
|
||||
else()
|
||||
set(HAVE_GDCM YES)
|
||||
# include(${GDCM_USE_FILE})
|
||||
set(GDCM_LIBRARIES gdcmMSFF) # GDCM does not set this variable for some reason
|
||||
endif()
|
||||
endif()
|
||||
|
@ -111,6 +111,9 @@
|
||||
/* libpng/png.h needs to be included */
|
||||
#cmakedefine HAVE_LIBPNG_PNG_H
|
||||
|
||||
/* GDCM DICOM codec */
|
||||
#cmakedefine HAVE_GDCM
|
||||
|
||||
/* V4L/V4L2 capturing support via libv4l */
|
||||
#cmakedefine HAVE_LIBV4L
|
||||
|
||||
|
@ -35,6 +35,11 @@ if(HAVE_PNG)
|
||||
list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_GDCM)
|
||||
ocv_include_directories(${GDCM_INCLUDE_DIRS})
|
||||
list(APPEND GRFMT_LIBS ${GDCM_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_TIFF)
|
||||
ocv_include_directories(${TIFF_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
|
||||
@ -57,6 +62,7 @@ endif()
|
||||
|
||||
file(GLOB grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.hpp)
|
||||
file(GLOB grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.cpp)
|
||||
|
||||
list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/bitstrm.hpp)
|
||||
list(APPEND grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/bitstrm.cpp)
|
||||
list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/rgbe.hpp)
|
||||
|
197
modules/imgcodecs/src/grfmt_gdcm.cpp
Normal file
197
modules/imgcodecs/src/grfmt_gdcm.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "grfmt_gdcm.hpp"
|
||||
|
||||
#ifdef HAVE_GDCM
|
||||
|
||||
//#define DBG(...) printf(__VA_ARGS__)
|
||||
#define DBG(...)
|
||||
|
||||
#include <gdcmImageReader.h>
|
||||
|
||||
static const size_t preamble_skip = 128;
|
||||
static const size_t magic_len = 4;
|
||||
|
||||
inline cv::String getMagic()
|
||||
{
|
||||
return cv::String("\x44\x49\x43\x4D", 4);
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
/************************ DICOM decoder *****************************/
|
||||
|
||||
DICOMDecoder::DICOMDecoder()
|
||||
{
|
||||
// DICOM preamble is 128 bytes (can have any value, defaults to 0) + 4 bytes magic number (DICM)
|
||||
m_signature = String(preamble_skip, (char)'\x0') + getMagic();
|
||||
m_buf_supported = false;
|
||||
}
|
||||
|
||||
bool DICOMDecoder::checkSignature( const String& signature ) const
|
||||
{
|
||||
if (signature.size() >= preamble_skip + magic_len)
|
||||
{
|
||||
if (signature.substr(preamble_skip, magic_len) == getMagic())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
DBG("GDCM | Signature does not match\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
ImageDecoder DICOMDecoder::newDecoder() const
|
||||
{
|
||||
return makePtr<DICOMDecoder>();
|
||||
}
|
||||
|
||||
bool DICOMDecoder::readHeader()
|
||||
{
|
||||
gdcm::ImageReader csImageReader;
|
||||
csImageReader.SetFileName(m_filename.c_str());
|
||||
if(!csImageReader.Read())
|
||||
{
|
||||
DBG("GDCM | Failed to open DICOM file\n");
|
||||
return(false);
|
||||
}
|
||||
|
||||
const gdcm::Image &csImage = csImageReader.GetImage();
|
||||
bool bOK = true;
|
||||
switch (csImage.GetPhotometricInterpretation().GetType())
|
||||
{
|
||||
case gdcm::PhotometricInterpretation::MONOCHROME1:
|
||||
case gdcm::PhotometricInterpretation::MONOCHROME2:
|
||||
{
|
||||
switch (csImage.GetPixelFormat().GetScalarType())
|
||||
{
|
||||
case gdcm::PixelFormat::INT8: m_type = CV_8SC1; break;
|
||||
case gdcm::PixelFormat::UINT8: m_type = CV_8UC1; break;
|
||||
case gdcm::PixelFormat::INT16: m_type = CV_16SC1; break;
|
||||
case gdcm::PixelFormat::UINT16: m_type = CV_16UC1; break;
|
||||
case gdcm::PixelFormat::INT32: m_type = CV_32SC1; break;
|
||||
case gdcm::PixelFormat::FLOAT32: m_type = CV_32FC1; break;
|
||||
case gdcm::PixelFormat::FLOAT64: m_type = CV_64FC1; break;
|
||||
default: bOK = false; DBG("GDCM | Monochrome scalar type not supported\n"); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case gdcm::PhotometricInterpretation::RGB:
|
||||
{
|
||||
switch (csImage.GetPixelFormat().GetScalarType())
|
||||
{
|
||||
case gdcm::PixelFormat::UINT8: m_type = CV_8UC3; break;
|
||||
default: bOK = false; DBG("GDCM | RGB scalar type not supported\n"); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
bOK = false;
|
||||
DBG("GDCM | PI not supported: %s\n", csImage.GetPhotometricInterpretation().GetString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(bOK)
|
||||
{
|
||||
unsigned int ndim = csImage.GetNumberOfDimensions();
|
||||
if (ndim != 2)
|
||||
{
|
||||
DBG("GDCM | Invalid dimensions number: %d\n", ndim);
|
||||
bOK = false;
|
||||
}
|
||||
}
|
||||
if (bOK)
|
||||
{
|
||||
const unsigned int *piDimension = csImage.GetDimensions();
|
||||
m_height = piDimension[0];
|
||||
m_width = piDimension[1];
|
||||
if( ( m_width <=0 ) || ( m_height <=0 ) )
|
||||
{
|
||||
DBG("GDCM | Invalid dimensions: %d x %d\n", piDimension[0], piDimension[1]);
|
||||
bOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
return(bOK);
|
||||
}
|
||||
|
||||
|
||||
bool DICOMDecoder::readData( Mat& csImage )
|
||||
{
|
||||
csImage.create(m_width,m_height,m_type);
|
||||
|
||||
gdcm::ImageReader csImageReader;
|
||||
csImageReader.SetFileName(m_filename.c_str());
|
||||
if(!csImageReader.Read())
|
||||
{
|
||||
DBG("GDCM | Failed to Read\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
const gdcm::Image &img = csImageReader.GetImage();
|
||||
|
||||
unsigned long len = img.GetBufferLength();
|
||||
if (len > csImage.elemSize() * csImage.total())
|
||||
{
|
||||
DBG("GDCM | Buffer is bigger than Mat: %ld > %ld * %ld\n", len, csImage.elemSize(), csImage.total());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!img.GetBuffer((char*)csImage.ptr()))
|
||||
{
|
||||
DBG("GDCM | Failed to GetBuffer\n");
|
||||
return false;
|
||||
}
|
||||
DBG("GDCM | Read OK\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // HAVE_GDCM
|
70
modules/imgcodecs/src/grfmt_gdcm.hpp
Normal file
70
modules/imgcodecs/src/grfmt_gdcm.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GDCM_DICOM_H_
|
||||
#define _GDCM_DICOM_H_
|
||||
|
||||
#include "cvconfig.h"
|
||||
|
||||
#ifdef HAVE_GDCM
|
||||
|
||||
#include "grfmt_base.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
// DICOM image reader using GDCM
|
||||
class DICOMDecoder : public BaseImageDecoder
|
||||
{
|
||||
public:
|
||||
DICOMDecoder();
|
||||
bool readData( Mat& img );
|
||||
bool readHeader();
|
||||
ImageDecoder newDecoder() const;
|
||||
virtual bool checkSignature( const String& signature ) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // HAVE_GDCM
|
||||
|
||||
#endif/*_GDCM_DICOM_H_*/
|
@ -54,5 +54,6 @@
|
||||
#include "grfmt_webp.hpp"
|
||||
#include "grfmt_hdr.hpp"
|
||||
#include "grfmt_gdal.hpp"
|
||||
#include "grfmt_gdcm.hpp"
|
||||
|
||||
#endif/*_GRFMTS_H_*/
|
||||
|
@ -93,6 +93,9 @@ struct ImageCodecInitializer
|
||||
decoders.push_back( makePtr<PngDecoder>() );
|
||||
encoders.push_back( makePtr<PngEncoder>() );
|
||||
#endif
|
||||
#ifdef HAVE_GDCM
|
||||
decoders.push_back( makePtr<DICOMDecoder>() );
|
||||
#endif
|
||||
#ifdef HAVE_JASPER
|
||||
decoders.push_back( makePtr<Jpeg2KDecoder>() );
|
||||
encoders.push_back( makePtr<Jpeg2KEncoder>() );
|
||||
|
Loading…
Reference in New Issue
Block a user