VtkImagingControlVideoSource

From IGSTK

Jump to: navigation, search

Contents

vktImagingControlVideoSource

This is a class build on top of the existing vtkVideoSource[1] class in VTK. It's purpose is to grab analog video signals on a windows platform.

Introduction

The class works as a VHS player. The 'tape' is represented by a internal buffer that can store X frames and functions like Record, Play and Stop are used to imitate the players functionality. In addition there's functionality for writing the buffers to file.

What you need

  • A windows platform
  • Hardware, i.e. a converter[2]
  • A analog video source, i.e. a VHS player
  • A licence from Imaging Source[3]
  • Imaging Control (IC), the SDK shipped with hardware bought from ImagingSource[4]
  • Drivers for the hardware, see [5]
  • VTK[6]
  • vktImagingControlVideoSource.h and .cpp, download with svn.

Install software

  • VTK.
  • Drivers.
    • Download the latest drivers for your Imaging Source hardware from their downloads page.
    • Follow the instructions on the screen.
  • IC.
    • Download the lastes version of the SDK. When purchasing a product from Imaging Source they'll send you a link you can download the SDK from. Alternatively you can download a trialversion from here.
    • Follow the instructions on the screen.
  • vktImagingControlVideoSource.
    • Copy the source files (vktImagingControlVideoSource.h and .cxx) into vtk's ../source/hybrid folder.
    • Copy all IC header fiels in the same folder as used in (1).
    • Copy TIS_UDSHL07_vc71d.lib, from ../IC Imaging Control 3.0/classlib/debug/, into VTKs ../bin/debug folder, found somewhere in the VTK build folder.
    • Add the line: "vtkImagingControlVideoSource.cxx" in SET(Kit_SCRS ...here...) in the CMakeList.txt in the ../source/hybrid folder.
    • CMake VTK
    • Build vtkHybrid

Connecting hardware

  • Connect:
    • Analog video source to converter with a s-video cable
    • Converter to computer with a firewire.
    • Converter to power outlet, only needed if you connected the converter to the computer with a 4-pin connector.

Testing the code

Usage

  • Save sourcecode and the CMakeLists.txt in the same folder
  • Make a build folder and run CMake on that folder
  • Copy TIS_DShowLib07_vc07d.dll and TIS_UDSHL07_vc71d.dll from ../IC Imaging Control 3.0/classlib/debug/ to ../TestCode/Build/debug
  • Build - ImagingControlSourceTest.exe can now be found in ../TestCode/Build/debug

Sourcecode

//TestCode.cxx

// First include the required header files for the VTK classes we are using.

#include <stdlib.h>
#include "vtkRenderWindowInteractor.h"
#include "vtkImagingControlVideoSource.h"
#include "vtkImageViewer.h"
#include "vtkCallbackCommand.h"
#include "vtkCommand.h"

vtkImagingControlVideoSource *imagingControlGrabber = NULL;
vtkImageViewer *viewer = NULL;
vtkRenderWindowInteractor *iren = NULL;

class vtkMyCallback : public vtkCommand
{
public:
	static vtkMyCallback *New()
	{return new vtkMyCallback;}
	virtual void Execute(vtkObject *caller, unsigned long, void*)
	{
		viewer->Render();
				
		//update the timer so it will trigger again
		//VTKI_TIMER_UPDATE = 1
		iren->CreateTimer(VTKI_TIMER_UPDATE);
	}
};

int main()
{
  //Adding a videosource
  imagingControlGrabber = vtkImagingControlVideoSource::New();
  //Set the license
  imagingControlGrabber->SetImagingControlLicenceKey("ISBXXXXXXXXXX");
  //Sets the number of frames the vtk buffer can store on the 'tape'
  imagingControlGrabber->SetFrameBufferSize(20); 
  
  //Start recording frame from the video
  imagingControlGrabber->Record();
  
  
  //Get the framesize
  int size[3];
  imagingControlGrabber->GetFrameSize(size);

  //Adding an imageviewer to display the images from the videosource
  viewer = vtkImageViewer::New();
  viewer->SetInput(imagingControlGrabber->GetOutput()); 
  viewer->SetSize(size[0],size[1]);
  viewer->SetColorWindow(255);
  viewer->SetColorLevel(127.5);
  viewer->SetZSlice(0);
	
  //Create the interactor that handles the event loop 
  iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(viewer->GetRenderWindow());
  viewer->SetupInteractor(iren);

  //Starts the rendering
  viewer->Render();
	
  //Establish timer event and create timer
  vtkMyCallback *call = vtkMyCallback::New();
  iren->AddObserver(vtkCommand::TimerEvent, call);
  iren->CreateTimer(VTKI_TIMER_FIRST);		//VTKI_TIMER_FIRST = 0

  //Iren must be initialized so that it can handle events
  iren->Initialize();
  
  if(imagingControlGrabber->GetPlaying() || imagingControlGrabber->GetRecording())
  {
    iren->Start();
  }

  //Stop the videograbbing
  imagingControlGrabber->Stop();
  
  //Play back the contents of the vtk buffer
  imagingControlGrabber->Play();
  if(imagingControlGrabber->GetPlaying() || imagingControlGrabber->GetRecording())
  {
	  iren->Start();
  }

  //Stop the videograbbing playback
  imagingControlGrabber->Stop();

  //Write the buffer to file
  imagingControlGrabber->Save("Image", vtkImagingControlVideoSource::BMP);
	
  //Delete all instances and release the hold the videosource
  imagingControlGrabber->ReleaseSystemResources();
  

  //Clean up
  imagingControlGrabber->Delete();
  viewer->Delete();
  iren->Delete();

  return 0;
}

CMakeLists.txt

PROJECT (ImagingControlSourceTest)


FIND_PACKAGE(VTK REQUIRED)

IF(NOT VTK_USE_RENDERING)

  MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")

ENDIF(NOT VTK_USE_RENDERING)

INCLUDE(${VTK_USE_FILE})



ADD_EXECUTABLE(ImagingControlSourceTest ImagingControlVideoSourceTest.cxx)

TARGET_LINK_LIBRARIES(ImagingControlSourceTest vtkRendering vtkHybrid)


Documentation

The code is documented with comments in both the source files and in the testcode.

Personal tools
TOOLBOX
LANGUAGES