unicap support

View: New views
4 Messages — Rating Filter:   Alert me  

unicap support

by Xavier Delacour :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi everyone,

The attached patch implements simple bindings to unicap, a library
that provides support for several devices from The Imaging Source that
aren't standards conforming (one of which I own). It's released under
the GPL, and disabled by default.
http://unicap-imaging.org/compatibility.htm
http://www.theimagingsource.com

I'd like to check this in, but thought I might send a note out before doing so.

Xavier

[unicap.diff]

diff -r feb2e2eefa8a configure.in
--- a/configure.in Sat Apr 26 14:19:54 2008 -0400
+++ b/configure.in Sun Apr 27 16:37:37 2008 -0400
@@ -149,6 +149,12 @@ AC_ARG_WITH([v4l],
             [with_v4l=$withval],
             [with_v4l=auto])
 
+# does the user want OpenCV to use the unicap library?
+AC_ARG_WITH([unicap],
+            [AS_HELP_STRING([--with-unicap],[use unicap (see LICENSE) [no]])],
+            [with_unicap=$withval],
+            [with_unicap=no])
+
 # does the user want OpenCV to use image libraries from OS X 10.4?
 AC_ARG_WITH([imageio],
             [AS_HELP_STRING([--with-imageio],[use ImageIO libraries [automatic]])],
@@ -483,6 +489,21 @@ AC_SUBST(GSTREAMER_CFLAGS)
 AC_SUBST(GSTREAMER_CFLAGS)
 AC_SUBST(GSTREAMER_LIBS)
 AM_CONDITIONAL([BUILD_GSTREAMER], [test x"$have_gstreamer" = "xyes"])
+
+# Check for the unicap library
+if test x"$with_unicap" = "xno"; then
+    have_unicap=no
+else
+ PKG_CHECK_MODULES(UNICAP_PACKAGE,libunicap)
+ AC_SUBST(UNICAP_PACKAGE_LIBS)
+ AC_SUBST(UNICAP_PACKAGE_CFLAGS)
+ PKG_CHECK_MODULES(UCIL_PACKAGE,libucil)
+ AC_SUBST(UCIL_PACKAGE_LIBS)
+ AC_SUBST(UCIL_PACKAGE_CFLAGS)
+ have_unicap=yes
+ AC_DEFINE(HAVE_UNICAP,,[Unicap video capture library])
+fi
+AM_CONDITIONAL([BUILD_UNICAP], [test x"$have_unicap" = "xyes"])
 
 # prefer XINE over FFMPEG for video reading because it is quick, has a cleaner API
 # and allows for easy seeking with some formats
@@ -1025,6 +1046,7 @@ HighGUI configuration ==================
     Use dc1394 & raw1394:     ${have_dc1394}
     Use v4l:                  ${have_v4l}
     Use v4l2:                 ${have_v4l2}
+    Use unicap:               ${have_unicap}
 
 Wrappers for other languages =========================================
     SWIG                      ${SWIG}
diff -r feb2e2eefa8a otherlibs/highgui/Makefile.am
--- a/otherlibs/highgui/Makefile.am Sat Apr 26 14:19:54 2008 -0400
+++ b/otherlibs/highgui/Makefile.am Sun Apr 27 16:37:37 2008 -0400
@@ -5,12 +5,14 @@ EXTRA_DIST = highgui.dsp highgui.vcproj
     cvcap_cmu.cpp cvcap_tyzx.cpp cvcap_vfw.cpp cvcap_mil.cpp     \
     cvcap_qt.cpp cvcap_dc1394.cpp cvcap_ffmpeg.cpp               \
     cvcap_v4l.cpp cvcap_xine.cpp cvcap_images.cpp                \
+    cvcap_unicap.cpp                                             \
     window_carbon.cpp window_gtk.cpp window_w32.cpp              \
     grfmt_imageio.cpp
 
 INCLUDES = -I. -I$(top_srcdir)/cxcore/include \
     -I$(top_srcdir)/cv/include @GTHREAD_CFLAGS@ @GTK_CFLAGS@ \
-    @GSTREAMER_CFLAGS@ @QUICKTIME_CFLAGS@ @CARBON_CFLAGS@
+    @GSTREAMER_CFLAGS@ @QUICKTIME_CFLAGS@ @CARBON_CFLAGS@    \
+    @UNICAP_PACKAGE_CFLAGS@ @UCIL_PACKAGE_CFLAGS@
 
 noinst_HEADERS     = \
     _highgui.h bitstrm.h grfmt_base.h grfmt_bmp.h \
@@ -30,6 +32,12 @@ TMP_V4L=cvcap_v4l.cpp
 TMP_V4L=cvcap_v4l.cpp
 else
 TMP_V4L=
+endif
+
+if BUILD_UNICAP
+TMP_UNICAP=cvcap_unicap.cpp
+else
+TMP_UNICAP=
 endif
 
 if BUILD_FFMPEG
@@ -77,12 +85,13 @@ endif
 
 # convenience library
 lib_highgui_la_SOURCES = \
-    bitstrm.cpp grfmt_base.cpp grfmt_bmp.cpp grfmt_jpeg.cpp      \
-    grfmt_png.cpp grfmt_pxm.cpp grfmt_jpeg2000.cpp grfmt_exr.cpp \
-    grfmt_sunras.cpp grfmt_tiff.cpp image.cpp loadsave.cpp       \
-    precomp.cpp utils.cpp cvcap.cpp cvcap_images.cpp window.cpp  \
-    $(TMP_DC1394) $(TMP_V4L) $(TMP_FFMPEG) $(TMP_GSTREAMER)      \
-    $(TMP_QT) $(TMP_XINE) $(TMP_GTK) $(TMP_CARBON) $(TMP_IMAGEIO)
+    bitstrm.cpp grfmt_base.cpp grfmt_bmp.cpp grfmt_jpeg.cpp       \
+    grfmt_png.cpp grfmt_pxm.cpp grfmt_jpeg2000.cpp grfmt_exr.cpp  \
+    grfmt_sunras.cpp grfmt_tiff.cpp image.cpp loadsave.cpp        \
+    precomp.cpp utils.cpp cvcap.cpp cvcap_images.cpp window.cpp   \
+    $(TMP_DC1394) $(TMP_V4L) $(TMP_FFMPEG) $(TMP_GSTREAMER)       \
+    $(TMP_QT) $(TMP_XINE) $(TMP_GTK) $(TMP_CARBON) $(TMP_IMAGEIO) \
+    $(TMP_UNICAP)
 lib_highgui_la_LDFLAGS = -no-undefined @LDFLAGS@
 
 # real library
@@ -94,5 +103,6 @@ libhighgui_la_LIBADD  = \
     lib_highgui.la \
     $(top_builddir)/cxcore/src/libcxcore.la \
     $(top_builddir)/cv/src/libcv.la         \
-    @GTHREAD_LIBS@ @GTK_LIBS@ @GSTREAMER_LIBS@ @IMAGELIBS@ @FFMPEGLIBS@ \
-    @IEEE1394LIBS@ @QUICKTIME_LIBS@ @CARBON_LIBS@ @XINE_LIBS@ @LTLIBOBJS@
+    @GTHREAD_LIBS@ @GTK_LIBS@ @GSTREAMER_LIBS@ @IMAGELIBS@ @FFMPEGLIBS@   \
+    @IEEE1394LIBS@ @QUICKTIME_LIBS@ @CARBON_LIBS@ @XINE_LIBS@ @LTLIBOBJS@ \
+    @UNICAP_PACKAGE_LIBS@ @UCIL_PACKAGE_LIBS@
diff -r feb2e2eefa8a otherlibs/highgui/_highgui.h
--- a/otherlibs/highgui/_highgui.h Sat Apr 26 14:19:54 2008 -0400
+++ b/otherlibs/highgui/_highgui.h Sun Apr 27 16:37:37 2008 -0400
@@ -211,4 +211,9 @@ CvVideoWriter* cvCreateVideoWriter_QT (
                                         double fps, CvSize frameSize, int is_color );
 #endif
 
+#ifdef HAVE_UNICAP
+CvCapture * cvCaptureFromCAM_Unicap  (const int     index);
+
+#endif
+
 #endif /* __HIGHGUI_H_ */
diff -r feb2e2eefa8a otherlibs/highgui/cvcap.cpp
--- a/otherlibs/highgui/cvcap.cpp Sat Apr 26 14:19:54 2008 -0400
+++ b/otherlibs/highgui/cvcap.cpp Sun Apr 27 16:37:37 2008 -0400
@@ -127,6 +127,7 @@ CV_IMPL CvCapture * cvCaptureFromCAM (in
  CV_CAP_VFW,        // identical to CV_CAP_V4L
  CV_CAP_MIL,
  CV_CAP_QT,
+ CV_CAP_UNICAP,
  -1
  };
 
@@ -211,6 +212,15 @@ CV_IMPL CvCapture * cvCaptureFromCAM (in
  return capture;
  break;
  #endif
+
+ #ifdef HAVE_UNICAP
+ case CV_CAP_UNICAP:
+  capture = cvCaptureFromCAM_Unicap (index);
+  if (capture)
+    return capture;
+  break;
+ #endif
+
  }
  }
 
diff -r feb2e2eefa8a otherlibs/highgui/cvcap_unicap.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/otherlibs/highgui/cvcap_unicap.cpp Sun Apr 27 16:37:37 2008 -0400
@@ -0,0 +1,303 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                        Intel License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2008, Xavier Delacour, all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+//   * Redistribution's of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//
+//   * Redistribution's in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation
+//     and/or other materials provided with the distribution.
+//
+//   * The name of Intel Corporation may not be used to endorse or promote products
+//     derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+// 2008-04-27 Xavier Delacour <xavier.delacour@...>
+
+#include <_highgui.h>
+#include <unistd.h>
+#include <unicap.h>
+extern "C" {
+#include <ucil.h>
+}
+
+#ifdef NDEBUG
+#define CV_WARN(message)
+#else
+#define CV_WARN(message) fprintf(stderr, "warning: %s (%s:%d)\n", message, __FILE__, __LINE__)
+#endif
+
+typedef struct CvCapture_Unicap
+{
+  CvCaptureVTable *vtable;
+
+  bool device_initialized;
+
+  int desired_device;
+  int desired_format;
+  CvSize desired_size;
+  bool convert_rgb;
+
+  unicap_handle_t handle;
+  unicap_device_t device;
+  unicap_format_t format_spec;
+  unicap_format_t format;
+  unicap_data_buffer_t raw_buffer;
+  unicap_data_buffer_t buffer;
+
+  IplImage *raw_frame;
+  IplImage *frame;
+} CvCapture_Unicap;
+
+static bool icvShutdownDevice(CvCapture_Unicap *cap) {
+  CV_FUNCNAME("icvShutdownDevice");
+  __BEGIN__;
+
+  if (!SUCCESS(unicap_stop_capture(cap->handle)))
+    CV_ERROR(CV_StsError, "unicap: failed to stop capture on device\n");
+  
+  if (!SUCCESS(unicap_close(cap->handle)))
+    CV_ERROR(CV_StsError, "unicap: failed to close the device\n");
+
+  cvReleaseImage(&cap->raw_frame);
+  cvReleaseImage(&cap->frame);
+
+  cap->device_initialized = false;
+
+  return true;
+  __END__;
+  return false;
+}
+
+static bool icvInitDevice(CvCapture_Unicap *cap) {
+  CV_FUNCNAME("icvInitDevice");
+  __BEGIN__;
+
+  if (cap->device_initialized && !icvShutdownDevice(cap))
+    return false;
+
+  if(!SUCCESS(unicap_enumerate_devices(NULL, &cap->device, cap->desired_device)))
+    CV_ERROR(CV_StsError, "unicap: failed to get info for device\n");
+
+  if(!SUCCESS(unicap_open( &cap->handle, &cap->device)))
+    CV_ERROR(CV_StsError, "unicap: failed to open device\n");
+
+  unicap_void_format(&cap->format_spec);
+
+  if (!SUCCESS(unicap_enumerate_formats(cap->handle, &cap->format_spec, &cap->format, cap->desired_format))) {
+    icvShutdownDevice(cap);
+    CV_ERROR(CV_StsError, "unicap: failed to get video format\n");
+  }
+
+  int i;
+  for (i = cap->format.size_count - 1; i > 0; i--)
+    if (cap->format.sizes[i].width == cap->desired_size.width &&
+ cap->format.sizes[i].height == cap->desired_size.height)
+      break;
+  cap->format.size.width = cap->format.sizes[i].width;
+  cap->format.size.height = cap->format.sizes[i].height;
+
+  if (!SUCCESS(unicap_set_format(cap->handle, &cap->format))) {
+    icvShutdownDevice(cap);
+    CV_ERROR(CV_StsError, "unicap: failed to set video format\n");
+  }
+
+  memset(&cap->raw_buffer, 0x0, sizeof(unicap_data_buffer_t));
+  cap->raw_frame = cvCreateImage(cvSize(cap->format.size.width,
+ cap->format.size.height),
+  8, cap->format.bpp / 8);
+  memcpy(&cap->raw_buffer.format, &cap->format, sizeof(cap->raw_buffer.format));
+  cap->raw_buffer.data = (unsigned char*)cap->raw_frame->imageData;
+  cap->raw_buffer.buffer_size = cap->format.size.width *
+    cap->format.size.height * cap->format.bpp / 8;
+
+  memset(&cap->buffer, 0x0, sizeof(unicap_data_buffer_t));
+  memcpy(&cap->buffer.format, &cap->format, sizeof(cap->buffer.format));
+
+  cap->buffer.format.fourcc = UCIL_FOURCC('B','G','R','3');
+  cap->buffer.format.bpp = 24;
+  // * todo support greyscale output
+  //    cap->buffer.format.fourcc = UCIL_FOURCC('G','R','E','Y');
+  //    cap->buffer.format.bpp = 8;
+
+  cap->frame = cvCreateImage(cvSize(cap->buffer.format.size.width,
+    cap->buffer.format.size.height),
+      8, cap->buffer.format.bpp / 8);
+  cap->buffer.data = (unsigned char*)cap->frame->imageData;
+  cap->buffer.buffer_size = cap->buffer.format.size.width *
+    cap->buffer.format.size.height * cap->buffer.format.bpp / 8;
+
+  if(!SUCCESS(unicap_start_capture(cap->handle))) {
+    icvShutdownDevice(cap);
+    CV_ERROR(CV_StsError, "unicap: failed to start capture on device\n");
+  }
+
+  cap->device_initialized = true;
+  return true;
+  __END__;
+  return false;
+}
+
+static void icvClose_Unicap(CvCapture_Unicap *cap) {
+  icvShutdownDevice(cap);
+  cvFree(&cap);
+}
+
+static int icvGrabFrame_Unicap(CvCapture_Unicap *cap) {
+  CV_FUNCNAME("icvGrabFrame_Unicap");
+  __BEGIN__;
+
+  unicap_data_buffer_t *returned_buffer;
+
+  int retry_count = 100;
+
+  while (retry_count--) {
+    if(!SUCCESS(unicap_queue_buffer(cap->handle, &cap->raw_buffer)))
+      CV_ERROR(CV_StsError, "unicap: failed to queue a buffer on device\n");
+
+    if(SUCCESS(unicap_wait_buffer(cap->handle, &returned_buffer)))
+      return 1;
+    
+    CV_WARN("unicap: failed to wait for buffer on device\n");
+    usleep(100 * 1000);
+  }
+
+  __END__;
+  return 0;
+}
+
+static IplImage *icvRetrieveFrame_Unicap(CvCapture_Unicap *cap) {
+  if (cap->convert_rgb) {
+    ucil_convert_buffer(&cap->buffer, &cap->raw_buffer);
+    return cap->frame;
+  }
+  return cap->raw_frame;
+}
+
+static double icvGetProperty_Unicap(CvCapture_Unicap *cap, int id) {
+  switch (id) {
+  case CV_CAP_PROP_POS_MSEC: break;
+  case CV_CAP_PROP_POS_FRAMES: break;
+  case CV_CAP_PROP_POS_AVI_RATIO: break;
+  case CV_CAP_PROP_FRAME_WIDTH:
+    return cap->desired_size.width;
+  case CV_CAP_PROP_FRAME_HEIGHT:
+    return cap->desired_size.height;
+  case CV_CAP_PROP_FPS: break;
+  case CV_CAP_PROP_FOURCC: break;
+  case CV_CAP_PROP_FRAME_COUNT: break;
+  case CV_CAP_PROP_FORMAT:
+    return cap->desired_format;
+  case CV_CAP_PROP_MODE: break;
+  case CV_CAP_PROP_BRIGHTNESS: break;
+  case CV_CAP_PROP_CONTRAST: break;
+  case CV_CAP_PROP_SATURATION: break;
+  case CV_CAP_PROP_HUE: break;
+  case CV_CAP_PROP_GAIN: break;
+  case CV_CAP_PROP_CONVERT_RGB:
+    return cap->convert_rgb;
+  }
+
+  return 0;
+}
+
+static int icvSetProperty_Unicap(CvCapture_Unicap *cap, int id, double value) {
+  bool reinit = false;
+
+  switch (id) {
+  case CV_CAP_PROP_POS_MSEC: break;
+  case CV_CAP_PROP_POS_FRAMES: break;
+  case CV_CAP_PROP_POS_AVI_RATIO: break;
+  case CV_CAP_PROP_FRAME_WIDTH:
+    cap->desired_size.width = (int)value;
+    reinit = true;
+    break;
+  case CV_CAP_PROP_FRAME_HEIGHT:
+    cap->desired_size.height = (int)value;
+    reinit = true;
+    break;
+  case CV_CAP_PROP_FPS: break;
+  case CV_CAP_PROP_FOURCC: break;
+  case CV_CAP_PROP_FRAME_COUNT: break;
+  case CV_CAP_PROP_FORMAT:
+    cap->desired_format = id;
+    reinit = true;
+    break;
+  case CV_CAP_PROP_MODE: break;
+  case CV_CAP_PROP_BRIGHTNESS: break;
+  case CV_CAP_PROP_CONTRAST: break;
+  case CV_CAP_PROP_SATURATION: break;
+  case CV_CAP_PROP_HUE: break;
+  case CV_CAP_PROP_GAIN: break;
+  case CV_CAP_PROP_CONVERT_RGB:
+    cap->convert_rgb = value != 0;
+    break;
+  }
+
+  if (reinit && !icvInitDevice(cap))
+    return 0;
+
+  return 1;
+}
+
+static CvCaptureVTable capture_vtable =
+  {
+    6,
+    ( CvCaptureCloseFunc ) icvClose_Unicap,
+    ( CvCaptureGrabFrameFunc ) icvGrabFrame_Unicap,
+    ( CvCaptureRetrieveFrameFunc ) icvRetrieveFrame_Unicap,
+    ( CvCaptureGetPropertyFunc ) icvGetProperty_Unicap,
+    ( CvCaptureSetPropertyFunc ) icvSetProperty_Unicap,
+    ( CvCaptureGetDescriptionFunc ) 0
+  };
+
+
+CvCapture * cvCaptureFromCAM_Unicap (const int index) {
+  CvCapture_Unicap *cap = 0;
+
+  cap = (CvCapture_Unicap *)cvAlloc(sizeof(CvCapture_Unicap));
+  memset(cap, 0, sizeof(CvCapture_Unicap));
+
+  cap->device_initialized = false;
+
+  cap->desired_device = index < 0 ? 0 : index;
+  cap->desired_format = 0;
+  cap->desired_size = cvSize(320, 240);
+  cap->convert_rgb = true;
+  
+  if (!icvInitDevice(cap)) {
+    cvFree(&cap);
+    return 0;
+  }
+
+  cap->vtable = &capture_vtable;
+
+  return (CvCapture *)cap;
+}
diff -r feb2e2eefa8a otherlibs/highgui/highgui.h
--- a/otherlibs/highgui/highgui.h Sat Apr 26 14:19:54 2008 -0400
+++ b/otherlibs/highgui/highgui.h Sun Apr 27 16:37:37 2008 -0400
@@ -240,6 +240,8 @@ CVAPI(CvCapture*) cvCreateFileCapture( c
 #define CV_TYZX_Z       403
 
 #define CV_CAP_QT       500   // QuickTime
+
+#define CV_CAP_UNICAP   600   // Unicap drivers
 
 /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
 CVAPI(CvCapture*) cvCreateCameraCapture( int index );


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: unicap support

by Nils Hasler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Xavier,

On Sunday 27 April 2008 22:47, Xavier Delacour wrote:
> The attached patch implements simple bindings to unicap, a library
> that provides support for several devices from The Imaging Source that
> aren't standards conforming (one of which I own). It's released under
> the GPL, and disabled by default.
> http://unicap-imaging.org/compatibility.htm
> http://www.theimagingsource.com
>
> I'd like to check this in, but thought I might send a note out before doing
> so.

I like the simplicity of the interface. I think you can safely add it. The
dual GPL/commercial license is annoying but disabling it by default should be
safe.

I do see one more general problem for meta-libraries like unicap or gstreamer.
It is non-obvious in which order camera drivers are enumerated: first
firewire and then v4l, or vice versa.

Maybe we should consider adding a camera enumeration function.

Apart from that do submit your patch.

cheers,
nils

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: unicap support

by Xavier Delacour :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Apr 27, 2008 at 6:04 PM, Nils Hasler <nils.hasler@...> wrote:

> Hi Xavier,
>
>
>
>  On Sunday 27 April 2008 22:47, Xavier Delacour wrote:
>  > The attached patch implements simple bindings to unicap, a library
>  > that provides support for several devices from The Imaging Source that
>  > aren't standards conforming (one of which I own). It's released under
>  > the GPL, and disabled by default.
>  > http://unicap-imaging.org/compatibility.htm
>  > http://www.theimagingsource.com
>  >
>  > I'd like to check this in, but thought I might send a note out before doing
>  > so.
>
>  I like the simplicity of the interface. I think you can safely add it. The
>  dual GPL/commercial license is annoying but disabling it by default should be
>  safe.
>
>  I do see one more general problem for meta-libraries like unicap or gstreamer.
>  It is non-obvious in which order camera drivers are enumerated: first
>  firewire and then v4l, or vice versa.
>
>  Maybe we should consider adding a camera enumeration function.

I would be in favor. A similar facility that enumerates camera options
would also be nice (modes, formats, frame sizes, fps, etc).

The only difficulty is choosing common descriptor structures. For
example, unicap uses the following to describe a device,

struct unicap_device_t
{
        char identifier[128];
        char model_name[128];
        char vendor_name[128];
               
        unsigned long long model_id;
        unsigned int vendor_id;
       
        char cpi_layer[1024];
        char device[1024];
               
        unsigned int flags;
};

For devices at least, something simple like two strings would probably
work and keep it simple (pretty print name and unique device name).

Xavier

>
>  Apart from that do submit your patch.
>
>  cheers,
>  nils
>

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: unicap support

by Nils Hasler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/4/28 Xavier Delacour <xavier.delacour@...>:

> On Sun, Apr 27, 2008 at 6:04 PM, Nils Hasler <nils.hasler@...> wrote:
>  >  Maybe we should consider adding a camera enumeration function.
>
>  I would be in favor. A similar facility that enumerates camera options
>  would also be nice (modes, formats, frame sizes, fps, etc).
>
>  The only difficulty is choosing common descriptor structures. For
>  example, unicap uses the following to describe a device,
>
>  struct unicap_device_t
>  {
>         char identifier[128];
>         char model_name[128];
>         char vendor_name[128];
>
>         unsigned long long model_id;
>         unsigned int vendor_id;
>
>         char cpi_layer[1024];
>         char device[1024];
>
>         unsigned int flags;
>  };

This looks fairly similar to the structure used by DC1394.
The V4L structure is simpler. Basically just a pretty name and some flags.
On Windows strings with device name and version are returned.

>  For devices at least, something simple like two strings would probably
>  work and keep it simple (pretty print name and unique device name).

Actually, instead of a unique device name the id of the device could
be used which identifies driver and camera. This would be the number
that is passed to cvCreateCameraCapture().
I suggest adding a string identifying the driver because the same
camera may show up several times when different drivers are available.
Alternatively, we could pack that into the pretty name.

struct CvCameraInfo {
    char *name;  // pretty identifier of camera/capture card
    char *driver;  // interface name such as unicap, DC1394, V4L, VfW,
Quicktime, ...
    int id;  // numerical identifier of camera. For example 301 for
the second Firewire camera. Pass this to cvCreateCameraCapture().
};

CvCameraInfo *cvEnumCameras(int *numcams, int interface = CV_CAP_ANY);

Returns an array of CvCameraInfo structures.
Interface can be one of CV_CAP_ANY, CV_CAP_MIL, CV_CAP_VFW, ...
If interface != CV_CAP_ANY, only cameras supported by the given
interface are returned.
The array returned by the function is stored completely in a single
buffer (CvMemStorage). That way it can be freed with a single call.

Generally I think it is a good idea to be able to enumerate camera
capabilities. I am not sure how to best enumerate available modes,
framerates and resolutions though. There may be quite a few possible
configurations and sometimes returning intervals may be more
appropriate than enumeration.

cheers,
nils

--
Max-Planck-Institut Informatik
Campus E1 4, D-66123 Saarbrücken
Phone: +49 681 9325-420
www.mpi-inf.mpg.de/~hasler

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel