分类目录归档:opencv

Matrox Imaging Libray 开发实例

一.数据类型

MIL_ID: MIL标准的实例化类型

MIL_INT:整数类型,可以转化未INT类型使用。但使用MIL库函数时,必须使用MIL_INT,不要用INT代替。部分情况下会计算错误

MIL_DOUBLE:类似同上

二.典型函数举例

1.实例化系统环境

MIL_ID MilApplication,MilSystem;

/* Allocate a MIL application. */
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);

/* Allocate a MIL system. */
MsysAlloc(M_DEFAULT, M_SYSTEM_HOST, M_DEFAULT, M_DEFAULT, &MilSystem);

2.载入/保存图片

MIL_ID MilImage;

MbufRestore(filename.toUtf8().data(), MilSystem,&MilImage);//读取图片

MbufExport(temps.toUtf8().data(),M_PNG,MilImage);//保存成PNG

3.获取图片信息

MIL_INT SrcImageSizeX = 0;
MIL_INT SrcImageSizeY = 0;
MIL_INT SrcImageType = 0;
void* SrcImageDataPtr = M_NULL;
MIL_INT SrcImagePitchByte = 0;
MIL_INT SrcImageDataSize = 0;

MbufInquire(MilImage, M_SIZE_X, &SrcImageSizeX);//宽
MbufInquire(MilImage, M_SIZE_Y, &SrcImageSizeY);//高
MbufInquire(MilImage, M_TYPE, &SrcImageType);//图片类型
MbufInquire(MilImage, M_HOST_ADDRESS, &SrcImageDataPtr);//数据指针
MbufInquire(MilImage, M_PITCH_BYTE, &SrcImagePitchByte);//PitchByte
MbufInquire(MilImage, M_SIZE_BYTE, &SrcImageDataSize);//DataSize

4.获取图片最大最小值

MimAllocResult(MilSystem, M_DEFAULT, M_STAT_LIST, &MilExtreme);
MimStat(MilImage, MilExtreme, M_MAX + M_MIN, M_NULL, M_NULL, M_NULL);//设置要获取值的类型
double max = 0;
double min = 0;
MimGetResult(MilExtreme, M_MAX + M_TYPE_DOUBLE, &max);
MimGetResult(MilExtreme, M_MIN + M_TYPE_DOUBLE, &min);

5.简单计算

MimArith(MilImage, -min, MilImage, M_ADD_CONST);//加一个常数
MimArith(MilImage, scale, MilImage, M_MULT_CONST);//乘一个常数

6.边缘检测

MIL_ID MilEdgeContext,MilEdgeResult;

MedgeAlloc(MilSystem, M_CONTOUR, M_DEFAULT, &MilEdgeContext);
MedgeAllocResult(MilSystem, M_DEFAULT, &MilEdgeResult);

MedgeControl(MilEdgeContext, M_CENTER_OF_GRAVITY, M_ENABLE);//启用计录轮廓位置
MedgeControl(MilEdgeContext, M_AVERAGE_STRENGTH+M_SORT1_DOWN, M_ENABLE);//计算平均强度,并设置排序方式
MedgeControl(MilEdgeContext, M_THRESHOLD_MODE, M_USER_DEFINED);//启用自定义THRESHOLD_MODE
MedgeControl(MilEdgeContext, M_THRESHOLD_LOW, 50);//设置阀值

MedgeCalculate(MilEdgeContext, MilImage, M_NULL,M_NULL, M_NULL, MilEdgeResult,M_DEFAULT);//计算轮廓

MedgeGetResult(MilEdgeResult, M_DEFAULT, M_NUMBER_OF_CHAINS+M_TYPE_MIL_INT,&NumEdgeFound, M_NULL);//获取轮廓数量

MedgeGetResult(MilEdgeResult, n, M_CENTER_OF_GRAVITY +M_TYPE_MIL_INT,
&CENTER_OF_GRAVITY_x, &CENTER_OF_GRAVITY_y);//获取特定轮廓的位置