Capturing a frame with Matrox commands

I am working on a project where I need to set the fps of the video stream (as 10) from the camera and capture a frame every 5 frames. I am working on a program that was already half written by someone else. The point is that they used the Matrox Framegrabber DLL. The device also has a Matrox Frame Grabber. But I cannot find any commands for framegrab in C #. I found the following code for C ++.

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

      

Where

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

      

The above command will highlight the display. Can someone please help me write a program in C #. Also, anyone with experience with Matrox DLLs give me an idea on how to approach frame grabbing and adjust fps. Thank.

+3


source to share


2 answers


This is for anyone new to Matrox Framegrabber. The first thing you should do is add the Matrox DLL as a reference. Be aware that there are currently two versions of Matrox out- Matrox 9 and Matrox 10. Depending on the version of Matrox installed on the user's system, a dll should be added. (This can be verified by searching the system catalogs for "MIL_PATH". Then declare some variables to be used when capturing matrox.

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 capturing, 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 the current image to the clipboard use

MIL.MbufGet(MilImage, myBuffer);

      

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

To save the current image to a file use

MIL.MbufSave(address,MilImage);

      

If you do not have the .dcf file, you can get the default file for free from the Matrox installation CD. Or just install Matrox Viewer and you can have it in the program files. Image parameters such as width, height and bit depth are obtained from the dcf file. But if you want, you can place them in Mbufalloc2d function above.

I will try to check this answer periodically. If anyone has any questions, ask. I will try to answer them as far as I know.

+2


source


It sounds like you figured it out, but for those who don't have it, all you have to do is include the MIL library and have the MIL.

function in front of the function name in C ++.

how

   MbufClear(MilImageDisp[0], 0x0);

      



->

MIL.MbufClear(MilImage, 0);

      

Edit your FPS setting question: it is automatically based on your camera and DCF.

0


source







All Articles