[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd cvd/Linux/dvbuffer3.h cvd_src/Linux/dvbu...
From: |
Gerhard Reitmayr |
Subject: |
[libcvd-members] libcvd cvd/Linux/dvbuffer3.h cvd_src/Linux/dvbu... |
Date: |
Mon, 09 Mar 2009 20:57:13 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Gerhard Reitmayr <gerhard> 09/03/09 20:57:13
Modified files:
cvd/Linux : dvbuffer3.h
cvd_src/Linux : dvbuffer3_dc1394v2.cc dvbuffer3_dc1394v1.cc
Log message:
support for Format 7 modes in DVBuffer3, if compiled against dc1394 v2
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/Linux/dvbuffer3.h?cvsroot=libcvd&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/Linux/dvbuffer3_dc1394v2.cc?cvsroot=libcvd&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/Linux/dvbuffer3_dc1394v1.cc?cvsroot=libcvd&r1=1.2&r2=1.3
Patches:
Index: cvd/Linux/dvbuffer3.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/Linux/dvbuffer3.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- cvd/Linux/dvbuffer3.h 2 Dec 2008 17:30:40 -0000 1.2
+++ cvd/Linux/dvbuffer3.h 9 Mar 2009 20:57:12 -0000 1.3
@@ -53,7 +53,7 @@
enum DV3Feature { BRIGHTNESS, EXPOSURE, SHARPNESS,
WHITE_BALANCE, HUE, SATURATION,
GAMMA, SHUTTER, GAIN, IRIS,
- FOCUS, ZOOM, PAN, TILT};
+ FOCUS, ZOOM, PAN, TILT, FRAME_RATE};
/// This enumerates all the colourspace types supported by DC1394
/// N.b. only a small fraction of these map 1:1 to libCVD types
@@ -62,6 +62,11 @@
YUV411, YUV422, YUV444,
RAW8, RAW16};
+ /// This enumerates the different colour filter tile patterns for Bayer
+ /// images. This can be queried from the RawDVBuffer3 for a Bayer mode.
+ /// This is only supported for DC1394 v2
+ enum DV3ColourFilter { RGGB, GBRG, GRBG, BGGR };
+
#ifndef DOXYGEN_IGNORE_INTERNAL
// Translation helper classes to go from CVD-types to the above
template<class C>
@@ -77,6 +82,8 @@
{ static const DV3ColourSpace space = YUV422;};
template<> struct CSConvert<Rgb<byte> >
{ static const DV3ColourSpace space = RGB8;};
+ template<> struct CSConvert<bayer>
+ { static const DV3ColourSpace space = RAW8; };
struct LibDCParams;
#endif
@@ -84,23 +91,30 @@
/// Non-templated libDC1394 interface. This is used by DVBuffer3. If you
want
/// typed video frames, you should use DVBuffer 3 instead..
/// The implementation of this class depends on which version of libDC1394
is
- /// installed on the system.
+ /// installed on the system. Format 7 support is only present for
libDC1394 V2.
class RawDVBuffer3
{
public:
- /// Mode-selecting constructor for all standard modes (not Mode7)
+ /// Mode-selecting constructor for all standard modes & Format 7. First
it tries
+ /// to find a standard mode, then it looks at the Format 7 modes. If an
offset
+ /// is given, standard modes are skipped (they don't allow offsets).
/// @param colourspace Enumerated colourspace requested
/// @param nCamNumber Which camera on the bus to use
/// @param irSize Requested video size; if left at (-1,-1) use biggest
available
/// @param fFrameRate Requested frame-rate; if negative, use fastest
available
+ /// @param irOffset offset of video frame in CCD; if left at (-1,-1) use
default modes or center window
RawDVBuffer3(DV3ColourSpace colourspace,
unsigned int nCamNumber=0,
ImageRef irSize = ImageRef(-1,-1),
- float fFrameRate=-1.0);
+ float fFrameRate=-1.0,
+ ImageRef irOffset = ImageRef(-1,-1));
~RawDVBuffer3();
inline ImageRef size() {return mirSize;}
+ inline ImageRef offset() {return mirOffset;}
inline double frame_rate() {return mdFramerate;}
+ inline DV3ColourFilter colour_filter() { return mColourfilter; }
+
VideoFrame<byte>* get_frame();
void put_frame(VideoFrame<byte>* f);
bool frame_pending();
@@ -112,7 +126,9 @@
private:
ImageRef mirSize;
+ ImageRef mirOffset;
double mdFramerate;
+ DV3ColourFilter mColourfilter;
/// This encapsulates the actual libDC1394 variables
LibDCParams *mpLDCP;
};
@@ -129,9 +145,10 @@
public:
DVBuffer3(unsigned int nCamNumber=0,
ImageRef irSize = ImageRef(-1,-1),
- float fFPS = -1.0)
+ float fFPS = -1.0,
+ ImageRef irOffset = ImageRef(-1,-1))
: VideoBuffer<pixel_T>(VideoBufferType::Live),
- RawDVBuffer3(DV3::CSConvert<pixel_T>::space, nCamNumber, irSize,
fFPS)
+ RawDVBuffer3(DV3::CSConvert<pixel_T>::space, nCamNumber, irSize,
fFPS, irOffset)
{
}
Index: cvd_src/Linux/dvbuffer3_dc1394v2.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/Linux/dvbuffer3_dc1394v2.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- cvd_src/Linux/dvbuffer3_dc1394v2.cc 2 Dec 2008 17:30:41 -0000 1.4
+++ cvd_src/Linux/dvbuffer3_dc1394v2.cc 9 Mar 2009 20:57:12 -0000 1.5
@@ -26,7 +26,6 @@
#include <vector>
#include <algorithm>
-
using namespace CVD;
using namespace DV3;
using CVD::Exceptions::DVBuffer3::All;
@@ -93,6 +92,7 @@
case ZOOM: return DC1394_FEATURE_ZOOM;
case PAN: return DC1394_FEATURE_PAN;
case TILT: return DC1394_FEATURE_TILT;
+ case FRAME_RATE: return DC1394_FEATURE_FRAME_RATE;
}
throw(All("DC_from_DV3: Invalid feature"));
}
@@ -100,7 +100,8 @@
RawDVBuffer3::RawDVBuffer3(DV3ColourSpace colourspace,
unsigned int nCamNumber,
ImageRef irSize,
- float fFrameRate)
+ float fFrameRate,
+ ImageRef irOffset)
{
mpLDCP = new LibDCParams;
@@ -137,36 +138,40 @@
// What mode to use?
+ dc1394color_coding_t nTargetColourCoding =
DC_from_DV3_ColourSpace(colourspace);
+ bool foundAStandardMode = false;
+ dc1394video_mode_t nMode;
+
+ if(irOffset.x == -1){
+ try {
// First, get a list of the modes which the camera supports.
dc1394video_modes_t modes;
error = dc1394_video_get_supported_modes(mpLDCP->pCamera, &modes);
if(error) throw(All("Could not get modelist"));
- dc1394color_coding_t nTargetColourCoding =
DC_from_DV3_ColourSpace(colourspace);
-
// Second: Build up a list of the modes which are the right colour-space
std::vector<dc1394video_mode_t> vModes;
for(unsigned int i = 0; i < modes.num; i++)
{
dc1394video_mode_t nMode = modes.modes[i];
+ // ignore format 7 for now
+ if(nMode >= DC1394_VIDEO_MODE_FORMAT7_0) continue;
dc1394color_coding_t nColourCoding;
error=dc1394_get_color_coding_from_video_mode(mpLDCP->pCamera,nMode,&nColourCoding);
if(error) throw(All("Error in get_color_coding_from_video_mode"));
if(nColourCoding == nTargetColourCoding)
vModes.push_back(nMode);
}
- if(vModes.size() == 0) throw(All("No mode matches requested
colourspace."));
+ if(vModes.size() == 0) throw(-1);
// Third: Select mode according to size
bool bModeFound = false;
dc1394video_mode_t nMode;
if(irSize.x != -1) // Has the user specified a target size? Choose
mode according to that..
- for(size_t i = 0; i<vModes.size(); i++)
- {
+ for(size_t i = 0; i<vModes.size(); i++){
uint32_t x,y;
dc1394_get_image_size_from_video_mode(mpLDCP->pCamera, vModes[i],
&x, &y);
- if(x == (uint32_t) irSize.x && y == (uint32_t) irSize.y)
- {
+ if(x == (uint32_t) irSize.x && y ==
(uint32_t) irSize.y) {
bModeFound = true;
nMode = vModes[i];
break;
@@ -178,13 +183,14 @@
bModeFound = true;
nMode = vModes.back();
}
- if(!bModeFound) throw(All("Could not find mode of requested size."));
+ if(!bModeFound) throw(-1);
// Store the size of the selected mode..
uint32_t x,y;
dc1394_get_image_size_from_video_mode(mpLDCP->pCamera, nMode, &x, &y);
mirSize.x = x;
mirSize.y = y;
+ mirOffset = irOffset;
// Got mode, now decide on frame-rate. Similar thing: first get list,
then choose from list.
dc1394framerates_t framerates;
@@ -195,43 +201,116 @@
if(fFrameRate > 0) // User wants a specific frame-rate?
{
- bool bFoundFrameRate = false;
- for(unsigned int i=0; i<framerates.num; i++)
- {
+ for(unsigned int i=0; i<framerates.num; i++){
float f_rate;
dc1394_framerate_as_float(framerates.framerates[i],&f_rate);
- if(f_rate == fFrameRate)
- {
- bFoundFrameRate = true;
+ if(f_rate == fFrameRate){
nChosenFramerate = framerates.framerates[i];
mdFramerate = f_rate;
break;
}
}
- if(!bFoundFrameRate)
- throw(All("Could not match requested frame-rate."));
- }
- else
- { // Just pick the highest frame-rate the camera can do.
- for(unsigned int i=0; i<framerates.num; i++)
- {
+ } else { // Just pick the highest frame-rate the camera
can do.
+ for(unsigned int i=0; i<framerates.num; i++){
float f_rate;
dc1394_framerate_as_float(framerates.framerates[i],&f_rate);
- if(f_rate > mdFramerate)
- {
+ if(f_rate > mdFramerate) {
nChosenFramerate = framerates.framerates[i];
mdFramerate = f_rate;
}
}
}
- if(mdFramerate == -1.0)
- throw(All("Could not find a frame-rate."));
+ if(mdFramerate == -1.0) throw(-1);
// Selected mode and frame-rate; Now tell the camera to use these.
// At the moment, hard-code the channel to speed 400. This is maybe
something to fix in future?
error = dc1394_video_set_iso_speed(mpLDCP->pCamera,
DC1394_ISO_SPEED_400);
if(error) throw(All("Could not set ISO speed."));
+ error = dc1394_video_set_iso_channel(mpLDCP->pCamera,
nCamNumber);
+ if(error) throw(All("Could not set ISO channel."));
+
+ error = dc1394_video_set_mode(mpLDCP->pCamera, nMode);
+ if(error) throw(All("Could not set video mode"));
+
+ error = dc1394_video_set_framerate(mpLDCP->pCamera,
nChosenFramerate);
+ if(error) throw(All("Could not set frame-rate"));
+ // no need to check Format 7 modes
+ foundAStandardMode = true;
+ }
+ catch(int e){
+ //cout << "DCBuffer is checking format 7 modes as well"
<< endl;
+ foundAStandardMode = false;
+ }
+ }
+ if(!foundAStandardMode){
+ dc1394format7modeset_t modeset;
+ error = dc1394_format7_get_modeset(mpLDCP->pCamera, &modeset);
+ if(error) throw(All("Could not get Format 7 modes."));
+ int index = 0;
+ if(irOffset.x == -1)
+ mirOffset = ImageRef(0,0);
+ else
+ mirOffset = irOffset;
+ for(; index < DC1394_VIDEO_MODE_FORMAT7_NUM; ++index){
+ const dc1394format7mode_t & mode = modeset.mode[index];
+ // does the mode exist ?
+ if(!mode.present) continue;
+ // does it support the colour format we need ?
+ unsigned int i;
+ for(i = 0; i < mode.color_codings.num; ++i)
+ if(mode.color_codings.codings[i] ==
nTargetColourCoding)
+ break;
+ if(i == mode.color_codings.num) continue;
+ if(irSize.x != -1){
+ // can it support the size ?
+ if((irSize.x + mirOffset.x) > mode.max_size_x
|| (irSize.y + mirOffset.y) > mode.max_size_y || irSize.x % mode.unit_size_x !=
0 || irSize.y % mode.unit_size_y != 0)
+ continue;
+ } else {
+ irSize.x = mode.max_size_x;
+ irSize.y = mode.max_size_y;
+ }
+ // found one
+ break;
+ }
+ if(index == DC1394_VIDEO_MODE_FORMAT7_NUM) throw(All("Could not
find any usable format!"));
+ const dc1394format7mode_t & mode = modeset.mode[index];
+ nMode = static_cast<dc1394video_mode_t>(
DC1394_VIDEO_MODE_FORMAT7_0 + index);
+
+ // At the moment, hard-code the channel to speed 400. This is
maybe something to fix in future?
+ error = dc1394_video_set_iso_speed(mpLDCP->pCamera,
DC1394_ISO_SPEED_400);
+ if(error) throw(All("Could not set ISO speed."));
+
+ error = dc1394_video_set_iso_channel(mpLDCP->pCamera,
nCamNumber);
+ if(error) throw(All("Could not set ISO channel."));
+
+ error = dc1394_video_set_mode(mpLDCP->pCamera, nMode);
+ if(error) throw(All("Could not set video mode."));
+
+ // frame rate calculations
+ int num_packets = (int)(8000.0/fFrameRate + 0.5);
+ int packet_size = (irSize.x * irSize.y * 8 + num_packets * 8 -
1 ) / (num_packets * 8);
+ mdFramerate = fFrameRate;
+ // offset calculations
+ if(irOffset.x == -1){
+ mirOffset.x = (mode.max_size_x - irSize.x) / 2;
+ mirOffset.y = (mode.max_size_y - irSize.y) / 2;
+ } else {
+ mirOffset = irOffset;
+ }
+ mirSize = irSize;
+ dc1394_format7_set_roi( mpLDCP->pCamera, nMode,
+
nTargetColourCoding,
+ packet_size,
+ mirOffset.x, //
left
+ mirOffset.y, //
top
+ mirSize.x, //
width
+ mirSize.y);
// height
+ dc1394color_filter_t filterType;
+ error = dc1394_format7_get_color_filter(mpLDCP->pCamera, nMode,
&filterType);
+ mColourfilter = static_cast<DV3ColourFilter>(filterType -
DC1394_COLOR_FILTER_MIN);
+ }
+
// Hack Alert: The code below sets the iso channel without this
// having been properly allocated! Likewise we never allocate
// bandwidth. Both of these could be allocated if the following
@@ -242,15 +321,6 @@
// properly.
// This hack emulates what dvbuffer.cc does using libdc1394v1.
- error = dc1394_video_set_iso_channel(mpLDCP->pCamera, nCamNumber);
- if(error) throw(All("Could not set ISO channel."));
-
- error = dc1394_video_set_mode(mpLDCP->pCamera, nMode);
- if(error) throw(All("Could not set video mode"));
-
- error = dc1394_video_set_framerate(mpLDCP->pCamera, nChosenFramerate);
- if(error) throw(All("Could not set frame-rate"));
-
// Hack to disable resource allocation -- see above
// error = dc1394_capture_setup(mpLDCP->pCamera, 4,
DC1394_CAPTURE_FLAGS_DEFAULT);
error = dc1394_capture_setup(mpLDCP->pCamera, 4, 0);
@@ -258,7 +328,6 @@
error = dc1394_video_set_transmission(mpLDCP->pCamera, DC1394_ON);
if(error) throw(All("Could not start ISO transmission."));
-
}
RawDVBuffer3::~RawDVBuffer3()
@@ -294,7 +363,6 @@
if(error) throw(All("Failed on deque"));
-
DV3::DV3Frame *pDV3Frame = new DV3::DV3Frame(pDC1394Frame);
return pDV3Frame;
@@ -361,11 +429,3 @@
}
}
-
-
-
-
-
-
-
-
Index: cvd_src/Linux/dvbuffer3_dc1394v1.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/Linux/dvbuffer3_dc1394v1.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- cvd_src/Linux/dvbuffer3_dc1394v1.cc 15 Jul 2008 15:03:45 -0000 1.2
+++ cvd_src/Linux/dvbuffer3_dc1394v1.cc 9 Mar 2009 20:57:13 -0000 1.3
@@ -65,7 +65,8 @@
RawDVBuffer3::RawDVBuffer3(DV3ColourSpace colourspace,
unsigned int nCamNumber,
ImageRef irSize,
- float fFrameRate)
+ float fFrameRate,
+ ImageRef irOffset)
{
int mode;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd cvd/Linux/dvbuffer3.h cvd_src/Linux/dvbu...,
Gerhard Reitmayr <=