使用Matrox命令捕获帧 [英] Frame Capture using Matrox Commands

查看:375
本文介绍了使用Matrox命令捕获帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,我必须从摄像机设置视频流的fps(为10)并每隔5帧抓一帧。我正在制作一个已被其他人写过一半的程序。问题是,他们使用了Matrox Framegrabber dll。设备上还有Matrox Frame Grabber。但我无法在C#中找到framegrab的任何命令。我找到了以下C ++代码。

I'm working on a project where I have to set the fps of a video stream (as 10) from a camera and grab a frame every 5th frame. I'm working on a program that has already been half written by someone else. The thing is, they have used Matrox Framegrabber dlls. There is also Matrox Frame Grabber on the device. But I cant find any commands for framegrab in C#. I found the following code for 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 dlls经验的人请告诉我如何进行帧捕获和fps设置。
谢谢。

The above command allocates a display. Can someone please help me write the program in C#. Also, anyone with experience in Matrox dlls please give me an idea on how to approach frame capture and fps set up. Thanks.

推荐答案

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

This is for everyone who is new to matrox framegrabber. The first thing you should do is add matrox dll as reference. Be aware that there are currently two matrox versions out- Matrox 9 and Matrox 10. Depending on version of matrox installed in user system dll should be added. (This can be checked by looking for "MIL_PATH" in system directories. Then, declare some variables which will be used in matrox grabbing.

我的一些如下:

 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];

然后运行f ollowing code

Then run the following code

 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);

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

When you want to start capture, run the following

 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);

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

To copy current image into a buffer, use

MIL.MbufGet(MilImage, myBuffer);

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

where myBuffer is a ushort buffer with size equal to total number of pixels in image.

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

To save current image to a file, use

MIL.MbufSave(address,MilImage);

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

If you dont have a .dcf file you can get a default one from matrox installation cd for free. Or just install matrox viewer and in program files you can have one. The image parameters such as width, height and bit depth are got from dcf file. But if you want, you can allocate them in Mbufalloc2d function above.

我会定期检查这个答案。如果有人有任何问题请问我。我会尽量回答这些问题。

I'll try to check this answer periodically. If anyone has any questions ask me. Ill try to answer them to the best of my knowledge.

这篇关于使用Matrox命令捕获帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆