golib  0.5
videocapture/videocapture.cpp
/* Copyright (C) 1998-2011 Christian Gosch, golib at goschs dot de
This file is part of the golib library.
For license regulations, see the file COPYING in the main
directory of the golib source tree. */
#include <govideocapture.h>
#include <gosignal3d.h>
#include <gosubsignal3d.h>
#include <gosignalhelper.h>
#include <gofileio.h>
#include <stdio.h>
/*
* Example program for goVideoCapture.
* Note that this works only for cameras providing RGB24 data,
* see source code for modifications if you have YUV420P data.
*
* Christian Gosch
*/
int main()
{
//= Set device.
vc.setDevice ("/dev/video0");
if (vc.open())
{
printf ("Opened the device /dev/video1\n");
goSize_t w = 640;
goSize_t h = 480;
sig.setDataType (GO_UINT8);
//= Make a signal that is linear in memory (necessary for goVideoCapture to directly grab
//= RGB24 data to the signal).
sig.make (goSize3D(w,h,1),goSize3D(w,h,1),goSize3D(0,0,0),3);
//= Get settings from device.
vc.setCaptureSize (w,h);
//= Push settings to device.
goString filebase = "grabbed-";
goString fileext = ".jpg";
goString num;
num.resize(3);
//= Give the camera some time to adjust.
sleep(5);
//= Take 10 pictures and save them (this needs libdevil support to be enabled in golib).
for (goIndex_t j = 0; j < 50; ++j)
{
//= NOTE: This assumes the camera is providing data as RGB24.
//= If your camera happens to return YUV420P (planar) data, you can use
//= the function goYUV420P_RGB() in gocolourspace.h to convert to RGB. If your camera
//= supports a different format, please write a conversion routine if you can!
vc.grab(sig);
//= Swap R and B channels (seem to come in different byte order from
//= our logitech camera).
#if 0
{
goSubSignal3D<void> sub0 (&sig,sig.getSizeX(),sig.getSizeY(),sig.getSizeZ());
temp.setDataType(sig.getDataType().getID());
temp.make(sig.getSize(),sig.getBlockSize(),sig.getBorderSize(),1);
sig.setChannel(0);
goCopySignalChannel(&sig,&temp);
sub0.setChannel(2);
goCopySignalChannel(&sub0,&sig);
goCopySignalChannel(&temp,&sub0);
}
#endif
goString name = filebase;
sprintf(num.getPtr(),"%3d",j);
name += num;
name += fileext;
goFileIO::writeImage(name.toCharPtr(),&sig);
}
vc.close();
}
else
{
printf ("Could not open device /dev/video0\n");
}
}
goVideoCapture::getSettings
void getSettings()
Get settings from device and store them internally. It is a good idea to call this after opening a de...
Definition: govideocapture.cpp:516
goVideoCapture::setCaptureSize
bool setCaptureSize(goSize_t width, goSize_t height)
Set capture frame size.
Definition: govideocapture.cpp:177
goSignal3DBase::setChannel
void setChannel(goSize_t c)
Definition: gosignal3dbase.cpp:2122
goFileIO::writeImage
static bool writeImage(const char *filename, const goSignal3DBase< void > *signal)
Write an image file from a goSignal3DBase<void> object.
Definition: gofileio.cc:741
goSignal3D::make
bool make(const goSize3D &size, const goSize3D &blockSize, const goSize3D &borderSize, goSize_t channelCount)
Allocate memory.
Definition: gosignal3d.cc:329
goSignal3D< void >
goVideoCapture::grab
bool grab(goSignal3DBase< void > &signal, const int *rgb_channels)
Grab a frame from the open device.
Definition: govideocapture.cpp:353
goSignal3DBase::getSizeY
goSize_t getSizeY() const
Definition: gosignal3dbase.cpp:2032
go3Vector< goSize_t >
goSize_t
size_t goSize_t
Definition: gotypes.h:96
goCopySignalChannel
bool goCopySignalChannel(const goSignal3DBase< void > *sig, goSignal3DBase< void > *targetSig)
Copies a channel from a signal to another signal.
Definition: gosignalhelper.cpp:457
goSignal3DBase::getSizeZ
goSize_t getSizeZ() const
Definition: gosignal3dbase.cpp:2039
goSignal3DBase::getSizeX
goSize_t getSizeX() const
Definition: gosignal3dbase.cpp:2025
goVideoCapture::close
void close()
Close the open device.
Definition: govideocapture.cpp:249
goVideoCapture::setSettings
bool setSettings()
Store settings from this object to the open device.
Definition: govideocapture.cpp:460
goSubSignal3D< void >
goType::getID
goTypeEnum getID() const
Get enumerator for the type set in this object.
Definition: gotype.cpp:662
goVideoCapture::open
bool open()
Open the device.
Definition: govideocapture.cpp:235
goVideoCapture::setDevice
bool setDevice(const char *name)
Set device file name.
Definition: govideocapture.cpp:137
goVideoCapture
Video capture class.
Definition: govideocapture.h:41
goString
String class.
Definition: gostring.h:28