This example introduces the SpinVideo class, which is used to quickly and easily create various types of video files. It demonstrates the creation of four types: uncompressed, MJPG, H264 (AVI) and H264 (MP4).
#include <iostream>
#include <sstream>
using namespace std;
{
};
int SaveVectorToVideo(INodeMap& nodeMap, INodeMap& nodeMapTLDevice, vector<ImagePtr>& images)
{
int result = 0;
cout << endl << endl << "*** CREATING VIDEO ***" << endl << endl;
try
{
string deviceSerialNumber = "";
CStringPtr ptrStringSerial = nodeMapTLDevice.GetNode(
"DeviceSerialNumber");
if (IsReadable(ptrStringSerial))
{
deviceSerialNumber = ptrStringSerial->GetValue();
cout << "Device serial number retrieved as " << deviceSerialNumber << "..." << endl;
}
CFloatPtr ptrAcquisitionFrameRate = nodeMap.GetNode(
"AcquisitionFrameRate");
{
cout << "Unable to retrieve frame rate. Aborting..." << endl << endl;
return -1;
}
float frameRateToSet = static_cast<float>(ptrAcquisitionFrameRate->GetValue());
{
}
cout << "Frame rate to be set to " << frameRateToSet << "..." << endl;
string videoFilename;
{
videoFilename = "SaveToVideo-Uncompressed";
if (deviceSerialNumber != "")
{
videoFilename = videoFilename + "-" + deviceSerialNumber.c_str();
}
break;
videoFilename = "SaveToVideo-MJPG";
if (deviceSerialNumber != "")
{
videoFilename = videoFilename + "-" + deviceSerialNumber.c_str();
}
break;
videoFilename = "SaveToVideo-H264";
if (deviceSerialNumber != "")
{
videoFilename = videoFilename + "-" + deviceSerialNumber.c_str();
}
}
const unsigned int k_videoFileSize = 2048;
{
option.frameRate = frameRateToSet;
option.height =
static_cast<unsigned int>(images[0]->GetHeight());
option.width =
static_cast<unsigned int>(images[0]->GetWidth());
}
{
option.frameRate = frameRateToSet;
option.height =
static_cast<unsigned int>(images[0]->GetHeight());
option.width =
static_cast<unsigned int>(images[0]->GetWidth());
}
{
option.frameRate = frameRateToSet;
option.height =
static_cast<unsigned int>(images[0]->GetHeight());
option.width =
static_cast<unsigned int>(images[0]->GetWidth());
}
cout << "Appending " << images.size() << " images to video file: " << videoFilename << endl
<< endl;
for (unsigned int imageCnt = 0; imageCnt < images.size(); imageCnt++)
{
video.
Append(images[imageCnt]);
cout << "\tAppended image " << imageCnt << "..." << endl;
}
cout << endl << "Video saved at " << videoFilename << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
FeatureList_t features;
CCategoryPtr category = nodeMap.GetNode(
"DeviceInformation");
{
category->GetFeatures(features);
FeatureList_t::const_iterator it;
for (it = features.begin(); it != features.end(); ++it)
{
cout << pfeatureNode->GetName() << " : ";
cout << (
IsReadable(pValue) ? pValue->ToString() :
"Node not readable");
cout << endl;
}
}
else
{
cout << "Device control information not readable." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
{
cout << "Unable to get or set acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to get acquisition mode to continuous (entry 'continuous' retrieval). Aborting..." << endl
<< endl;
return -1;
}
int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
cout << "Acquisition mode set to continuous..." << endl;
pCam->BeginAcquisition();
cout << "Acquiring images..." << endl << endl;
for (
unsigned int imageCnt = 0; imageCnt <
numImages; imageCnt++)
{
try
{
ImagePtr pResultImage = pCam->GetNextImage(1000);
if (pResultImage->IsIncomplete())
{
cout << "Image incomplete with image status " << pResultImage->GetImageStatus() << "..." << endl
<< endl;
}
else
{
cout << "Grabbed image " << imageCnt << ", width = " << pResultImage->GetWidth()
<< ", height = " << pResultImage->GetHeight() << endl;
images.push_back(processor.
Convert(pResultImage, PixelFormat_Mono8));
}
pResultImage->Release();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
}
pCam->EndAcquisition();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
int err = 0;
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
pCam->Init();
vector<ImagePtr> images;
if (err < 0)
{
return err;
}
pCam->DeInit();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << "Application build date: " << __DATE__ << " " << __TIME__ << endl << endl;
const LibraryVersion spinnakerLibraryVersion = system->GetLibraryVersion();
cout <<
"Spinnaker library version: " << spinnakerLibraryVersion.
major <<
"." << spinnakerLibraryVersion.
minor
<<
"." << spinnakerLibraryVersion.
type <<
"." << spinnakerLibraryVersion.
build << endl
<< endl;
unsigned int numCameras = camList.
GetSize();
cout << "Number of cameras detected: " << numCameras << endl << endl;
if (numCameras == 0)
{
system->ReleaseInstance();
cout << "Not enough cameras!" << endl;
cout << "Done! Press Enter to exit..." << endl;
getchar();
return -1;
}
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Running example for camera " << i << "..." << endl;
cout << "Camera " << i << " example complete..." << endl << endl;
}
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
return result;
}
int AcquireImages(CameraPtr pCam, INodeMap &nodeMap, INodeMap &nodeMapTLDevice)
Definition Acquisition.cpp:199
int main(int, char **)
Definition Acquisition.cpp:527
int RunSingleCamera(CameraPtr pCam)
Definition Acquisition.cpp:479
int PrintDeviceInfo(INodeMap &nodeMap)
Definition Acquisition.cpp:441
const bool useCustomFrameRate
Definition SaveToVideo.cpp:72
const videoFileType chosenVideoFileType
Definition SaveToVideo.cpp:58
int SaveVectorToVideo(INodeMap &nodeMap, INodeMap &nodeMapTLDevice, vector< ImagePtr > &images)
Definition SaveToVideo.cpp:76
videoFileType
Definition SaveToVideo.cpp:51
@ H264_MP4
Definition SaveToVideo.cpp:55
@ UNCOMPRESSED
Definition SaveToVideo.cpp:52
@ MJPG
Definition SaveToVideo.cpp:53
@ H264_AVI
Definition SaveToVideo.cpp:54
const float customFrameRate
Definition SaveToVideo.cpp:73
const unsigned int numImages
Definition SaveToVideo.cpp:46
Used to hold a list of camera objects.
Definition CameraList.h:42
void Clear()
Clears the list of cameras and destroys their corresponding reference counted objects.
CameraPtr GetByIndex(unsigned int index) const
Returns a pointer to a camera object at the "index".
unsigned int GetSize() const
Returns the size of the camera list.
A reference tracked pointer to a camera object.
Definition CameraPtr.h:44
The Exception object represents an error that is returned from the library.
Definition Exception.h:51
virtual const char * what() const
virtual override for what().
SmartPointer for IFloat interface pointer.
Definition Pointer.h:421
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:75
Image post processing class for converting a source image to another pixel format.
Definition ImageProcessor.h:159
void SetColorProcessing(ColorProcessingAlgorithm colorAlgorithm)
Sets the color processing algorithm used at the time of the Convert() call, therefore the most recent...
ImagePtr Convert(const ImagePtr &srcImage, PixelFormatEnums destFormat) const
Converts the source image buffer to the specified destination pixel format and returns the result in ...
A reference tracked pointer to an image object.
Definition ImagePtr.h:46
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
Provides the functionality for the user to record images to an AVI/MP4 file.
Definition SpinVideo.h:44
virtual void Append(ImagePtr pImage)
Append an image to the video file.
virtual void Open(const char *pFileName, AVIOption &pOption)
Open an video file in preparation for writing Images to disk.
virtual void Close()
Close the video file.
virtual void SetMaximumFileSize(unsigned int size)
Set the maximum file size (in megabytes) of a AVI/MP4 file.
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition INode.h:277
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition INode.h:253
interface SPINNAKER_API_ABSTRACT INodeMap
Interface to access the node map.
Definition INodeMap.h:54
Definition Autovector.h:36
Definition SpinVideo.h:28
Provides easier access to the current version of Spinnaker.
Definition SpinnakerDefs.h:657
unsigned int minor
Minor version of the library.
Definition SpinnakerDefs.h:662
unsigned int major
Major version of the library.
Definition SpinnakerDefs.h:659
unsigned int type
Version type of the library.
Definition SpinnakerDefs.h:665
unsigned int build
Build number of the library.
Definition SpinnakerDefs.h:668
Options for saving AVI files.
Definition SpinVideoDefs.h:117
Options for saving H264 files.
Definition SpinVideoDefs.h:77
Options for saving MJPG files.
Definition SpinVideoDefs.h:47