]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
integrated Prosilica GigE video capturing module by Justin G. Eskesen)
authorvp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Mon, 25 Jan 2010 16:39:22 +0000 (16:39 +0000)
committervp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Mon, 25 Jan 2010 16:39:22 +0000 (16:39 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@2619 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/CMakeLists.txt
opencv/include/opencv/highgui.h
opencv/src/highgui/CMakeLists.txt
opencv/src/highgui/_highgui.h
opencv/src/highgui/cvcap.cpp
opencv/src/highgui/cvcap_pvapi.cpp [new file with mode: 0644]

index 31058248d2d2b5db07cb12252a3083704f9916c4..6c9043a01f8194ab7016de8e0bf9b9de382df33f 100644 (file)
@@ -240,6 +240,7 @@ set(WITH_TIFF ON CACHE BOOL "Include TIFF support")
 if(UNIX)\r
     set(WITH_FFMPEG ON CACHE BOOL "Include FFMPEG support")\r
     set(WITH_UNICAP ON CACHE BOOL "Include Unicap support")\r
+    set(WITH_PVAPI ON CACHE BOOL "Include Prosilica GigE support")\r
     set(WITH_GTK ON CACHE BOOL "Include GTK support")\r
     set(WITH_GSTREAMER ON CACHE BOOL "Include Gstreamer support")\r
     set(WITH_1394 ON CACHE BOOL "Include IEEE1394 support")\r
@@ -310,6 +311,15 @@ if(UNIX)
     else()\r
       set(HAVE_UNICAP FALSE)\r
     endif()\r
+    \r
+    if(WITH_PVAPI)\r
+      find_path(PVAPI_INCLUDE_PATH "PvApi.h"\r
+                PATHS "/usr/include" "/usr/local/include"\r
+                DOC "The path to PvAPI header")\r
+      if(PVAPI_INCLUDE_PATH)\r
+        set(HAVE_PVAPI 1)\r
+      endif()\r
+    endif()\r
 \r
     set(HAVE_FFMPEG 0)\r
     if(WITH_FFMPEG)\r
@@ -971,6 +981,7 @@ message(STATUS "      swscale:                 ${HAVE_FFMPEG_SWSCALE}")
 message(STATUS "      gentoo-style:            ${HAVE_GENTOO_FFMPEG}")\r
 message(STATUS "    GStreamer:                 ${HAVE_GSTREAMER}")\r
 message(STATUS "    UniCap:                    ${HAVE_UNICAP}")\r
+message(STATUS "    PvAPI:                     ${HAVE_PVAPI}")\r
 if(HAVE_LIBV4L)\r
 message(STATUS "    V4L/V4L2:                  Using libv4l")\r
 else()\r
index f2649a28972ccb8a46e5662bc7c8831e8714817c..237d1548e5646ffad29e9018260aea5469128599 100644 (file)
@@ -266,6 +266,8 @@ CVAPI(CvCapture*) cvCreateFileCapture( const char* filename );
 
 #define CV_CAP_DSHOW    700   // DirectShow (via videoInput)
 
+#define CV_CAP_PVAPI    800   // PvAPI, Prosilica GigE SDK
+
 /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
 CVAPI(CvCapture*) cvCreateCameraCapture( int index );
 
index aa9129dad62a9a1591d065397d272b9962c51b6a..f99c897ad4e75ff23b8443e077d910171adc006d 100644 (file)
@@ -93,6 +93,12 @@ if(UNIX)
     if(HAVE_FFMPEG)
         set(highgui_srcs ${highgui_srcs} cvcap_ffmpeg.cpp)
     endif()
+    
+    if(HAVE_PVAPI)
+        add_definitions(-DHAVE_PVAPI)
+        set(highgui_srcs cvcap_pvapi.cpp ${highgui_srcs})
+        set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} PvAPI)
+    endif()
 
     if(HAVE_GSTREAMER)
         set(highgui_srcs ${highgui_srcs} cvcap_gstreamer.cpp)
@@ -235,8 +241,8 @@ endif()
 if(WIN32)
        target_link_libraries(${the_target} comctl32 gdi32 ole32)
        
-       if (MSVC)\r
-               target_link_libraries(${the_target} vfw32)\r
+       if (MSVC)
+               target_link_libraries(${the_target} vfw32)
        endif()
 
        if(MINGW)
index f89f5bb87224eb17f72320fc18c077fd5ca57050..173f433c658c2cead2cad23bda5dc437ea8117de 100644 (file)
@@ -155,6 +155,7 @@ CvVideoWriter* cvCreateVideoWriter_QT ( const char* filename, int fourcc,
                                         double fps, CvSize frameSize, int is_color );
 
 CvCapture * cvCreateCameraCapture_Unicap  (const int     index);
+CvCapture * cvCreateCameraCapture_PvAPI  (const int     index);
 CvVideoWriter* cvCreateVideoWriter_GStreamer( const char* filename, int fourcc,
                                             double fps, CvSize frameSize, int is_color );
 /*namespace cv
index 75a785b0a060b4868b99102dac22e97ee05d77c8..f1c5a57401e429c5eea0d3f01754a6736a681ea6 100644 (file)
@@ -101,43 +101,44 @@ CV_IMPL int cvGetCaptureDomain( CvCapture* capture)
  */
 CV_IMPL CvCapture * cvCreateCameraCapture (int index)
 {
-       int  domains[] =
-       {
+    int  domains[] =
+    {
 #ifdef HAVE_VIDEOINPUT
         CV_CAP_DSHOW,
 #endif
-               CV_CAP_IEEE1394,   // identical to CV_CAP_DC1394
-               CV_CAP_STEREO,
-               CV_CAP_VFW,        // identical to CV_CAP_V4L
-               CV_CAP_MIL,
-               CV_CAP_QT,
-               CV_CAP_UNICAP,
-               -1
-       };
-
-       // interpret preferred interface (0 = autodetect)
-       int pref = (index / 100) * 100;
-       if (pref)
-       {
-               domains[0]=pref;
-               index %= 100;
-               domains[1]=-1;
-       }
-
-       // try every possibly installed camera API
-       for (int i = 0; domains[i] >= 0; i++)
-       {
+        CV_CAP_IEEE1394,   // identical to CV_CAP_DC1394
+        CV_CAP_STEREO,
+        CV_CAP_PVAPI,
+        CV_CAP_VFW,        // identical to CV_CAP_V4L
+        CV_CAP_MIL,
+        CV_CAP_QT,
+        CV_CAP_UNICAP,
+        -1
+    };
+
+    // interpret preferred interface (0 = autodetect)
+    int pref = (index / 100) * 100;
+    if (pref)
+    {
+        domains[0]=pref;
+        index %= 100;
+        domains[1]=-1;
+    }
+
+    // try every possibly installed camera API
+    for (int i = 0; domains[i] >= 0; i++)
+    {
         #if defined(HAVE_VIDEOINPUT) || defined(HAVE_TYZX) || defined(HAVE_VFW) || \
-           defined(HAVE_CAMV4L) || defined (HAVE_CAMV4L2) || defined(HAVE_GSTREAMER) || \
-           defined(HAVE_DC1394_2) || defined(HAVE_DC1394) || defined(HAVE_CMU1394) || \
-           defined(HAVE_GSTREAMER) || defined(HAVE_MIL) || defined(HAVE_QUICKTIME) || \
-           defined(HAVE_UNICAP)
-               // local variable to memorize the captured device
-               CvCapture *capture;
-       #endif
+        defined(HAVE_CAMV4L) || defined (HAVE_CAMV4L2) || defined(HAVE_GSTREAMER) || \
+        defined(HAVE_DC1394_2) || defined(HAVE_DC1394) || defined(HAVE_CMU1394) || \
+        defined(HAVE_GSTREAMER) || defined(HAVE_MIL) || defined(HAVE_QUICKTIME) || \
+        defined(HAVE_UNICAP) || defined(HAVE_PVAPI)
+        // local variable to memorize the captured device
+        CvCapture *capture;
+        #endif
 
-               switch (domains[i])
-               {
+        switch (domains[i])
+        {
         #ifdef HAVE_VIDEOINPUT
         case CV_CAP_DSHOW:
             capture = cvCreateCameraCapture_DShow (index);
@@ -146,88 +147,96 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
             break;
         #endif
 
-               #ifdef HAVE_TYZX
-               case CV_CAP_STEREO:
-                       capture = cvCreateCameraCapture_TYZX (index);
-                       if (capture)
-                               return capture;
-                       break;
-               #endif
-
-               case CV_CAP_VFW:
-               #ifdef HAVE_VFW
-                       capture = cvCreateCameraCapture_VFW (index);
-                       if (capture)
-                               return capture;
-               #endif
-               #if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)
-                       capture = cvCreateCameraCapture_V4L (index);
-                       if (capture)
-                               return capture;
-               #endif
-               #ifdef HAVE_GSTREAMER
-                       capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, 0);
-                       if (capture)
-                               return capture;
-                       capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L, 0);
-                       if (capture)
-                               return capture;
-               #endif
-                       break;
-
-               case CV_CAP_FIREWIRE:
-               #ifdef HAVE_DC1394_2
-                       capture = cvCreateCameraCapture_DC1394_2 (index);
-                       if (capture)
-                               return capture;
-               #endif
-               #ifdef HAVE_DC1394
-                       capture = cvCreateCameraCapture_DC1394 (index);
-                       if (capture)
-                               return capture;
-               #endif
-               #ifdef HAVE_CMU1394
-                       capture = cvCreateCameraCapture_CMU (index);
-                       if (capture)
-                               return capture;
-               #endif
-       /* Re-enable again when gstreamer 1394 support will land in the backend code    
-               #ifdef HAVE_GSTREAMER
-                       capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_1394, 0);
-                       if (capture)
-                               return capture;
-               #endif
-       */ 
-                       break;
-               #ifdef HAVE_MIL
-               case CV_CAP_MIL:
-                       capture = cvCreateCameraCapture_MIL (index);
-                       if (capture)
-                               return capture;
-                       break;
-               #endif
-
-               #ifdef HAVE_QUICKTIME
-               case CV_CAP_QT:
-                       capture = cvCreateCameraCapture_QT (index);
-                       if (capture)
-                               return capture;
-                       break;
-               #endif
-
-               #ifdef HAVE_UNICAP
-               case CV_CAP_UNICAP:
-                 capture = cvCreateCameraCapture_Unicap (index);
-                 if (capture)
-                   return capture;
-                 break;
-               #endif
-
-               }
-       }
-
-       // failed open a camera
-       return 0;
+        #ifdef HAVE_TYZX
+        case CV_CAP_STEREO:
+            capture = cvCreateCameraCapture_TYZX (index);
+            if (capture)
+                return capture;
+            break;
+        #endif
+
+        case CV_CAP_VFW:
+        #ifdef HAVE_VFW
+            capture = cvCreateCameraCapture_VFW (index);
+            if (capture)
+                return capture;
+        #endif
+        #if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)
+            capture = cvCreateCameraCapture_V4L (index);
+            if (capture)
+                return capture;
+        #endif
+        #ifdef HAVE_GSTREAMER
+            capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, 0);
+            if (capture)
+                return capture;
+            capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L, 0);
+            if (capture)
+                return capture;
+        #endif
+            break;
+
+        case CV_CAP_FIREWIRE:
+        #ifdef HAVE_DC1394_2
+            capture = cvCreateCameraCapture_DC1394_2 (index);
+            if (capture)
+                return capture;
+        #endif
+        #ifdef HAVE_DC1394
+            capture = cvCreateCameraCapture_DC1394 (index);
+            if (capture)
+                return capture;
+        #endif
+        #ifdef HAVE_CMU1394
+            capture = cvCreateCameraCapture_CMU (index);
+            if (capture)
+                return capture;
+        #endif
+    /* Re-enable again when gstreamer 1394 support will land in the backend code       
+        #ifdef HAVE_GSTREAMER
+            capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_1394, 0);
+            if (capture)
+                return capture;
+        #endif
+    */ 
+            break;
+        #ifdef HAVE_MIL
+        case CV_CAP_MIL:
+            capture = cvCreateCameraCapture_MIL (index);
+            if (capture)
+                return capture;
+            break;
+        #endif
+
+        #ifdef HAVE_QUICKTIME
+        case CV_CAP_QT:
+            capture = cvCreateCameraCapture_QT (index);
+            if (capture)
+                return capture;
+            break;
+        #endif
+
+        #ifdef HAVE_UNICAP
+        case CV_CAP_UNICAP:
+        capture = cvCreateCameraCapture_Unicap (index);
+        if (capture)
+            return capture;
+        break;
+        #endif
+        
+        #ifdef HAVE_PVAPI
+        case CV_CAP_PVAPI:
+        capture = cvCreateCameraCapture_PvAPI (index);
+        if (capture)
+            return capture;
+        break;
+        #endif
+        
+        }
+    }
+
+    // failed open a camera
+    return 0;
 }
 
 /**
diff --git a/opencv/src/highgui/cvcap_pvapi.cpp b/opencv/src/highgui/cvcap_pvapi.cpp
new file mode 100644 (file)
index 0000000..e746f45
--- /dev/null
@@ -0,0 +1,249 @@
+////////////////////////////////////////////////////////////////////////////////////////
+//
+//  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) 2000, Intel Corporation, 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.
+//
+//
+
+//
+// The code has been contributed by Justin G. Eskesen on 2010 Jan
+//
+
+#include "_highgui.h"
+#include <cv.h>
+#ifdef HAVE_PVAPI
+#if !defined WIN32 && !defined _WIN32 && !defined _LINUX
+#define _LINUX
+#endif
+
+#if defined(_x64) || defined (__x86_64) || defined (_WIN64)
+#define _x64 1
+#endif
+
+#include <PvApi.h>
+
+#define MAX_CAMERAS 10
+
+/********************* Capturing video from camera via PvAPI *********************/
+
+class CvCaptureCAM_PvAPI : public CvCapture
+{
+public:
+    CvCaptureCAM_PvAPI();
+    virtual ~CvCaptureCAM_PvAPI() 
+    {
+        close();
+    }
+
+    virtual bool open( int index );
+    virtual void close();
+    virtual double getProperty(int);
+    virtual bool setProperty(int, double);
+    virtual bool grabFrame();
+    virtual IplImage* retrieveFrame(int);
+    virtual int getCaptureDomain() 
+    {
+        return CV_CAP_PVAPI;
+    }
+
+protected:
+    typedef struct
+    {
+        unsigned long   UID;
+        tPvHandle       Handle;
+        tPvFrame        Frame;
+
+    } tCamera;
+    IplImage *frame;
+    tCamera Camera;
+    tPvErr          Errcode;
+
+
+};
+
+
+CvCaptureCAM_PvAPI::CvCaptureCAM_PvAPI()
+{
+
+}
+
+void CvCaptureCAM_PvAPI::close()
+{
+
+    // Stop the acquisition & free the camera
+    PvCommandRun(Camera.Handle, "AcquisitionStop");
+
+    PvCaptureEnd(Camera.Handle);
+    PvCameraClose(Camera.Handle);
+
+    cvReleaseImage(&frame);
+}
+
+// Initialize camera input
+bool CvCaptureCAM_PvAPI::open( int index )
+{
+
+    tPvCameraInfo cameraInfo[MAX_CAMERAS];
+    if (PvInitialize())
+        return false;
+        
+    usleep(250000);
+    
+    //close();
+    int numCameras = PvCameraList(cameraInfo, MAX_CAMERAS, NULL);
+    if (numCameras <= 0 || index >= numCameras)
+        return false;
+
+    Camera.UID = cameraInfo[index].UniqueId;
+    if (PvCameraOpen(Camera.UID, ePvAccessMaster, &(Camera.Handle))==ePvErrSuccess)
+    {
+    
+
+        //Set Pixel Format to BRG24 to follow conventions 
+        Errcode = PvAttrEnumSet(Camera.Handle, "PixelFormat", "Bgr24");
+        if (Errcode != ePvErrSuccess)
+        {
+            fprintf(stderr, "PvAPI: couldn't set PixelFormat to Bgr24\n");
+            return NULL;
+        }
+
+        tPvUint32 frameWidth, frameHeight, frameSize;
+
+        PvAttrUint32Get(Camera.Handle, "TotalBytesPerFrame", &frameSize);
+        PvAttrUint32Get(Camera.Handle, "Width", &frameWidth);
+        PvAttrUint32Get(Camera.Handle, "Height", &frameHeight);
+        
+
+        // Create an image (24 bits RGB Color image)
+        frame = cvCreateImage(cvSize(frameWidth, frameHeight), IPL_DEPTH_8U, 3);
+        frame->widthStep = frameWidth*3;
+
+        Camera.Frame.ImageBufferSize = frameSize;
+        Camera.Frame.ImageBuffer = frame->imageData;
+
+        // Start the camera
+        PvCaptureStart(Camera.Handle);
+
+        // Set the camera to capture continuously
+        if(PvAttrEnumSet(Camera.Handle, "AcquisitionMode", "Continuous")!= ePvErrSuccess)
+        {
+            fprintf(stderr,"Could not set Prosilica Acquisition Mode\n");
+            return false;
+        }
+        
+        if(PvCommandRun(Camera.Handle, "AcquisitionStart")!= ePvErrSuccess)
+        {
+            fprintf(stderr,"Could not start Prosilica acquisition\n");
+            return false;
+        }
+        
+        if(PvAttrEnumSet(Camera.Handle, "FrameStartTriggerMode", "Freerun")!= ePvErrSuccess)
+        {
+            fprintf(stderr,"Error setting Prosilica trigger to \"Freerun\"");
+            return false;
+        }
+        
+        return true;
+    }
+    return false;
+
+}
+
+bool CvCaptureCAM_PvAPI::grabFrame()
+{
+    return PvCaptureQueueFrame(Camera.Handle, &(Camera.Frame), NULL) == ePvErrSuccess;
+}
+
+
+IplImage* CvCaptureCAM_PvAPI::retrieveFrame(int)
+{
+
+    return (PvCaptureWaitForFrameDone(Camera.Handle, &(Camera.Frame), 1000) == ePvErrSuccess) 
+       ? frame : NULL;
+}
+
+double CvCaptureCAM_PvAPI::getProperty( int property_id )
+{
+    tPvUint32 nTemp;
+
+    switch ( property_id )
+    {
+    case CV_CAP_PROP_FRAME_WIDTH:
+        PvAttrUint32Get(Camera.Handle, "Width", &nTemp);
+        return (double)nTemp;
+    case CV_CAP_PROP_FRAME_HEIGHT:
+        PvAttrUint32Get(Camera.Handle, "Height", &nTemp);
+        return (double)nTemp;
+    }
+    return -1.0;
+}
+
+bool CvCaptureCAM_PvAPI::setProperty( int property_id, double value )
+{
+    switch ( property_id )
+    {
+    /*  TODO: Camera works, but IplImage must be modified for the new size
+    case CV_CAP_PROP_FRAME_WIDTH:
+        PvAttrUint32Set(Camera.Handle, "Width", (tPvUint32)value);
+        break;
+    case CV_CAP_PROP_FRAME_HEIGHT:
+        PvAttrUint32Set(Camera.Handle, "Heigth", (tPvUint32)value);
+        break;
+    */
+    default:
+        return false;
+    }
+    return true;
+}
+
+
+CvCapture* cvCreateCameraCapture_PvAPI( int index )
+{
+    CvCaptureCAM_PvAPI* capture = new CvCaptureCAM_PvAPI;
+
+    if ( capture->open( index ))
+        return capture;
+
+    delete capture;
+    return NULL;
+}
+
+#ifdef _MSC_VER
+#pragma comment(lib, "PvAPI.lib")
+#endif
+
+#endif