This commit is contained in:
Ivan
2022-04-05 11:42:28 +03:00
commit 6dc0eb0fcf
5565 changed files with 1200500 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
namespace pangolin
{
// Enum to match libdc1394's dc1394_bayer_method_t
typedef enum {
BAYER_METHOD_NEAREST = 0,
BAYER_METHOD_SIMPLE,
BAYER_METHOD_BILINEAR,
BAYER_METHOD_HQLINEAR,
BAYER_METHOD_DOWNSAMPLE_,
BAYER_METHOD_EDGESENSE,
BAYER_METHOD_VNG,
BAYER_METHOD_AHD,
// Pangolin custom defines
BAYER_METHOD_NONE = 512,
BAYER_METHOD_DOWNSAMPLE,
BAYER_METHOD_DOWNSAMPLE_MONO
} bayer_method_t;
// Enum to match libdc1394's dc1394_color_filter_t
typedef enum {
DC1394_COLOR_FILTER_RGGB = 512,
DC1394_COLOR_FILTER_GBRG,
DC1394_COLOR_FILTER_GRBG,
DC1394_COLOR_FILTER_BGGR
} color_filter_t;
// Video class that debayers its video input using the given method.
class PANGOLIN_EXPORT DebayerVideo :
public VideoInterface,
public VideoFilterInterface,
public BufferAwareVideoInterface
{
public:
DebayerVideo(std::unique_ptr<VideoInterface>& videoin, const std::vector<bayer_method_t> &method, color_filter_t tile);
~DebayerVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
std::vector<VideoInterface*>& InputStreams();
static color_filter_t ColorFilterFromString(std::string str);
static bayer_method_t BayerMethodFromString(std::string str);
uint32_t AvailableFrames() const;
bool DropNFrames(uint32_t n);
protected:
void ProcessStreams(unsigned char* out, const unsigned char* in);
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
std::vector<StreamInfo> streams;
size_t size_bytes;
std::unique_ptr<unsigned char[]> buffer;
std::vector<bayer_method_t> methods;
color_filter_t tile;
picojson::value device_properties;
picojson::value frame_properties;
};
}

View File

@@ -0,0 +1,62 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/video/video.h>
#include <vector>
namespace pangolin
{
class PANGOLIN_EXPORT DeinterlaceVideo
: public VideoInterface
{
public:
DeinterlaceVideo(std::unique_ptr<VideoInterface>& videoin);
~DeinterlaceVideo();
size_t SizeBytes() const;
const std::vector<StreamInfo>& Streams() const;
void Start();
void Stop();
bool GrabNext( unsigned char* image, bool wait = true );
bool GrabNewest( unsigned char* image, bool wait = true );
protected:
std::unique_ptr<VideoInterface> videoin;
std::vector<StreamInfo> streams;
unsigned char* buffer;
};
}

View File

@@ -0,0 +1,171 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/iostream_operators.h>
#include <pangolin/video/video.h>
#include <thread>
#include <mutex>
#include <condition_variable>
// DepthSense SDK for SoftKinetic cameras from Creative
#include <DepthSense.hxx>
namespace pangolin
{
enum DepthSenseSensorType
{
DepthSenseUnassigned = -1,
DepthSenseRgb = 0,
DepthSenseDepth
};
// Video class that outputs test video signal.
class PANGOLIN_EXPORT DepthSenseVideo :
public VideoInterface, public VideoPropertiesInterface
{
public:
DepthSenseVideo(DepthSense::Device device, DepthSenseSensorType s1, DepthSenseSensorType s2, ImageDim dim1, ImageDim dim2, unsigned int fps1, unsigned int fps2, const Uri& uri);
~DepthSenseVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
//! Implement VideoInput::DeviceProperties()
const picojson::value& DeviceProperties() const {
return device_properties;
}
//! Implement VideoInput::DeviceProperties()
const picojson::value& FrameProperties() const {
return frame_properties;
}
protected:
void onNewColorSample(DepthSense::ColorNode node, DepthSense::ColorNode::NewSampleReceivedData data);
void onNewDepthSample(DepthSense::DepthNode node, DepthSense::DepthNode::NewSampleReceivedData data);
struct SensorConfig
{
DepthSenseSensorType type;
ImageDim dim;
unsigned int fps;
};
void UpdateParameters(const DepthSense::Node& node, const Uri& uri);
void ConfigureNodes(const Uri& uri);
void ConfigureDepthNode(const SensorConfig& sensorConfig, const Uri& uri);
void ConfigureColorNode(const SensorConfig& sensorConfig, const Uri& uri);
double GetDeltaTime() const;
std::vector<StreamInfo> streams;
picojson::value device_properties;
picojson::value frame_properties;
picojson::value* streams_properties;
DepthSense::Device device;
DepthSense::DepthNode g_dnode;
DepthSense::ColorNode g_cnode;
unsigned char* fill_image;
int depthmap_stream;
int rgb_stream;
int gotDepth;
int gotColor;
std::mutex update_mutex;
std::condition_variable cond_image_filled;
std::condition_variable cond_image_requested;
SensorConfig sensorConfig[2];
bool enableDepth;
bool enableColor;
double depthTs;
double colorTs;
size_t size_bytes;
};
class DepthSenseContext
{
friend class DepthSenseVideo;
public:
// Singleton Instance
static DepthSenseContext& I();
DepthSenseVideo* GetDepthSenseVideo(size_t device_num, DepthSenseSensorType s1, DepthSenseSensorType s2, ImageDim dim1, ImageDim dim2, unsigned int fps1, unsigned int fps2, const Uri& uri);
protected:
// Protected Constructor
DepthSenseContext();
~DepthSenseContext();
DepthSense::Context& Context();
void NewDeviceRunning();
void DeviceClosing();
void StartNodes();
void StopNodes();
void EventLoop();
void onDeviceConnected(DepthSense::Context context, DepthSense::Context::DeviceAddedData data);
void onDeviceDisconnected(DepthSense::Context context, DepthSense::Context::DeviceRemovedData data);
DepthSense::Context g_context;
std::thread event_thread;
bool is_running;
int running_devices;
};
}

View File

@@ -0,0 +1,207 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
extern "C"
{
// HACK for some versions of FFMPEG
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/pixdesc.h>
#include <libavcodec/avcodec.h>
}
#ifndef HAVE_FFMPEG_AVPIXELFORMAT
# define AVPixelFormat PixelFormat
#endif
namespace pangolin
{
class PANGOLIN_EXPORT FfmpegVideo : public VideoInterface
{
public:
FfmpegVideo(const std::string filename, const std::string fmtout = "RGB24", const std::string codec_hint = "", bool dump_info = false, int user_video_stream = -1, ImageDim size = ImageDim(0,0));
~FfmpegVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
protected:
void InitUrl(const std::string filename, const std::string fmtout = "RGB24", const std::string codec_hint = "", bool dump_info = false , int user_video_stream = -1, ImageDim size= ImageDim(0,0));
std::vector<StreamInfo> streams;
SwsContext *img_convert_ctx;
AVFormatContext *pFormatCtx;
int videoStream;
int audioStream;
AVCodecContext *pVidCodecCtx;
AVCodecContext *pAudCodecCtx;
AVCodec *pVidCodec;
AVCodec *pAudCodec;
AVFrame *pFrame;
AVFrame *pFrameOut;
AVPacket packet;
int numBytesOut;
uint8_t *buffer;
AVPixelFormat fmtout;
};
enum FfmpegMethod
{
FFMPEG_FAST_BILINEAR = 1,
FFMPEG_BILINEAR = 2,
FFMPEG_BICUBIC = 4,
FFMPEG_X = 8,
FFMPEG_POINT = 0x10,
FFMPEG_AREA = 0x20,
FFMPEG_BICUBLIN = 0x40,
FFMPEG_GAUSS = 0x80,
FFMPEG_SINC =0x100,
FFMPEG_LANCZOS =0x200,
FFMPEG_SPLINE =0x400
};
class PANGOLIN_EXPORT FfmpegConverter : public VideoInterface
{
public:
FfmpegConverter(std::unique_ptr<VideoInterface>& videoin, const std::string pixelfmtout = "RGB24", FfmpegMethod method = FFMPEG_POINT);
~FfmpegConverter();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
protected:
std::vector<StreamInfo> streams;
struct ConvertContext
{
SwsContext* img_convert_ctx;
AVPixelFormat fmtsrc;
AVPixelFormat fmtdst;
AVFrame* avsrc;
AVFrame* avdst;
size_t w,h;
size_t src_buffer_offset;
size_t dst_buffer_offset;
void convert(const unsigned char * src, unsigned char* dst);
};
std::unique_ptr<VideoInterface> videoin;
std::unique_ptr<unsigned char[]> input_buffer;
std::vector<ConvertContext> converters;
//size_t src_buffer_size;
size_t dst_buffer_size;
};
#if (LIBAVFORMAT_VERSION_MAJOR > 55) || ((LIBAVFORMAT_VERSION_MAJOR == 55) && (LIBAVFORMAT_VERSION_MINOR >= 7))
typedef AVCodecID CodecID;
#endif
// Forward declaration
class FfmpegVideoOutputStream;
class PANGOLIN_EXPORT FfmpegVideoOutput
: public VideoOutputInterface
{
friend class FfmpegVideoOutputStream;
public:
FfmpegVideoOutput( const std::string& filename, int base_frame_rate, int bit_rate, bool flip = false );
~FfmpegVideoOutput();
const std::vector<StreamInfo>& Streams() const override;
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const picojson::value& properties) override;
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties) override;
bool IsPipe() const override;
protected:
void Initialise(std::string filename);
void StartStream();
void Close();
std::string filename;
bool started;
AVFormatContext *oc;
std::vector<FfmpegVideoOutputStream*> streams;
std::vector<StreamInfo> strs;
int frame_count;
int base_frame_rate;
int bit_rate;
bool is_pipe;
bool flip;
};
}

View File

@@ -0,0 +1,254 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <dc1394/dc1394.h>
#ifndef _WIN32
#include <unistd.h>
#endif
namespace pangolin
{
PANGOLIN_EXPORT
std::string Dc1394ColorCodingToString(dc1394color_coding_t coding);
PANGOLIN_EXPORT
dc1394color_coding_t Dc1394ColorCodingFromString(std::string coding);
PANGOLIN_EXPORT
void Dc1394ModeDetails(dc1394video_mode_t mode, unsigned& w, unsigned& h, std::string& format );
class PANGOLIN_EXPORT FirewireFrame
{
friend class FirewireVideo;
public:
bool isValid() { return frame; }
unsigned char* Image() { return frame ? frame->image : 0; }
unsigned Width() const { return frame ? frame->size[0] : 0; }
unsigned Height() const { return frame ? frame->size[1] : 0; }
unsigned ImageBytes() const { return frame ? frame->image_bytes : 0; }
int FramesBehind() const { return frame ? frame->frames_behind : -1; }
unsigned Timestamp() const { return frame ? frame->timestamp : 0; }
int Id() const { return frame ? frame->id : -1; }
protected:
FirewireFrame(dc1394video_frame_t* frame) : frame(frame) {}
dc1394video_frame_t *frame;
};
struct PANGOLIN_EXPORT Guid
{
Guid(uint64_t guid):guid(guid){}
uint64_t guid;
};
class PANGOLIN_EXPORT FirewireVideo : public VideoInterface
{
public:
const static int MAX_FR = -1;
const static int EXT_TRIG = -1;
const static uint32_t GPIO_CTRL_PIN0 = 0x1110;
const static uint32_t GPIO_CTRL_PIN1 = 0x1120;
const static uint32_t GPIO_CTRL_PIN2 = 0x1130;
const static uint32_t GPIO_CTRL_PIN3 = 0x1140;
FirewireVideo(
unsigned deviceid = 0,
dc1394video_mode_t video_mode = DC1394_VIDEO_MODE_640x480_RGB8,
dc1394framerate_t framerate = DC1394_FRAMERATE_30,
dc1394speed_t iso_speed = DC1394_ISO_SPEED_400,
int dma_buffers = 10
);
FirewireVideo(
Guid guid,
dc1394video_mode_t video_mode = DC1394_VIDEO_MODE_640x480_RGB8,
dc1394framerate_t framerate = DC1394_FRAMERATE_30,
dc1394speed_t iso_speed = DC1394_ISO_SPEED_400,
int dma_buffers = 10
);
FirewireVideo(
Guid guid,
dc1394video_mode_t video_mode,
float framerate,
uint32_t width, uint32_t height,
uint32_t left, uint32_t top,
dc1394speed_t iso_speed,
int dma_buffers, bool reset_at_boot=false
);
FirewireVideo(
unsigned deviceid,
dc1394video_mode_t video_mode,
float framerate,
uint32_t width, uint32_t height,
uint32_t left, uint32_t top,
dc1394speed_t iso_speed,
int dma_buffers, bool reset_at_boot=false
);
~FirewireVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
//! (deprecated: use Streams[i].Width())
//! Return image width
unsigned Width() const { return width; }
//! (deprecated: use Streams[i].Height())
//! Return image height
unsigned Height() const { return height; }
//! Return object containing reference to image data within
//! DMA buffer. The FirewireFrame must be returned to
//! signal that it can be reused with a corresponding PutFrame()
FirewireFrame GetNext(bool wait = true);
//! Return object containing reference to newest image data within
//! DMA buffer discarding old images. The FirewireFrame must be
//! returned to signal that it can be reused with a corresponding PutFrame()
FirewireFrame GetNewest(bool wait = true);
//! Return FirewireFrame object. Data held by FirewireFrame is
//! invalidated on return.
void PutFrame(FirewireFrame& frame);
//! return absolute shutter value
float GetShutterTime() const;
//! set absolute shutter value
void SetShutterTime(float val);
//! set auto shutter value
void SetAutoShutterTime();
//! return absolute gain value
float GetGain() const;
//! set absolute gain value
void SetGain(float val);
//! set auto gain value
void SetAutoGain();
//! return absolute brightness value
float GetBrightness() const;
//! set absolute brightness value
void SetBrightness(float val);
//! set auto brightness
void SetAutoBrightness();
//! return absolute gamma value
float GetGamma() const;
//! return quantised shutter value
void SetShutterTimeQuant(int shutter);
//! set the trigger to internal, i.e. determined by video mode
void SetInternalTrigger();
//! set the trigger to external
void SetExternalTrigger(
dc1394trigger_mode_t mode=DC1394_TRIGGER_MODE_0,
dc1394trigger_polarity_t polarity=DC1394_TRIGGER_ACTIVE_HIGH,
dc1394trigger_source_t source=DC1394_TRIGGER_SOURCE_0
);
//! set a camera register
void SetRegister(uint64_t offset, uint32_t value);
//! read camera register
uint32_t GetRegister(uint64_t offset);
//! set a camera control register
void SetControlRegister(uint64_t offset, uint32_t value);
//! read camera control register
uint32_t GetControlRegister(uint64_t offset);
protected:
void init_stream_info();
void init_camera(
uint64_t guid, int dma_frames,
dc1394speed_t iso_speed,
dc1394video_mode_t video_mode,
dc1394framerate_t framerate
);
void init_format7_camera(
uint64_t guid, int dma_frames,
dc1394speed_t iso_speed,
dc1394video_mode_t video_mode,
float framerate,
uint32_t width, uint32_t height,
uint32_t left, uint32_t top, bool reset_at_boot
);
static int nearest_value(int value, int step, int min, int max);
static double bus_period_from_iso_speed(dc1394speed_t iso_speed);
size_t frame_size_bytes;
std::vector<StreamInfo> streams;
bool running;
dc1394camera_t *camera;
unsigned width, height, top, left;
//dc1394featureset_t features;
dc1394_t * d;
dc1394camera_list_t * list;
mutable dc1394error_t err;
};
}

View File

@@ -0,0 +1,121 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/image/image_io.h>
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <deque>
#include <vector>
namespace pangolin
{
// Video class that outputs test video signal.
class PANGOLIN_EXPORT ImagesVideo : public VideoInterface, public VideoPlaybackInterface, public VideoPropertiesInterface
{
public:
ImagesVideo(const std::string& wildcard_path);
ImagesVideo(const std::string& wildcard_path, const PixelFormat& raw_fmt, size_t raw_width, size_t raw_height);
// Explicitly delete copy ctor and assignment operator.
// See http://stackoverflow.com/questions/29565299/how-to-use-a-vector-of-unique-pointers-in-a-dll-exported-class-with-visual-studi
// >> It appears adding __declspec(dllexport) forces the compiler to define the implicitly-declared copy constructor and copy assignment operator
ImagesVideo(const ImagesVideo&) = delete;
ImagesVideo& operator=(const ImagesVideo&) = delete;
~ImagesVideo();
///////////////////////////////////
// Implement VideoInterface
void Start() override;
void Stop() override;
size_t SizeBytes() const override;
const std::vector<StreamInfo>& Streams() const override;
bool GrabNext( unsigned char* image, bool wait = true ) override;
bool GrabNewest( unsigned char* image, bool wait = true ) override;
///////////////////////////////////
// Implement VideoPlaybackInterface
size_t GetCurrentFrameId() const override;
size_t GetTotalFrames() const override;
size_t Seek(size_t frameid) override;
///////////////////////////////////
// Implement VideoPropertiesInterface
const picojson::value& DeviceProperties() const override;
const picojson::value& FrameProperties() const override;
protected:
typedef std::vector<TypedImage> Frame;
const std::string& Filename(size_t frameNum, size_t channelNum) {
return filenames[channelNum][frameNum];
}
void PopulateFilenames(const std::string& wildcard_path);
void PopulateFilenamesFromJson(const std::string& filename);
bool LoadFrame(size_t i);
void ConfigureStreamSizes();
std::vector<StreamInfo> streams;
size_t size_bytes;
size_t num_files;
size_t num_channels;
size_t next_frame_id;
std::vector<std::vector<std::string> > filenames;
std::vector<Frame> loaded;
bool unknowns_are_raw;
PixelFormat raw_fmt;
size_t raw_width;
size_t raw_height;
// Load any json properties if they are defined
picojson::value device_properties;
picojson::value json_frames;
picojson::value null_props;
};
}

View File

@@ -0,0 +1,60 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <fstream>
#include <pangolin/video/video_output.h>
#include <pangolin/log/packetstream_writer.h>
namespace pangolin
{
class PANGOLIN_EXPORT ImagesVideoOutput : public VideoOutputInterface
{
public:
ImagesVideoOutput(const std::string& image_folder, const std::string& json_file_out, const std::string &image_file_extension);
~ImagesVideoOutput();
const std::vector<StreamInfo>& Streams() const override;
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const picojson::value& device_properties) override;
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties) override;
bool IsPipe() const override;
protected:
std::vector<StreamInfo> streams;
std::string input_uri;
picojson::value device_properties;
picojson::value json_frames;
size_t image_index;
std::string image_folder;
std::string image_file_extension;
std::ofstream file;
};
}

View File

@@ -0,0 +1,78 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/video/video.h>
namespace pangolin
{
class PANGOLIN_EXPORT JoinVideo
: public VideoInterface, public VideoFilterInterface
{
public:
JoinVideo(std::vector<std::unique_ptr<VideoInterface>> &src);
~JoinVideo();
// Explicitly delete copy ctor and assignment operator.
// See http://stackoverflow.com/questions/29565299/how-to-use-a-vector-of-unique-pointers-in-a-dll-exported-class-with-visual-studi
// >> It appears adding __declspec(dllexport) forces the compiler to define the implicitly-declared copy constructor and copy assignment operator
JoinVideo(const JoinVideo&) = delete;
JoinVideo& operator=(const JoinVideo&) = delete;
size_t SizeBytes() const;
const std::vector<StreamInfo>& Streams() const;
void Start();
void Stop();
bool Sync(int64_t tolerance_us, double transfer_bandwidth_gbps = 0);
bool GrabNext( unsigned char* image, bool wait = true );
bool GrabNewest( unsigned char* image, bool wait = true );
std::vector<VideoInterface*>& InputStreams();
protected:
int64_t GetAdjustedCaptureTime(size_t src_index);
std::vector<std::unique_ptr<VideoInterface>> storage;
std::vector<VideoInterface*> src;
std::vector<StreamInfo> streams;
size_t size_bytes;
int64_t sync_tolerance_us;
int64_t transfer_bandwidth_bytes_per_us;
};
}

View File

@@ -0,0 +1,70 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/video/iostream_operators.h>
namespace pangolin
{
// Take N streams, and place them into one big buffer.
class PANGOLIN_EXPORT MergeVideo : public VideoInterface, public VideoFilterInterface
{
public:
MergeVideo(std::unique_ptr<VideoInterface>& src, const std::vector<Point>& stream_pos, size_t w, size_t h);
~MergeVideo();
void Start() override;
void Stop() override;
size_t SizeBytes() const override;
const std::vector<StreamInfo>& Streams() const override;
bool GrabNext( unsigned char* image, bool wait = true ) override;
bool GrabNewest( unsigned char* image, bool wait = true ) override;
std::vector<VideoInterface*>& InputStreams() override;
protected:
void CopyBuffer(unsigned char* dst_bytes, unsigned char* src_bytes);
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
std::unique_ptr<uint8_t[]> buffer;
std::vector<Point> stream_pos;
std::vector<StreamInfo> streams;
size_t size_bytes;
};
}

View File

@@ -0,0 +1,96 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
namespace pangolin
{
enum MirrorOptions
{
MirrorOptionsNone = 0,
MirrorOptionsFlipX,
MirrorOptionsFlipY,
MirrorOptionsFlipXY,
MirrorOptionsTranspose,
MirrorOptionsRotateCW,
MirrorOptionsRotateCCW,
};
// Video class that debayers its video input using the given method.
class PANGOLIN_EXPORT MirrorVideo :
public VideoInterface,
public VideoFilterInterface,
public BufferAwareVideoInterface
{
public:
MirrorVideo(std::unique_ptr<VideoInterface>& videoin, const std::vector<MirrorOptions>& flips);
~MirrorVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
//! Implement VideoFilterInterface method
std::vector<VideoInterface*>& InputStreams();
uint32_t AvailableFrames() const;
bool DropNFrames(uint32_t n);
protected:
void Process(unsigned char* image, const unsigned char* buffer);
std::unique_ptr<VideoInterface> videoin;
std::vector<VideoInterface*> inputs;
std::vector<StreamInfo> streams;
std::vector<MirrorOptions> flips;
size_t size_bytes;
unsigned char* buffer;
picojson::value device_properties;
picojson::value frame_properties;
};
}

View File

@@ -0,0 +1,72 @@
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/video/drivers/openni_common.h>
// Workaround poor OpenNI Platform test on Linux before including XnCppWrapper.h
// See https://github.com/dennishamester/OpenNI/commit/ca99f6181234c682bba42a6ba
#ifdef _LINUX_
#define linux 1
#endif // _LINUX_
// OpenNI generates SO MANY warnings, we'll just disable all for this header(!)
// GCC and clang will listen to this pramga.
#ifndef _MSVC_
#pragma GCC system_header
#endif
#include <XnCppWrapper.h>
namespace pangolin
{
//! Interface to video capture sources
struct PANGOLIN_EXPORT OpenNiVideo : public VideoInterface
{
public:
OpenNiVideo(OpenNiSensorType s1, OpenNiSensorType s2, ImageDim dim = ImageDim(640,480), int fps = 30);
~OpenNiVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
void SetAutoExposure(bool enabled)
{
#if XN_MINOR_VERSION > 5 || (XN_MINOR_VERSION == 5 && XN_BUILD_VERSION >= 7)
if(imageNode.IsValid()) {
imageNode.GetAutoExposureCap().Set(enabled ? 1 : 0);
}
#else
throw pangolin::VideoException("SetAutoExposure Not supported for this version of OpenNI.");
#endif
}
protected:
std::vector<StreamInfo> streams;
OpenNiSensorType sensor_type[2];
xn::Context context;
xn::DepthGenerator depthNode;
xn::ImageGenerator imageNode;
xn::IRGenerator irNode;
size_t sizeBytes;
};
}

View File

@@ -0,0 +1,147 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Richard Newcombe
* 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/video/drivers/openni_common.h>
#include <OpenNI.h>
namespace pangolin
{
const int MAX_OPENNI2_STREAMS = 2 * ONI_MAX_SENSORS;
//! Interface to video capture sources
struct OpenNi2Video : public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
{
public:
// Open all RGB and Depth streams from all devices
OpenNi2Video(ImageDim dim=ImageDim(640,480), ImageRoi roi=ImageRoi(0,0,0,0), int fps=30);
// Open streams specified
OpenNi2Video(std::vector<OpenNiStreamMode>& stream_modes);
// Open openni file
OpenNi2Video(const std::string& filename);
// Open openni file with certain params
OpenNi2Video(const std::string& filename, std::vector<OpenNiStreamMode>& stream_modes);
void UpdateProperties();
void SetMirroring(bool enable);
void SetAutoExposure(bool enable);
void SetAutoWhiteBalance(bool enable);
void SetDepthCloseRange(bool enable);
void SetDepthHoleFilter(bool enable);
void SetDepthColorSyncEnabled(bool enable);
void SetFastCrop(bool enable);
void SetRegisterDepthToImage(bool enable);
void SetPlaybackSpeed(float speed);
void SetPlaybackRepeat(bool enabled);
~OpenNi2Video();
//! Implement VideoInput::Start()
void Start() override;
//! Implement VideoInput::Stop()
void Stop() override;
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const override;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const override;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true ) override;
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true ) override;
//! Implement VideoPropertiesInterface::Properties()
const picojson::value& DeviceProperties() const override{
return device_properties;
}
//! Implement VideoPropertiesInterface::Properties()
const picojson::value& FrameProperties() const override{
return frame_properties;
}
//! Implement VideoPlaybackInterface::GetCurrentFrameId
size_t GetCurrentFrameId() const override;
//! Implement VideoPlaybackInterface::GetTotalFrames
size_t GetTotalFrames() const override;
//! Implement VideoPlaybackInterface::Seek
size_t Seek(size_t frameid) override;
openni::VideoStream* GetVideoStream(int stream);
protected:
void InitialiseOpenNI();
int AddDevice(const std::string& device_uri);
void AddStream(const OpenNiStreamMode& mode);
void SetupStreamModes();
void PrintOpenNI2Modes(openni::SensorType sensorType);
openni::VideoMode FindOpenNI2Mode(openni::Device &device, openni::SensorType sensorType, int width, int height, int fps, openni::PixelFormat fmt );
size_t numDevices;
size_t numStreams;
openni::Device devices[ONI_MAX_SENSORS];
OpenNiStreamMode sensor_type[ONI_MAX_SENSORS];
openni::VideoStream video_stream[ONI_MAX_SENSORS];
openni::VideoFrameRef video_frame[ONI_MAX_SENSORS];
std::vector<StreamInfo> streams;
size_t sizeBytes;
picojson::value device_properties;
picojson::value frame_properties;
picojson::value* streams_properties;
bool use_depth;
bool use_ir;
bool use_rgb;
bool depth_to_color;
bool use_ir_and_rgb;
size_t current_frame_index;
size_t total_frames;
};
}

View File

@@ -0,0 +1,153 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
* 2015 Richard Newcombe
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/video/iostream_operators.h>
namespace pangolin
{
enum OpenNiSensorType
{
OpenNiUnassigned = -1,
OpenNiRgb = 0,
OpenNiIr,
OpenNiDepth_1mm,
OpenNiDepth_1mm_Registered,
OpenNiDepth_100um,
OpenNiIr8bit,
OpenNiIr24bit,
OpenNiIrProj,
OpenNiIr8bitProj,
OpenNiGrey
};
struct PANGOLIN_EXPORT OpenNiStreamMode
{
OpenNiStreamMode(
OpenNiSensorType sensor_type=OpenNiUnassigned,
ImageDim dim=ImageDim(640,480), ImageRoi roi=ImageRoi(0,0,0,0), int fps=30, int device=0
)
: sensor_type(sensor_type), dim(dim), roi(roi), fps(fps), device(device)
{
}
OpenNiSensorType sensor_type;
ImageDim dim;
ImageRoi roi;
int fps;
int device;
};
inline OpenNiSensorType openni_sensor(const std::string& str)
{
if( !str.compare("grey") || !str.compare("gray") ) {
return OpenNiGrey;
}else if( !str.compare("rgb") ) {
return OpenNiRgb;
}else if( !str.compare("ir") ) {
return OpenNiIr;
}else if( !str.compare("depth1mm") || !str.compare("depth") ) {
return OpenNiDepth_1mm;
}else if( !str.compare("depth100um") ) {
return OpenNiDepth_100um;
}else if( !str.compare("depth_reg") || !str.compare("reg_depth")) {
return OpenNiDepth_1mm_Registered;
}else if( !str.compare("ir8") ) {
return OpenNiIr8bit;
}else if( !str.compare("ir24") ) {
return OpenNiIr24bit;
}else if( !str.compare("ir+") ) {
return OpenNiIrProj;
}else if( !str.compare("ir8+") ) {
return OpenNiIr8bitProj;
}else if( str.empty() ) {
return OpenNiUnassigned;
}else{
throw pangolin::VideoException("Unknown OpenNi sensor", str );
}
}
// Find prefix character key
// Given arguments "depth!5:320x240@15", "!:@", would return map
// \0->"depth", !->"5", :->"320x240", @->"15"
inline std::map<char,std::string> GetTokenSplits(const std::string& str, const std::string& tokens)
{
std::map<char,std::string> splits;
char last_token = 0;
size_t last_start = 0;
for(unsigned int i=0; i<str.size(); ++i) {
size_t token_pos = tokens.find(str[i]);
if(token_pos != std::string::npos) {
splits[last_token] = str.substr(last_start, i-last_start);
last_token = tokens[token_pos];
last_start = i+1;
}
}
if(last_start < str.size()) {
splits[last_token] = str.substr(last_start);
}
return splits;
}
inline std::istream& operator>> (std::istream &is, OpenNiStreamMode& fmt)
{
std::string str;
is >> str;
std::map<char,std::string> splits = GetTokenSplits(str, "!:@#");
if(splits.count(0)) {
fmt.sensor_type = openni_sensor(splits[0]);
}
if(splits.count('@')) {
fmt.fps = pangolin::Convert<int,std::string>::Do(splits['@']);
}
if(splits.count(':')) {
fmt.dim = pangolin::Convert<ImageDim,std::string>::Do(splits[':']);
}
if(splits.count('!')) {
fmt.device = pangolin::Convert<int,std::string>::Do(splits['!']);
}
if(splits.count('#')) {
fmt.roi = pangolin::Convert<ImageRoi,std::string>::Do(splits['#']);
}
return is;
}
}

View File

@@ -0,0 +1,84 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
namespace pangolin
{
// Video class that packs its video input using the given method.
class PANGOLIN_EXPORT PackVideo :
public VideoInterface,
public VideoFilterInterface,
public BufferAwareVideoInterface
{
public:
PackVideo(std::unique_ptr<VideoInterface>& videoin, PixelFormat new_fmt);
~PackVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
//! Implement VideoFilterInterface method
std::vector<VideoInterface*>& InputStreams();
uint32_t AvailableFrames() const;
bool DropNFrames(uint32_t n);
protected:
void Process(unsigned char* image, const unsigned char* buffer);
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
std::vector<StreamInfo> streams;
size_t size_bytes;
unsigned char* buffer;
picojson::value device_properties;
picojson::value frame_properties;
};
}

View File

@@ -0,0 +1,104 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/log/packetstream_reader.h>
#include <pangolin/log/playback_session.h>
#include <pangolin/video/stream_encoder_factory.h>
#include <pangolin/video/video.h>
namespace pangolin
{
class PANGOLIN_EXPORT PangoVideo
: public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
{
public:
PangoVideo(const std::string& filename, std::shared_ptr<PlaybackSession> playback_session);
~PangoVideo();
// Implement VideoInterface
size_t SizeBytes() const override;
const std::vector<StreamInfo>& Streams() const override;
void Start() override;
void Stop() override;
bool GrabNext( unsigned char* image, bool wait = true ) override;
bool GrabNewest( unsigned char* image, bool wait = true ) override;
// Implement VideoPropertiesInterface
const picojson::value& DeviceProperties() const override {
if (-1 == _src_id) throw std::runtime_error("Not initialised");
return _device_properties;
}
const picojson::value& FrameProperties() const override {
return _frame_properties;
}
// Implement VideoPlaybackInterface
size_t GetCurrentFrameId() const override;
size_t GetTotalFrames() const override;
size_t Seek(size_t frameid) override;
std::string GetSourceUri();
private:
void HandlePipeClosed();
protected:
int FindPacketStreamSource();
void SetupStreams(const PacketStreamSource& src);
const std::string _filename;
std::shared_ptr<PlaybackSession> _playback_session;
std::shared_ptr<PacketStreamReader> _reader;
SyncTimeEventPromise _event_promise;
int _src_id;
const PacketStreamSource* _source;
size_t _size_bytes;
bool _fixed_size;
std::vector<StreamInfo> _streams;
std::vector<ImageDecoderFunc> stream_decoder;
picojson::value _device_properties;
picojson::value _frame_properties;
std::string _source_uri;
Registration<size_t> session_seek;
};
}

View File

@@ -0,0 +1,70 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/log/packetstream_writer.h>
#include <pangolin/video/video_output.h>
#include <pangolin/video/stream_encoder_factory.h>
#include <functional>
namespace pangolin
{
class PANGOLIN_EXPORT PangoVideoOutput : public VideoOutputInterface
{
public:
PangoVideoOutput(const std::string& filename, size_t buffer_size_bytes, const std::map<size_t, std::string> &stream_encoder_uris);
~PangoVideoOutput();
const std::vector<StreamInfo>& Streams() const override;
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const picojson::value& device_properties) override;
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties) override;
bool IsPipe() const override;
protected:
// void WriteHeader();
std::vector<StreamInfo> streams;
std::string input_uri;
const std::string filename;
picojson::value device_properties;
PacketStreamWriter packetstream;
size_t packetstream_buffer_size_bytes;
int packetstreamsrcid;
size_t total_frame_size;
bool is_pipe;
bool fixed_size;
std::map<size_t, std::string> stream_encoder_uris;
std::vector<ImageEncoderFunc> stream_encoders;
};
}

View File

@@ -0,0 +1,196 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2015 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <PvDevice.h>
#include <PvDeviceGEV.h>
#include <PvDeviceU3V.h>
#include <PvStream.h>
#include <PvStreamGEV.h>
#include <PvStreamU3V.h>
#include <PvBuffer.h>
#include <PvSystem.h>
#include <stdlib.h>
#include <list>
namespace pangolin
{
struct GrabbedBuffer {
inline GrabbedBuffer(PvBuffer* b,PvResult r,bool v)
: buff(b), res(r), valid(v)
{
}
PvBuffer* buff;
PvResult res;
bool valid;
};
typedef std::list<GrabbedBuffer> GrabbedBufferList;
typedef std::list<PvBuffer *> BufferList;
class PANGOLIN_EXPORT PleoraVideo : public VideoInterface, public VideoPropertiesInterface,
public BufferAwareVideoInterface, public GenicamVideoInterface
{
public:
static const size_t DEFAULT_BUFFER_COUNT = 30;
PleoraVideo(const Params& p);
~PleoraVideo();
void Start();
void Stop();
size_t SizeBytes() const;
const std::vector<StreamInfo>& Streams() const;
bool GrabNext( unsigned char* image, bool wait = true );
bool GrabNewest( unsigned char* image, bool wait = true );
std::string GetParameter(const std::string& name);
void SetParameter(const std::string& name, const std::string& value);
void SetGain(int64_t val);
int64_t GetGain();
void SetAnalogBlackLevel(int64_t val);
int64_t GetAnalogBlackLevel();
void SetExposure(double val);
double GetExposure();
void SetGamma(double val);
double GetGamma();
void SetupTrigger(bool triggerActive, int64_t triggerSource, int64_t acquisitionMode);
const picojson::value& DeviceProperties() const {
return device_properties;
}
const picojson::value& FrameProperties() const {
return frame_properties;
}
uint32_t AvailableFrames() const;
bool DropNFrames(uint32_t n);
protected:
void InitDevice(const char *model_name, const char *serial_num, size_t index);
void DeinitDevice();
void SetDeviceParams(Params& p);
void InitStream();
void DeinitStream();
void InitPangoStreams();
void InitPangoDeviceProperties();
void InitBuffers(size_t buffer_count);
void DeinitBuffers();
template<typename T>
T DeviceParam(const char* name);
template<typename T>
bool SetDeviceParam(const char* name, T val);
template<typename T>
T StreamParam(const char* name);
template<typename T>
bool SetStreamParam(const char* name, T val);
bool ParseBuffer(PvBuffer* lBuffer, unsigned char* image);
void RetriveAllAvailableBuffers(uint32_t timeout);
std::vector<StreamInfo> streams;
picojson::value device_properties;
picojson::value frame_properties;
size_t size_bytes;
// Pleora handles
PvSystem* lPvSystem;
const PvDeviceInfo* lDeviceInfo;
PvDevice* lDevice;
PvStream* lStream;
// Genicam device parameters
PvGenParameterArray* lDeviceParams;
PvGenCommand* lStart;
PvGenCommand* lStop;
PvGenInteger* lAnalogGain;
PvGenInteger* lAnalogBlackLevel;
PvGenFloat* lExposure;
PvGenFloat* lGamma;
PvGenEnum* lAquisitionMode;
PvGenEnum* lTriggerSource;
PvGenEnum* lTriggerMode;
PvGenFloat* lTemperatureCelcius;
bool getTemp;
// Genicam stream parameters
PvGenParameterArray* lStreamParams;
BufferList lBufferList;
GrabbedBufferList lGrabbedBuffList;
uint32_t validGrabbedBuffers;
};
}

View File

@@ -0,0 +1,77 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/utils/timer.h>
#include <fstream>
namespace pangolin
{
class PANGOLIN_EXPORT PvnVideo : public VideoInterface
{
public:
PvnVideo(const std::string& filename, bool realtime = false);
~PvnVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
protected:
int frames;
std::ifstream file;
std::vector<StreamInfo> streams;
size_t frame_size_bytes;
bool realtime;
pangolin::basetime frame_interval;
pangolin::basetime last_frame;
void ReadFileHeader();
};
}

View File

@@ -0,0 +1,87 @@
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/video/iostream_operators.h>
namespace rs {
class context;
class device;
}
namespace pangolin
{
//! Interface to video capture sources
struct RealSenseVideo : public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
{
public:
// Open all RGB and Depth streams from all devices
RealSenseVideo(ImageDim dim=ImageDim(640,480), int fps=30);
// Open streams specified
// TODO
//RealSenseVideo(std::vector<OpenNiStreamMode>& stream_modes);
~RealSenseVideo();
//! Implement VideoInput::Start()
void Start() override;
//! Implement VideoInput::Stop()
void Stop() override;
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const override;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const override;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true ) override;
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true ) override;
//! Implement VideoPropertiesInterface::Properties()
const picojson::value& DeviceProperties() const override {
return device_properties;
}
//! Implement VideoPropertiesInterface::Properties()
const picojson::value& FrameProperties() const override {
return frame_properties;
}
//! Implement VideoPlaybackInterface::GetCurrentFrameId
size_t GetCurrentFrameId() const override;
//! Implement VideoPlaybackInterface::GetTotalFrames
size_t GetTotalFrames() const override;
//! Implement VideoPlaybackInterface::Seek
size_t Seek(size_t frameid) override;
protected:
size_t sizeBytes;
std::vector<StreamInfo> streams;
picojson::value device_properties;
picojson::value frame_properties;
picojson::value* streams_properties;
size_t current_frame_index;
size_t total_frames;
rs::context* ctx_;
std::vector<rs::device*> devs_;
ImageDim dim_;
size_t fps_;
};
}

View File

@@ -0,0 +1,87 @@
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/video/iostream_operators.h>
namespace rs2 {
class pipeline;
class config;
}
namespace pangolin
{
//! Interface to video capture sources
struct RealSense2Video : public VideoInterface, public VideoPropertiesInterface, public VideoPlaybackInterface
{
public:
// Open all RGB and Depth streams from all devices
RealSense2Video(ImageDim dim=ImageDim(640,480), int fps=30);
// Open streams specified
// TODO
//RealSense2Video(std::vector<OpenNiStreamMode>& stream_modes);
~RealSense2Video();
//! Implement VideoInput::Start()
void Start() override;
//! Implement VideoInput::Stop()
void Stop() override;
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const override;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const override;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true ) override;
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true ) override;
//! Implement VideoPropertiesInterface::Properties()
const picojson::value& DeviceProperties() const override {
return device_properties;
}
//! Implement VideoPropertiesInterface::Properties()
const picojson::value& FrameProperties() const override {
return frame_properties;
}
//! Implement VideoPlaybackInterface::GetCurrentFrameId
size_t GetCurrentFrameId() const override;
//! Implement VideoPlaybackInterface::GetTotalFrames
size_t GetTotalFrames() const override;
//! Implement VideoPlaybackInterface::Seek
size_t Seek(size_t frameid) override;
protected:
size_t sizeBytes;
std::vector<StreamInfo> streams;
picojson::value device_properties;
picojson::value frame_properties;
picojson::value* streams_properties;
size_t current_frame_index;
size_t total_frames;
rs2::pipeline* pipe;
rs2::config* cfg;
ImageDim dim_;
size_t fps_;
};
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/utils/posix/condition_variable.h>
#include <pangolin/utils/posix/shared_memory_buffer.h>
#include <memory>
#include <vector>
namespace pangolin
{
class SharedMemoryVideo : public VideoInterface
{
public:
SharedMemoryVideo(size_t w, size_t h, std::string pix_fmt,
const std::shared_ptr<SharedMemoryBufferInterface>& shared_memory,
const std::shared_ptr<ConditionVariableInterface>& buffer_full);
~SharedMemoryVideo();
size_t SizeBytes() const;
const std::vector<StreamInfo>& Streams() const;
void Start();
void Stop();
bool GrabNext(unsigned char *image, bool wait);
bool GrabNewest(unsigned char *image, bool wait);
private:
PixelFormat _fmt;
size_t _frame_size;
std::vector<StreamInfo> _streams;
std::shared_ptr<SharedMemoryBufferInterface> _shared_memory;
std::shared_ptr<ConditionVariableInterface> _buffer_full;
};
}

View File

@@ -0,0 +1,73 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
namespace pangolin
{
// Video class that debayers its video input using the given method.
class PANGOLIN_EXPORT ShiftVideo : public VideoInterface, public VideoFilterInterface
{
public:
ShiftVideo(std::unique_ptr<VideoInterface>& videoin, PixelFormat new_fmt, int shift_right_bits = 0, unsigned int mask = 0xFFFF);
~ShiftVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
std::vector<VideoInterface*>& InputStreams();
protected:
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
std::vector<StreamInfo> streams;
size_t size_bytes;
unsigned char* buffer;
int shift_right_bits;
unsigned int mask;
};
}

View File

@@ -0,0 +1,65 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/video/video.h>
#include <vector>
namespace pangolin
{
class PANGOLIN_EXPORT SplitVideo
: public VideoInterface, public VideoFilterInterface
{
public:
SplitVideo(std::unique_ptr<VideoInterface>& videoin, const std::vector<StreamInfo>& streams);
~SplitVideo();
size_t SizeBytes() const;
const std::vector<StreamInfo>& Streams() const;
void Start();
void Stop();
bool GrabNext( unsigned char* image, bool wait = true );
bool GrabNewest( unsigned char* image, bool wait = true );
std::vector<VideoInterface*>& InputStreams();
protected:
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
std::vector<StreamInfo> streams;
};
}

View File

@@ -0,0 +1,118 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2015 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/utils/timer.h>
#include <pangolin/video/video.h>
#include <TeliCamApi.h>
namespace pangolin
{
// Video class that outputs test video signal.
class PANGOLIN_EXPORT TeliVideo : public VideoInterface, public VideoPropertiesInterface,
public BufferAwareVideoInterface, public GenicamVideoInterface
{
public:
TeliVideo(const Params &p);
~TeliVideo();
Params OpenCameraAndGetRemainingParameters(Params &params);
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
inline Teli::CAM_HANDLE GetCameraHandle() {
return cam;
}
inline Teli::CAM_STRM_HANDLE GetCameraStreamHandle() {
return strm;
}
bool GetParameter(const std::string& name, std::string& result);
bool SetParameter(const std::string& name, const std::string& value);
//! Returns number of available frames
uint32_t AvailableFrames() const;
//! Drops N frames in the queue starting from the oldest
//! returns false if less than n frames arae available
bool DropNFrames(uint32_t n);
//! Access JSON properties of device
const picojson::value& DeviceProperties() const;
//! Access JSON properties of most recently captured frame
const picojson::value& FrameProperties() const;
void PopulateEstimatedCenterCaptureTime(pangolin::basetime host_reception_time);
protected:
void Initialise();
void InitPangoDeviceProperties();
void SetDeviceParams(const Params &p);
void SetNodeValStr(Teli::CAM_HANDLE cam, Teli::CAM_NODE_HANDLE node, std::string node_str, std::string val_str);
std::vector<StreamInfo> streams;
size_t size_bytes;
Teli::CAM_HANDLE cam;
Teli::CAM_STRM_HANDLE strm;
#ifdef _WIN_
HANDLE hStrmCmpEvt;
#endif
#ifdef _LINUX_
Teli::SIGNAL_HANDLE hStrmCmpEvt;
#endif
double transfer_bandwidth_gbps;
int exposure_us;
picojson::value device_properties;
picojson::value frame_properties;
};
}

View File

@@ -0,0 +1,66 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
namespace pangolin
{
// Video class that outputs test video signal.
class PANGOLIN_EXPORT TestVideo : public VideoInterface
{
public:
TestVideo(size_t w, size_t h, size_t n, std::string pix_fmt);
~TestVideo();
//! Implement VideoInput::Start()
void Start() override;
//! Implement VideoInput::Stop()
void Stop() override;
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const override;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const override;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true ) override;
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true ) override;
protected:
std::vector<StreamInfo> streams;
size_t size_bytes;
};
}

View File

@@ -0,0 +1,112 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <memory>
#include <pangolin/utils/fix_size_buffer_queue.h>
namespace pangolin
{
// Video class that creates a thread that keeps pulling frames and processing from its children.
class PANGOLIN_EXPORT ThreadVideo : public VideoInterface, public VideoPropertiesInterface,
public BufferAwareVideoInterface, public VideoFilterInterface
{
public:
ThreadVideo(std::unique_ptr<VideoInterface>& videoin, size_t num_buffers);
~ThreadVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
const picojson::value& DeviceProperties() const;
const picojson::value& FrameProperties() const;
uint32_t AvailableFrames() const;
bool DropNFrames(uint32_t n);
void operator()();
std::vector<VideoInterface*>& InputStreams();
protected:
struct GrabResult
{
GrabResult(const size_t buffer_size)
: return_status(false),
buffer(new unsigned char[buffer_size])
{
}
// No copy constructor.
GrabResult(const GrabResult& o) = delete;
// Default move constructor
GrabResult(GrabResult&& o) = default;
bool return_status;
std::unique_ptr<unsigned char[]> buffer;
picojson::value frame_properties;
};
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
bool quit_grab_thread;
FixSizeBuffersQueue<GrabResult> queue;
std::condition_variable cv;
std::mutex cvMtx;
std::thread grab_thread;
mutable picojson::value device_properties;
picojson::value frame_properties;
};
}

View File

@@ -0,0 +1,71 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/video/video.h>
#include <vector>
namespace pangolin
{
class PANGOLIN_EXPORT TruncateVideo
: public VideoInterface, public VideoFilterInterface
{
public:
TruncateVideo(std::unique_ptr<VideoInterface>& videoin, size_t begin, size_t end);
~TruncateVideo();
size_t SizeBytes() const;
const std::vector<StreamInfo>& Streams() const;
void Start();
void Stop();
bool GrabNext( unsigned char* image, bool wait = true );
bool GrabNewest( unsigned char* image, bool wait = true );
std::vector<VideoInterface*>& InputStreams();
protected:
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
std::vector<StreamInfo> streams;
size_t begin;
size_t end;
size_t next_frame_to_grab;
inline VideoPlaybackInterface* GetVideoPlaybackInterface(){ return dynamic_cast<VideoPlaybackInterface*>(src.get()); }
};
}

View File

@@ -0,0 +1,84 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2014 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
namespace pangolin
{
// Video class that debayers its video input using the given method.
class PANGOLIN_EXPORT UnpackVideo :
public VideoInterface,
public VideoFilterInterface,
public BufferAwareVideoInterface
{
public:
UnpackVideo(std::unique_ptr<VideoInterface>& videoin, PixelFormat new_fmt);
~UnpackVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
//! Implement VideoFilterInterface method
std::vector<VideoInterface*>& InputStreams();
uint32_t AvailableFrames() const;
bool DropNFrames(uint32_t n);
protected:
void Process(unsigned char* image, const unsigned char* buffer);
std::unique_ptr<VideoInterface> src;
std::vector<VideoInterface*> videoin;
std::vector<StreamInfo> streams;
size_t size_bytes;
unsigned char* buffer;
picojson::value device_properties;
picojson::value frame_properties;
};
}

View File

@@ -0,0 +1,115 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/utils/timer.h>
#ifdef _MSC_VER
// Define missing timeval struct
typedef struct timeval {
long tv_sec;
long tv_usec;
} timeval;
#endif // _MSC_VER
#include <libuvc/libuvc.h>
namespace pangolin
{
class PANGOLIN_EXPORT UvcVideo : public VideoInterface, public VideoUvcInterface, public VideoPropertiesInterface
{
public:
UvcVideo(int vendor_id, int product_id, const char* sn, int deviceid, int width, int height, int fps);
~UvcVideo();
void InitDevice(int vid, int pid, const char* sn, int deviceid, int width, int height, int fps);
void DeinitDevice();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
//! Implement VideoUvcInterface::GetCtrl()
int IoCtrl(uint8_t unit, uint8_t ctrl, unsigned char* data, int len, UvcRequestCode req_code);
//! Implement VideoUvcInterface::GetExposure()
bool GetExposure(int& exp_us);
//! Implement VideoUvcInterface::SetExposure()
bool SetExposure(int exp_us);
//! Implement VideoUvcInterface::GetGain()
bool GetGain(float& gain);
//! Implement VideoUvcInterface::SetGain()
bool SetGain(float gain);
//! Access JSON properties of device
const picojson::value& DeviceProperties() const;
//! Access JSON properties of most recently captured frame
const picojson::value& FrameProperties() const;
protected:
void InitPangoDeviceProperties();
static uvc_error_t FindDevice(
uvc_context_t *ctx, uvc_device_t **dev,
int vid, int pid, const char *sn, int device_id);
std::vector<StreamInfo> streams;
size_t size_bytes;
uvc_context* ctx_;
uvc_device* dev_;
uvc_device_handle* devh_;
uvc_stream_handle* strm_;
uvc_stream_ctrl_t ctrl_;
uvc_frame_t* frame_;
picojson::value device_properties;
picojson::value frame_properties;
bool is_streaming;
};
}

View File

@@ -0,0 +1,82 @@
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <pangolin/video/video_interface.h>
struct IMFActivate;
struct IMFMediaSource;
struct IMFSourceReader;
struct IBaseFilter;
struct IKsControl;
namespace pangolin
{
class PANGOLIN_EXPORT UvcMediaFoundationVideo
: public pangolin::VideoInterface, public pangolin::VideoUvcInterface, public pangolin::VideoPropertiesInterface
{
public:
UvcMediaFoundationVideo(int vendorId, int productId, int deviceId, size_t width, size_t height, int fps);
~UvcMediaFoundationVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<pangolin::StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext(unsigned char* image, bool wait = true);
//! Implement VideoInput::GrabNewest()
bool GrabNewest(unsigned char* image, bool wait = true);
//! Implement VideoUvcInterface::GetCtrl()
int IoCtrl(uint8_t unit, uint8_t ctrl, unsigned char* data, int len, pangolin::UvcRequestCode req_code);
//! Implement VideoUvcInterface::GetExposure()
bool GetExposure(int& exp_us);
//! Implement VideoUvcInterface::SetExposure()
bool SetExposure(int exp_us);
//! Implement VideoUvcInterface::GetGain()
bool GetGain(float& gain);
//! Implement VideoUvcInterface::SetGain()
bool SetGain(float gain);
//! Access JSON properties of device
const picojson::value& DeviceProperties() const;
//! Access JSON properties of most recently captured frame
const picojson::value& FrameProperties() const;
protected:
bool FindDevice(int vendorId, int productId, int deviceId);
void InitDevice(size_t width, size_t height, int fps);
void DeinitDevice();
static bool DeviceMatches(const std::wstring& symLink, int vendorId, int productId);
static bool SymLinkIDMatches(const std::wstring& symLink, const wchar_t* idStr, int id);
std::vector<pangolin::StreamInfo> streams;
size_t size_bytes;
IMFMediaSource* mediaSource;
IMFSourceReader* sourceReader;
IBaseFilter* baseFilter;
IKsControl* ksControl;
DWORD ksControlNodeId;
picojson::value device_properties;
picojson::value frame_properties;
};
}

View File

@@ -0,0 +1,128 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <pangolin/pangolin.h>
#include <pangolin/video/video.h>
#include <asm/types.h>
#include <linux/videodev2.h>
namespace pangolin
{
typedef enum {
IO_METHOD_READ,
IO_METHOD_MMAP,
IO_METHOD_USERPTR,
} io_method;
struct buffer {
void* start;
size_t length;
};
class PANGOLIN_EXPORT V4lVideo : public VideoInterface, public VideoUvcInterface, public VideoPropertiesInterface
{
public:
V4lVideo(const char* dev_name, io_method io = IO_METHOD_MMAP, unsigned iwidth=0, unsigned iheight=0);
~V4lVideo();
//! Implement VideoInput::Start()
void Start();
//! Implement VideoInput::Stop()
void Stop();
//! Implement VideoInput::SizeBytes()
size_t SizeBytes() const;
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& Streams() const;
//! Implement VideoInput::GrabNext()
bool GrabNext( unsigned char* image, bool wait = true );
//! Implement VideoInput::GrabNewest()
bool GrabNewest( unsigned char* image, bool wait = true );
//! Implement VideoUvcInterface::IoCtrl()
int IoCtrl(uint8_t unit, uint8_t ctrl, unsigned char* data, int len, UvcRequestCode req_code);
bool GetExposure(int& exp_us);
bool SetExposure(int exp_us);
bool GetGain(float& gain);
bool SetGain(float gain);
int GetFileDescriptor() const{
return fd;
}
//! Access JSON properties of device
const picojson::value& DeviceProperties() const;
//! Access JSON properties of most recently captured frame
const picojson::value& FrameProperties() const;
protected:
void InitPangoDeviceProperties();
int ReadFrame(unsigned char* image);
void Mainloop();
void init_read(unsigned int buffer_size);
void init_mmap(const char* dev_name);
void init_userp(const char* dev_name, unsigned int buffer_size);
void init_device(const char* dev_name, unsigned iwidth, unsigned iheight, unsigned ifps, unsigned v4l_format = V4L2_PIX_FMT_YUYV, v4l2_field field = V4L2_FIELD_INTERLACED);
void uninit_device();
void open_device(const char* dev_name);
void close_device();
std::vector<StreamInfo> streams;
io_method io;
int fd;
buffer* buffers;
unsigned int n_buffers;
bool running;
unsigned width;
unsigned height;
float fps;
size_t image_size;
picojson::value device_properties;
picojson::value frame_properties;
};
}