Skip to content

Commit 6d0407b

Browse files
committed
VideoCapture with digital camera and gPhoto2 library
1 parent 298c98e commit 6d0407b

File tree

11 files changed

+1787
-9
lines changed

11 files changed

+1787
-9
lines changed

CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON
205205
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF (WIN32 AND NOT WINRT) )
206206
OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) )
207207
OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
208+
OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" ON IF (UNIX AND NOT ANDROID) )
208209

209210
# OpenCV build components
210211
# ===================================================
@@ -1032,6 +1033,10 @@ if(DEFINED WITH_INTELPERC)
10321033
status(" Intel PerC:" HAVE_INTELPERC THEN "YES" ELSE NO)
10331034
endif(DEFINED WITH_INTELPERC)
10341035

1036+
if(DEFINED WITH_GPHOTO2)
1037+
status(" gPhoto2:" HAVE_GPHOTO2 THEN "YES" ELSE NO)
1038+
endif(DEFINED WITH_GPHOTO2)
1039+
10351040

10361041
# ========================== Other third-party libraries ==========================
10371042
status("")

cmake/OpenCVFindLibsVideo.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,9 @@ endif()
311311
if(WITH_INTELPERC)
312312
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindIntelPerCSDK.cmake")
313313
endif(WITH_INTELPERC)
314+
315+
# --- gPhoto2 ---
316+
ocv_clear_vars(HAVE_GPHOTO2)
317+
if(WITH_GPHOTO2)
318+
CHECK_MODULE(libgphoto2 HAVE_GPHOTO2)
319+
endif(WITH_GPHOTO2)

cmake/templates/cvconfig.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,6 @@
178178
/* Define if your processor stores words with the most significant byte
179179
first (like Motorola and SPARC, unlike Intel and VAX). */
180180
#cmakedefine WORDS_BIGENDIAN
181+
182+
/* gPhoto2 library */
183+
#cmakedefine HAVE_GPHOTO2

modules/videoio/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ if(HAVE_INTELPERC)
186186
list(APPEND VIDEOIO_LIBRARIES ${INTELPERC_LIBRARIES})
187187
endif(HAVE_INTELPERC)
188188

189+
if(HAVE_GPHOTO2)
190+
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_gphoto2.cpp)
191+
endif(HAVE_GPHOTO2)
192+
189193
if(IOS)
190194
add_definitions(-DHAVE_IOS=1)
191195
list(APPEND videoio_srcs

modules/videoio/include/opencv2/videoio.hpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ enum { CAP_ANY = 0, // autodetect
8989
CAP_WINRT = 1410, // Microsoft Windows Runtime using Media Foundation
9090
CAP_INTELPERC = 1500, // Intel Perceptual Computing SDK
9191
CAP_OPENNI2 = 1600, // OpenNI2 (for Kinect)
92-
CAP_OPENNI2_ASUS = 1610 // OpenNI2 (for Asus Xtion and Occipital Structure sensors)
92+
CAP_OPENNI2_ASUS = 1610, // OpenNI2 (for Asus Xtion and Occipital Structure sensors)
93+
CAP_GPHOTO2 = 1700 // gPhoto2 connection
9394
};
9495

9596
// generic properties (based on DC1394 properties)
@@ -382,6 +383,23 @@ enum { VIDEOWRITER_PROP_QUALITY = 1, // Quality (0..100%) of the videostream
382383
VIDEOWRITER_PROP_FRAMEBYTES = 2, // (Read-only): Size of just encoded video frame
383384
};
384385

386+
// gPhoto2 properties, if propertyId is less than 0 then work on widget with that __additive inversed__ camera setting ID
387+
// Get IDs by using CAP_PROP_GPHOTO2_WIDGET_ENUMERATE.
388+
// @see CvCaptureCAM_GPHOTO2 for more info
389+
enum { CAP_PROP_GPHOTO2_PREVIEW = 17001, // Capture only preview from liveview mode.
390+
CAP_PROP_GPHOTO2_WIDGET_ENUMERATE = 17002, // Readonly, returns (const char *).
391+
CAP_PROP_GPHOTO2_RELOAD_CONFIG = 17003, // Trigger, only by set. Reload camera settings.
392+
CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE = 17004, // Reload all settings on set.
393+
CAP_PROP_GPHOTO2_COLLECT_MSGS = 17005, // Collect messages with details.
394+
CAP_PROP_GPHOTO2_FLUSH_MSGS = 17006, // Readonly, returns (const char *).
395+
CAP_PROP_SPEED = 17007, // Exposure speed. Can be readonly, depends on camera program.
396+
CAP_PROP_APERTURE = 17008, // Aperture. Can be readonly, depends on camera program.
397+
CAP_PROP_EXPOSUREPROGRAM = 17009, // Camera exposure program.
398+
CAP_PROP_VIEWFINDER = 17010 // Enter liveview mode.
399+
};
400+
401+
//enum {
402+
385403
class IVideoCapture;
386404

387405
/** @brief Class for video capturing from video files, image sequences or cameras. The class provides C++ API

modules/videoio/include/opencv2/videoio/videoio_c.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ enum
110110

111111
CV_CAP_INTELPERC = 1500, // Intel Perceptual Computing
112112

113-
CV_CAP_OPENNI2 = 1600 // OpenNI2 (for Kinect)
113+
CV_CAP_OPENNI2 = 1600, // OpenNI2 (for Kinect)
114+
115+
CV_CAP_GPHOTO2 = 1700
114116
};
115117

116118
/* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
@@ -391,6 +393,23 @@ enum
391393
CV_CAP_INTELPERC_IMAGE = 3
392394
};
393395

396+
// gPhoto2 properties, if propertyId is less than 0 then work on widget with that __additive inversed__ camera setting ID
397+
// Get IDs by using CAP_PROP_GPHOTO2_WIDGET_ENUMERATE.
398+
// @see CvCaptureCAM_GPHOTO2 for more info
399+
enum
400+
{
401+
CV_CAP_PROP_GPHOTO2_PREVIEW = 17001, // Capture only preview from liveview mode.
402+
CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE = 17002, // Readonly, returns (const char *).
403+
CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG = 17003, // Trigger, only by set. Reload camera settings.
404+
CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE = 17004, // Reload all settings on set.
405+
CV_CAP_PROP_GPHOTO2_COLLECT_MSGS = 17005, // Collect messages with details.
406+
CV_CAP_PROP_GPHOTO2_FLUSH_MSGS = 17006, // Readonly, returns (const char *).
407+
CV_CAP_PROP_SPEED = 17007, // Exposure speed. Can be readonly, depends on camera program.
408+
CV_CAP_PROP_APERTURE = 17008, // Aperture. Can be readonly, depends on camera program.
409+
CV_CAP_PROP_EXPOSUREPROGRAM = 17009, // Camera exposure program.
410+
CV_CAP_PROP_VIEWFINDER = 17010 // Enter liveview mode.
411+
};
412+
394413
/* retrieve or set capture properties */
395414
CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
396415
CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value );

modules/videoio/src/cap.cpp

+39-7
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
518518
#endif
519519
#ifdef WINRT_VIDEO
520520
CAP_WINRT,
521+
#endif
522+
#ifdef HAVE_GPHOTO2
523+
CV_CAP_GPHOTO2,
521524
#endif
522525
-1, -1
523526
};
@@ -536,7 +539,8 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
536539
{
537540
#if defined(HAVE_DSHOW) || \
538541
defined(HAVE_INTELPERC) || \
539-
defined(WINRT_VIDEO) || \
542+
defined(WINRT_VIDEO) || \
543+
defined(HAVE_GPHOTO2) || \
540544
(0)
541545
Ptr<IVideoCapture> capture;
542546

@@ -558,6 +562,11 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
558562
if (capture)
559563
return capture;
560564
break; // CAP_WINRT
565+
#endif
566+
#ifdef HAVE_GPHOTO2
567+
case CV_CAP_GPHOTO2:
568+
capture = createGPhoto2Capture(index);
569+
break;
561570
#endif
562571
}
563572
if (capture && capture->isOpened())
@@ -572,14 +581,37 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
572581

573582
static Ptr<IVideoCapture> IVideoCapture_create(const String& filename)
574583
{
575-
Ptr<IVideoCapture> capture;
584+
int domains[] =
585+
{
586+
CV_CAP_ANY,
587+
#ifdef HAVE_GPHOTO2
588+
CV_CAP_GPHOTO2,
589+
#endif
590+
-1, -1
591+
};
576592

577-
capture = createMotionJpegCapture(filename);
578-
if (capture && capture->isOpened())
593+
// try every possibly installed camera API
594+
for (int i = 0; domains[i] >= 0; i++)
579595
{
580-
return capture;
581-
}
596+
Ptr<IVideoCapture> capture;
597+
598+
switch (domains[i])
599+
{
600+
case CV_CAP_ANY:
601+
capture = createMotionJpegCapture(filename);
602+
break;
603+
#ifdef HAVE_GPHOTO2
604+
case CV_CAP_GPHOTO2:
605+
capture = createGPhoto2Capture(filename);
606+
break;
607+
#endif
608+
}
582609

610+
if (capture && capture->isOpened())
611+
{
612+
return capture;
613+
}
614+
}
583615
// failed open a camera
584616
return Ptr<IVideoCapture>();
585617
}
@@ -800,4 +832,4 @@ int VideoWriter::fourcc(char c1, char c2, char c3, char c4)
800832
return (c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24);
801833
}
802834

803-
}
835+
}

0 commit comments

Comments
 (0)