This source file includes following definitions.
- what
- getCaptureDomain
- ctxErrorFunc
- ctxStatusFunc
- ctxMessageFunc
- initContext
- open
- isOpened
- close
- getGenericProperty
- getProperty
- setGenericProperty
- setProperty
- grabFrame
- retrieveFrame
- deviceExist
- findDevice
- reloadConfig
- getWidget
- findWidgetByName
- readFrameFromFile
- widgetDescription
- collectWidgets
- message
- createGPhoto2Capture
- createGPhoto2Capture
#include "precomp.hpp"
#ifdef HAVE_GPHOTO2
#include <gphoto2/gphoto2.h>
#include <algorithm>
#include <clocale>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <map>
#include <ostream>
#include <string>
namespace cv
{
namespace gphoto2 {
class GPhoto2Exception: public std::exception
{
private:
int result;
const char * method;
public:
GPhoto2Exception(const char * methodStr, int gPhoto2Result)
{
result = gPhoto2Result;
method = methodStr;
}
virtual const char * what() const throw ()
{
return gp_result_as_string(result);
}
friend std::ostream & operator<<(std::ostream & ostream,
GPhoto2Exception & e)
{
return ostream << e.method << ": " << e.what();
}
};
class DigitalCameraCapture: public IVideoCapture
{
public:
static const char * separator;
static const char * lineDelimiter;
DigitalCameraCapture();
DigitalCameraCapture(int index);
DigitalCameraCapture(const String &deviceName);
virtual ~DigitalCameraCapture();
virtual bool isOpened() const;
virtual double getProperty(int) const;
virtual bool setProperty(int, double);
virtual bool grabFrame();
virtual bool retrieveFrame(int, OutputArray);
virtual int getCaptureDomain()
{
return CV_CAP_GPHOTO2;
}
bool open(int index);
void close();
bool deviceExist(int index) const;
int findDevice(const char * deviceName) const;
protected:
static const char * PROP_EXPOSURE_COMPENSACTION;
static const char * PROP_SELF_TIMER_DELAY;
static const char * PROP_MANUALFOCUS;
static const char * PROP_AUTOFOCUS;
static const char * PROP_ISO;
static const char * PROP_SPEED;
static const char * PROP_APERTURE_NIKON;
static const char * PROP_APERTURE_CANON;
static const char * PROP_EXPOSURE_PROGRAM;
static const char * PROP_VIEWFINDER;
GPContext * context = NULL;
int numDevices;
void initContext();
bool opened;
Camera * camera = NULL;
Mat frame;
CameraWidget * rootWidget = NULL;
CameraWidget * getGenericProperty(int propertyId, double & output) const;
CameraWidget * setGenericProperty(int propertyId, double value,
bool & output) const;
void reloadConfig() throw (GPhoto2Exception);
CameraWidget * getWidget(int widgetId) const;
CameraWidget * findWidgetByName(const char * name) const;
void readFrameFromFile(CameraFile * file, OutputArray outputFrame) throw (GPhoto2Exception);
friend void ctxErrorFunc(GPContext *, const char *, void *);
friend void ctxStatusFunc(GPContext *, const char *, void *);
friend void ctxMessageFunc(GPContext *, const char *, void *);
enum MsgType
{
ERROR = (int) 'E',
WARNING = (int) 'W',
STATUS = (int) 'S',
OTHER = (int) 'O'
};
template<typename OsstreamPrintable>
void message(MsgType msgType, const char * msg,
OsstreamPrintable & arg) const;
private:
CameraAbilitiesList * abilitiesList = NULL;
GPPortInfoList * capablePorts = NULL;
CameraList * allDevices = NULL;
CameraAbilities cameraAbilities;
std::deque<CameraFile *> grabbedFrames;
bool preview;
std::string widgetInfo;
std::map<int, CameraWidget *> widgets;
bool reloadOnChange;
time_t firstCapturedFrameTime;
unsigned long int capturedFrames;
DigitalCameraCapture(const DigitalCameraCapture&);
DigitalCameraCapture& operator=(DigitalCameraCapture const&);
int noOfWidgets;
int widgetDescription(std::ostream &os, CameraWidget * widget) const
throw (GPhoto2Exception);
int collectWidgets(std::ostream &os, CameraWidget * widget)
throw (GPhoto2Exception);
mutable std::ostringstream msgsBuffer;
mutable std::string lastFlush;
bool collectMsgs;
};
#define CR(GPHOTO2_FUN) do {\
int r_0629c47b758;\
if ((r_0629c47b758 = (GPHOTO2_FUN)) < GP_OK) {\
throw GPhoto2Exception(#GPHOTO2_FUN, r_0629c47b758);\
};\
} while(0)
void ctxErrorFunc(GPContext *, const char * str, void * thatGPhotoCap)
{
const DigitalCameraCapture * self =
(const DigitalCameraCapture *) thatGPhotoCap;
self->message(self->ERROR, "context feedback", str);
}
void ctxStatusFunc(GPContext *, const char * str, void * thatGPhotoCap)
{
const DigitalCameraCapture * self =
(const DigitalCameraCapture *) thatGPhotoCap;
self->message(self->STATUS, "context feedback", str);
}
void ctxMessageFunc(GPContext *, const char * str, void * thatGPhotoCap)
{
const DigitalCameraCapture * self =
(const DigitalCameraCapture *) thatGPhotoCap;
self->message(self->OTHER, "context feedback", str);
}
const char * DigitalCameraCapture::separator = ",";
const char * DigitalCameraCapture::lineDelimiter = "\n";
const char * DigitalCameraCapture::PROP_EXPOSURE_COMPENSACTION =
"exposurecompensation";
const char * DigitalCameraCapture::PROP_SELF_TIMER_DELAY = "selftimerdelay";
const char * DigitalCameraCapture::PROP_MANUALFOCUS = "manualfocusdrive";
const char * DigitalCameraCapture::PROP_AUTOFOCUS = "autofocusdrive";
const char * DigitalCameraCapture::PROP_ISO = "iso";
const char * DigitalCameraCapture::PROP_SPEED = "shutterspeed";
const char * DigitalCameraCapture::PROP_APERTURE_NIKON = "f-number";
const char * DigitalCameraCapture::PROP_APERTURE_CANON = "aperture";
const char * DigitalCameraCapture::PROP_EXPOSURE_PROGRAM = "expprogram";
const char * DigitalCameraCapture::PROP_VIEWFINDER = "viewfinder";
void DigitalCameraCapture::initContext()
{
capturedFrames = noOfWidgets = numDevices = 0;
opened = preview = reloadOnChange = false;
firstCapturedFrameTime = 0;
context = gp_context_new();
gp_context_set_error_func(context, ctxErrorFunc, (void*) this);
gp_context_set_status_func(context, ctxStatusFunc, (void*) this);
gp_context_set_message_func(context, ctxMessageFunc, (void*) this);
try
{
CR(gp_abilities_list_new(&abilitiesList));
CR(gp_abilities_list_load(abilitiesList, context));
CR(gp_port_info_list_new(&capablePorts));
CR(gp_port_info_list_load(capablePorts));
CR(gp_list_new(&allDevices));
CR(gp_camera_autodetect(allDevices, context));
CR(numDevices = gp_list_count(allDevices));
}
catch (GPhoto2Exception & e)
{
numDevices = 0;
}
}
DigitalCameraCapture::DigitalCameraCapture()
{
initContext();
}
DigitalCameraCapture::DigitalCameraCapture(int index)
{
initContext();
if (deviceExist(index))
open(index);
}
DigitalCameraCapture::DigitalCameraCapture(const String & deviceName)
{
initContext();
int index = findDevice(deviceName.c_str());
if (deviceExist(index))
open(index);
}
DigitalCameraCapture::~DigitalCameraCapture()
{
close();
try
{
CR(gp_abilities_list_free(abilitiesList));
abilitiesList = NULL;
CR(gp_port_info_list_free(capablePorts));
capablePorts = NULL;
CR(gp_list_unref(allDevices));
allDevices = NULL;
gp_context_unref(context);
context = NULL;
}
catch (GPhoto2Exception & e)
{
message(ERROR, "destruction error", e);
}
}
bool DigitalCameraCapture::open(int index)
{
const char * model = 0, *path = 0;
int m, p;
GPPortInfo portInfo;
if (isOpened()) {
close();
}
try
{
CR(gp_camera_new(&camera));
CR(gp_list_get_name(allDevices, index, &model));
CR(gp_list_get_value(allDevices, index, &path));
CR(m = gp_abilities_list_lookup_model(abilitiesList, model));
CR(gp_abilities_list_get_abilities(abilitiesList, m, &cameraAbilities));
CR(gp_camera_set_abilities(camera, cameraAbilities));
CR(p = gp_port_info_list_lookup_path(capablePorts, path));
CR(gp_port_info_list_get_info(capablePorts, p, &portInfo));
CR(gp_camera_set_port_info(camera, portInfo));
CR(gp_camera_init(camera, context));
message(STATUS, "connected camera", model);
message(STATUS, "connected using", path);
firstCapturedFrameTime = 0;
capturedFrames = 0;
preview = false;
reloadOnChange = false;
collectMsgs = false;
reloadConfig();
opened = true;
return true;
}
catch (GPhoto2Exception & e)
{
message(WARNING, "opening device failed", e);
return false;
}
}
bool DigitalCameraCapture::isOpened() const
{
return opened;
}
void DigitalCameraCapture::close()
{
try
{
if (!frame.empty())
{
frame.release();
}
if (camera)
{
CR(gp_camera_exit(camera, context));
CR(gp_camera_unref(camera));
camera = NULL;
}
opened = false;
if (int frames = grabbedFrames.size() > 0)
{
while (frames--)
{
CameraFile * file = grabbedFrames.front();
grabbedFrames.pop_front();
CR(gp_file_unref(file));
}
}
if (rootWidget)
{
widgetInfo.clear();
CR(gp_widget_unref(rootWidget));
rootWidget = NULL;
}
}
catch (GPhoto2Exception & e)
{
message(ERROR, "cannot close device properly", e);
}
}
CameraWidget * DigitalCameraCapture::getGenericProperty(int propertyId,
double & output) const
{
switch (propertyId)
{
case CV_CAP_PROP_POS_MSEC:
{
output = (time(0) - firstCapturedFrameTime) * 1e2;
return NULL;
}
case CV_CAP_PROP_POS_FRAMES:
{
output = capturedFrames;
return NULL;
}
case CV_CAP_PROP_FRAME_WIDTH:
{
if (!frame.empty())
{
output = frame.cols;
}
return NULL;
}
case CV_CAP_PROP_FRAME_HEIGHT:
{
if (!frame.empty())
{
output = frame.rows;
}
return NULL;
}
case CV_CAP_PROP_FORMAT:
{
if (!frame.empty())
{
output = frame.type();
}
return NULL;
}
case CV_CAP_PROP_FPS:
{
double wholeProcessTime = 0;
getGenericProperty(CV_CAP_PROP_POS_MSEC, wholeProcessTime);
wholeProcessTime /= 1e2;
output = capturedFrames / wholeProcessTime;
return NULL;
}
case CV_CAP_PROP_FRAME_COUNT:
{
output = capturedFrames;
return NULL;
}
case CV_CAP_PROP_EXPOSURE:
return findWidgetByName(PROP_EXPOSURE_COMPENSACTION);
case CV_CAP_PROP_TRIGGER_DELAY:
return findWidgetByName(PROP_SELF_TIMER_DELAY);
case CV_CAP_PROP_ZOOM:
return findWidgetByName(PROP_MANUALFOCUS);
case CV_CAP_PROP_FOCUS:
return findWidgetByName(PROP_AUTOFOCUS);
case CV_CAP_PROP_ISO_SPEED:
return findWidgetByName(PROP_ISO);
case CV_CAP_PROP_SPEED:
return findWidgetByName(PROP_SPEED);
case CV_CAP_PROP_APERTURE:
{
CameraWidget * widget = findWidgetByName(PROP_APERTURE_NIKON);
return (widget == 0) ? findWidgetByName(PROP_APERTURE_CANON) : widget;
}
case CV_CAP_PROP_EXPOSUREPROGRAM:
return findWidgetByName(PROP_EXPOSURE_PROGRAM);
case CV_CAP_PROP_VIEWFINDER:
return findWidgetByName(PROP_VIEWFINDER);
}
return NULL;
}
double DigitalCameraCapture::getProperty(int propertyId) const
{
CameraWidget * widget = NULL;
double output = 0;
if (propertyId < 0)
{
widget = getWidget(-propertyId);
}
else
{
switch (propertyId)
{
case CV_CAP_PROP_GPHOTO2_PREVIEW:
return preview;
case CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE:
if (rootWidget == NULL)
return 0;
return (intptr_t) widgetInfo.c_str();
case CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG:
return 0;
case CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE:
return reloadOnChange;
case CV_CAP_PROP_GPHOTO2_COLLECT_MSGS:
return collectMsgs;
case CV_CAP_PROP_GPHOTO2_FLUSH_MSGS:
lastFlush = msgsBuffer.str();
msgsBuffer.str("");
msgsBuffer.clear();
return (intptr_t) lastFlush.c_str();
default:
widget = getGenericProperty(propertyId, output);
}
}
if (widget == NULL)
return output;
try
{
CameraWidgetType type;
CR(gp_widget_get_type(widget, &type));
switch (type)
{
case GP_WIDGET_MENU:
case GP_WIDGET_RADIO:
{
int cnt = 0, i;
const char * current;
CR(gp_widget_get_value(widget, ¤t));
CR(cnt = gp_widget_count_choices(widget));
for (i = 0; i < cnt; i++)
{
const char *choice;
CR(gp_widget_get_choice(widget, i, &choice));
if (std::strcmp(choice, current) == 0)
{
return i;
}
}
return -1;
}
case GP_WIDGET_TOGGLE:
{
int value;
CR(gp_widget_get_value(widget, &value));
return value;
}
case GP_WIDGET_RANGE:
{
float value;
CR(gp_widget_get_value(widget, &value));
return value;
}
default:
{
char* value;
CR(gp_widget_get_value(widget, &value));
return (intptr_t) value;
}
}
}
catch (GPhoto2Exception & e)
{
char buf[128] = "";
sprintf(buf, "cannot get property: %d", propertyId);
message(WARNING, (const char *) buf, e);
return 0;
}
}
CameraWidget * DigitalCameraCapture::setGenericProperty(int propertyId,
double , bool & output) const
{
switch (propertyId)
{
case CV_CAP_PROP_POS_MSEC:
case CV_CAP_PROP_POS_FRAMES:
case CV_CAP_PROP_FRAME_WIDTH:
case CV_CAP_PROP_FRAME_HEIGHT:
case CV_CAP_PROP_FPS:
case CV_CAP_PROP_FRAME_COUNT:
case CV_CAP_PROP_FORMAT:
output = false;
return NULL;
case CV_CAP_PROP_EXPOSURE:
return findWidgetByName(PROP_EXPOSURE_COMPENSACTION);
case CV_CAP_PROP_TRIGGER_DELAY:
return findWidgetByName(PROP_SELF_TIMER_DELAY);
case CV_CAP_PROP_ZOOM:
return findWidgetByName(PROP_MANUALFOCUS);
case CV_CAP_PROP_FOCUS:
return findWidgetByName(PROP_AUTOFOCUS);
case CV_CAP_PROP_ISO_SPEED:
return findWidgetByName(PROP_ISO);
case CV_CAP_PROP_SPEED:
return findWidgetByName(PROP_SPEED);
case CV_CAP_PROP_APERTURE:
{
CameraWidget * widget = findWidgetByName(PROP_APERTURE_NIKON);
return (widget == NULL) ? findWidgetByName(PROP_APERTURE_CANON) : widget;
}
case CV_CAP_PROP_EXPOSUREPROGRAM:
return findWidgetByName(PROP_EXPOSURE_PROGRAM);
case CV_CAP_PROP_VIEWFINDER:
return findWidgetByName(PROP_VIEWFINDER);
}
return NULL;
}
bool DigitalCameraCapture::setProperty(int propertyId, double value)
{
CameraWidget * widget = NULL;
bool output = false;
if (propertyId < 0)
{
widget = getWidget(-propertyId);
}
else
{
switch (propertyId)
{
case CV_CAP_PROP_GPHOTO2_PREVIEW:
preview = value != 0;
return true;
case CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE:
return false;
case CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG:
reloadConfig();
return true;
case CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE:
reloadOnChange = value != 0;
return true;
case CV_CAP_PROP_GPHOTO2_COLLECT_MSGS:
collectMsgs = value != 0;
return true;
case CV_CAP_PROP_GPHOTO2_FLUSH_MSGS:
return false;
default:
widget = setGenericProperty(propertyId, value, output);
}
}
if (widget == NULL)
return output;
try
{
CameraWidgetType type;
CR(gp_widget_get_type(widget, &type));
switch (type)
{
case GP_WIDGET_RADIO:
case GP_WIDGET_MENU:
{
int i = static_cast<int>(value);
char *choice;
CR(gp_widget_get_choice(widget, i, (const char**)&choice));
CR(gp_widget_set_value(widget, choice));
break;
}
case GP_WIDGET_TOGGLE:
{
int i = static_cast<int>(value);
CR(gp_widget_set_value(widget, &i));
break;
}
case GP_WIDGET_RANGE:
{
float v = static_cast<float>(value);
CR(gp_widget_set_value(widget, &v));
break;
}
default:
{
CR(gp_widget_set_value(widget, (void* )(intptr_t )&value));
break;
}
}
if (!reloadOnChange)
{
CR(gp_widget_set_changed(widget, 1));
}
char * localeTmp = setlocale(LC_ALL, "C");
CR(gp_camera_set_config(camera, rootWidget, context));
setlocale(LC_ALL, localeTmp);
if (reloadOnChange)
{
reloadConfig();
} else {
CR(gp_widget_set_changed(widget, 0));
}
}
catch (GPhoto2Exception & e)
{
char buf[128] = "";
sprintf(buf, "cannot set property: %d to %f", propertyId, value);
message(WARNING, (const char *) buf, e);
return false;
}
return true;
}
bool DigitalCameraCapture::grabFrame()
{
CameraFilePath filePath;
CameraFile * file = NULL;
try
{
CR(gp_file_new(&file));
if (preview)
{
CR(gp_camera_capture_preview(camera, file, context));
}
else
{
CR(gp_camera_capture(camera, GP_CAPTURE_IMAGE, &filePath, context));
CR(gp_camera_file_get(camera, filePath.folder, filePath.name, GP_FILE_TYPE_NORMAL,
file, context));
CR(gp_camera_file_delete(camera, filePath.folder, filePath.name, context));
}
if (firstCapturedFrameTime == 0)
{
firstCapturedFrameTime = time(0);
}
capturedFrames++;
grabbedFrames.push_back(file);
}
catch (GPhoto2Exception & e)
{
if (file)
gp_file_unref(file);
message(WARNING, "cannot grab new frame", e);
return false;
}
return true;
}
bool DigitalCameraCapture::retrieveFrame(int, OutputArray outputFrame)
{
if (grabbedFrames.size() > 0)
{
CameraFile * file = grabbedFrames.front();
grabbedFrames.pop_front();
try
{
readFrameFromFile(file, outputFrame);
CR(gp_file_unref(file));
}
catch (GPhoto2Exception & e)
{
message(WARNING, "cannot read file grabbed from device", e);
return false;
}
}
else
{
return false;
}
return true;
}
bool DigitalCameraCapture::deviceExist(int index) const
{
return (numDevices > 0) && (index < numDevices);
}
int DigitalCameraCapture::findDevice(const char * deviceName) const
{
const char * model = 0;
try
{
if (deviceName != 0)
{
for (int i = 0; i < numDevices; ++i)
{
CR(gp_list_get_name(allDevices, i, &model));
if (model != 0 && strstr(model, deviceName))
{
return i;
}
}
}
}
catch (GPhoto2Exception & e)
{
;
}
return -1;
}
void DigitalCameraCapture::reloadConfig() throw (GPhoto2Exception)
{
std::ostringstream widgetInfoListStream;
if (rootWidget != NULL)
{
widgetInfo.clear();
CR(gp_widget_unref(rootWidget));
rootWidget = NULL;
widgets.clear();
}
char * localeTmp = setlocale(LC_ALL, "C");
CR(gp_camera_get_config(camera, &rootWidget, context));
setlocale(LC_ALL, localeTmp);
widgetInfoListStream << "id,label,name,info,readonly,type,value,"
<< lineDelimiter;
noOfWidgets = collectWidgets(widgetInfoListStream, rootWidget) + 1;
widgetInfo = widgetInfoListStream.str();
}
CameraWidget * DigitalCameraCapture::getWidget(int widgetId) const
{
CameraWidget * widget;
std::map<int, CameraWidget *>::const_iterator it = widgets.find(widgetId);
if (it == widgets.end())
return 0;
widget = it->second;
return widget;
}
CameraWidget * DigitalCameraCapture::findWidgetByName(
const char * subName) const
{
if (subName != NULL)
{
try
{
const char * name;
typedef std::map<int, CameraWidget *>::const_iterator it_t;
it_t it = widgets.begin(), end = widgets.end();
while (it != end)
{
CR(gp_widget_get_name(it->second, &name));
if (strstr(name, subName))
break;
it++;
}
return (it != end) ? it->second : NULL;
}
catch (GPhoto2Exception & e)
{
message(WARNING, "error while searching for widget", e);
}
}
return 0;
}
void DigitalCameraCapture::readFrameFromFile(CameraFile * file, OutputArray outputFrame)
throw (GPhoto2Exception)
{
const char * data;
unsigned long int size;
CR(gp_file_get_data_and_size(file, &data, &size));
if (size > 0)
{
Mat buf = Mat(1, size, CV_8UC1, (void *) data);
if(!buf.empty())
{
frame = imdecode(buf, CV_LOAD_IMAGE_UNCHANGED);
}
frame.copyTo(outputFrame);
}
}
int DigitalCameraCapture::widgetDescription(std::ostream &os,
CameraWidget * widget) const throw (GPhoto2Exception)
{
const char * label, *name, *info;
int id, readonly;
CameraWidgetType type;
CR(gp_widget_get_id(widget, &id));
CR(gp_widget_get_label(widget, &label));
CR(gp_widget_get_name(widget, &name));
CR(gp_widget_get_info(widget, &info));
CR(gp_widget_get_type(widget, &type));
CR(gp_widget_get_readonly(widget, &readonly));
if ((type == GP_WIDGET_WINDOW) || (type == GP_WIDGET_SECTION)
|| (type == GP_WIDGET_BUTTON))
{
readonly = 1;
}
os << (id - noOfWidgets) << separator << label << separator << name
<< separator << info << separator << readonly << separator;
switch (type)
{
case GP_WIDGET_WINDOW:
{
os << "window" << separator << separator;
break;
}
case GP_WIDGET_SECTION:
{
os << "section" << separator << separator;
break;
}
case GP_WIDGET_TEXT:
{
os << "text" << separator;
char *txt;
CR(gp_widget_get_value(widget, &txt));
os << txt << separator;
break;
}
case GP_WIDGET_RANGE:
{
os << "range" << separator;
float f, t, b, s;
CR(gp_widget_get_range(widget, &b, &t, &s));
CR(gp_widget_get_value(widget, &f));
os << "(" << b << ":" << t << ":" << s << "):" << f << separator;
break;
}
case GP_WIDGET_TOGGLE:
{
os << "toggle" << separator;
int t;
CR(gp_widget_get_value(widget, &t));
os << t << separator;
break;
}
case GP_WIDGET_RADIO:
case GP_WIDGET_MENU:
{
if (type == GP_WIDGET_RADIO)
{
os << "radio" << separator;
}
else
{
os << "menu" << separator;
}
int cnt = 0, i;
char *current;
CR(gp_widget_get_value(widget, ¤t));
CR(cnt = gp_widget_count_choices(widget));
os << "(";
for (i = 0; i < cnt; i++)
{
const char *choice;
CR(gp_widget_get_choice(widget, i, &choice));
os << i << ":" << choice;
if (i + 1 < cnt)
{
os << ";";
}
}
os << "):" << current << separator;
break;
}
case GP_WIDGET_BUTTON:
{
os << "button" << separator << separator;
break;
}
case GP_WIDGET_DATE:
{
os << "date" << separator;
int t;
time_t xtime;
struct tm *xtm;
char timebuf[200];
CR(gp_widget_get_value(widget, &t));
xtime = t;
xtm = localtime(&xtime);
strftime(timebuf, sizeof(timebuf), "%c", xtm);
os << t << ":" << timebuf << separator;
break;
}
}
return id;
}
int DigitalCameraCapture::collectWidgets(std::ostream & os,
CameraWidget * widget) throw (GPhoto2Exception)
{
int id = widgetDescription(os, widget);
os << lineDelimiter;
widgets[id - noOfWidgets] = widget;
CameraWidget * child;
CameraWidgetType type;
CR(gp_widget_get_type(widget, &type));
if ((type == GP_WIDGET_WINDOW) || (type == GP_WIDGET_SECTION))
{
for (int x = 0; x < gp_widget_count_children(widget); x++)
{
CR(gp_widget_get_child(widget, x, &child));
id = std::max(id, collectWidgets(os, child));
}
}
return id;
}
template<typename OsstreamPrintable>
void DigitalCameraCapture::message(MsgType msgType, const char * msg,
OsstreamPrintable & arg) const
{
#if defined(NDEBUG)
if (collectMsgs)
{
#endif
std::ostringstream msgCreator;
std::string out;
char type = (char) msgType;
msgCreator << "[gPhoto2][" << type << "]: " << msg << ": " << arg
<< lineDelimiter;
out = msgCreator.str();
#if !defined(NDEBUG)
if (collectMsgs)
{
#endif
msgsBuffer << out;
}
#if !defined(NDEBUG)
#if defined(WIN32) || defined(_WIN32)
::OutputDebugString(out.c_str());
#else
fputs(out.c_str(), stderr);
#endif
#endif
}
}
Ptr<IVideoCapture> createGPhoto2Capture(int index)
{
Ptr<IVideoCapture> capture = makePtr<gphoto2::DigitalCameraCapture>(index);
if (capture->isOpened())
return capture;
return Ptr<gphoto2::DigitalCameraCapture>();
}
Ptr<IVideoCapture> createGPhoto2Capture(const String & deviceName)
{
Ptr<IVideoCapture> capture = makePtr<gphoto2::DigitalCameraCapture>(deviceName);
if (capture->isOpened())
return capture;
return Ptr<gphoto2::DigitalCameraCapture>();
}
}
#endif