29 : m_VideoCapture(new
cv::VideoCapture()),
30 m_IsVideoReady(false),
33 m_ResolutionOverrideWidth(0),
34 m_ResolutionOverrideHeight(0),
35 m_ResolutionOverride(false),
43 m_VideoCapture->release();
44 delete m_VideoCapture;
49 m_VideoCapture->open(path.c_str());
52 if(!m_VideoCapture->isOpened()) { m_IsVideoReady =
false; }
53 else { m_IsVideoReady =
true; }
56 if (m_ResolutionOverride)
58 m_VideoCapture->set(CV_CAP_PROP_FRAME_WIDTH, this->m_ResolutionOverrideWidth);
59 m_VideoCapture->set(CV_CAP_PROP_FRAME_HEIGHT, this->m_ResolutionOverrideHeight);
65 m_VideoCapture->open(deviceID);
66 if(!m_VideoCapture->isOpened())
67 m_IsVideoReady =
false;
69 m_IsVideoReady =
true;
72 if (m_ResolutionOverride)
74 m_VideoCapture->set(CV_CAP_PROP_FRAME_WIDTH, this->m_ResolutionOverrideWidth);
75 m_VideoCapture->set(CV_CAP_PROP_FRAME_HEIGHT, this->m_ResolutionOverrideHeight);
81 m_VideoCapture->release();
82 delete m_VideoCapture;
83 m_VideoCapture =
new cv::VideoCapture();
87 if ( ! isColor && ! m_IsGreyscale )
89 this->PushFilter(m_GrayscaleFilter.GetPointer());
91 else if ( isColor && m_IsGreyscale )
93 this->RemoveFilter(m_GrayscaleFilter.GetPointer());
96 m_IsGreyscale = !isColor;
101 if (m_VideoCapture) {
return m_VideoCapture->get(CV_CAP_PROP_FRAME_HEIGHT); }
107 if (m_VideoCapture) {
return m_VideoCapture->get(CV_CAP_PROP_FRAME_WIDTH); }
113 if (!m_VideoCapture) {
return false; }
115 return m_VideoCapture->isOpened();
120 m_CropFilter->SetCropRegion(topLeftX, topLeftY, bottomRightX, bottomRightY);
122 if (! m_IsCropped && ! m_CropFilter->GetIsCropRegionEmpty())
124 this->PushFilter(m_CropFilter.GetPointer());
136 int width = this->GetImageWidth();
137 int height = this->GetImageHeight();
139 this->SetRegionOfInterest(cropping.
left, cropping.
top, width - cropping.
right, height - cropping.
bottom);
144 cv::Rect cropRect = m_CropFilter->GetCropRegion();
147 cropping.
left = cropRect.x;
148 cropping.
top = cropRect.y;
150 if ( cropRect.height == 0 )
156 cropping.
bottom = this->GetImageHeight() - (cropRect.y + cropRect.height);
159 if ( cropRect.width == 0 )
165 cropping.
right = this->GetImageWidth() - (cropRect.x + cropRect.width);
173 cv::Rect cropRect = m_CropFilter->GetCropRegion();
175 return USImageRoi(cropRect.x, cropRect.y, cropRect.x + cropRect.width, cropRect.y + cropRect.height);
180 this->RemoveFilter(m_CropFilter.GetPointer());
195 *m_VideoCapture >> image;
202 this->GetNextRawImage(cv_img);
205 IplImage ipl_img = cv_img;
207 this->m_OpenCVToMitkFilter->SetOpenCVImage(&ipl_img);
208 this->m_OpenCVToMitkFilter->Update();
211 image = this->m_OpenCVToMitkFilter->GetOutput();
219 this->m_ResolutionOverrideHeight = height;
220 this->m_ResolutionOverrideWidth = width;
222 if (m_VideoCapture !=
nullptr)
224 m_VideoCapture->set(CV_CAP_PROP_FRAME_WIDTH, width);
225 m_VideoCapture->set(CV_CAP_PROP_FRAME_HEIGHT, height);
virtual ~USImageVideoSource()
Defines a region of interest by distances to the four image borders.
USImageRoi GetRegionOfInterest()
void RemoveRegionOfInterest()
USImageCropping GetCropping()
DataCollection - Class to facilitate loading/accessing structured data.
Defines a region of interest by top left and bottom right corner.
virtual void GetNextRawImage(cv::Mat &image) override
Next image is gathered from the image source.
bool GetIsReady()
Returns true if images can be delivered.
void SetVideoFileInput(std::string path)
Opens a video file for streaming. If nothing goes wrong, the VideoSource is ready to deliver images a...
void OverrideResolution(int width, int height)
This is a workaround for a problem that happens with some video device drivers.
void SetCameraInput(int deviceID)
Opens a video device for streaming. Takes the Device id. Try -1 for "grab the first you can get" whic...
void SetColorOutput(bool isColor)
Sets the output image to rgb or grayscale. Output is color by default and can be set to color by pass...
void SetCropping(USImageCropping cropping)
Defines the cropping area. The rectangle will be justified to the image borders if the given rectangl...
void SetRegionOfInterest(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
Defines the cropping area. The rectangle will be justified to the image borders if the given rectangl...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.