Frame Capture using Matrox Commands

雨燕双飞 提交于 2019-12-06 01:54:19
DetectiveFishLegs

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.

Some of mine are below:

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

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

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

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.

Seems like you have figured it out but for the ones that have not, all you need to do is include the MIL library and have MIL. before the function name in C++.

Like,

   MbufClear(MilImageDisp[0], 0x0);

->

MIL.MbufClear(MilImage, 0);

Edit for your question on FPS setup: It's automatic based on your camera and DCF.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!