Ask Your Question
0

Allied Vision VIMBA and OpenCV

asked 2014-04-25 02:48:59 -0600

Julien Seinturier gravatar image

Hello,

I saw that OpenCV can deal with Allied Vision PvAPI to grab data for GigaE cameras but can anyone give me a sample of code that grab a frame for a camera and srote it within a cv::MAt object ?

More over, for now PvAPI has been replaced by VIMBA SDK from Allied Vision. Do anyone has already used this SDK with OpenCV and do anyone has a sample of code that grab a frame for a camera and srote it within a cv::MAt object ?

Thanks a lot,

Julien

edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
1

answered 2014-11-05 14:11:27 -0600

Sorry, I cannot post the complete working code (I wrote it in office and I'm not allowed to post it here and at home, I only have a simple webcam), but here's how I done it:

I made a DLL with the most important functions (so I can switch the SDK if I have to).

Opening the camera is pretty easy (one call with Vimba SDK, openCamera or s.th. like that).

When you aquire the image (acquireImage), you get a pointer to the frame. I used 8bit gray and BayerRG, both are well formatted for use with OpenCV.

Make an IplImage with the appropriate resolution and set the data with imagedata to the memory region the frame pointer points. setData did not work for me! Don't listen to the docs!

Generate your Mat out of the IplImage. If you like RGB use cvtColor() to convert it.

Remember to .clone() your Mat if your frame can come out of scope, elsewise your program will crash.

Hope, it'll help someone!

edit flag offensive delete link more
1

answered 2014-04-25 02:56:41 -0600

updated 2014-04-25 03:01:27 -0600

I supplied earlier in this topic a way to work with the old pvapi like we do in our research group.

Basically you would like to use this code snippet to connect to the camera and perform the correct openCV functionality in the provided part of the code. Have fun experimenting with it and feel free to contact me if it goes wrong.

Tough this snippet is for windows, I already adapted it on my own system to linux, which is fairly simple by removing the stdafx header and some windows specific commands if they are there with their linux counterparts.

Also I suggest everyone to replace the C-style API with the newer C++ API, I will see if I can dig up a clean C++ version of this snippet

SNIPPET WINDOWS C-CODE OPENCV

/**********************************************************************************
* Copyright (C) 2008 Metron Hong Kong Limited.  All Rights Reserved.
*
* Reproduction or disclosure of this file or its contents is granted without 
* prior written consent of Metron Hong Kong Limited.
***
* Code name: CaptureSaveMono.cpp
* Written by: Antonio Yu, Chief Consultant
* Date: 1 May, 2008
* Version: 1.0
* 
* Adapted by Stijn De Beugher on 2/04/2012
* Tested in combination with a AVT MANTA 201 MonoChrome camera
***
* Adapted by Steven Puttemans on 03/05/2013 
* Changed compatibility to windows environments
**********************************************************************************/

#include <PvApi.h>
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <string.h>
#include <iostream>
#include <time.h>

// Added this library in order to be windows compatible
#include <io.h>

using namespace std;

// camera's data type definition
typedef struct 
{
    unsigned long   UID;
    tPvHandle       Handle;
    tPvFrame        Frame;

} tCamera;

#define CH_MONO 1   // Single channel for mono images

int main(int argc, char* argv[])
{
    string input = "";
    string output_folder = "";
    int maxframecounter  = 100;
    string extension = ".pgm";  
    tCamera myCamera;
    tPvCameraInfo   cameraInfo;
    unsigned long   frameSize;
    tPvErr  Errcode;

    cout << "Frame capturing configured, starting the actual capture." << endl;

    // Initialize the API
    if(!PvInitialize())
    { 
        // Wait for the response from a camera after the initialization of the driver
        ////////////////////////////////////////////////////////////        
        clock_t startT, endT;
        startT = clock();
        float start = float(startT/CLOCKS_PER_SEC); 
        while(PvCameraCount() == 0)
        {           
            endT = clock();
            float end = float(endT/CLOCKS_PER_SEC); 
            if(end>(start+5))
            {               
                break;
            }
        }

        /////////////////////////////////////////////////////////////
        unsigned long numCams = PvCameraList(&cameraInfo, 1, NULL);
        cout << "numcams = \t" << numCams << endl;      
        if (numCams == 1)
        {
            // Get the camera ID
            myCamera.UID = cameraInfo.UniqueId;
            cout << "Camera ID =  \t " << myCamera.UID << endl;     

            // Open the camera
            if(!PvCameraOpen(myCamera.UID, ePvAccessMaster, &(myCamera.Handle)))
            {
                // Get the image size of every capture
                Errcode = PvAttrUint32Get(myCamera.Handle, "TotalBytesPerFrame", &frameSize);
                if (Errcode != ePvErrSuccess)
                    throw Errcode;

                cout << "Frame size = \t" << frameSize << endl;

                // Allocate a buffer to store the image
                memset(&myCamera.Frame, 0, sizeof(tPvFrame));
                myCamera.Frame.ImageBufferSize = frameSize;
                myCamera.Frame.ImageBuffer = new char[frameSize];

                // Get the width & height of the image
                tPvUint32 width, height;
                PvAttrUint32Get(myCamera.Handle, "Width", &width);
                PvAttrUint32Get(myCamera.Handle, "Height", &height);

                cout << "Frame width = \t" << width << endl;
                cout << "Frame height = \t" << height << endl;

                // Start the camera
                PvCaptureStart(myCamera.Handle);

                // Set the camera to capture continuously
                Errcode = PvAttrEnumSet(myCamera.Handle, "AcquisitionMode", "Continuous");
                if (Errcode != ePvErrSuccess)
                    throw Errcode;

                cout <<"start the acquisition" << endl;
                Errcode = PvCommandRun(myCamera.Handle, "AcquisitionStart ...
(more)
edit flag offensive delete link more

Comments

Thanks a lot. But have you ever tested your code with VIMBA SDK that replace now the PvAPI ?

Julien Seinturier gravatar imageJulien Seinturier ( 2014-04-25 03:53:34 -0600 )edit

Nope. I have done some research, since I couldn't get the VIMBA SDK to work properly and it seemed that others all resulted to the depricated PvAPI since it integrates well with openCV. You are even able to build OpenCV with the library, resulting in VideoCapture to be able to capture from the gigE cam without problems. But also there, no experience.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-25 04:04:15 -0600 )edit

I am working on a simple implementation with Vimba right now, I have gotten pretty close. I can connect to the camera, get data from it, and (I assume) set properties. What I am struggling with right now is converting from the Vimba frame type to the OCV Mat type.

I have created a Mat of the same dimensions as the image and (I strongly believe) the same depth, I just can't get the data to copy correctly. Any thoughts?

TuckerD gravatar imageTuckerD ( 2014-07-11 09:03:35 -0600 )edit
1

I have to resend that, I have it working!

TuckerD gravatar imageTuckerD ( 2014-07-11 09:07:05 -0600 )edit

You are welcome!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-14 02:07:26 -0600 )edit

And maybe share your VIMBA implementation with the world?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-14 02:08:08 -0600 )edit

Yes please SHARE IT :)

RiSaMa gravatar imageRiSaMa ( 2014-10-23 06:42:56 -0600 )edit
0

answered 2015-04-16 10:45:49 -0600

Hello, I made a wrapper to use Vimba SDK with OpenCV (tested in Linux/Ubuntu).

You can check the code here : https://github.com/AlexandreCampo/use.... Take a look at vimba directory, and capture/CaptureAVTCamera.cpp./.h

Hope this helps, let me know if you need more info. Cheers!

edit flag offensive delete link more

Comments

@Alexandre Campo, in the late months we compeletely reviewed the pvpapi capture interface and integrated it in OpenCV. Could you supply a similar interface through a PR using the VimbaSDK?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-04-17 03:25:32 -0600 )edit

Hi

anybody succeeded in integrating vimba with opencv .

Nitin_mewada gravatar imageNitin_mewada ( 2016-06-03 01:12:02 -0600 )edit
0

answered 2017-07-25 12:32:13 -0600

updated 2017-07-25 12:40:45 -0600

Hi all: I spent a lot of time trying to find the best way to get Vimba and OpenCV to play together - here's what I have.

Crux of the issue:

FramePtr pFrame;
VmbUchar_t *pImage = Null;
VmbUint32_t timeout = 500;
VmbUint43_t nWidth = 0;
VmbUint43_t nHeight = 0;

if (VmbErrorSuccess == cameras[ 0 ]->Camera::AcquireSingleImage( pFrame, timeout ) ) {

if (VmbErrorSuccess != pFrame->getWidth( nWidth ); std::cout << "FAILED to aquire width of frame!" << std::endl;

if (VmbErrorSuccess != pFrame->getWidth( nHeight ); std::cout << "FAILED to aquire height of frame!" << std::endl;

if (VmbErrorSuccess != pFrame->getImage( pImage ); std::cout << "FAILED to acquire image data of frame!" << std::endl;

cv::Mat cvMat = cv::Mat(nHeight, nWidth, CV_8UC1, pImage ); cv::cvtColor(cvMat, cvMat, CV_BayerBG2RGB); // My camera is set up to publish BayerBG. It's an efficient codec.

cv::imshow("Our Great Window", cvMat); cv::waitKey(1); }

Also below is more of my program (~250 lines) if you want to see how I also find my cameras, open them, and store that information. https://pastebin.com/z7i6dRbn

Good luck.

Good luck to all of you!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-04-25 02:48:59 -0600

Seen: 10,264 times

Last updated: Jul 25 '17