Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to integrate Opencv with specific camera control libs from the manufacturer?

Hi I am using the camera ProgRes speedxt core 5. I wanted to work with this camera using opencv but unfortunately it is not possible in fact. I have startet to read the libs of the camera sent by the manufacturer. Now I can open the camera but I would like to visualize the image on the desctop using opencv library. Could somebody help me? Here is my code for opening the camera:

include <opencv2\core\core.hpp>

include <opencv2\highgui\highgui.hpp>

include <opencv2\opencv.hpp>

include <opencv2\imgproc\imgproc.hpp>

include <iostream>

include <time.h>

include <windows.h>

include "MexCam.h"

include "MexCC.h"

include <iomanip>

include <process.h>

using namespace cv; using namespace std;

int __stdcall CompletionProc (unsigned long status, mexImg* pImg, mexUsrVal completionUser);

int imageCounter=0; mexImg Imgs[3]; // 3 images for CC-Live mexImg* ImgPointerList[3]={&Imgs[0],&Imgs[1],&Imgs[2]}; // List of pointers to use in calls to mexAcquire mexAcquisParams Pars; //HANDLE hThread=NULL; DWORD dwThreadID=0;

unsigned long channelBytes;

int main(){

unsigned __int64 GuidList[5]={0,0,0,0,0}; unsigned int NumberOfCameras=5; unsigned char *pRgbI = new unsigned char[channelBytes];

// MexConsole must announce begin of session with MexJCam.dll

mexInit(NULL,0); // By NULL,0 no callback are requested with respect to plug and play events for FireWire-cameras

// Find all present ProgRes-cameras long mexResult=mexFindCameras(&NumberOfCameras,GuidList);

long mexOpen=NOCAMERA; char q='q'; int i=0;

for(i=0; i<3; i++) { memset(&Imgs[i],0,sizeof(mexImg)); Imgs[i].Bytes=sizeof(mexImg); Imgs[i].Version=MEXIMGVERSION; }

if(NOERR==mexResult && NumberOfCameras>0) { mexCameraTypeSummary camTS; mexGetCameraTypeSummary(GuidList[0],&camTS); cout << "Try to open Camera " << camTS.TypeName << endl << endl; mexOpen=mexOpenCamera(GuidList[0]); // Use the first found camera if(NOERR==mexOpen) { cout << "Camera " << camTS.TypeName << " successful opened." << endl; cout << "Camera GUID " << setbase(16)<< setw(16) << setfill('0') << GuidList[0] << endl << endl; mexCamInfo camInfo;

  memset(&camInfo,0,sizeof(mexCamInfo));

  mexImageInfo imgInfo;
  memset(&imgInfo,0,sizeof(mexImageInfo));

  memset(&Pars,0,sizeof(mexAcquisParams));
  Pars.Bytes=sizeof(mexAcquisParams);
  Pars.Version=MEXACQUISPARAMSVERSION;
  mexCamType camtype=mexGetCameraType(GuidList[0]);
  mexResult=mexGetCameraInfo(GuidList[0],&camInfo);
  if(NOERR==mexResult)
  {
    // prepare acquisition parameter
//    Pars.runas=runas_snap;
    Pars.runas=runas_cclive;
    switch(camtype)
    {
      case cam10plus:
      case cam12plus:
        Pars.mode=mexShot2F_lowqualitycol;
        break;
      case cam14Cplus:
        Pars.mode=mexc14_Shot_colhighres;
        break;
      case cam14Mplus:
        Pars.mode=mexm14_Shot_bwhighres;
        break;
      case camCt3:
        Pars.mode=mexct3_std;
        break;
      case camC7:
        Pars.mode=mexC7_colhighspeed1;
        break;
      case camC3usb:
           //LinCi
           Pars.mode = mexC3usb_bin2col;
           break;
      case camC5usb:
          Pars.mode = mexShot2F_Raw;// This is my camera;
          cout << "My camera" << endl;
          break;


    }
    ::SetRect(&Pars.rcsensorBounds,0,0,camInfo.SensorX,camInfo.SensorY);
    Pars.buseblackref=FALSE;
    Pars.busewhiteref=FALSE;
    Pars.bwhitebalance=FALSE;
    Pars.correctColors=0;
    Pars.ciCode=0;
    Pars.ccdtransferCode=0;
    Pars.notifymask=0;
    Pars.stdTicks=::mexMSecToTicks(GuidList[0],10,Pars.mode,0); // 10 milliseconds
    Pars.addTicks=0;
    Pars.complProc=&CompletionProc;
    Pars.completionUser=0;
    Pars.progressProc=NULL;
    Pars.progressUser=0;

    mexResult=mexGetAcquisitionInfo(GuidList[0],&Pars,&imgInfo);
    if(NOERR==mexResult)
    {
           channelBytes=imgInfo.DimY*imgInfo.DimX*imgInfo.PlaneBytes;        
      if(mex_chan_dib==imgInfo.Channels)
      {
        channelBytes=((3*imgInfo.DimX+3)&0xfffffffc)*imgInfo.DimY;
      } 

      // attention: Set all available information into mexImg-Objects
      // If not, then you receive no image by calls to CompletionProc
      for(i=0; i<3; i++)
      {
        Imgs[i].dimX=imgInfo.DimX;
        Imgs[i].dimY=imgInfo.DimY;
        Imgs[i].channels=imgInfo.Channels;
      }

      if(mex_chan_3==imgInfo.Channels)
      {
        for(i=0; i<3; i++)
        {
          Imgs[i].channelBytes=channelBytes; // attention also for this assignment
          Imgs[i].pBw=NULL;

          unsigned char* pRgbImg = new unsigned char[channelBytes*3];

          Imgs[i].pRed   = pRgbImg;
          Imgs[i].pGreen = pRgbImg + channelBytes;
          Imgs[i].pBlue  = pRgbImg + (2 * channelBytes);
        }
      }
      else if(mex_chan_1==imgInfo.Channels || mex_chan_dib==imgInfo.Channels)
      {
        for(i=0; i<3; i++)
        {
          Imgs[i].channelBytes=channelBytes;  // attention also for this assignment
          unsigned char* p = new unsigned char[channelBytes];
          Imgs[i].pBw=p;
          //Imgs[i].pBw=new unsigned char[channelBytes];
          pRgbI = p;
          Imgs[i].pRed   = NULL;
          Imgs[i].pGreen = NULL;
          Imgs[i].pBlue  = NULL;
        }
      }
      cout << "Try to start CC-Live by a call to mexAcquire" << endl;

      // Note that also a direct call to mexAcquire is possible instead of execution of the call to mexAcquire
      // is delegated to an extra thread.

       mexResult=mexAcquire(GuidList[0],&Pars,ImgPointerList,3);

      // try out to remove the comment from the line above and comment out the Thread start above.

      // Now mexAcquire should be started by ThreadFunc in an extra thread
      // The main thread waits for an input from keyboard of a single key like a 'q' for "Quit".
      // While the main thread waits, the implementation of CxxPlus.dll
      // calls CompletionProc continuously for to anounce completed Images.


      IplImage* videoFrame = cvCreateImage(cvSize(camInfo.SensorX, camInfo.SensorY), IPL_DEPTH_32F, 3);
      namedWindow("wind1", 0);
      unsigned long chB;
      chB = channelBytes*3;
      while (1){
      for (int i = 0; i < chB; i++)
      {
          //videoFrame->imageData[i] = pRgbImg[i];
          videoFrame = pRgbI;
          break;

      }
      cvFlip(videoFrame, NULL, 0);
      cvShowImage("wind1", videoFrame);
      int key = cvWaitKey(1);
         if (key == 27) break;
      }


      WaitForSingleObject(hThread,INFINITE);
      cout << "Hit any key+Enter to abort CC-Live: ";
      cin >> q;

mexExit(); cout << "Hit any key+Enter to terminate this application: "; cin >> q;

return 0; } int __stdcall CompletionProc (unsigned long status, mexImg* pImg, mexUsrVal completionUser) { if(IMAGE_READY==status && pImg) { ++imageCounter; } return 0; }

click to hide/show revision 2
No.2 Revision

updated 2014-02-19 06:32:50 -0600

berak gravatar image

How to integrate Opencv with specific camera control libs from the manufacturer?

Hi I am using the camera ProgRes speedxt core 5. I wanted to work with this camera using opencv but unfortunately it is not possible in fact. I have startet to read the libs of the camera sent by the manufacturer. Now I can open the camera but I would like to visualize the image on the desctop using opencv library. Could somebody help me? Here is my code for opening the camera:

include <opencv2\core\core.hpp>

include <opencv2\highgui\highgui.hpp>

include <opencv2\opencv.hpp>

include <opencv2\imgproc\imgproc.hpp>

include <iostream>

include <time.h>

include <windows.h>

include "MexCam.h"

include "MexCC.h"

include <iomanip>

include <process.h>

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\opencv.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>
#include <time.h>
#include <Windows.h>
#include "MexCam.h"
#include "MexCC.h"
#include <iomanip>
#include <process.h>


using namespace cv;
using namespace std;

std; int __stdcall CompletionProc (unsigned long status, mexImg* pImg, mexUsrVal completionUser);

completionUser); int imageCounter=0; mexImg Imgs[3]; // 3 images for CC-Live mexImg* ImgPointerList[3]={&Imgs[0],&Imgs[1],&Imgs[2]}; // List of pointers to use in calls to mexAcquire mexAcquisParams Pars; //HANDLE hThread=NULL; DWORD dwThreadID=0;

dwThreadID=0; unsigned long channelBytes;

channelBytes; int main(){

main(){ unsigned __int64 GuidList[5]={0,0,0,0,0}; unsigned int NumberOfCameras=5; unsigned char *pRgbI = new unsigned char[channelBytes];

char[channelBytes];

    // MexConsole must announce begin of session with MexJCam.dll

mexInit(NULL,0); // By NULL,0 no callback are requested with respect to plug and play events for FireWire-cameras

FireWire-cameras // Find all present ProgRes-cameras long mexResult=mexFindCameras(&NumberOfCameras,GuidList);

mexResult=mexFindCameras(&NumberOfCameras,GuidList); long mexOpen=NOCAMERA; char q='q'; int i=0;

i=0; for(i=0; i<3; i++) { memset(&Imgs[i],0,sizeof(mexImg)); Imgs[i].Bytes=sizeof(mexImg); Imgs[i].Version=MEXIMGVERSION; }

} if(NOERR==mexResult && NumberOfCameras>0) { mexCameraTypeSummary camTS; mexGetCameraTypeSummary(GuidList[0],&camTS); cout << "Try to open Camera " << camTS.TypeName << endl << endl; mexOpen=mexOpenCamera(GuidList[0]); // Use the first found camera if(NOERR==mexOpen) { cout << "Camera " << camTS.TypeName << " successful opened." << endl; cout << "Camera GUID " << setbase(16)<< setw(16) << setfill('0') << GuidList[0] << endl << endl; mexCamInfo camInfo;

camInfo;

      memset(&camInfo,0,sizeof(mexCamInfo));

   mexImageInfo imgInfo;
   memset(&imgInfo,0,sizeof(mexImageInfo));

   memset(&Pars,0,sizeof(mexAcquisParams));
   Pars.Bytes=sizeof(mexAcquisParams);
   Pars.Version=MEXACQUISPARAMSVERSION;
   mexCamType camtype=mexGetCameraType(GuidList[0]);
   mexResult=mexGetCameraInfo(GuidList[0],&camInfo);
   if(NOERR==mexResult)
   {
     // prepare acquisition parameter
 //    Pars.runas=runas_snap;
     Pars.runas=runas_cclive;
     switch(camtype)
     {
       case cam10plus:
       case cam12plus:
         Pars.mode=mexShot2F_lowqualitycol;
         break;
       case cam14Cplus:
         Pars.mode=mexc14_Shot_colhighres;
         break;
       case cam14Mplus:
         Pars.mode=mexm14_Shot_bwhighres;
         break;
       case camCt3:
         Pars.mode=mexct3_std;
         break;
       case camC7:
         Pars.mode=mexC7_colhighspeed1;
         break;
       case camC3usb:
            //LinCi
            Pars.mode = mexC3usb_bin2col;
            break;
       case camC5usb:
           Pars.mode = mexShot2F_Raw;// This is my camera;
           cout << "My camera" << endl;
           break;


     }
     ::SetRect(&Pars.rcsensorBounds,0,0,camInfo.SensorX,camInfo.SensorY);
     Pars.buseblackref=FALSE;
     Pars.busewhiteref=FALSE;
     Pars.bwhitebalance=FALSE;
     Pars.correctColors=0;
     Pars.ciCode=0;
     Pars.ccdtransferCode=0;
     Pars.notifymask=0;
     Pars.stdTicks=::mexMSecToTicks(GuidList[0],10,Pars.mode,0); // 10 milliseconds
     Pars.addTicks=0;
     Pars.complProc=&CompletionProc;
     Pars.completionUser=0;
     Pars.progressProc=NULL;
     Pars.progressUser=0;

     mexResult=mexGetAcquisitionInfo(GuidList[0],&Pars,&imgInfo);
     if(NOERR==mexResult)
     {
            channelBytes=imgInfo.DimY*imgInfo.DimX*imgInfo.PlaneBytes;        
       if(mex_chan_dib==imgInfo.Channels)
       {
         channelBytes=((3*imgInfo.DimX+3)&0xfffffffc)*imgInfo.DimY;
       } 

       // attention: Set all available information into mexImg-Objects
       // If not, then you receive no image by calls to CompletionProc
       for(i=0; i<3; i++)
       {
         Imgs[i].dimX=imgInfo.DimX;
         Imgs[i].dimY=imgInfo.DimY;
         Imgs[i].channels=imgInfo.Channels;
       }

       if(mex_chan_3==imgInfo.Channels)
       {
         for(i=0; i<3; i++)
         {
           Imgs[i].channelBytes=channelBytes; // attention also for this assignment
           Imgs[i].pBw=NULL;

           unsigned char* pRgbImg = new unsigned char[channelBytes*3];

           Imgs[i].pRed   = pRgbImg;
           Imgs[i].pGreen = pRgbImg + channelBytes;
           Imgs[i].pBlue  = pRgbImg + (2 * channelBytes);
         }
       }
       else if(mex_chan_1==imgInfo.Channels || mex_chan_dib==imgInfo.Channels)
       {
         for(i=0; i<3; i++)
         {
           Imgs[i].channelBytes=channelBytes;  // attention also for this assignment
           unsigned char* p = new unsigned char[channelBytes];
           Imgs[i].pBw=p;
           //Imgs[i].pBw=new unsigned char[channelBytes];
           pRgbI = p;
           Imgs[i].pRed   = NULL;
           Imgs[i].pGreen = NULL;
           Imgs[i].pBlue  = NULL;
         }
       }
       cout << "Try to start CC-Live by a call to mexAcquire" << endl;

       // Note that also a direct call to mexAcquire is possible instead of execution of the call to mexAcquire
       // is delegated to an extra thread.

        mexResult=mexAcquire(GuidList[0],&Pars,ImgPointerList,3);

       // try out to remove the comment from the line above and comment out the Thread start above.

       // Now mexAcquire should be started by ThreadFunc in an extra thread
       // The main thread waits for an input from keyboard of a single key like a 'q' for "Quit".
       // While the main thread waits, the implementation of CxxPlus.dll
       // calls CompletionProc continuously for to anounce completed Images.


       IplImage* videoFrame = cvCreateImage(cvSize(camInfo.SensorX, camInfo.SensorY), IPL_DEPTH_32F, 3);
       namedWindow("wind1", 0);
       unsigned long chB;
       chB = channelBytes*3;
       while (1){
       for (int i = 0; i < chB; i++)
       {
           //videoFrame->imageData[i] = pRgbImg[i];
           videoFrame = pRgbI;
           break;

       }
       cvFlip(videoFrame, NULL, 0);
       cvShowImage("wind1", videoFrame);
       int key = cvWaitKey(1);
          if (key == 27) break;
       }


       WaitForSingleObject(hThread,INFINITE);
       cout << "Hit any key+Enter to abort CC-Live: ";
       cin >> q;

mexExit(); cout << "Hit any key+Enter to terminate this application: "; cin >> q;

q; return 0; } int __stdcall CompletionProc (unsigned long status, mexImg* pImg, mexUsrVal completionUser) { if(IMAGE_READY==status && pImg) { ++imageCounter; } return 0; }

}