diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.cpp b/Modules/US/USFilters/mitkUSImageVideoSource.cpp index 4ae1a6d51f..34e9ced354 100644 --- a/Modules/US/USFilters/mitkUSImageVideoSource.cpp +++ b/Modules/US/USFilters/mitkUSImageVideoSource.cpp @@ -1,112 +1,111 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // MITK HEADER #include "mitkUSImageVideoSource.h" #include "mitkImage.h" //OpenCV HEADER #include #include //Other #include mitk::USImageVideoSource::USImageVideoSource() : itk::Object() { m_IsVideoReady = false; m_IsMetadataReady = false; m_IsGeometryReady = false; + m_IsGreyscale = true; this->m_OpenCVToMitkFilter = mitk::OpenCVToMitkImageFilter::New(); } mitk::USImageVideoSource::~USImageVideoSource() { } void mitk::USImageVideoSource::SetVideoFileInput(std::string path) { m_OpenCVVideoSource = mitk::OpenCVVideoSource::New(); // Example: "C:\\Users\\maerz\\Videos\\Debut\\us.avi" m_OpenCVVideoSource->SetVideoFileInput(path.c_str(),true,false); m_OpenCVVideoSource->StartCapturing(); m_OpenCVVideoSource->FetchFrame(); // Let's see if we have been successful m_IsVideoReady = m_OpenCVVideoSource->IsCapturingEnabled(); } void mitk::USImageVideoSource::SetCameraInput(int deviceID) { - - - - // Old Code, this may not work m_OpenCVVideoSource = mitk::OpenCVVideoSource::New(); m_OpenCVVideoSource->SetVideoCameraInput(deviceID); m_OpenCVVideoSource->StartCapturing(); m_OpenCVVideoSource->FetchFrame(); // Let's see if we have been successful m_IsVideoReady = m_OpenCVVideoSource->IsCapturingEnabled(); } +void mitk::USImageVideoSource::SetColorOutput(bool isColor){ + m_IsGreyscale = !isColor; +} + mitk::USImage::Pointer mitk::USImageVideoSource::GetNextImage() { + // Setup Pointers + IplImage *rgbImage = NULL; + IplImage *greyImage = NULL; -// The following code utilizes open CV directly do access images - //IplImage *m_cvCurrentVideoFrame = NULL; - //CvCapture* capture = cvCaptureFromCAM( 1000 ); - // if ( !capture ) { - // fprintf( stderr, "ERROR: capture is NULL \n" ); - // getchar(); - // return NULL; - // } - // // Show the image captured from the camera in the window and repeat - // - // // Get one frame - // m_cvCurrentVideoFrame = cvQueryFrame( capture ); - // -/// WORKING CODE - - - IplImage *m_cvCurrentVideoFrame = NULL; + //Get Dimensions and init rgb int height = m_OpenCVVideoSource->GetImageHeight(); int width = m_OpenCVVideoSource->GetImageWidth(); - m_cvCurrentVideoFrame = cvCreateImage(cvSize(width,height),8,3); - m_OpenCVVideoSource->GetCurrentFrameAsOpenCVImage(m_cvCurrentVideoFrame); + rgbImage = cvCreateImage(cvSize(width,height),8,3); + + // Get Frame from Source + m_OpenCVVideoSource->GetCurrentFrameAsOpenCVImage(rgbImage); m_OpenCVVideoSource->FetchFrame(); - this->m_OpenCVToMitkFilter->SetOpenCVImage(m_cvCurrentVideoFrame); + + // If this is a greyscale image, convert it and put into the filter. + if (m_IsGreyscale){ + greyImage = cvCreateImage(cvSize(width,height),8,1); + cvCvtColor( rgbImage, greyImage, CV_RGB2GRAY ); + this->m_OpenCVToMitkFilter->SetOpenCVImage(greyImage); + } else { + this->m_OpenCVToMitkFilter->SetOpenCVImage(rgbImage); + } this->m_OpenCVToMitkFilter->Update(); // OpenCVToMitkImageFilter returns a standard mit::image. We then transform it into an USImage mitk::USImage::Pointer result = mitk::USImage::New(this->m_OpenCVToMitkFilter->GetOutput(0)); - cvReleaseImage (&m_cvCurrentVideoFrame); + cvReleaseImage (&rgbImage); + cvReleaseImage (&greyImage); return result; } diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.h b/Modules/US/USFilters/mitkUSImageVideoSource.h index 954114ca95..7efab109d5 100644 --- a/Modules/US/USFilters/mitkUSImageVideoSource.h +++ b/Modules/US/USFilters/mitkUSImageVideoSource.h @@ -1,87 +1,95 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKUSImageVideoSource_H_HEADER_INCLUDED_ #define MITKUSImageVideoSource_H_HEADER_INCLUDED_ #include #include "mitkUSImage.h" #include "mitkOpenCVVideoSource.h" #include "mitkOpenCVToMitkImageFilter.h" namespace mitk { /**Documentation * \brief This class can be pointed to a video file or a videodevice and delivers USImages with default metadata Sets * * \ingroup US */ class MitkUS_EXPORT USImageVideoSource : public itk::Object { public: mitkClassMacro(USImageVideoSource, itk::ProcessObject); itkNewMacro(Self); /** *\brief Opens a video file for streaming. If nothing goes wrong, the * VideoSource is ready to deliver images after calling this function. */ void SetVideoFileInput(std::string path); /** *\brief Opens a video device for streaming. Takes the Device id. Try -1 for "grab the first you can get" * which works quite well if only one device is available. If nothing goes wrong, the * VideoSource is ready to deliver images after calling this function. */ void SetCameraInput(int deviceID); + /** + *\brief Opens a video device for streaming. Takes the Device id. Try -1 for "grab the first you can get" + * which works quite well if only one device is available. If nothing goes wrong, the + * VideoSource is ready to deliver images after calling this function. + */ + void SetColorOutput(bool isColor); + /** *\brief Retrieves the next frame. This will typically be the next frame in a file * or the last cahced file in a devcie. */ mitk::USImage::Pointer GetNextImage(); // Getter & Setter itkGetMacro(OpenCVVideoSource, mitk::OpenCVVideoSource::Pointer); itkSetMacro(OpenCVVideoSource, mitk::OpenCVVideoSource::Pointer); itkGetMacro(IsVideoReady, bool); itkGetMacro(IsMetadataReady, bool); itkGetMacro(IsGeometryReady, bool); protected: USImageVideoSource(); virtual ~USImageVideoSource(); /** * \brief The source of the video */ mitk::OpenCVVideoSource::Pointer m_OpenCVVideoSource; /** * \brief The Following flags are used internally, to assure that all necessary steps are taken before capturing */ bool m_IsVideoReady; bool m_IsMetadataReady; bool m_IsGeometryReady; + bool m_IsGreyscale; mitk::OpenCVToMitkImageFilter::Pointer m_OpenCVToMitkFilter; }; } // namespace mitk #endif /* MITKUSImageVideoSource_H_HEADER_INCLUDED_ */