Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkVideoInputSource.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkVideoInputSource.h"
14 
15 #include <iostream>
16 #include <algorithm>
17 #include <videoInput.h>
18 
20 : m_ShowSettingsWindow(false)
21 {
22 
23 
24  m_CaptureWidth = 1024;
25  m_CaptureHeight = 720;
26  m_CapturingInProcess = false;
27 
28  m_DeviceNumber = -1;
29  m_CaptureSize = 0;
30 
31  m_CurrentVideoTexture = nullptr;
32  m_CurrentImage = nullptr;
33  m_VideoInput = new videoInput;
34 
35 
36  m_UndistortImage = false;
37 }
38 
40 {
41  m_VideoInput->stopDevice(m_DeviceNumber);
42  m_CapturingInProcess = false;
43  delete m_VideoInput;
44 }
45 
47 { // main procedure for updating video data
48 
49 // if(m_CurrentVideoTexture == nullptr)
50 // m_CurrentVideoTexture = new unsigned char[m_CaptureSize];
51 
53  {
54  if(m_CurrentImage == nullptr)
55  m_CurrentImage = cvCreateImage(cvSize(m_CaptureWidth,m_CaptureHeight),IPL_DEPTH_8U,3);
56 
57  if(m_VideoInput->isFrameNew(m_DeviceNumber))
58  {
59  //m_VideoInput->getPixels(m_DeviceNumber, m_CurrentVideoTexture, true, false);
60  m_VideoInput->getPixels(m_DeviceNumber, reinterpret_cast<unsigned char*>(m_CurrentImage->imageData), false, true);
61  // only undistort if not paused
62  if(m_UndistortImage && m_UndistortCameraImage.IsNotNull())
63  m_UndistortCameraImage->UndistortImageFast(m_CurrentImage, 0);
64  }
65  }
66 }
67 
69 {
70  //Prints out a list of available devices and returns num of devices found
71  int numDevices = m_VideoInput->listDevices();
72 
73  try
74  {
75  m_VideoInput->setupDevice(m_DeviceNumber, m_CaptureWidth, m_CaptureHeight, VI_COMPOSITE);
76  }
77  catch(...)
78  {
79  MITK_WARN << "error setting up device";
80  }
81 
82  //to get a settings dialog for the device
84  m_VideoInput->showSettingsWindow(m_DeviceNumber);
85 
86  //As requested width and height can not always be accomodated
87  //make sure to check the size once the device is setup
88 
92 
93  MITK_INFO << "starting capturing with VideoInputLib. Size: " << m_CaptureWidth << " x " << m_CaptureHeight;
94  m_CapturingInProcess = true;
95 
96 }
97 
99 {
100  MITK_INFO << "stopping cpaturing process";
101  m_VideoInput->stopDevice(m_DeviceNumber);
102  m_CapturingInProcess = false;
103 
104 }
105 
106 void mitk::VideoInputSource::SetVideoCameraInput(int cameraindex, bool useCVCAMLib)
107 {
108  m_DeviceNumber = cameraindex;
109 }
110 void mitk::VideoInputSource::SetVideoFileInput(const char * filename, bool repeatVideo, bool useCVCAMLib)
111 {
112 }
113 
#define MITK_INFO
Definition: mitkLogMacros.h:18
mitk::UndistortCameraImage::Pointer m_UndistortCameraImage
unsigned char * m_CurrentVideoTexture
#define MITK_WARN
Definition: mitkLogMacros.h:19
void SetVideoCameraInput(int cameraindex, bool useCVCAMLib)
void SetVideoFileInput(const char *filename, bool repeatVideo, bool useCVCAMLib)