Mil学习之Mcal
Posted Thomas会写字
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mil学习之Mcal相关的知识,希望对你有一定的参考价值。
将常用的Mcal模块函数梳理了一下
代码没有调试,可能会有Bug
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Matrox.MatroxImagingLibrary;
using System.IO;
namespace WindowsFormsApplication1
{
public class MilCal
{
MIL_ID MilSystem = MIL.M_NULL;
MIL_ID MilCalibration = MIL.M_NULL;
String strCalFilePath = "";
public MilCal(MIL_ID MilSystem, String strMac)
{
if (MilSystem == MIL.M_NULL)
return;
this.MilSystem = MilSystem;
this.strCalFilePath = strMac;
MIL.McalRestore(strCalFilePath, MilSystem, MIL.M_DEFAULT, ref MilCalibration);
}
public MilCal(MIL_ID MilCalID)
{
if (MilCalID == MIL.M_NULL)
return;
StringBuilder ObjectFilePath = new StringBuilder();
MIL.MobjInquire(MilCalID, MIL.M_OWNER_SYSTEM, ref MilSystem);
MIL.MobjInquire(MilCalID, MIL.M_OBJECT_FILE_PATH, ObjectFilePath);
strCalFilePath = ObjectFilePath.ToString();
}
public MilCal(MIL_ID MilSystem, MIL_ID MilCalID)
{
if (MilSystem == MIL.M_NULL)
return;
this.MilSystem = MilSystem;
this.MilCalibration = MilCalID;
StringBuilder ObjectFilePath = new StringBuilder();
MIL.MobjInquire(MilCalID, MIL.M_OBJECT_FILE_PATH, ObjectFilePath);
strCalFilePath = ObjectFilePath.ToString();
}
public void MilCalFree()
{
if (MilCalibration != MIL.M_NULL)
{
MIL.McalFree(MilCalibration);
MilCalibration = MIL.M_NULL;
}
}
public int MilCalCamera(ref MIL_ID MilInputImg, MIL_INT ChessGrid_Rows, MIL_INT ChessGrid_Cols, double ChessGrid_RowSpacing, double ChessGrid_ColSpacing)
{
if (MilInputImg == MIL.M_NULL)
{
return 1;
}
MilCalFree();
MIL.McalAlloc(MilSystem, MIL.M_DEFAULT, MIL.M_DEFAULT, ref MilCalibration);
if (ChessGrid_Rows * ChessGrid_Cols > 0)
MIL.McalGrid(MilCalibration, MilInputImg, 0, 0, 0,
ChessGrid_Rows, ChessGrid_Cols,
ChessGrid_RowSpacing, ChessGrid_ColSpacing,
MIL.M_DEFAULT, MIL.M_CHESSBOARD_GRID);
else
{
MIL.McalControl(MilCalibration, MIL.M_GRID_PARTIAL, MIL.M_ENABLE);
MIL.McalGrid(MilCalibration, MilInputImg, 0.0, 0.0,
MIL.M_NULL, MIL.M_UNKNOWN, MIL.M_UNKNOWN,
ChessGrid_RowSpacing, ChessGrid_ColSpacing,
MIL.M_FULL_CALIBRATION, MIL.M_CHESSBOARD_GRID);
}
if (MilCalGetCalState() == true)
return 0;
MilCalFree();
return 2;
}
public void MilCalSave(string strFilePathAndFileName)
{
MIL.McalSave(strFilePathAndFileName, MilCalibration, MIL.M_DEFAULT);
}
public void MilCalTransPixel2World(double dPixelX, double dPixelY, ref double dWordX, ref double dWordY)
{
if (MilCalibration != MIL.M_NULL)
{
MIL.McalTransformCoordinate(MilCalibration,
MIL.M_PIXEL_TO_WORLD,
dPixelX, dPixelY, ref dWordX, ref dWordY);
}
}
public void MilCalTransWorld2Pixel(double dWordX, double dWordY, ref double dPixelX, ref double dPixelY)
{
if (MilCalibration != MIL.M_NULL)
{
MIL.McalTransformCoordinate(MilCalibration,
MIL.M_WORLD_TO_PIXEL,
dWordX, dWordY, ref dPixelX, ref dPixelY);
}
}
public void MilCalTransPixel2World(double dLenPixel, ref double dLenWorld)
{
if (MilCalibration != MIL.M_NULL)
{
MIL.McalTransformResult(MilCalibration, MIL.M_PIXEL_TO_WORLD, MIL.M_LENGTH, dLenPixel, ref dLenWorld);
}
}
public void MilCalTransWorld2Pixel(double dLenWorld, ref double dLenPixel)
{
if (MilCalibration != MIL.M_NULL)
{
MIL.McalTransformResult(MilCalibration, MIL.M_WORLD_TO_PIXEL, MIL.M_LENGTH, dLenWorld, ref dLenPixel);
}
}
public bool MilCalGetCalState()
{
MIL_ID CalibrationStatus = MIL.M_NULL;
MIL.McalInquire(MilCalibration, MIL.M_CALIBRATION_STATUS + MIL.M_TYPE_MIL_INT, ref CalibrationStatus);
return CalibrationStatus == MIL.M_CALIBRATED;
}
public void MilCalGetCalInfo(ref int nRowNum, ref int nColNum, ref double dRowSpacing, ref double dColSpacing)
{
MIL.McalInquire(MilCalibration, MIL.M_COLUMN_NUMBER + MIL.M_TYPE_MIL_INT, ref nColNum);
MIL.McalInquire(MilCalibration, MIL.M_ROW_NUMBER + MIL.M_TYPE_MIL_INT, ref nRowNum);
MIL.McalInquire(MilCalibration, MIL.M_COLUMN_SPACING, ref dColSpacing);
MIL.McalInquire(MilCalibration, MIL.M_ROW_SPACING, ref dRowSpacing);
}
public void MilCalGetCalPoints(ref double[] dPtsX, ref double[] dPtsY)
{
MIL_INT PtNum = 0;
MIL.McalInquire(MilCalibration, MIL.M_CALIBRATION_IMAGE_POINTS_X + MIL.M_NB_ELEMENTS + MIL.M_TYPE_MIL_INT, ref PtNum);
dPtsX = new double[PtNum];
MIL.McalInquire(MilCalibration, MIL.M_CALIBRATION_IMAGE_POINTS_X, dPtsX);
MIL.McalInquire(MilCalibration, MIL.M_CALIBRATION_IMAGE_POINTS_Y + MIL.M_NB_ELEMENTS + MIL.M_TYPE_MIL_INT, ref PtNum);
dPtsY = new double[PtNum];
MIL.McalInquire(MilCalibration, MIL.M_CALIBRATION_IMAGE_POINTS_Y, dPtsY);
}
public void MilCalDrawAxis(MIL_ID MilGraContext, MIL_ID MilGraList, double dColor)
{
MIL.MgraColor(MilGraContext, dColor);
MIL.McalDraw(MilGraContext, MilCalibration, MilGraList, MIL.M_DRAW_RELATIVE_COORDINATE_SYSTEM + MIL.M_DRAW_FRAME, MIL.M_DEFAULT, MIL.M_DEFAULT);
}
public void MilCalDrawPoints(MIL_ID MilGraContext, MIL_ID MilGraList, double dColor)
{
MIL.MgraColor(MilGraContext, dColor);
MIL.McalDraw(MilGraContext, MilCalibration, MilGraList, MIL.M_DRAW_IMAGE_POINTS, MIL.M_DEFAULT, MIL.M_DEFAULT);
}
public void MilCalDrawRegion(MIL_ID MilGraContext, MIL_ID MilGraList, double dColor)
{
MIL.MgraColor(MIL.M_DEFAULT, dColor);
MIL.McalDraw(MilGraContext, MilCalibration, MilGraList, MIL.M_DRAW_VALID_REGION, MIL.M_DEFAULT, MIL.M_DEFAULT);
}
}
}
以上是关于Mil学习之Mcal的主要内容,如果未能解决你的问题,请参考以下文章
Mil学习之 MimLocateEvent 获取特定属性的像素坐标