DALSA网口相机C++二次开发

        用的是DALSA Nano的网口相机进行连续采图,根据官方给的GigECameraMultiCast 的Demo进行了一下修改,使其能够按指定的相机配置文件ccf进行指定数量的连续采图,并存储在指定路径的文件夹下。

        附上DALSA官网网站Home | Teledyne DALSA

        

        二次开发之前得进行环境的配置。

        下面是编写好的连续采图的代码,目前设置是连续采图10张并进行存储。

#ifdef _MSC_VER
   #pragma warning(disable: 4786)
#endif

// Disable deprecated function warnings with Visual Studio 2005
#if defined(_MSC_VER) && _MSC_VER >= 1400
   #pragma warning(disable: 4995)
#endif

#include "stdio.h"
#include "conio.h"
#include "sapclassbasic.h"
#include "ExampleUtils.h"
#include <iostream>
#include <vector>
#include <string>
#include<opencv2/opencv.hpp>

// Restore deprecated function warnings with Visual Studio 2005
#if defined(_MSC_VER) && _MSC_VER >= 1400
   #pragma warning(default: 4995)
#endif

// Static Functions
static void AcqCallback(SapXferCallbackInfo *pInfo);
static BOOL GetOptions(int argc, char *argv[], char *acqServerName, UINT32 *pAcqDeviceIndex);
static BOOL GetOptionsFromCommandLine(int argc, char *argv[], char *acqServerName, UINT32 *pAcqDeviceIndex);

BYTE* pData;


int main(int argc, char* argv[])
{
   BOOL     master = FALSE;
   BOOL     selectionOk = FALSE;
   UINT32   acqDeviceNumber;
   char     acqServerName[CORSERVER_MAX_STRLEN];
   
   uchar* imgData = new uchar[4912*3684*10];
   
   char *ccf_path = "C:\\Users\\86152\\Desktop\\001.ccf";
   if (!GetOptions(argc, argv, acqServerName, &acqDeviceNumber))
   {
      printf("\nPress any key to terminate\n");
      CorGetch(); 
      return 0;
   }

   printf("M or m: Start as a master\n");
   printf("R or r: Start as a receiver\n");

   do
   {
      char key = (char)_getch();

      if (key != 0)
      {
         if (key == 'q')
            return FALSE;

         if ((key == 'm') || (key == 'M'))
         {
            printf("\n---> Starting as a MASTER <---\n\n");
            selectionOk = TRUE;
            master = TRUE;
         }

         if ((key == 'r') || (key == 'R'))
         {
            printf("\n---> Starting as a RECEIVER <---\n\n");
            selectionOk = TRUE;
         }
      }

   } while (!selectionOk);

   //SapAcqDevice   AcqDevice;
   SapBuffer      Buffers;
   SapTransfer    Xfer;
   SapView        View;


   //SapLocation loc(acqServerName);
   SapLocation loc(acqServerName,0);
   SapAcqDevice AcqDevice;
   if (SapManager::GetResourceCount(acqServerName, SapManager::ResourceAcqDevice) > 0)
   {
      if (master)
      {
         // Create the Acquisition Device in read/write mode.
         // You must have set the "Camera Default Write Mode" to "Control"
         // with Network Configuration Tool.
         AcqDevice = SapAcqDevice(SapLocation(1, 0), ccf_path);
      }
      else
      {
         // Create the Acquisition Device in read-only mode.
         // Make sure the Camera is properly set by the MASTER before
         // the Acquisition Device Creation.
         AcqDevice = SapAcqDevice(SapLocation(1,0), ccf_path);
         // No change must be done by the MASTER to the Camera configuration after the
         // Acquisition Device creation by a RECEIVER... except enabling multicast.

      }
      


      Buffers = SapBufferWithTrash(10, &AcqDevice);
      View = SapView(&Buffers, SapHwndAutomatic);
      //View = SapView(&Buffers, SapHwndDesktop);
      Xfer = SapAcqDeviceToBuf(&AcqDevice, &Buffers, AcqCallback, &View);
   }

   // Create acquisition object
   if (!AcqDevice.Create())
      goto FreeHandles;

   if (master)
   {
      INT64 multicastAddress = 0xef0b0b0b; //239.11.11.11

      // Set the multicast IP address used by the Camera (optional... only if
      // you don't want to use the default value of 239.10.10.10.
      AcqDevice.SetFeatureValue("multiCastStreamingIPAddress", multicastAddress);

      // Enable the multicast.
      AcqDevice.SetFeatureValue("multiCastStreamingEnable", TRUE);
   }
   else
   {
      unsigned int streamingEnable = 0;

      do
      {
         Sleep(5000);

         // Loop until the multicast is enabled by the MASTER.
         if (AcqDevice.GetFeatureValue("multiCastStreamingEnable", &streamingEnable) == FALSE)
            goto FreeHandles;

      } while (!streamingEnable);

      Sleep(1000);
   }

   // Create buffer object
   if (!Buffers.Create())
      goto FreeHandles;

   // Create transfer object
   if (!Xfer.Create())
      goto FreeHandles;

   // Create view object
   if (!View.Create())
      goto FreeHandles;


   int flag = 0;
   int PanDuan = 0;
   static int framcount = 0;
   // Start continous grab
    Xfer.Grab();
    flag = 1;


    while (true)
    {
        if (flag == 1)
        {
            std::cout << "Grab" << std::endl;
            //Sleep(1000);
            std::stringstream ss;
            ss << "C:\\Users\\86152\\Desktop\\test1\\" << framcount << ".bmp";
            std::string name = ss.str();
            const char* savename = name.c_str();
            Buffers.Save(savename, "-format bmp");
            Buffers.Clear();
            
            
            //m_Mats.push_back(m_Mat);
            framcount++;

            if (framcount > int(10))
            {
                framcount = 0;
                std::cout << "Grab Finished" << std::endl;//停止采集
                Xfer.Freeze();
                break;
            }


        }
    }


   // Stop grab
   /*
   Xfer.Freeze();
   if (!Xfer.Wait(5000))
      printf("Grab could not stop properly.\n");
*/
FreeHandles:
   printf("Press any key to terminate\n");
   CorGetch();
   
   // Destroy view object
   if (!View.Destroy()) return FALSE;

   // Destroy transfer object
   if (!Xfer.Destroy()) return FALSE;

   // Destroy buffer object
   if (!Buffers.Destroy()) return FALSE;

   // Destroy acquisition object
   if (!AcqDevice.Destroy()) return FALSE;


   Sleep(1000);



   return 0;
   


}

static void AcqCallback(SapXferCallbackInfo *pInfo)
{
   SapView *pView= (SapView *) pInfo->GetContext();

   // Refresh view
   pView->Show();
}

static BOOL GetOptions(int argc, char *argv[], char *acqServerName, UINT32 *pAcqDeviceIndex)
{
   // Check if arguments were passed
   if (argc > 1)
      return GetOptionsFromCommandLine(argc, argv, acqServerName, pAcqDeviceIndex);
   else
      return GetCorAcqDeviceOptionsFromQuestions(acqServerName, pAcqDeviceIndex, TRUE);
}

static BOOL GetOptionsFromCommandLine(int argc, char *argv[], char *acqServerName, UINT32 *pAcqDeviceIndex)
{
   // Check the command line for user commands
   if ((strcmp(argv[1], "/?") == 0) || (strcmp(argv[1], "-?") == 0))
   {
      // print help
      printf("Usage:\n");
      printf("GigECameraMulticast [<acquisition server name> <acquisition device index>]\n");
      return FALSE;
   }

   // Check if enough arguments were passed
   if (argc < 3)
   {
      printf("Invalid command line!\n");
      return FALSE;
   }

   // Validate server name
   if (SapManager::GetServerIndex(argv[1]) < 0)
   {
      printf("Invalid acquisition server name!\n");
      return FALSE;
   }

   // Does the server support acquisition?
   int deviceCount = SapManager::GetResourceCount(argv[1], SapManager::ResourceAcqDevice);

   if (deviceCount == 0)
   {
      printf("This server does not support acquisition!\n");
      return FALSE;
   }

   // Validate device index
   if (atoi(argv[2]) < 0 || atoi(argv[2]) >= deviceCount)
   {
      printf("Invalid acquisition device index!\n");
      return FALSE;
   }

   // Fill-in output variables
   CorStrncpy(acqServerName, argv[1], CORSERVER_MAX_STRLEN);
   *pAcqDeviceIndex = atoi(argv[2]);

   return TRUE;
}

  • 12
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要进行dalsa线扫相机SDK的二次开发,首先需要搭建相应的开发环境。以下是具体的步骤: 1. 下载安装DAQ库:在dalsa官网上下载适用于相机型号的相应版本的DAQ库。安装DAQ库时,选择适当的操作系统以及语言和编译器。 2. 安装C编译器:如果您的操作系统中没有C编译器,需要安装一个合适的C编译器。常见的C编译器有GCC(GNU Compiler Collection)和Visual Studio等。 3. 创建工程:打开一个集成开发环境,如Visual Studio或者Code::Blocks等,创建一个新的C项目。 4. 配置项目:在项目的属性设置中,添加DAQ库的路径,指定C编译器的位置和其他必要的设置。 5. 引入头文件:在代码中引入DAQ库的头文件。通常,可以使用`#include`命令将头文件包含进来。 6. 编写代码:根据您的需求,编写相机控制、图像采集等相关功能的代码。 7. 构建和调试:编译代码,并在开发环境中进行调试。查看编译错误并修复,确保代码能够正确运行。 8. 部署应用程序:将生成的可执行文件或动态链接库部署到您的目标计算机上,并确保目标计算机上已安装了DAQ库。 总结:搭建dalsa线扫相机SDK的C开发环境需要下载安装DAQ库,安装C编译器,创建项目并配置相应属性,引入头文件,编写代码,构建和调试,最后部署应用程序到目标机器上。这样就可以进行dalsa线扫相机SDK的二次开发了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值