[vtkusers] capturing video
Mark E Roberts
mroberts at andrew.cmu.edu
Tue Nov 13 10:59:43 EST 2007
Narjes,
For a project that I am working on, I have some video coming in through an S-video cable. I sent out an e-mail to the mailing group and got a response back from David Gobbi, who gave me some example code in TCL. I changed it to C++ and have included it below.
I've also included the CMakeFile that I use below the code. Watch out for the file that you are going to use and change it if necessary in the ADD_EXECUTABLE.
I believe you also have to turn on VTK_USE_VIDEO_FOR_WINDOWS when compiling VTK with CMAKE. So, if you didn't turn that on when compiling VTK, you are going to need to go back and fix that.
If you have any questions, please feel free to e-mail me back.
Mark Roberts
/******************************
Example Code
******************************/
// First include the required header files for the VTK classes we are using.
#include <stdlib.h>
#include "vtkRenderWindowInteractor.h"
#include "vtkWin32VideoSource.h"
#include "vtkImageViewer.h"
#include "vtkCallbackCommand.h"
#include "vtkCommand.h"
vtkWin32VideoSource *grabber = 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*)
{
//re-grab and image and render
grabber->Grab();
viewer->Render();
//update the timer so it will trigger again
//VTKI_TIMER_UPDATE = 1
iren->CreateTimer(VTKI_TIMER_UPDATE);
}
};
int main()
{
//Add the video source here
grabber = vtkWin32VideoSource::New();
grabber->SetFrameSize(740, 480, 1);
grabber->VideoSourceDialog();
grabber->VideoFormatDialog();
grabber->Grab(); //grab a single frame from the video
viewer = vtkImageViewer::New();
viewer->SetInput(grabber->GetOutput()); //set image to the render and window
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);
viewer->Render(); //must be called after iren and viewer are linked
//or there will be problems
//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();
iren->Start();
//delete all instances and release the hold the win32videosource
//has on the pci card
grabber->ReleaseSystemResources();
grabber->Delete();
viewer->Delete();
iren->Delete();
}
/************************
CMakeFile
************************/
PROJECT (Step1)
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})
# Check if vfw32 supports the video capture functions
IF(VTK_USE_VIDEO_FOR_WINDOWS)
IF("VTK_VFW_SUPPORTS_CAPTURE" MATCHES "^VTK_VFW_SUPPORTS_CAPTURE$")
MESSAGE(STATUS "Checking if vfw32 supports video capture")
TRY_COMPILE(VTK_VFW_SUPPORTS_CAPTURE
${VTK_BINARY_DIR}/CMakeTmp
${VTK_CMAKE_DIR}/vtkTestvfw32Capture.cxx
CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=vfw32"
OUTPUT_VARIABLE OUTPUT)
IF(VTK_VFW_SUPPORTS_CAPTURE)
MESSAGE(STATUS "Checking if vfw32 supports video capture -- yes")
SET(VTK_VFW_SUPPORTS_CAPTURE 1 CACHE INTERNAL "Enable using Video for Windows (vfw32) for video capture.")
WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
"Checking if vfw32 supports video capture "
"passed with the following output:\n"
"${OUTPUT}\n" APPEND)
ELSE(VTK_VFW_SUPPORTS_CAPTURE)
MESSAGE(STATUS "Checking if vfw32 supports video capture -- no")
SET(VTK_VFW_SUPPORTS_CAPTURE 0 CACHE INTERNAL "Enable using Video for Windows (vfw32) for video capture.")
WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
"Checking if vfw32 supports video capture "
"failed with the following output:\n"
"${OUTPUT}\n" APPEND)
ENDIF(VTK_VFW_SUPPORTS_CAPTURE)
ENDIF("VTK_VFW_SUPPORTS_CAPTURE" MATCHES "^VTK_VFW_SUPPORTS_CAPTURE$")
ELSE(VTK_USE_VIDEO_FOR_WINDOWS)
SET(VTK_VFW_SUPPORTS_CAPTURE 0)
ENDIF(VTK_USE_VIDEO_FOR_WINDOWS)
ENDIF(VTK_USE_RENDERING AND WIN32)
ADD_EXECUTABLE(Cone Win32c.cxx)
TARGET_LINK_LIBRARIES(Cone vtkRendering vtkHybrid)
/********************************************
End of .cxx code and CMAKE
********************************************/
> Hey VTK
>
> I have a real time video and i want to capture and save it . But i'm a new
> user of VTK with zero experience, so unfortunately i have no idea where
> to start from. Any help would be really appreciated
>
> Thanx in advance narjes
>
>
> --------------------------------- Be a better sports nut! Let your teams
> follow you with Yahoo Mobile. Try it now.
--
Mark Roberts
Masters of Science, Project Student
CER Lab
Carnegie Mellon University
301-806-6529
MRoberts at andrew.cmu.edu
MeerkyJ at gmail.com
More information about the vtkusers
mailing list