迈创采集卡搭配工业相机二次开发介绍(一)SDK简介
- 迈创采集卡介绍
-
- 迈创采集卡SDK简介
-
- MIL SDK获取路径
- 接口函数说明
-
- MIL接口简单介绍
迈创采集卡介绍
MIL全称为Matrox Imaging Library,由加拿大Matrox公司开发;MIL软件包是一个独立于硬件的、含有多个标准模块或组件的图像库,可以对图像进行采集、处理、分析、显示和存取操作,其功能覆盖图像领域的所有方面,使用起来也相当简单和方便;
MIL-Lite是MIL的子集,含有MIL的部分模块,可以进行图像的采集、显示、存取操作,还可以在图像上进行图形操作及LUT变换等;
MIL/MIL-Lite支持Matrox公司所有采集卡,如果应用程序采用其它公司的采集卡,则不能使用MIL/MIL-Lite的采集功能,但应用程序可以使用MIL/MIL-Lite的其它功能。
在工作中呢,主要接触到迈创的cameralink采集卡、coxpress采集卡,型 例如:CML;solios系列的的SOL 2M EV CLF、SOL 6M CLB E,CXP:rapixo的RAP 4G 4C6 、RAP 4G 4C12
虽然采集卡型 多,但是mil二次开发的基本思路是一样的
迈创采集卡SDK简介
首先,要理解MIL中的五大基本对象,如下图:
MIL的初始化与资源释放需要严格按照顺序进行
1、初始化定义mil的各种变量
2、初始app、systerm、digitizer
不管你使用多少个相机,使用多少张采集卡,同一时间,只有一个app在运行;
MsysAlloc这里需要注意第一个参数,M_SYSTEM_SOLIOS以为着我们使用的采集类型,不同的采集卡,使用不同的参数;
MdigAlloc的第三个参数,通常是传入dcf路径的,官方给的示例,往往传入的是M_DEFAULT默认值,那么就需要在milconfig中进行配置
上面的三个接口,都是分开初始化app、systerm、digitizer,具备更多的灵活性,当然也可以使用MappAllocDefault,进行默认配置,如下面的接口
使用MappAllocDefault,那么默认的卡选项,dcf路径,都需在milconfig中进行配置,如下图所示:
分配buffer呢,有多种情况需要考虑,例如黑白相机,彩色相机,8位图像,10位图像,12位图像,彩色bayer格式,彩色RGB格式等
黑白统一使用MbufAlloc2d这个接口,彩色要使用MbufAllocColor或者MbufAllocColor2d
4、取流函数
mil的取流函数,分成三种连续抓图,单帧抓图,回调抓图
- 连续抓图使用MdigGrabContinuous,搭配MdigHalt(停止采集使用),一般不推荐使用连续抓图
- 单帧抓图MdigGrab,从指定的相机digitizer中获取一张图片,搭配MdigGrabWait,可以在指定超时时间内获取一帧数据
- 回调抓图MdigProcess,支持同步与异步回调两种
下面,跟着注释,来看一下官方提供的MdigProcess例程,结合上面简单讲的,应该就能更好的理解mil sdk开发逻辑
/***************************************************************************************//* * File name: MdigProcess.cpp * * Synopsis: This program shows the use of the MdigProcess() function and its multiple * buffering acquisition to do robust real-time processing. * * The user's processing code to execute is located in a callback function * that will be called for each frame acquired (see ProcessingFunction()). * * Note: The average processing time must be shorter than the grab time or some * frames will be missed. Also, if the processing results are not displayed * and the frame count is not drawn or printed, the CPU usage is reduced * significantly. * * Copyright ? Matrox Electronic Systems Ltd., 1992-2021. * All Rights Reserved */#include /* Number of images in the buffering grab queue. Generally, increasing this number gives a better real-time grab. */#define BUFFERING_SIZE_MAX 20/* User's processing function prototype. */MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType, MIL_ID HookId, void* HookDataPtr);/* User's processing function hook data structure. */typedef struct { MIL_ID MilDigitizer; MIL_ID MilImageDisp; MIL_INT ProcessedImageCount; } HookDataStruct;/* Main function. *//* ---------------*/int MosMain(void){ MIL_ID MilApplication; MIL_ID MilSystem ; MIL_ID MilDigitizer ; MIL_ID MilDisplay ; MIL_ID MilImageDisp ; MIL_ID MilGrabBufferList[BUFFERING_SIZE_MAX] = { 0 }; MIL_INT MilGrabBufferListSize; MIL_INT ProcessFrameCount = 0; MIL_DOUBLE ProcessFrameRate = 0; MIL_INT NbFrames = 0, n = 0; HookDataStruct UserHookData;//上面都是初始化后面要用到的各种变量 /* Allocate defaults. */ //使用MappAllocDefault默认分配app、system等资源,也可以使用MappAlloc、MsysAlloc等函数,单独分配 MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay,&MilDigitizer, M_NULL); /* Allocate a monochrome display buffer. */ //申请一块黑白的8位图像缓存 MbufAlloc2d(MilSystem, MdigInquire(MilDigitizer, M_SIZE_X, M_NULL), MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL), 8 + M_UNSIGNED, M_IMAGE + M_GRAB + M_PROC + M_DISP, &MilImageDisp); MbufClear(MilImageDisp, M_COLOR_BLACK); /* Display the image buffer. */ //锁定显示窗口,使用mil的显示窗 MdispSelect(MilDisplay, MilImageDisp); /* Print a message. */ MosPrintf(MIL_TEXT("nMULTIPLE BUFFERED PROCESSING.n")); MosPrintf(MIL_TEXT("-----------------------------nn")); MosPrintf(MIL_TEXT("Press to start processing.nn" )); /* Grab continuously on the display and wait for a key press. */ //演示连续抓图,直到调用MdigHalt停止 MdigGrabContinuous(MilDigitizer, MilImageDisp); MosGetch();//键盘暂停命令 /* Halt continuous grab. */ MdigHalt(MilDigitizer); /* Allocate the grab buffers and clear them. */ MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);//关闭弹窗打印 错信息 //申请一串buffer,用于回调取流,跟MilImageDisp类似,主要去看BUFFERING_SIZE_MAX,默认申请了20个buffer缓存,避免回调阻塞 for (MilGrabBufferListSize = 0; MilGrabBufferListSizeBUFFERING_SIZE_MAX; MilGrabBufferListSize++) { MbufAlloc2d(MilSystem, MdigInquire(MilDigitizer, M_SIZE_X, M_NULL), MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL), 8 + M_UNSIGNED, M_IMAGE + M_GRAB + M_PROC, &MilGrabBufferList[MilGrabBufferListSize]); if (MilGrabBufferList[MilGrabBufferListSize]) MbufClear(MilGrabBufferList[MilGrabBufferListSize], 0xFF); else break; } MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);//开启弹窗打印 错信息 /* Initialize the user's processing function data structure. */ //回调里面自定义的一些变量初始化,用户也可以自己加一下变量,初始化就行 UserHookData.MilDigitizer = MilDigitizer; UserHookData.MilImageDisp = MilImageDisp; UserHookData.ProcessedImageCount = 0; /* Start the processing. The processing function is called with every frame grabbed. */ //开启回调函数M_START,MilGrabBufferList就是我们想要的buffer MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize,M_START, M_DEFAULT, ProcessingFunction, &UserHookData); /* Here the main() is free to perform other tasks while the processing is executing. */ /* --------------------------------------------------------------------------------- */ /* Print a message and wait for a key press after a minimum number of frames. */ MosPrintf(MIL_TEXT("Press to stop. nn" )); MosGetch(); /* Stop the processing. */ //关闭回调函数M_STOP MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize,M_STOP, M_DEFAULT, ProcessingFunction, &UserHookData); /* Print statistics. */ MdigInquire(MilDigitizer, M_PROCESS_FRAME_COUNT, &ProcessFrameCount);//获取一下回调里面的统计信息,帧 MdigInquire(MilDigitizer, M_PROCESS_FRAME_RATE, &ProcessFrameRate); MosPrintf(MIL_TEXT("nn%d frames grabbed at %.1f frames/sec (%.1f ms/frame).n"), (int)ProcessFrameCount, ProcessFrameRate, 1000.0/ProcessFrameRate); MosPrintf(MIL_TEXT("Press to end.nn" )); MosGetch(); /* Free the grab buffers. */ //清除缓存,注意顺序 while(MilGrabBufferListSize > 0) MbufFree(MilGrabBufferList[--MilGrabBufferListSize]); /* Free display buffer. */ MbufFree(MilImageDisp); /* Release defaults. */ //也有单独释放每一个关键角色的函数 MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, M_NULL); return 0;}/* User's processing function called every time a grab buffer is ready. *//* -------------------------------------------------------------------- *//* Local defines. */#define STRING_LENGTH_MAX 20声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!