诊断慢写速度问题

时间:2014-05-28 12:01:34

标签: c video-capture frame-grab

所以我希望有人可以帮我解决这个问题,对于任何有编程经验的人来说这似乎都是显而易见的,但对我来说却没有!请原谅我糟糕的描述,因为我不知道很多事情的正确术语。

基本上我使用安装了framegrabber卡的旧(ish)计算机继承了一个项目(Matrox Meteor II)。我的基本目标是简单地从相机中实时捕捉实时视频,并将其解压缩到计算机的硬盘上。该卡的编程在C中完成,并使用与其捆绑在一起的库,称为Matrox Imaging Library(MIL)。

目前我只是将我的所有图像以raw格式编写,并使用imageJ来查看它们。我编写了一个使用双缓冲的基本程序,因此将图像捕获到缓冲区,然后写入文本文件,同时将下一个图像捕获到另一个缓冲区。我将在下面放置一个代码片段,所有M-prefix命令都来自MIL库。但是,你实际上并不需要了解它们来帮助我。

我只使用以下内容:

/* Put the digitizer in asynchronous mode. */
MdigControl(MilDigitizer, M_GRAB_MODE, M_ASYNCHRONOUS);

/* Grab the first buffer. */
MdigGrab(MilDigitizer, MilImage[0]);

/*open my file where I will write the images*/
pfile = fopen("myfile.txt", "wb");

/* Process one buffer while grabbing the other. */
while( !kbhit() )
  {

  /* Grab second buffer while processing first buffer. */
  MdigGrab(MilDigitizer, MilImage[1]);

  /* Synchronize and start the timer. */
  if (NbProc == 0)
     {
     MappTimer(M_TIMER_RESET, M_NULL);
     }

  /* Process the first buffer already grabbed.  */

  /*copy the image to a display buffer*/
  #if COPY_IMAGE 
  MbufCopy(MilImage[0], MilImageDisp);
  #endif      

  /*Here we copy the buffer into a user supplied array*/
  MbufGet(MilImage[0], my_array);

  /* Then we write the array into the text file using fwrite*/
  fwrite(my_array,sizeof(char),sizeof(my_array),pfile);

    /*Output the amount of time it took to process that image*/
    MappTimer(M_TIMER_READ, &Time);
Capture_Time = Time - Time_Holder;
printf("IMG %s took %.7f .\n", text, Capture_Time);
Time_Holder = Time;
    /* Count processed buffers.  */
     NbProc++;         


  /* Grab first buffer while processing second buffer. */
  MdigGrab(MilDigitizer, MilImage[0]);

  /* Process the second buffer already grabbed.  */

  #if COPY_IMAGE 
  MbufCopy(MilImage[1], MilImageDisp);
  #endif      




  /*Here we copy the buffer into our array*/
  MbufGet(MilImage[1], my_array);

  /* Then we write the array into the text file using fwrite*/
  fwrite(my_array,sizeof(char),sizeof(my_array),pfile);

  MappTimer(M_TIMER_READ, &Time);
Capture_Time = Time - Time_Holder;
printf("IMG %s took %.7f .\n", text, Capture_Time);
Time_Holder = Time;


  /* Count processed buffers. */
  NbProc++;         
  }
  getchar();   
   /* Wait last grab end and stop timer. */
   MdigGrabWait(MilDigitizer, M_GRAB_END);

   /*Close our file*/
   fclose(pfile);

我的问题是我希望以24fps的帧速率执行上述操作,但我发现捕获图像并将其写入硬盘的过程略慢于有时(放慢速度不一致但是该程序似乎偶尔挂在一帧~500ms)。

我想知道是否有人知道如何诊断导致这些减速的原因,以及它是否可能是我硬盘的写入速度。

1 个答案:

答案 0 :(得分:0)

这将通过启用磁盘写入缓存来帮助您修复偶尔在单帧挂起。 你可以去C:drive->属性 - >硬件 - >选择驱动器 - >驱动器属性 - >策略 - >在设备上启用写缓存。

可以对代码进行的其他修改对应于代码的第一行,您将数字化仪置于ASYNCHRONOUS模式而不是该使用模式 MdigControl(milDigitizer,M_GRAB_MODE,M_ASYNCHRONOUS_QUEUED); 这将在每次抓取排队后继续,并且不等待Mil抓取功能退出。

相关问题