[Insight-users] Connecting Output from vtkWin32VideoSource to ITK

PeterW p.worel at ast-jena.de
Wed Oct 21 03:34:31 EDT 2009


Thanks for your reply.

I'm sorry, I've postet just some piece of testcode because I couldn't get
any input from VTK to work with ITK. I thought my mistakes were in that
part. Here is the whole code from my project...

//------------------------------------VTK-Includes-------------------------------------
//Random
#include "vtkCamera.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageViewer.h"
#include "vtkCallbackCommand.h"
#include "vtkCommand.h"
#include "vtkImageCast.h"
//Video
#include "vtkWin32VideoSource.h"
//------------------------------------ITK-Includes-------------------------------------
#include "itkImage.h"
#include "itkVTKImageToImageFilter.h"
#include "itkImageToVTKImageFilter.h"
#include "itkGradientMagnitudeImageFilter.h" //Testfilter

//Globale VTK-Variablen
vtkWin32VideoSource *grabber = NULL;
vtkImageViewer *viewer = NULL;
vtkRenderWindowInteractor *reni = NULL;

//Callback-Funktion für kontinuierliches "Frame-Grabben"
class vtkMyCallback : public vtkCommand
{
    public:
        static vtkMyCallback *New()
        {
			return new vtkMyCallback;
		}
        
		virtual void Execute(vtkObject *caller, unsigned long, void*)
        {
			//Neuer Grab, Neuer Render
            grabber->Grab();
            viewer->Render();
                               
             //Timer-Update
             reni->CreateTimer(VTKI_TIMER_UPDATE);
		}
};

//Hauptprogramm
int main( int argc, char *argv[] )
{


//-----------------Video-Frame-Viewer-------------------------------------------------

	grabber = vtkWin32VideoSource::New();
	grabber->VideoSourceDialog();
	grabber->VideoFormatDialog();
	grabber->Initialize();
	grabber->Grab();
	grabber->UpdateWholeExtent();

	vtkImageCast *caster = vtkImageCast::New();
        caster->SetInput(grabber->GetOutput());
        caster->SetOutputScalarTypeToFloat();
        caster->Modified();
        caster->Update(); 

	//ITK-Part---------------------------------------------------------

	//ITK-typedefs
	typedef itk::Image<float,2> ImageType;
	typedef itk::VTKImageToImageFilter<ImageType> InputFilterType;
	typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
	typedef itk::GradientMagnitudeImageFilter<ImageType,ImageType> FilterType;

	InputFilterType::Pointer vtktoitk = InputFilterType::New();
	ConnectorType::Pointer itktovtk = ConnectorType::New();
	FilterType::Pointer itkfilter1 = FilterType::New();
	
	//VTK-Import
	vtktoitk->SetInput(caster->GetOutput());
	
	//ITK-Filter1
	itkfilter1->SetInput(vtktoitk->GetOutput());
	itkfilter1->Update();

	//VTK-Export
	itktovtk->SetInput(itkfilter1->GetOutput());

	//Second
VTK-Part-----------------------------------------------------------

	//Image-Viewer
	viewer = vtkImageViewer::New();
	viewer->SetInput(itktovtk->GetOutput());
	viewer->SetColorLevel(25);
	viewer->SetColorWindow(125);

	//Interactor
        reni = vtkRenderWindowInteractor::New();
	reni->SetRenderWindow(viewer->GetRenderWindow());

	viewer->SetupInteractor(reni);
	viewer->Render();

	//Timer
	vtkMyCallback *call = vtkMyCallback::New();
	reni->AddObserver(vtkCommand::TimerEvent, call);
	reni->CreateTimer(VTKI_TIMER_FIRST);

	//Window anzeigen
	reni->Initialize();
	reni->Start();

	//Aufräumen
        grabber->ReleaseSystemResources();
	grabber->Delete();
	viewer->Delete();
        reni->Delete();

  return 0;
}

Sorry for some german comments, but I think the important parts are in
english.




Luis Ibanez wrote:
> 
> Hi Peter,
> 
> Passing the output of the vtkWin32VideoSource to
> an ITK filter should work fine.
> 
> We have done that for IGSTK
> 
>                  http://www.igstk.org
> 
> 
> In particular in the
> 
>          igstkWebcamWinVideoImager.cxx
> 
> and
> 
>            igstkWebCameraTracker.cxx
> 
> 
> One of the key things to do, is to make the calls:
> 
>   videoSource->Grab();
>   videoSource->UpdateWholeExtent();
> 
> Before you call Update() in the ITK filter that is receiving
> the converted vtkImageData.
> 
> BTW in the code that you posted, I couldn't find any trace
> of the vtkWin32VideoSource instance.
> 
> Maybe you posted an incomplete section of the code ?
> 
> So, your code,
> doesn't seem to correspond to your question.
> 
> 
>      Regards
> 
> 
>             Luis
> 
> 

-- 
View this message in context: http://n2.nabble.com/Connecting-Output-from-vtkWin32VideoSource-to-ITK-tp3857870p3863654.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list