Mil 中 不同相机、不同DCF,在同一个digitizer中采集图像

        如果有A和B共两个相机,只有一个digitizer,一般情况下,要用一个DCF分配一个digitizer,然后采集一帧图像,再释放digitizer, 然后再用第二个DCF来分配一个digitizer,采集一帧图像,如此循环。这种情况下是很费时间的。 mil可以通过快速切换技术规避这个问题。

        一般,黑白模拟信号相机有两个格式: CCIR和RS170,图像采集卡一般两种都支持;这种图像采集卡包括:

the Matrox Meteor-II,  Meteor-II/MC, Matrox Corona-II, Matrox CronosPlus and Matrox Orion

令RS170的相机使用channel0, CCIR的相机使用 channnel 1,在循环中这两个通道快速切换,达到两个相机几乎同时采集同时显示图像的效果。示例代码如下:

 

#include "stdafx.h"
#include <conio.h> 
#include <mil.h>


/* Image scale. */
#define IMAGE_SCALE        0.5

void main(void)
{ 
   MIL_ID   MilApplication;
   MIL_ID   MilSystem;
   MIL_ID   MilDigitizerRs170;
   MIL_ID   MilDigitizerCcir;
   MIL_ID   MilImageRs170;
   MIL_ID   MilImageCcir;
   MIL_ID   MilDisplayRs170;
   MIL_ID   MilDisplayCcir;
   double   Time;
   long     NbGrab = 0;
   long     BoardType;

   /* Allocate defaults. */
   MappAlloc(M_DEFAULT, &MilApplication);
   MsysAlloc(M_SYSTEM_METEOR_II, M_DEV0, M_DEFAULT, &MilSystem);

   /* Check if this example is supported on the allocated system. */
   BoardType = MsysInquire(MilSystem, M_BOARD_TYPE, M_NULL);
   if ( (BoardType != M_METEOR_II)           &&
        (BoardType != M_METEOR_II_MC)        &&
        (BoardType != M_ORION)               &&
        (BoardType != M_CORONA_II)           &&
        (BoardType != M_CORONA_II_WITH_DIG_MODULE))
      {
      printf("\nSorry this example is not supported on the allocated system.\n");
      printf("\nSupported boards are:\n");
      printf("Matrox Meteor-II.\n");
      printf("Matrox Meteor-II/MC.\n");
      printf("Matrox Corona-II.\n");
      printf("Matrox CronosPlus.\n");
      printf("Matrox Orion.\n");
      printf("Matrox Orion for 4Sight-II.\n");
      MsysFree(MilSystem);
      MappFree(MilApplication);
      return;
      }

   printf("\nThis example shows how to grab from multiple\n");
   printf("cameras with different DCFs.\n");
   printf("\nBe sure you have a RS170 camera on channel 0 and\n");
   printf("an a CCIR camera on channel 1.\n\n");
   printf("Press Enter to begin.\n");
   getchar();

   /* Allocate multiple digitizers on M_DEV0 with different DCFs.*/
   MdigAlloc(MilSystem, M_DEV0, MIL_TEXT("M_RS170"), M_DEFAULT, &MilDigitizerRs170);
   MdigAlloc(MilSystem, M_DEV0, MIL_TEXT("M_CCIR"), M_DEFAULT, &MilDigitizerCcir);

   /* A history of all calls to MdigControl, MdigChannel, MdigReference and 
      MdigHookFunction are maintained for each allocated digitizer. It is 
      therefore not necessary to redo these calls after a digitizer context
      switch, the restore is done automatically by the driver. */
   MdigControl(MilDigitizerRs170, M_GRAB_SCALE, IMAGE_SCALE);

   /* Enable camera lock, this is done to make shure we are locked on the new
      camera signal after a digitizer context switch.
      Note: changing M_CAMERA_LOCK_SENSITIVITY, and M_CAMERA_UNLOCK_SENSITIVITY
      will affect frame rate performance and grab stability, The user should
      be aware that he may need to change these values for his specific camera
      combination. A lower value of lock and unlock sentivity gives a higher locking/
      unlocking speed but might result in grab sync-lost error messages. */

   MdigControl(MilDigitizerRs170, M_CAMERA_LOCK, M_ENABLE);
   MdigControl(MilDigitizerRs170, M_CAMERA_LOCK_SENSITIVITY, M_DEFAULT);
   MdigControl(MilDigitizerRs170, M_CAMERA_UNLOCK_SENSITIVITY, M_DEFAULT);
   MdigChannel(MilDigitizerRs170, M_CH0);

   MdigControl(MilDigitizerCcir, M_GRAB_SCALE, IMAGE_SCALE);
   MdigControl(MilDigitizerCcir, M_CAMERA_LOCK, M_ENABLE);
   MdigControl(MilDigitizerCcir, M_CAMERA_LOCK_SENSITIVITY, M_DEFAULT);
   MdigControl(MilDigitizerCcir, M_CAMERA_UNLOCK_SENSITIVITY, M_DEFAULT);
   MdigChannel(MilDigitizerCcir, M_CH1);

   MbufAllocColor(MilSystem,
                  (long)MdigInquire(MilDigitizerRs170, M_SIZE_BAND, M_NULL),
                  (long)(MdigInquire(MilDigitizerRs170, M_SIZE_X, M_NULL)*IMAGE_SCALE),
                  (long)(MdigInquire(MilDigitizerRs170, M_SIZE_Y, M_NULL)*IMAGE_SCALE),
                  8L+M_UNSIGNED, 
                  M_IMAGE+M_GRAB+M_DISP,
                  &MilImageRs170);
   MbufAllocColor(MilSystem,
                  (long)MdigInquire(MilDigitizerCcir, M_SIZE_BAND, M_NULL),
                  (long)(MdigInquire(MilDigitizerCcir, M_SIZE_X, M_NULL)*IMAGE_SCALE),
                  (long)(MdigInquire(MilDigitizerCcir, M_SIZE_Y, M_NULL)*IMAGE_SCALE),
                  8L+M_UNSIGNED, 
                  M_IMAGE+M_GRAB+M_DISP,
                  &MilImageCcir);
   MbufClear(MilImageRs170, 128L);
   MbufClear(MilImageCcir, 128L);

   MdispAlloc(MilSystem, M_DEFAULT, M_DEF_DISPLAY_FORMAT, M_DEFAULT, &MilDisplayRs170);
   MdispAlloc(MilSystem, M_DEFAULT, M_DEF_DISPLAY_FORMAT, M_DEFAULT, &MilDisplayCcir);
   MdispControl(MilDisplayRs170, M_WINDOW_TITLE_NAME, (long)MIL_TEXT("Rs170 Display"));
   MdispControl(MilDisplayCcir,  M_WINDOW_TITLE_NAME, (long)MIL_TEXT("Ccir Display"));
   MdispSelect(MilDisplayRs170, MilImageRs170);
   MdispSelect(MilDisplayCcir,  MilImageCcir);

   MappTimer(M_TIMER_RESET, M_NULL);
   while(!kbhit())//等待键盘输入
      {
      /* Here a digitizer context switch is made at every loop:
         the new digitizer state is restored along with all controls. */
      /* Note: For faster digitizer switching time the user should
               create custom DCF's with the channel already selected,
               the user should also remove the call to MdigChannel
               at the initialisation phase of this example. You can
               create these DCF's using Matrox Intellicam. */
      if((NbGrab % 2) == 0)
         MdigGrab(MilDigitizerRs170, MilImageRs170);
      else
         MdigGrab(MilDigitizerCcir, MilImageCcir);

      NbGrab++;
      if((NbGrab % 30) == 0)
         {
         MappTimer(M_TIMER_READ, &Time);
         printf("\r%d\tframes grabbed at %f fps.", NbGrab, 30/Time);
         MappTimer(M_TIMER_RESET, M_NULL);
         }
      }
   getchar();

   /* Free all allocated buffers. */
   MdispFree(MilDisplayRs170);
   MdispFree(MilDisplayCcir);
   MdigFree(MilDigitizerRs170);
   MdigFree(MilDigitizerCcir);
   MbufFree(MilImageRs170);
   MbufFree(MilImageCcir);

   MsysFree(MilSystem);
   MappFree(MilApplication);

   return;
} 

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值