[vtkusers] Re: Some question of the using of vtkWin32VideoSource

David Gobbi dgobbi at irus.rri.on.ca
Mon May 21 13:14:33 EDT 2001

Hi Zhang,

The problem is that while the 'for' loop is running, Windows is unable
to process events.  This is not a problem with e.g. the
vtkMILVideoSource because the MIL interface is multi-threaded, but
unfortunately Video for Windows relies on Windows event handling to
process the callbacks.

The only solution is for you write a program that does proper event
handling.  If you call Grab from somewhere within your main WNDPROC
message handler, then Video for Windows won't be blocked.
Does anyone out there who has used vtkWin32VideoSource have a simple
example of this?  I don't do much applications-level programming
in C++ myself.

Another solution is to write your program in tcl or python/Tkinter
and to only do the grabs after you have started the 'mainloop'.
See 'video.tcl' for an example.

 - David

  David Gobbi, MSc                    dgobbi at irus.rri.on.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Mon, 21 May 2001, zhangzhijun wrote:

> Dear all:
>          When using the vtkWin32VideoSource, I find some question, I want to
> know
> whether you can help me to overcome them:
>           I use this code to display a video from the camera, this is the
> code:
> I think every time when a vtkWin32VideoSource object is created , it must be
> deleted
> in the program otherwise the hardware will not be accessed next time when
> the application
> is executed. I encounter this kind of question, in which every time there
> will be a
> message box saying"can't find video hardware". because I use a for loop in
> the
> program and it seems it's a infinite loop because when I close the window,
> and I open
> the window again, I will be give this "can't find video hardware"
> information . but How
> to solve it?
> void main( int argc, char *argv[] )
> {
>   vtkRenderer *ren = vtkRenderer::New();
>   vtkRenderWindow *renWindow = vtkRenderWindow::New();
>   renWindow->AddRenderer(ren);
>   renWindow->SetSize( 320, 240 );
>   vtkRenderWindowInteractor *Interactor=vtkRenderWindowInteractor::New();
>   Interactor->SetRenderWindow(renWindow);
>   vtkWin32VideoSource *videoSource=vtkWin32VideoSource::New();
>   videoSource->SetFrameBufferSize(50);
>   videoSource->SetNumberOfOutputFrames(50);
>   videoSource->Grab();
>   vtkImageViewer *imageViewer=vtkImageViewer::New();
>   imageViewer->SetInput(videoSource->GetOutput());
>   imageViewer->GetImageWindow()->DoubleBufferOn();
>   imageViewer->SetColorWindow(255);
>   imageViewer->SetColorLevel(127.5);
>   imageViewer->SetZSlice(0);
>   vtkImageData* imageData=vtkImageData::New();
>   imageData=imageViewer->GetInput();
>   vtkImageMapper* imageMapper=vtkImageMapper::New();
>   imageMapper->SetInput(imageData);
>   imageMapper->SetColorWindow(100);
>   imageMapper->SetColorLevel(100);
>   vtkActor2D *actor=vtkActor2D::New();
>   actor->SetMapper(imageMapper);
>   ren->AddActor(actor);
>   for (int i=0;i=1;i++)
>   {
>   videoSource->Grab();
>   renWindow->Render();
>   }
>   videoSource->Stop();
>   if (videoSource)
>    videoSource->Delete();
>   if (imageViewer)
>    imageViewer->Delete();
> }
> regards,
> zj zhang

More information about the vtkusers mailing list