This commit is contained in:
PodmogilnyjIvan
2021-12-03 03:34:31 -08:00
commit ff4acf84be
542 changed files with 136810 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;
};
}

View File

@@ -0,0 +1,132 @@
/* 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 <iostream>
#include <cctype>
#include <pangolin/video/video_exception.h>
#include <pangolin/utils/file_utils.h>
#include <pangolin/video/stream_info.h>
namespace pangolin
{
struct PANGOLIN_EXPORT Point
{
inline Point() : x(0), y(0) {}
inline Point(size_t x, size_t y) : x(x), y(y) {}
size_t x;
size_t y;
};
typedef Point ImageDim;
struct PANGOLIN_EXPORT ImageRoi
{
inline ImageRoi() : x(0), y(0), w(0), h(0) {}
inline ImageRoi(size_t x, size_t y, size_t w, size_t h) : x(x), y(y), w(w), h(h) {}
size_t x; size_t y;
size_t w; size_t h;
};
inline std::istream& operator>> (std::istream &is, ImageDim &dim)
{
if(std::isdigit(is.peek()) ) {
// Expect 640x480, 640*480, ...
is >> dim.x; is.get(); is >> dim.y;
}else{
// Expect 'VGA', 'QVGA', etc
std::string sdim;
is >> sdim;
ToUpper(sdim);
if( !sdim.compare("QQVGA") ) {
dim = ImageDim(160,120);
}else if( !sdim.compare("HQVGA") ) {
dim = ImageDim(240,160);
}else if( !sdim.compare("QVGA") ) {
dim = ImageDim(320,240);
}else if( !sdim.compare("WQVGA") ) {
dim = ImageDim(360,240);
}else if( !sdim.compare("HVGA") ) {
dim = ImageDim(480,320);
}else if( !sdim.compare("VGA") ) {
dim = ImageDim(640,480);
}else if( !sdim.compare("WVGA") ) {
dim = ImageDim(720,480);
}else if( !sdim.compare("SVGA") ) {
dim = ImageDim(800,600);
}else if( !sdim.compare("DVGA") ) {
dim = ImageDim(960,640);
}else if( !sdim.compare("WSVGA") ) {
dim = ImageDim(1024,600);
}else{
throw VideoException("Unrecognised image-size string.");
}
}
return is;
}
inline std::istream& operator>> (std::istream &is, ImageRoi &roi)
{
is >> roi.x; is.get(); is >> roi.y; is.get();
is >> roi.w; is.get(); is >> roi.h;
return is;
}
inline std::istream& operator>> (std::istream &is, PixelFormat& fmt)
{
std::string sfmt;
is >> sfmt;
fmt = PixelFormatFromString(sfmt);
return is;
}
inline std::istream& operator>> (std::istream &is, Image<unsigned char>& img)
{
size_t offset;
is >> offset; is.get();
img.ptr = (unsigned char*)(offset);
is >> img.w; is.get();
is >> img.h; is.get();
is >> img.pitch;
return is;
}
inline std::istream& operator>> (std::istream &is, StreamInfo &stream)
{
PixelFormat fmt;
Image<unsigned char> img_offset;
is >> img_offset; is.get();
is >> fmt;
stream = StreamInfo(fmt, img_offset);
return is;
}
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include <memory>
#include <pangolin/image/image_io.h>
namespace pangolin {
using ImageEncoderFunc = std::function<void(std::ostream&, const Image<unsigned char>&)>;
using ImageDecoderFunc = std::function<TypedImage(std::istream&)>;
class StreamEncoderFactory
{
public:
static StreamEncoderFactory& I();
ImageEncoderFunc GetEncoder(const std::string& encoder_spec, const PixelFormat& fmt);
ImageDecoderFunc GetDecoder(const std::string& encoder_spec, const PixelFormat& fmt);
};
}

View File

@@ -0,0 +1,100 @@
/* 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/image/image.h>
#include <pangolin/image/pixel_format.h>
namespace pangolin {
class PANGOLIN_EXPORT StreamInfo
{
public:
inline StreamInfo()
: fmt(PixelFormatFromString("GRAY8")) {}
inline StreamInfo(PixelFormat fmt, const Image<unsigned char> img_offset )
: fmt(fmt), img_offset(img_offset) {}
inline StreamInfo(PixelFormat fmt, size_t w, size_t h, size_t pitch, unsigned char* offset = 0)
: fmt(fmt), img_offset(offset,w,h,pitch) {}
//! Format representing how image is laid out in memory
inline const PixelFormat &PixFormat() const { return fmt; }
//! Image width in pixels
inline size_t Width() const { return img_offset.w; }
//! Image height in pixels
inline size_t Height() const { return img_offset.h; }
inline double Aspect() const { return (double)Width() / (double)Height(); }
//! Pitch: Number of bytes between one image row and the next
inline size_t Pitch() const { return img_offset.pitch; }
//! Number of contiguous bytes in memory that the image occupies
inline size_t RowBytes() const {
// Row size without padding
return (fmt.bpp*img_offset.w)/8;
}
//! Returns true iff image contains padding or stridded access
//! This implies that the image data is not contiguous in memory.
inline bool IsPitched() const {
return Pitch() != RowBytes();
}
//! Number of contiguous bytes in memory that the image occupies
inline size_t SizeBytes() const {
return (img_offset.h-1) * img_offset.pitch + RowBytes();
}
//! Offset in bytes relative to start of frame buffer
inline unsigned char* Offset() const { return img_offset.ptr; }
//! Return Image wrapper around raw base pointer
inline Image<unsigned char> StreamImage(unsigned char* base_ptr) const {
Image<unsigned char> img = img_offset;
img.ptr += (size_t)base_ptr;
return img;
}
//! Return Image wrapper around raw base pointer
inline const Image<unsigned char> StreamImage(const unsigned char* base_ptr) const {
Image<unsigned char> img = img_offset;
img.ptr += (size_t)base_ptr;
return img;
}
protected:
PixelFormat fmt;
Image<unsigned char> img_offset;
};
}

View File

@@ -0,0 +1,261 @@
/* 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
// Pangolin video supports various cameras and file formats through
// different 3rd party libraries.
//
// Video URI's take the following form:
// scheme:[param1=value1,param2=value2,...]//device
//
// scheme = file | files | pango | shmem | dc1394 | uvc | v4l | openni2 |
// openni | depthsense | pleora | teli | mjpeg | test |
// thread | convert | debayer | split | join | shift | mirror | unpack
//
// file/files - read one or more streams from image file(s) / video
// e.g. "files://~/data/dataset/img_*.jpg"
// e.g. "files://~/data/dataset/img_[left,right]_*.pgm"
// e.g. "files:///home/user/sequence/foo%03d.jpeg"
//
// e.g. "file:[fmt=GRAY8,size=640x480]///home/user/raw_image.bin"
// e.g. "file:[realtime=1]///home/user/video/movie.pango"
// e.g. "file:[stream=1]///home/user/video/movie.avi"
//
// dc1394 - capture video through a firewire camera
// e.g. "dc1394:[fmt=RGB24,size=640x480,fps=30,iso=400,dma=10]//0"
// e.g. "dc1394:[fmt=FORMAT7_1,size=640x480,pos=2+2,iso=400,dma=10]//0"
// e.g. "dc1394:[fmt=FORMAT7_3,deinterlace=1]//0"
//
// v4l - capture video from a Video4Linux (USB) camera (normally YUVY422 format)
// method=mmap|read|userptr
// e.g. "v4l:///dev/video0"
// e.g. "v4l[method=mmap]:///dev/video0"
//
// openni2 - capture video / depth from OpenNI2 SDK (Kinect / Xtrion etc)
// imgN=grey|rgb|ir|ir8|ir24|depth|reg_depth
// e.g. "openni2://'
// e.g. "openni2:[img1=rgb,img2=depth,coloursync=true]//"
// e.g. "openni2:[img1=depth,close=closerange,holefilter=true]//"
// e.g. "openni2:[size=320x240,fps=60,img1=ir]//"
//
// openni - capture video / depth from OpenNI 1.0 SDK (Kinect / Xtrion etc)
// Sensor modes containing '8' will truncate to 8-bits.
// Sensor modes containing '+' explicitly enable IR illuminator
// imgN=rgb|ir|ir8|ir+|ir8+|depth|reg_depth
// autoexposure=true|false
// e.g. "openni://'
// e.g. "openni:[img1=rgb,img2=depth]//"
// e.g. "openni:[size=320x240,fps=60,img1=ir]//"
//
// depthsense - capture video / depth from DepthSense SDK.
// DepthSenseViewer can be used to alter capture settings.
// imgN=depth|rgb
// sizeN=QVGA|320x240|...
// fpsN=25|30|60|...
// e.g. "depthsense://"
// e.g. "depthsense:[img1=depth,img2=rgb]//"
//
// pleora - USB 3 vision cameras accepts any option in the same format reported by eBUSPlayer
// e.g. for lightwise cameras: "pleora:[size=512x256,pos=712x512,sn=00000274,ExposureTime=10000,PixelFormat=Mono12p,AcquisitionMode=SingleFrame,TriggerSource=Line0,TriggerMode=On]//"
// e.g. for toshiba cameras: "pleora:[size=512x256,pos=712x512,sn=0300056,PixelSize=Bpp12,ExposureTime=10000,ImageFormatSelector=Format1,BinningHorizontal=2,BinningVertical=2]//"
// e.g. toshiba alternated "pleora:[UserSetSelector=UserSet1,ExposureTime=10000,PixelSize=Bpp12,Width=1400,OffsetX=0,Height=1800,OffsetY=124,LineSelector=Line1,LineSource=ExposureActive,LineSelector=Line2,LineSource=Off,LineModeAll=6,LineInverterAll=6,UserSetSave=Execute,
// UserSetSelector=UserSet2,PixelSize=Bpp12,Width=1400,OffsetX=1048,Height=1800,OffsetY=124,ExposureTime=10000,LineSelector=Line1,LineSource=Off,LineSelector=Line2,LineSource=ExposureActive,LineModeAll=6,LineInverterAll=6,UserSetSave=Execute,
// SequentialShutterIndex=1,SequentialShutterEntry=1,SequentialShutterIndex=2,SequentialShutterEntry=2,SequentialShutterTerminateAt=2,SequentialShutterEnable=On,,AcquisitionFrameRateControl=Manual,AcquisitionFrameRate=70]//"
//
// thread - thread that continuously pulls from the child streams so that data in, unpacking, debayering etc can be decoupled from the main application thread
// e.g. thread://pleora://
// e.g. thread://unpack://pleora:[PixelFormat=Mono12p]//
//
// convert - use FFMPEG to convert between video pixel formats
// e.g. "convert:[fmt=RGB24]//v4l:///dev/video0"
// e.g. "convert:[fmt=GRAY8]//v4l:///dev/video0"
//
// mjpeg - capture from (possibly networked) motion jpeg stream using FFMPEG
// e.g. "mjpeg://http://127.0.0.1/?action=stream"
//
// debayer - debayer an input video stream
// e.g. "debayer:[tile="BGGR",method="downsample"]//v4l:///dev/video0
//
// split - split an input video into a one or more streams based on Region of Interest / memory specification
// roiN=X+Y+WxH
// memN=Offset:WxH:PitchBytes:Format
// e.g. "split:[roi1=0+0+640x480,roi2=640+0+640x480]//files:///home/user/sequence/foo%03d.jpeg"
// e.g. "split:[mem1=307200:640x480:1280:GRAY8,roi2=640+0+640x480]//files:///home/user/sequence/foo%03d.jpeg"
// e.g. "split:[stream1=2,stream2=1]//pango://video.pango"
//
// truncate - select a subregion of a video based on start and end (last index+1) index
// e.g. Generate 30 random frames: "truncate:[end=30]//test://"
// e.g. "truncate:[begin=100,end=120]"
//
// join - join streams
// e.g. "join:[sync_tolerance_us=100, sync_continuously=true]//{pleora:[sn=00000274]//}{pleora:[sn=00000275]//}"
//
// test - output test video sequence
// e.g. "test://"
// e.g. "test:[size=640x480,fmt=RGB24]//"
#include <pangolin/utils/uri.h>
#include <pangolin/video/video_exception.h>
#include <pangolin/video/video_interface.h>
#include <pangolin/video/video_output_interface.h>
namespace pangolin
{
//! Open Video Interface from string specification (as described in this files header)
PANGOLIN_EXPORT
std::unique_ptr<VideoInterface> OpenVideo(const std::string& uri);
//! Open Video Interface from Uri specification
PANGOLIN_EXPORT
std::unique_ptr<VideoInterface> OpenVideo(const Uri& uri);
//! Open VideoOutput Interface from string specification (as described in this files header)
PANGOLIN_EXPORT
std::unique_ptr<VideoOutputInterface> OpenVideoOutput(const std::string& str_uri);
//! Open VideoOutput Interface from Uri specification
PANGOLIN_EXPORT
std::unique_ptr<VideoOutputInterface> OpenVideoOutput(const Uri& uri);
//! Create vector of matching interfaces either through direct cast or filter interface.
template<typename T>
std::vector<T*> FindMatchingVideoInterfaces( VideoInterface& video )
{
std::vector<T*> matches;
T* vid = dynamic_cast<T*>(&video);
if(vid) {
matches.push_back(vid);
}
VideoFilterInterface* vidf = dynamic_cast<VideoFilterInterface*>(&video);
if(vidf) {
std::vector<T*> fmatches = vidf->FindMatchingStreams<T>();
matches.insert(matches.begin(), fmatches.begin(), fmatches.end());
}
return matches;
}
template<typename T>
T* FindFirstMatchingVideoInterface( VideoInterface& video )
{
T* vid = dynamic_cast<T*>(&video);
if(vid) {
return vid;
}
VideoFilterInterface* vidf = dynamic_cast<VideoFilterInterface*>(&video);
if(vidf) {
std::vector<T*> fmatches = vidf->FindMatchingStreams<T>();
if(fmatches.size()) {
return fmatches[0];
}
}
return 0;
}
inline
picojson::value GetVideoFrameProperties(VideoInterface* video)
{
VideoPropertiesInterface* pi = dynamic_cast<VideoPropertiesInterface*>(video);
VideoFilterInterface* fi = dynamic_cast<VideoFilterInterface*>(video);
if(pi) {
return pi->FrameProperties();
}else if(fi){
if(fi->InputStreams().size() == 1) {
return GetVideoFrameProperties(fi->InputStreams()[0]);
}else if(fi->InputStreams().size() > 0){
picojson::value streams;
for(size_t i=0; i< fi->InputStreams().size(); ++i) {
const picojson::value dev_props = GetVideoFrameProperties(fi->InputStreams()[i]);
if(dev_props.contains("streams")) {
const picojson::value& dev_streams = dev_props["streams"];
for(size_t j=0; j < dev_streams.size(); ++j) {
streams.push_back(dev_streams[j]);
}
}else{
streams.push_back(dev_props);
}
}
if(streams.size() > 1) {
picojson::value json = streams[0];
json["streams"] = streams;
return json;
}else{
return streams[0];
}
}
}
return picojson::value();
}
inline
picojson::value GetVideoDeviceProperties(VideoInterface* video)
{
VideoPropertiesInterface* pi = dynamic_cast<VideoPropertiesInterface*>(video);
VideoFilterInterface* fi = dynamic_cast<VideoFilterInterface*>(video);
if(pi) {
return pi->DeviceProperties();
}else if(fi){
if(fi->InputStreams().size() == 1) {
return GetVideoDeviceProperties(fi->InputStreams()[0]);
}else if(fi->InputStreams().size() > 0){
picojson::value streams;
for(size_t i=0; i< fi->InputStreams().size(); ++i) {
const picojson::value dev_props = GetVideoDeviceProperties(fi->InputStreams()[i]);
if(dev_props.contains("streams")) {
const picojson::value& dev_streams = dev_props["streams"];
for(size_t j=0; j < dev_streams.size(); ++j) {
streams.push_back(dev_streams[j]);
}
}else{
streams.push_back(dev_props);
}
}
if(streams.size() > 1) {
picojson::value json = streams[0];
json["streams"] = streams;
return json;
}else{
return streams[0];
}
}
}
return picojson::value();
}
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <exception>
#include <pangolin/platform.h>
#include <string>
namespace pangolin {
struct PANGOLIN_EXPORT VideoException : std::exception
{
VideoException(std::string str) : desc(str) {}
VideoException(std::string str, std::string detail) {
desc = str + "\n\t" + detail;
}
~VideoException() throw() {}
const char* what() const throw() { return desc.c_str(); }
std::string desc;
};
struct PANGOLIN_EXPORT VideoExceptionNoKnownHandler : public VideoException
{
VideoExceptionNoKnownHandler(const std::string& scheme)
: VideoException("No known video handler for URI '" + scheme + "'")
{
}
};
}

View File

@@ -0,0 +1,140 @@
/* 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/video/video.h>
#include <pangolin/video/video_output.h>
namespace pangolin
{
struct PANGOLIN_EXPORT VideoInput
: public VideoInterface,
public VideoFilterInterface
{
/////////////////////////////////////////////////////////////
// VideoInterface Methods
/////////////////////////////////////////////////////////////
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;
/////////////////////////////////////////////////////////////
// VideoFilterInterface Methods
/////////////////////////////////////////////////////////////
std::vector<VideoInterface*>& InputStreams() override
{
return videos;
}
/////////////////////////////////////////////////////////////
// VideoInput Methods
/////////////////////////////////////////////////////////////
VideoInput();
VideoInput(VideoInput&& other) = default;
VideoInput(const std::string &input_uri, const std::string &output_uri = "pango:[buffer_size_mb=100]//video_log.pango");
~VideoInput();
void Open(const std::string &input_uri, const std::string &output_uri = "pango:[buffer_size_mb=100]//video_log.pango");
void Close();
// experimental - not stable
bool Grab( unsigned char* buffer, std::vector<Image<unsigned char> >& images, bool wait = true, bool newest = false);
// Return details of first stream
unsigned int Width() const {
return (unsigned int)Streams()[0].Width();
}
unsigned int Height() const {
return (unsigned int)Streams()[0].Height();
}
PixelFormat PixFormat() const {
return Streams()[0].PixFormat();
}
const Uri& VideoUri() const {
return uri_input;
}
void Reset() {
Close();
Open(uri_input.full_uri, uri_output.full_uri);
}
// Return pointer to inner video class as VideoType
template<typename VideoType>
VideoType* Cast() {
return dynamic_cast<VideoType*>(video_src.get());
}
const std::string& LogFilename() const;
std::string& LogFilename();
// Switch to live video and record output to file
void Record();
// Switch to live video and record a single frame
void RecordOneFrame();
// Specify that one in n frames are logged to file. Default is 1.
void SetTimelapse(size_t one_in_n_frames);
// True iff grabbed live frames are being logged to file
bool IsRecording() const;
protected:
void InitialiseRecorder();
Uri uri_input;
Uri uri_output;
std::unique_ptr<VideoInterface> video_src;
std::unique_ptr<VideoOutputInterface> video_recorder;
// Use to store either video_src or video_file for VideoFilterInterface,
// depending on which is active
std::vector<VideoInterface*> videos;
int buffer_size_bytes;
int frame_num;
size_t record_frame_skip;
bool record_once;
bool record_continuous;
};
// VideoInput subsumes the previous VideoRecordRepeat class.
typedef VideoInput VideoRecordRepeat;
}

View File

@@ -0,0 +1,183 @@
/* 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/utils/picojson.h>
#include <pangolin/video/stream_info.h>
#include <memory>
#include <vector>
#define PANGO_HAS_TIMING_DATA "has_timing_data"
#define PANGO_HOST_RECEPTION_TIME_US "host_reception_time_us"
#define PANGO_CAPTURE_TIME_US "capture_time_us"
#define PANGO_EXPOSURE_US "exposure_us"
#define PANGO_GAMMA "gamma"
// analog gain is in linear scale and not dB
#define PANGO_ANALOG_GAIN "analog_gain"
#define PANGO_ANALOG_BLACK_LEVEL "analog_black_level"
#define PANGO_SENSOR_TEMPERATURE_C "sensor_temperature_C"
#define PANGO_ESTIMATED_CENTER_CAPTURE_TIME_US "estimated_center_capture_time_us"
#define PANGO_JOIN_OFFSET_US "join_offset_us"
#define PANGO_FRAME_COUNTER "frame_counter"
namespace pangolin {
//! Interface to video capture sources
struct PANGOLIN_EXPORT VideoInterface
{
virtual ~VideoInterface() {}
//! Required buffer size to store all frames
virtual size_t SizeBytes() const = 0;
//! Get format and dimensions of all video streams
virtual const std::vector<StreamInfo>& Streams() const = 0;
//! Start Video device
virtual void Start() = 0;
//! Stop Video device
virtual void Stop() = 0;
//! Copy the next frame from the camera to image.
//! Optionally wait for a frame if one isn't ready
//! Returns true iff image was copied
virtual bool GrabNext( unsigned char* image, bool wait = true ) = 0;
//! Copy the newest frame from the camera to image
//! discarding all older frames.
//! Optionally wait for a frame if one isn't ready
//! Returns true iff image was copied
virtual bool GrabNewest( unsigned char* image, bool wait = true ) = 0;
};
//! Interface to GENICAM video capture sources
struct PANGOLIN_EXPORT GenicamVideoInterface
{
virtual ~GenicamVideoInterface() {}
virtual bool GetParameter(const std::string& name, std::string& result) = 0;
virtual bool SetParameter(const std::string& name, const std::string& value) = 0;
virtual size_t CameraCount() const
{
return 1;
}
};
struct PANGOLIN_EXPORT BufferAwareVideoInterface
{
virtual ~BufferAwareVideoInterface() {}
//! Returns number of available frames
virtual uint32_t AvailableFrames() const = 0;
//! Drops N frames in the queue starting from the oldest
//! returns false if less than n frames arae available
virtual bool DropNFrames(uint32_t n) = 0;
};
struct PANGOLIN_EXPORT VideoPropertiesInterface
{
virtual ~VideoPropertiesInterface() {}
//! Access JSON properties of device
virtual const picojson::value& DeviceProperties() const = 0;
//! Access JSON properties of most recently captured frame
virtual const picojson::value& FrameProperties() const = 0;
};
enum UvcRequestCode {
UVC_RC_UNDEFINED = 0x00,
UVC_SET_CUR = 0x01,
UVC_GET_CUR = 0x81,
UVC_GET_MIN = 0x82,
UVC_GET_MAX = 0x83,
UVC_GET_RES = 0x84,
UVC_GET_LEN = 0x85,
UVC_GET_INFO = 0x86,
UVC_GET_DEF = 0x87
};
struct PANGOLIN_EXPORT VideoFilterInterface
{
virtual ~VideoFilterInterface() {}
template<typename T>
std::vector<T*> FindMatchingStreams()
{
std::vector<T*> matches;
std::vector<VideoInterface*> children = InputStreams();
for(size_t c=0; c < children.size(); ++c) {
T* concrete_video = dynamic_cast<T*>(children[c]);
if(concrete_video) {
matches.push_back(concrete_video);
}else{
VideoFilterInterface* filter_video = dynamic_cast<VideoFilterInterface*>(children[c]);
if(filter_video) {
std::vector<T*> child_matches = filter_video->FindMatchingStreams<T>();
matches.insert(matches.end(), child_matches.begin(), child_matches.end());
}
}
}
return matches;
}
virtual std::vector<VideoInterface*>& InputStreams() = 0;
};
struct PANGOLIN_EXPORT VideoUvcInterface
{
virtual ~VideoUvcInterface() {}
virtual int IoCtrl(uint8_t unit, uint8_t ctrl, unsigned char* data, int len, UvcRequestCode req_code) = 0;
virtual bool GetExposure(int& exp_us) = 0;
virtual bool SetExposure(int exp_us) = 0;
virtual bool GetGain(float& gain) = 0;
virtual bool SetGain(float gain) = 0;
};
struct PANGOLIN_EXPORT VideoPlaybackInterface
{
virtual ~VideoPlaybackInterface() {}
/// Return monotonic id of current frame
/// The 'current frame' is the frame returned from the last successful call to Grab
virtual size_t GetCurrentFrameId() const = 0;
/// Return total number of frames to be captured from device,
/// or 0 if unknown.
virtual size_t GetTotalFrames() const = 0;
/// Return frameid on success, or next frame on failure
virtual size_t Seek(size_t frameid) = 0;
};
}

View File

@@ -0,0 +1,93 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011-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
// Pangolin video output supports various formats using
// different 3rd party libraries. (Only one right now)
//
// VideoOutput URI's take the following form:
// scheme:[param1=value1,param2=value2,...]//device
//
// scheme = ffmpeg
//
// ffmpeg - encode to compressed file using ffmpeg
// fps : fps to embed in encoded file.
// bps : bits per second
// unique_filename : append unique suffix if file already exists
//
// e.g. ffmpeg://output_file.avi
// e.g. ffmpeg:[fps=30,bps=1000000,unique_filename]//output_file.avi
#include <pangolin/video/video_output_interface.h>
#include <pangolin/utils/uri.h>
#include <memory>
namespace pangolin
{
//! VideoOutput wrap to generically construct instances of VideoOutputInterface.
class PANGOLIN_EXPORT VideoOutput : public VideoOutputInterface
{
public:
VideoOutput();
VideoOutput(VideoOutput&& other) = default;
VideoOutput(const std::string& uri);
~VideoOutput();
bool IsOpen() const;
void Open(const std::string& uri);
void Close();
const std::vector<StreamInfo>& Streams() const override;
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri = "", const picojson::value& properties = picojson::value() ) override;
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties = picojson::value() ) override;
bool IsPipe() const override;
void AddStream(const PixelFormat& pf, size_t w,size_t h,size_t pitch);
void AddStream(const PixelFormat& pf, size_t w,size_t h);
void SetStreams(const std::string& uri = "", const picojson::value& properties = picojson::value() );
size_t SizeBytes(void) const ;
std::vector<Image<unsigned char>> GetOutputImages(unsigned char* buffer) const ;
std::vector<Image<unsigned char>> GetOutputImages(std::vector<unsigned char>& buffer) const ;
protected:
std::vector<StreamInfo> streams;
Uri uri;
std::unique_ptr<VideoOutputInterface> recorder;
};
}

View File

@@ -0,0 +1,52 @@
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2011-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 <vector>
#include <pangolin/platform.h>
#include <pangolin/video/stream_info.h>
#include <pangolin/utils/picojson.h>
namespace pangolin {
//! Interface to video recording destinations
struct PANGOLIN_EXPORT VideoOutputInterface
{
virtual ~VideoOutputInterface() {}
//! Get format and dimensions of all video streams
virtual const std::vector<StreamInfo>& Streams() const = 0;
virtual void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri ="", const picojson::value& properties = picojson::value() ) = 0;
virtual int WriteStreams(const unsigned char* data, const picojson::value& frame_properties = picojson::value() ) = 0;
virtual bool IsPipe() const = 0;
};
}

View File

@@ -0,0 +1,31 @@
/* 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
// VideoInput subsumes the previous VideoRecordRepeat class.
#include <pangolin/video/video_input.h>