Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkVideoInputSource.h"
18 
19 #include <iostream>
20 #include <algorithm>
21 #include <videoInput.h>
22 
24 : m_ShowSettingsWindow(false)
25 {
26 
27 
28  m_CaptureWidth = 1024;
29  m_CaptureHeight = 720;
30  m_CapturingInProcess = false;
31 
32  m_DeviceNumber = -1;
33  m_CaptureSize = 0;
34 
35  m_CurrentVideoTexture = NULL;
36  m_CurrentImage = NULL;
37  m_VideoInput = new videoInput;
38 
39 
40  m_UndistortImage = false;
41 }
42 
44 {
45  m_VideoInput->stopDevice(m_DeviceNumber);
46  m_CapturingInProcess = false;
47  delete m_VideoInput;
48 }
49 
51 { // main procedure for updating video data
52 
53 // if(m_CurrentVideoTexture == NULL)
54 // m_CurrentVideoTexture = new unsigned char[m_CaptureSize];
55 
56  if(m_CapturingInProcess && !m_CapturePaused)
57  {
58  if(m_CurrentImage == NULL)
59  m_CurrentImage = cvCreateImage(cvSize(m_CaptureWidth,m_CaptureHeight),IPL_DEPTH_8U,3);
60 
61  if(m_VideoInput->isFrameNew(m_DeviceNumber))
62  {
63  //m_VideoInput->getPixels(m_DeviceNumber, m_CurrentVideoTexture, true, false);
64  m_VideoInput->getPixels(m_DeviceNumber, reinterpret_cast<unsigned char*>(m_CurrentImage->imageData), false, true);
65  // only undistort if not paused
66  if(m_UndistortImage && m_UndistortCameraImage.IsNotNull())
67  m_UndistortCameraImage->UndistortImageFast(m_CurrentImage, 0);
68  }
69  }
70 }
71 
73 {
74  //Prints out a list of available devices and returns num of devices found
75  int numDevices = m_VideoInput->listDevices();
76 
77  try
78  {
79  m_VideoInput->setupDevice(m_DeviceNumber, m_CaptureWidth, m_CaptureHeight, VI_COMPOSITE);
80  }
81  catch(...)
82  {
83  MITK_WARN << "error setting up device";
84  }
85 
86  //to get a settings dialog for the device
87  if(m_ShowSettingsWindow)
88  m_VideoInput->showSettingsWindow(m_DeviceNumber);
89 
90  //As requested width and height can not always be accomodated
91  //make sure to check the size once the device is setup
92 
93  m_CaptureWidth = m_VideoInput->getWidth(m_DeviceNumber);
94  m_CaptureHeight = m_VideoInput->getHeight(m_DeviceNumber);
95  m_CaptureSize = m_VideoInput->getSize(m_DeviceNumber);
96 
97  MITK_INFO << "starting capturing with VideoInputLib. Size: " << m_CaptureWidth << " x " << m_CaptureHeight;
98  m_CapturingInProcess = true;
99 
100 }
101 
103 {
104  MITK_INFO << "stopping cpaturing process";
105  m_VideoInput->stopDevice(m_DeviceNumber);
106  m_CapturingInProcess = false;
107 
108 }
109 
110 void mitk::VideoInputSource::SetVideoCameraInput(int cameraindex, bool useCVCAMLib)
111 {
112  m_DeviceNumber = cameraindex;
113 }
114 void mitk::VideoInputSource::SetVideoFileInput(const char * filename, bool repeatVideo, bool useCVCAMLib)
115 {
116 }
117 
#define MITK_INFO
Definition: mitkLogMacros.h:22
unsigned char * m_CurrentVideoTexture
#define MITK_WARN
Definition: mitkLogMacros.h:23
static const std::string filename
void SetVideoCameraInput(int cameraindex, bool useCVCAMLib)
void SetVideoFileInput(const char *filename, bool repeatVideo, bool useCVCAMLib)