【问题标题】:Frame Capture using Matrox Commands使用 Matrox 命令进行帧捕捉
【发布时间】:2019-03-24 16:37:25
【问题描述】:

我正在做一个项目,我必须设置来自相机的视频流的 fps(为 10),并每隔 5 帧抓取一帧。我正在开发一个已经由其他人编写了一半的程序。问题是,他们使用了 Matrox Framegrabber dll。设备上还有 Matrox Frame Grabber。但我在 C# 中找不到任何用于 framegrab 的命令。我找到了以下 C++ 代码。

MIL_ID MdispAlloc(SystemId, DispNum, DispFormat, InitFlag,
DisplayIdPtr)

在哪里

MIL_ID SystemId; System identifier
long DispNum; Display number
char *DispFormat; Display format name or file name
long InitFlag; Initialization flag
MIL_ID *DisplayIdPtr; Storage location for the display identifier

上面的命令分配一个显示器。有人可以帮我用 C# 编写程序吗?另外,任何有 Matrox dll 经验的人请给我一个关于如何处理帧捕获和 fps 设置的想法。 谢谢。

【问题讨论】:

    标签: c# image-processing dllimport frame-rate frame-grab


    【解决方案1】:

    这是为所有刚接触matrox framegrabber 的人准备的。 您应该做的第一件事是添加matrox dll 作为参考。请注意,目前有两个 Matrox 版本 - Matrox 9 和 Matrox 10。 根据安装在用户系统 dll 中的matrox 版本,应该添加。 (这可以通过在系统目录中查找“MIL_PATH”来检查。 然后,声明一些将用于matrox 抓取的变量。

    我的一些如下:

     public static MIL_ID MilApplication = MIL.M_NULL;       // Application identifier.
        public static MIL_ID MilSystem = MIL.M_NULL;       // System identifier.     
        public static MIL_ID MilDisplay = MIL.M_NULL;       // Display identifier.    
        public static MIL_ID MilDigitizer = MIL.M_NULL;       // Digitizer identifier.  
        public static MIL_ID MilImage = MIL.M_NULL;       // Image identifier.
        public static MIL_ID MilRecord = MIL.M_NULL;       // 8 bit Pointer only for Video Recording.
        public MIL_INT MilINT = MIL.M_NULL;
        public MIL_INT NbPixelsPtr = MIL.M_NULL;
        MIL_ID MilImageDisp = MIL.M_NULL;
        MIL_ID[] MilGrabBufferList = new MIL_ID[BUFFERING_SIZE_MAX];
    

    然后运行以下代码

    string MilSystemDet = "";
    MilSystemDet = Environment.GetEnvironmentVariable("Mil_Path");
    if (MilSystemDet != null)
    { 
        string dcfFilePath = "";
        FileDialog OpenFile = new OpenFileDialog();
        OpenFile.Filter = "File Formats(*.dcf)|*.DCF;";
        if (OpenFile.ShowDialog() == DialogResult.OK)
        { 
            dcfFilePath = OpenFile.FileName;
            MIL.MdigAlloc(MilSystem, MIL.M_DEFAULT, dcfFilePath, MIL.M_DEFAULT, ref MilDigitizer);
            MIL.MbufAlloc2d(
                MilSystem, 
                MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL), 
                MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL), 
                8 + MIL.M_UNSIGNED, 
                MIL.M_IMAGE + MIL.M_DISP + MIL.M_GRAB, 
                ref MilImage);
            MIL.MdispAlloc(MilSystem, MIL.M_DEFAULT, ("M_DEFAULT"), MIL.M_DEFAULT, ref MilDisplay);
            MIL.MdigHalt(MilDigitizer);
        }
    }
    

    当你想开始捕获时,运行以下命令

     MIL.MbufClear(MilImage, 0);
     MIL.MdigGrabContinuous(MilDigitizer, MilImage);
     MIL.MdispControl(MilDisplay, MIL.M_VIEW_MODE, MIL.M_AUTO_SCALE);
     MIL.MdispControl(MilDisplay, MIL.M_SCALE_DISPLAY, MIL.M_ENABLE);
    

    要将当前图像复制到缓冲区中,请使用

    MIL.MbufGet(MilImage, myBuffer);
    

    其中 myBuffer 是一个 ushort 缓冲区,大小等于图像中的总像素数。

    要将当前图像保存到文件中,请使用

    MIL.MbufSave(address,MilImage);
    

    如果您没有.dcf 文件,您可以从matrox 安装光盘免费获得一个默认文件。或者只需安装matrox 查看器,然后在程序文件中就可以拥有一个。 图像的宽度、高度和位深等参数都是从 dcf 文件中获取的。但如果你愿意,你可以在上面的 Mbufalloc2d 函数中分配它们。

    我会尝试定期检查此答案。如果有人有任何问题问我。我会尽我所能回答他们。

    【讨论】:

      【解决方案2】:

      似乎您已经弄明白了,但对于那些还没有弄明白的人,您需要做的就是包含 MIL 库并在 C++ 中的函数名称前加上 MIL.

      喜欢,

         MbufClear(MilImageDisp[0], 0x0);
      

      ->

      MIL.MbufClear(MilImage, 0);
      

      编辑关于 FPS 设置的问题:它会根据您的相机和 DCF 自动进行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-03
        • 1970-01-01
        • 1970-01-01
        • 2013-02-23
        • 1970-01-01
        • 2013-06-10
        • 1970-01-01
        相关资源
        最近更新 更多