Commit f35a56e9 刘韬

添加项目文件。

1 个父辈 0d3629f7

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarerayImage", "CarerayImage\CarerayImage.csproj", "{BFCB03F8-CD69-4F02-8336-65DDFF73D385}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarerayImage_Test", "CarerayImage_Test\CarerayImage_Test.csproj", "{01B38047-138C-45CB-A5F8-7F472E92A43A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Debug|x64.ActiveCfg = Debug|Any CPU
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Debug|x64.Build.0 = Debug|Any CPU
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Release|Any CPU.Build.0 = Release|Any CPU
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Release|x64.ActiveCfg = Release|Any CPU
{BFCB03F8-CD69-4F02-8336-65DDFF73D385}.Release|x64.Build.0 = Release|Any CPU
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Debug|x64.ActiveCfg = Debug|x64
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Debug|x64.Build.0 = Debug|x64
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Release|Any CPU.Build.0 = Release|Any CPU
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Release|x64.ActiveCfg = Release|x64
{01B38047-138C-45CB-A5F8-7F472E92A43A}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC65A33D-383F-4115-B862-0DF1F134F1B8}
EndGlobalSection
EndGlobal
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Threading.Tasks;
using static Asa.eyemLib;
namespace Asa
{
/// <summary>
/// Careray平板图像
/// </summary>
public class CarerayImage : XrayImageInterface
{
private byte[] buffer;
private API.CR_EventID eventID;
private API.CallbackDelegate callback;
private const int HEAD = 64;
private const int DEV_INDEX = 1;
private const int MODE_ID = 103;
private readonly log4net.ILog LOG;
/// <summary>
/// Careray平板图像
/// </summary>
public CarerayImage(string logName = "CarerayImage")
{
callback = new API.CallbackDelegate(Process);
LOG = log4net.LogManager.GetLogger(logName);
}
/// <summary>
/// 窗宽
/// </summary>
public int WindowWidth { set; get; } = 65535;
/// <summary>
/// 窗位
/// </summary>
public int WindowLevel { set; get; } = 32768;
/// <summary>
/// 图像宽度
/// </summary>
public int ImageWidth { private set; get; } = 2816;
/// <summary>
/// 图像高度
/// </summary>
public int ImageHeight { private set; get; } = 2816;
/// <summary>
/// IP地址
/// </summary>
public string IP { private set; get; }
/// <summary>
/// 打开设备
/// </summary>
/// <returns></returns>
public bool Open()
{
int rtn;
//注册回调函数
callback = new API.CallbackDelegate(Process);
rtn = API.CR_RegisterEventCallbackFun(DEV_INDEX, callback);
LOG.Info("CR_RegisterEventCallbackFun Return " + rtn);
if (rtn != 0) return false;
GC.KeepAlive(callback);
//连接设备
rtn = API.CR_Connect(DEV_INDEX);
LOG.Info("CR_Connect Return " + rtn);
if (rtn != 0) return false;
//获取IP
rtn = API.CR_GetDetectorIndexAndIPAddress(out API.CR_DetrIdxAndIPAddr pDetrIdxAndIPAddr, out int pDetrNum);
LOG.Info("CR_GetDetectorIndexAndIPAddress Return " + rtn + " DetrNum=" + pDetrNum);
if (rtn != 0) return false;
int len = Array.FindIndex(pDetrIdxAndIPAddr.szIPAddr, b => b == 0);
IP = System.Text.Encoding.ASCII.GetString(pDetrIdxAndIPAddr.szIPAddr, 0, len);
//重置不重启
rtn = API.CR_ResetDetector(DEV_INDEX, false);
LOG.Info("CR_ResetDetector Return " + rtn);
if (rtn != 0) return false;
//获取应用模式
API.CR_ModeInfo[] pModeInfo = new API.CR_ModeInfo[10];
for (int i = 0; i < pModeInfo.Length; i++)
pModeInfo[i] = new API.CR_ModeInfo();
rtn = API.CR_GetApplicationMode(DEV_INDEX, pModeInfo, out int pModeNum);
LOG.Info("CR_GetApplicationMode Return " + rtn + " ModeNum=" + pModeNum);
if (rtn != 0) return false;
//获取图像宽度高度
for (int i = 0; i < pModeNum; i++)
{
if (pModeInfo[i].nModeID == MODE_ID)
{
ImageWidth = pModeInfo[i].nImageWidth;
ImageHeight = pModeInfo[i].nImageHeight;
LOG.Info("ImageWidth=" + ImageWidth + ", ImageHeight=" + ImageHeight);
break;
}
}
//设置参数
float pFrameRate = 1.2f; //帧率
int pExposureTime = 0; //积分时间
int nTriggType = 9; //触发类型,内触发
int nGainIndex = 6; //增益
rtn = API.CR_SetApplicationModeWithParam(DEV_INDEX, MODE_ID, ref pFrameRate, ref pExposureTime, nTriggType, nGainIndex);
LOG.Info(string.Format("CR_SetApplicationModeWithParam({0},{1},{2},{3},{4},{5}) Return {6}", DEV_INDEX, MODE_ID, pFrameRate, pExposureTime, nTriggType, nGainIndex, rtn));
if (rtn != 0) return false;
return true;
}
/// <summary>
/// 关闭设备
/// </summary>
/// <returns></returns>
public bool Close()
{
int rtn;
//还在采集图像
if (eventID == API.CR_EventID.CR_EVT_NEW_FRAME)
{
rtn = API.CR_StopAcquisition(DEV_INDEX);
LOG.Info("CR_StopAcquisition Return " + rtn);
}
//关闭设备
rtn = API.CR_Disconnect(DEV_INDEX);
LOG.Info("CR_Disconnect Return " + rtn);
if (rtn != 0) return false;
return true;
}
CancellationTokenSource AcquisitionWaitstopToken = new CancellationTokenSource();
int addFrameCount = 0;
int MaxFrameCount = 3;
/// <summary>
/// 获取图像
/// </summary>
/// <returns></returns>
public bool GetImage(int _MaxFrameCount=3,int MaxDelay=5000)
{
MaxFrameCount = _MaxFrameCount;
AcquisitionWaitstopToken = new CancellationTokenSource();
addFrameCount = 0;
buffer = new byte[ImageWidth * ImageHeight * 2 + HEAD];
for (int i = 0; i < buffer.Length; i++)
buffer[i] = 255;
int rtn;
rtn = API.CR_StartAcquisition(DEV_INDEX, 1, buffer);
LOG.Info("CR_StartAcquisition Return " + rtn);
if (rtn != 0) return false;
Task.Delay(MaxDelay, AcquisitionWaitstopToken.Token).Wait();
rtn = API.CR_StopAcquisition(DEV_INDEX);
LOG.Info("CR_StopAcquisition Return " + rtn);
if (rtn != 0) return false;
return true;
}
/// <summary>
/// 加载本地RAW图片,64字节头
/// </summary>
/// <param name="filePath">图片路径</param>
public void LoadRAW(string filePath)
{
buffer = System.IO.File.ReadAllBytes(filePath);
}
/// <summary>
/// 保存本地RAW图片
/// </summary>
/// <param name="filePath">图片路径</param>
public void SaveRAW(string filePath)
{
if (buffer == null) return;
System.IO.File.WriteAllBytes(filePath, buffer);
}
/// <summary>
/// 获取48位RGB图像
/// </summary>
/// <returns></returns>
public Bitmap Get48bImage()
{
if (buffer == null) return null;
if (ImageWidth <= 0 || ImageHeight <= 0)
{
LOG.Info("宽高不正确,ImageWidth=" + ImageWidth + ", ImageHeight=" + ImageHeight);
return null;
}
//2020年6月12日
//RemoveCircle();
int count = ImageWidth * ImageHeight;
byte[] gray = new byte[count * 2];
Array.Copy(buffer, HEAD, gray, 0, gray.Length);
int idx1 = 0;
int idx2 = 0;
int half = WindowWidth / 2;
byte[] buff = new byte[gray.Length * 3];
for (int i = 0; i < count; i++)
{
short point = BitConverter.ToInt16(gray, idx1);
//point += 20000;
if (point < WindowLevel - half)
{
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
}
else if (point > WindowLevel + half)
{
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
}
else
{
byte[] bb = BitConverter.GetBytes(point);
buff[idx2++] = bb[0];
buff[idx2++] = bb[1];
buff[idx2++] = bb[0];
buff[idx2++] = bb[1];
buff[idx2++] = bb[0];
buff[idx2++] = bb[1];
}
idx1 += 2;
}
/*
var bufferGCHandle = GCHandle.Alloc(buffer);
IntPtr intPtr = Marshal.UnsafeAddrOfPinnedArrayElement<byte>(buff, 0);
Bitmap bmp1 = new Bitmap(ImageWidth, ImageHeight, ImageWidth * 6, System.Drawing.Imaging.PixelFormat.Format48bppRgb, intPtr);
Bitmap bmp = DeepClone(bmp1);
for (int i = 0; i < buff.Length; i++)
buff[i] = 255;
bufferGCHandle.Free();
*/
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, System.Drawing.Imaging.PixelFormat.Format48bppRgb);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, ImageWidth, ImageHeight), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
Marshal.Copy(buff, 0, bmpData.Scan0, bmpData.Stride * ImageHeight);
bmp.UnlockBits(bmpData);
return bmp;
}
IntPtr BufferPtr;
/// <summary>
/// 获取raw数据指针
/// </summary>
/// <returns></returns>
public EyemImage GetRawBufferHandle()
{
EyemImage eyemImage = new EyemImage();
if (buffer == null)
throw new Exception("图像buffer为空");
if (ImageWidth <= 0 || ImageHeight <= 0)
{
LOG.Info("宽高不正确,ImageWidth=" + ImageWidth + ", ImageHeight=" + ImageHeight);
throw new Exception("图像宽高不正确");
}
BufferPtr = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, HEAD, BufferPtr, buffer.Length - HEAD);
eyemImage.ucpImage = BufferPtr;
eyemImage.iWidth = ImageWidth;
eyemImage.iHeight = ImageHeight;
//eyemImage.iChannel = 0;
eyemImage.iChannels = 1;
eyemImage.iDepth = 2;
return eyemImage;
}
/// <summary>
/// 释放RawBuffer指针
/// </summary>
public void FreeRawBufferHandle() {
try
{
Marshal.FreeHGlobal(BufferPtr);
}
catch { }
}
internal void Process(int nEventID, ref API.CR_Event pEvent)
{
eventID = (API.CR_EventID)nEventID;
Debug.Print("nEventID=" + nEventID);
if (eventID == API.CR_EventID.CR_EVT_NEW_FRAME)
{
addFrameCount++;
LOG.Debug(string.Format("nEventID={0} {1} {2}", nEventID, eventID, addFrameCount));
if (addFrameCount > MaxFrameCount)
{
AcquisitionWaitstopToken.Cancel();
LOG.Debug("AcquisitionWaitstopToken.Cancel");
}
}
else {
LOG.Debug(string.Format("nEventID={0} {1}", nEventID, eventID));
}
}
}
/// <summary>
/// CRInterface API
/// </summary>
public static class API
{
[DllImport("CRInterface.dll")]
internal static extern int CR_Connect(int nDetrIndex);
[DllImport("CRInterface.dll")]
internal static extern int CR_Disconnect(int nDetrIndex);
[DllImport("CRInterface.dll")]
internal static extern int CR_GetSystemInformation(int nDetrIndex, out CR_SystemInfo pSystemInformation);
[DllImport("CRInterface.dll")]
internal static extern int CR_ResetDetector(int nDetrIndex, bool needReboot);
[DllImport("CRInterface.dll")]
internal static extern int CR_StartAcquisition(int nDetrIndex, int nFrameNum, [In, Out] byte[] pBuffer, int nNumFrmReqFromDetr = -1); // nNumFrmReqFromDetr == -1 means that detector sends out frames continuously until StopAcquisition() is received.
[DllImport("CRInterface.dll")]
internal static extern int CR_StopAcquisition(int nDetrIndex);
[DllImport("CRCallback.dll")]
internal static extern int CR_RegisterEventCallbackFun(int nDetrIndex, CallbackDelegate pCallback);
[DllImport("CRInterface.dll")]
internal static extern int CR_SetApplicationMode(int nDetrIndex, int nModeIndex);
[DllImport("CRInterface.dll")]
internal static extern int CR_GetApplicationMode(int nDetrIndex, [In, Out] CR_ModeInfo[] pModeInfo, out int pModeNum);
[DllImport("CRInterface.dll")]
internal static extern int CR_GetDetectorIndexAndIPAddress(out CR_DetrIdxAndIPAddr pDetrIdxAndIPAddr, out int pDetrNum);
[DllImport("CRInterface.dll")]
internal static extern int CR_SetApplicationModeWithParam(int nDetrIndex, int nModeIndex, ref float pFrameRate, ref int pExposureTime, int nTriggType, int nGainIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void CallbackDelegate(int nEventID, ref CR_Event pEvent);
[StructLayout(LayoutKind.Sequential)]
internal struct CR_Event
{
internal int nDetrIndex;
internal int nWidth;
internal int nHeight;
internal int nPixelDepth;
internal int pData;
}
[StructLayout(LayoutKind.Sequential)]
internal struct CR_SystemInfo
{
internal uint nRawImageWidth;
internal uint nRawImageHeight;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
internal byte[] szHardwareVersion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
internal byte[] szSerialNumber;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
internal byte[] szSoftwareVersion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
internal byte[] szFirmwareVersion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
internal byte[] szDetrMachineID;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
internal byte[] szDetrDesc;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
internal byte[] szReserved;
}
[StructLayout(LayoutKind.Sequential)]
internal struct CR_ModeInfo
{
internal int nModeID; // Application mode ID
internal int nImageWidth;
internal int nImageHeight;
internal int nCutoffX;
internal int nCutoffY;
internal int nBinX; // Binning scheme along X direction
internal int nBinY; // Binning scheme along Y direction
internal float fMaxFrmRate; // Maximal frame rate in fps
internal int nMaxExpTime; // Maximal exposure time in ms
internal int nPixelDepth; // Pixel depth in bits
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
internal int[] nTrigTypes;
internal int nTrigTypeNum; // 0 - 15
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
internal int[] nGainLevels;
internal int nGainLevelNum; // 0 - 15
internal int nDefaultTrigType; // Default trigger type
internal int nDefaultGainLevel; // Default gain level
internal int nRoiX;
internal int nRoiY;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
internal byte[] szDesc; // Additional description
}
[StructLayout(LayoutKind.Sequential)]
internal struct CR_DetrIdxAndIPAddr
{
internal int nIdx;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
internal byte[] szIPAddr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
internal byte[] szReserved;
}
internal enum CR_EventID
{
CR_EVT_SERVER_DISCONNECTED,
CR_EVT_DETR_DISCONNECTED,
CR_EVT_EXPOSURE_INFO,
CR_EVT_TEMPERATURE_INFO,
CR_EVT_BATTERY_INFO,
CR_EVT_WIRELESS_INFO,
CR_EVT_NEW_FRAME,
CR_EVT_CALIBRATION_IN_PROGRESS,
CR_EVT_CALIBRATION_FINISHED,
CR_EVT_ACQ_STAT_INFO
};
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BFCB03F8-CD69-4F02-8336-65DDFF73D385}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Asa</RootNamespace>
<AssemblyName>Asa.CarerayImage</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Asa.CarerayImage.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ConfigHelper">
<HintPath>..\..\ConfigHelper\ConfigHelper\bin\Debug\ConfigHelper.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\..\..\DLL\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="eyemLib.cs" />
<Compile Include="haobo.cs" />
<Compile Include="HaoboSDK\HBI_FPD_DLL.cs" />
<Compile Include="XrayImage.cs" />
<Compile Include="CarerayImage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XrayImageInterface.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="bin\Debug\Asa.CarerayImage.dll" />
<Content Include="bin\Debug\Asa.CarerayImage.pdb" />
<Content Include="bin\Debug\Asa.CarerayImage.xml" />
<Content Include="bin\Debug\CRCallback.dll" />
<Content Include="bin\Debug\CRInterface.dll" />
<Content Include="bin\Debug\log4net.dll" />
</ItemGroup>
<ItemGroup>
<None Include="bin\Debug\CRCallback.lib" />
</ItemGroup>
<ItemGroup>
<Folder Include="bin\Release\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file \ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Asa.HaoboSDK
{
public class HBI_FPD_DLL
{
/// <summary>
/// 记录与Detector连接后的句柄
/// </summary>
public static IntPtr _handel;
#region functions
/*********************************************************
* 函 数 名: HBI_Init
* 功能描述: 初始化动态库
* 参数说明:
* 返 回 值:IntPtr
失败:NULL,成功:非空
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_Init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr HBI_Init();
/*********************************************************
* 函 数 名: HBI_Destroy
* 功能描述: 释放动态库资源
* 参数说明:
In: IntPtr handle - 句柄
Out: 无
* 返 回 值:void
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_Destroy", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern void HBI_Destroy(IntPtr handle);
/*********************************************************
* 函 数 名: HBI_RegEventCallBackFun
* 功能描述: 注册回调函数
* 参数说明:
In: IntPtr handle - 句柄(无符号指针)
USER_CALLBACK_HANDLE_ENVENT handleEventfun - 注册回调函数
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_RegEventCallBackFun", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_RegEventCallBackFun(IntPtr handle, USER_CALLBACK_HANDLE_ENVENT handleEventfun);
/*********************************************************
* 函 数 名: HBI_ConnectDetector
* 功能描述: 建立连接
* 参数说明:
In: IntPtr handle - 句柄(无符号指针)
String szRemoteIp - 平板IP地址,如192.168.10.40
ushort remotePort - 平板端口,如32897(0x8081)
String szlocalIp - 上位机地址,如192.168.10.20
ushort localPort -上位机端口,如192.168.10.40
int timeout - 上位机接收超时,如20ms
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_ConnectDetector", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_ConnectDetector(IntPtr handle, string szRemoteIp, ushort remotePort, string szlocalIp, ushort localPort, int timeout);
/*********************************************************
* 函 数 名: HBI_DisConnectDetector
* 功能描述: 断开连接
* 参数说明:
In: IntPtr handle - 句柄(无符号指针)
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_DisConnectDetector", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_DisConnectDetector(IntPtr handle);
/*********************************************************
* 函 数 名: HBI_GetDevCfgInfo
* 功能描述: 获取固件ROM参数
* 参数说明:
In: void *handle - 句柄(无符号指针)
Out:RegCfgInfo* pRegCfg,见HbDllType.h。
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_GetDevCfgInfo", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_GetDevCfgInfo(IntPtr handle, ref RegCfgInfo pRegCfg);
/*********************************************************
* 函 数 名: HBI_Prepare
* 功能描述: 软触发,清空准备指令
* 参数说明:
In: IntPtr handle - 句柄(无符号指针)
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
0 成功
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_Prepare", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_Prepare(IntPtr handle);
/*********************************************************
* 函 数 名: HBI_SingleAcquisition
* 功能描述: 单帧采集
* 参数说明:
In: IntPtr handle - 句柄(无符号指针)
FPD_AQC_MODE _mode - 采集模式以及参数
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_SingleAcquisition", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_SingleAcquisition(IntPtr handle, FPD_AQC_MODE _mode);
/*********************************************************
* 函 数 名: HBI_LiveAcquisition
* 功能描述: 连续采集
* 参数说明:
In: IntPtr handle - 句柄(无符号指针)
FPD_AQC_MODE _mode - 采集模式以及参数
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_LiveAcquisition", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_LiveAcquisition(IntPtr handle, FPD_AQC_MODE _mode);
/*********************************************************
* 函 数 名: HBI_StopAcquisition
* 功能描述: 停止连续采集
* 参数说明:
In: IntPtr handle - 句柄(无符号指针)
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_StopAcquisition", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_StopAcquisition(IntPtr handle);
/*********************************************************
* 函 数 名: HBI_GetImageProperty
* 功能描述: 获取图像属性
* 参数说明:
In: void *handle - 句柄(无符号指针)
Out: IMAGE_PROPERTY *img_pro,见HbDllType.h。
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_GetImageProperty", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_GetImageProperty(IntPtr handle, ref IMAGE_PROPERTY img_pro);
/*********************************************************
* 函 数 名: HBI_UpdateTriggerMode
* 功能描述: 设置触发模式
* 参数说明:
In: void *handle - 句柄(无符号指针)
int _triggerMode,1-软触发,3-高压触发,4-FreeAED。
Out:无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_UpdateTriggerMode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_UpdateTriggerMode(IntPtr handle, int _triggerMode);
/*********************************************************
* 函 数 名: HBI_TriggerAndCorrectApplay
* 功能描述: 设置触发模式和图像校正使能(工作站)新版本
* 参数说明:
In: void *handle - 句柄(无符号指针)
int _triggerMode,1-软触发,3-高压触发,4-FreeAED。
IMAGE_CORRECT_ENABLE* pCorrect,见HbDllType.h。
Out:无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_TriggerAndCorrectApplay", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_TriggerAndCorrectApplay(IntPtr handle, int _triggerMode, ref IMAGE_CORRECT_ENABLE pCorrect);
/*********************************************************
* 函 数 名: HBI_UpdateCorrectEnable
* 功能描述: 更新图像固件校正使能
* 参数说明:
In: void *handle - 句柄(无符号指针)
IMAGE_CORRECT_ENABLE* pCorrect,见HbDllType.h。
Out:无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_UpdateCorrectEnable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_UpdateCorrectEnable(IntPtr handle, ref IMAGE_CORRECT_ENABLE pCorrect);
/*********************************************************
* 函 数 名: HBI_GetCorrectEnable
* 功能描述: 获取图像固件校正使能
* 参数说明:
In: void *handle - 句柄(无符号指针)
IMAGE_CORRECT_ENABLE* pCorrect,见HbDllType.h。
Out:无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_GetCorrectEnable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_GetCorrectEnable(IntPtr handle, ref IMAGE_CORRECT_ENABLE pCorrect);
/*********************************************************
* 函 数 名: HBI_GetFirmareVerion
* 功能描述: 获取固件版本号
* 参数说明:
In: void *handle - 句柄(无符号指针)
Out: char *szVer
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_GetFirmareVerion", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_GetFirmareVerion(IntPtr handle, StringBuilder szFirmwareVer);
/*********************************************************
* 函 数 名: HBI_GetSDKVerion
* 功能描述: 获取SDK版本号
* 参数说明:
In: void *handle - 句柄(无符号指针)
Out: char *szVer
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_GetSDKVerion", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_GetSDKVerion(IntPtr handle, StringBuilder szSDKVer);
/*********************************************************
* 函 数 名: HBI_SetAcqSpanTm
* 功能描述: 设置采集时间间隔
* 参数说明:
In: void *handle - 句柄(无符号指针)
int time - 间隔时间,单位是毫秒ms,>= 1000ms
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_SetAcqSpanTm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_SetAcqSpanTm(IntPtr handle, int time);
/*********************************************************
* 函 数 名: HBI_GetAcqSpanTm
* 功能描述: 获取采集时间间隔
* 参数说明:
In: void *handle - 句柄(无符号指针)
out:int *out_time - 时间,单位是毫秒ms
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_GetAcqSpanTm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_GetAcqSpanTm(IntPtr handle, ref int time);
/*********************************************************
* 函 数 名: HBI_SetPreAcqTm
* 功能描述: 设置软触发单帧采集清空和采集之间的时间间隔
* 参数说明:
In: void *handle - 句柄(无符号指针)
int *in_itime - 时间 [0~10000] 单位:mm
0-表示软触发单帧采集先HBI_Prepare后HBI_SingleAcquisition完成单帧采集
非0-表示软触发单帧采集,只需HBI_Prepare即可按照预定时间完成单帧采集
* 返 回 值:int
0 - 成功(
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_SetPreAcqTm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_SetPreAcqTm(IntPtr handle, int intime);
/*********************************************************
* 函 数 名: HBI_GetPreAcqTm
* 功能描述: 获取软触发单帧采集清空和采集之间的时间间隔
* 参数说明:
In: void *handle - 句柄(无符号指针)
out:int *out_itime - 时间 [0~10000] 单位:mm
0-表示软触发单帧采集先HBI_Prepare后HBI_SingleAcquisition完成单帧采集
非0-表示软触发单帧采集,只需HBI_Prepare即可按照预定时间完成单帧采集
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_GetPreAcqTm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_GetPreAcqTm(IntPtr handle, ref int outtime);
/*********************************************************
* 函 数 名: HBI_16UCConvertTo8UC
* 功能描述: 16位数据转换为8位
* 参数说明:
In: void *handle - 句柄(无符号指针)
In/Out: unsigned char *imgbuff
In/Out: int *nbufflen
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_16UCConvertTo8UC", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_16UCConvertTo8UC(IntPtr handle, IntPtr imgbuff, ref int nbufflen);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//// 其他接口类似,用户根据需求添加
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#endregion
}
#region delegate
// Notice: call back function
// @USER_CALLBACK_HANDLE_ENVENT
// @cmd:enum eEventCallbackCommType
// @buff
// @len
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int USER_CALLBACK_HANDLE_ENVENT(byte cmd, IntPtr buff, int len, int id);
#endregion
#region enum
public enum EFpdStatusType
{
FPD_STATUS_CONN = 0x00,
FPD_STATUS_DISCONN,
FPD_STATUS_READY,
FPD_STATUS_BUSY,
FPD_STATUS_PREPARE
};
// Notice:Fpd Trigger Work Mode
public enum EnumTRIGGER_MODE
{
INVALID_TRIGGER_MODE = 0x00, // 无效触发模式
STATIC_SOFTWARE_TRIGGER_MODE = 0x01, // 软触发模式
STATIC_PREP_TRIGGER_MODE = 0x02, //
STATIC_HVG_TRIGGER_MODE = 0x03, // 高压触发
STATIC_AED_TRIGGER_MODE = 0x04, // AED
DYNAMIC_HVG_TRIGGER_MODE = 0x05,
DYNAMIC_FPD_TRIGGER_MODE = 0x06
};
// Notice: acq mode:static and dynamic
public enum EnumIMAGE_ACQ_MODE
{
//STATIC_ACQ_DEFAULT_MODE = 0x00, // 默认单帧采集
//DYNAMIC_ACQ_DEFAULT_MODE, // 默认连续采集
//DYNAMIC_ACQ_BARK_MODE, // 生成模板-连续采集暗场图
//DYNAMIC_ACQ_BRIGHT_MODE, // 生成模板-连续采集亮场图
//STATIC_ACQ_BRIGHT_MODE // 生成模板-单帧采集亮场图
STATIC_ACQ_DEFAULT_MODE = 0x00, // 默认单帧采集
DYNAMIC_ACQ_DEFAULT_MODE, // 默认连续采集
DYNAMIC_ACQ_BARK_MODE, // 创建Offset模板-连续采集暗场图
DYNAMIC_ACQ_BRIGHT_MODE, // 创建Gain模板-连续采集亮场图
STATIC_ACQ_BRIGHT_MODE, // 创建Gain模板-单帧采集亮场图
STATIC_DEFECT_ACQ_MODE, // 创建Defect模板-单帧采集亮场图
DYNAMIC_DEFECT_ACQ_MODE // 创建Defect模板-连续采集亮场图
};
// Notice: After Each Member Variables, show Variables enum ,
// before '-' is variables' value, after '-' is the meaning of the value;
// each value departed by ';' symbol
public enum eRequestCommType
{
EDL_COMMON_TYPE_INVALVE = 0x00,
EDL_COMMON_TYPE_GLOBAL_RESET = 0x01,
EDL_COMMON_TYPE_PREPARE = 0x02,
EDL_COMMON_TYPE_SINGLE_SHORT = 0x03,
EDL_COMMON_TYPE_LIVE_ACQ = 0x04,
EDL_COMMON_TYPE_STOP_ACQ = 0x05,
EDL_COMMON_TYPE_PACKET_MISS = 0x06,
EDL_COMMON_TYPE_FRAME_MISS = 0x07,
EDL_COMMON_TYPE_DUMMPING = 0x08,
EDL_COMMON_TYPE_END_RESPONSE = 0x0A, // End response packet
EDL_COMMON_TYPE_SET_RAM_PARAM_CFG = 0x10,
EDL_COMMON_TYPE_GET_RAM_PARAM_CFG = 0x11,
EDL_COMMON_TYPE_SET_ROM_PARAM_CFG = 0x12,
EDL_COMMON_TYPE_GET_ROM_PARAM_CFG = 0x13,
EDL_COMMON_TYPE_SET_FACTORY_PARAM_CFG = 0x14,
EDL_COMMON_TYPE_GET_FACTORY_PARAM_CFG = 0x15,
EDL_COMMON_TYPE_RESET_FIRM_PARAM_CFG = 0x16,
EDL_COMMON_UPLOAD_GAIN_TEMPLATE = 0x2F,// Upload gain template
EDL_COMMON_UPLOAD_DEFECT_TEMPLATE = 0x30,// Upload defect template
EDL_COMMON_ERASE_FIRMWARE = 0x4F,// Erase old firmware package request
EDL_COMMON_UPDATE_FIRMWARE = 0x50,// Update new firmware package request
EDL_COMMON_TYPE_SET_AQC_MODE = 0xFF
};
// Notice: After Each Member Variables, show Variables enum ,
// before '-' is variables' value, after '-' is the meaning of the value;
// each value departed by ';' symbol
public enum eCallbackEventCommType
{
ECALLBACK_TYPE_INVALVE = 0X00,
ECALLBACK_TYPE_COMM_RIGHT = 0X01,
ECALLBACK_TYPE_COMM_WRONG = 0X02,
ECALLBACK_TYPE_DUMMPLING = 0X03,
ECALLBACK_TYPE_ACQ_END = 0X04,
ECALLBACK_TYPE_UPDATE_FIRMWARE = 0X06, // Update old firmware package answer
ECALLBACK_TYPE_ERASE_FIRMWARE = 0X07, // Update new firmware package answer
ECALLBACK_TYPE_FPD_STATUS = 0X09, // Status package
ECALLBACK_TYPE_ROM_UPLOAD = 0X10,
ECALLBACK_TYPE_RAM_UPLOAD = 0X11,
ECALLBACK_TYPE_FACTORY_UPLOAD = 0X12,
ECALLBACK_TYPE_SINGLE_IMAGE = 0X51,
ECALLBACK_TYPE_MULTIPLE_IMAGE = 0X52,
ECALLBACK_TYPE_PACKET_MISS = 0X5B,
ECALLBACK_TYPE_LIVE_ACQ_OK = 0XA0,
ECALLBACK_TYPE_ADMIN_CFG_UPDATA = 0XA1,
ECALLBACK_TYPE_USER_CFG_UPDATA = 0XA2,
ECALLBACK_TYPE_PACKET_MISS_MSG = 0XA4,
ECALLBACK_TYPE_THREAD_EVENT = 0XA5,
ECALLBACK_TYPE_CALIBRATE_ACQ_MSG = 0XA6,
ECALLBACK_TYPE_OFFSET_ERR_MSG = 0XA7,
ECALLBACK_TYPE_GAIN_ERR_MSG = 0XA8,
ECALLBACK_TYPE_DEFECT_ERR_MSG = 0XA9,
ECALLBACK_TYPE_NET_ERR_MSG = 0XAA,
ECALLBACK_TYPE_SET_CFG_OK = 0XAB // 设置参数成功
};
public enum eCallbackUpdateFirmwareStatus
{
ECALLBACK_UPDATE_STATUS_ERASE = 0XB0,
ECALLBACK_UPDATE_STATUS_PROGRESS = 0XB1,
ECALLBACK_UPDATE_STATUS_RESULT = 0XB2
};
public enum HBIRETCODE
{
HBI_SUCCSS = 0,
HBI_ERR_OPEN_DETECTOR_FAILED = 8001,
HBI_ERR_INVALID_PARAMS = 8002,
HBI_ERR_CONNECT_FAILED = 8003,
HBI_ERR_MALLOC_FAILED = 8004,
HBI_ERR_RELIMGMEM_FAILED = 8005,
HBI_ERR_RETIMGMEM_FAILED = 8006,
HBI_ERR_NODEVICE = 8007,
HBI_ERR_NODEVICE_TRY_CONNECT = 8008,
HBI_ERR_DEVICE_BUSY = 8009,
HBI_ERR_SENDDATA_FAILED = 8010,
HBI_ERR_RECEIVE_DATA_FAILED = 8011,
HBI_ERR_COMMAND_DISMATCH = 8012,
HBI_ERR_NO_IMAGE_RAW = 8013,
HBI_ERR_PTHREAD_ACTIVE_FAILED = 8014,
HBI_ERR_STOP_ACQUISITION = 8015,
HBI_ERR_INSERT_FAILED = 8016,
HBI_ERR_GET_CFG_FAILED = 8017,
HBI_NOT_SUPPORT = 8018,
HBI_REGISTER_CALLBACK_FAILED = 8019,
HBI_SEND_MESSAGE_FAILD = 8020,
HBI_ERR_WORKMODE = 8021,
HBI_END
};
public enum EnumTempType
{
OFFSETFILE = 0x00,
GAINFILE,
BADPIXFILE,
GAINA,
GAINB
};
//public static const CodeStringTable CrErrStrList[] = {
// { 0,HBIRETCODE.HBI_SUCCSS, "Success" },
// { 1, HBI_ERR_OPEN_DETECTOR_FAILED, "Open device driver failed" },
// { 2, HBI_ERR_INVALID_PARAMS, "Parameter error" },
// { 3, HBI_ERR_CONNECT_FAILED, "Connect failed" },
// { 4, HBI_ERR_MALLOC_FAILED, "Malloc memory failed" },
// { 5, BHI_ERR_RELIMGMEM_FAILED, "Releaseimagemem fail" },
// { 6, BHI_ERR_RETIMGMEM_FAILED, "ReturnImageMem fail" },
// { 7, BHI_ERR_NODEVICE, "No Device" },
// { 8, BHI_ERR_NODEVICE_TRY_CONNECT, "No Device,Try again" },
// { 9, BHI_ERR_DEVICE_BUSY, "Device busy" },
// { 10, BHI_ERR_SENDDATA_FAILED, "SendData failed" },
// { 11, BHI_ERR_RECEIVE_DATA_FAILED, "Receive Data failed" },
// { 12, BHI_ERR_COMMAND_DISMATCH, "Command dismatch" },
// { 13, BHI_ERR_NO_IMAGE_RAW, "No Image raw" },
// { 14, BHI_ERR_PTHREAD_ACTIVE_FAILED, "Pthread active failed" },
// { 15, BHI_ERR_STOP_ACQUISITION, "Pthread stop data acquisition failed" },
//};
#endregion
#region struct
#region
public struct IMAGE_PROPERTY
{
public int nSize; //fpd_size
public int nwidth; //image width
public int nheight; //image height
public int datatype; //data type:0-unsigned char,1-char,2-unsigned short,3-float,4-double
public int ndatabit; //data bit:0-16bit,1-14bit,2-12bit,3-8bit
public int nendian; //endian:0-little endian,1-biger endian
public int packet_sum; //fpd send packet sum per frame
public int frame_size; //data size per frame
};
[StructLayout(LayoutKind.Sequential)]
public struct CodeStringTable
{
int num;
int HBIRETCODE;
String errString;// const char *errString;
};
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SOFTWARE_CALIBRATE_ENABLE
{
[MarshalAs(UnmanagedType.U1)]
public bool enableOffsetCalib;
[MarshalAs(UnmanagedType.U1)]
public bool enableGainCalib;
[MarshalAs(UnmanagedType.U1)]
public bool enableDefectCalib;
[MarshalAs(UnmanagedType.U1)]
public bool enableDummyCalib;
};
// Notice:fpd software calibrate enable info.
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct IMAGE_CORRECT_ENABLE
{
[MarshalAs(UnmanagedType.U1)]
public bool bFeedbackCfg; //true-ECALLBACK_TYPE_ROM_UPLOAD Event,false-ECALLBACK_TYPE_SET_CFG_OK Event
public char ucOffsetCorrection; //00-"Do nothing";01-"prepare Offset Correction"; 02-"post Offset Correction";
public char ucGainCorrection; //00-"Do nothing";01-"Software Gain Correction"; 02-"Hardware Gain Correction"
public char ucDefectCorrection; //00-"Do nothing";01-"Software Defect Correction"; 02-"Software Defect Correction"
public char ucDummyCorrection; //00-"Do nothing";01-"Software Dummy Correction"; 02-"Software Dummy Correction"
};
// Notice:fpd aqc mode
[StructLayout(LayoutKind.Sequential)]
public struct FPD_AQC_MODE
{
public EnumIMAGE_ACQ_MODE aqc_mode;
public int ngroupno;
public int nframesum;
public int ndiscard;
public int nframeid;
};
// Notice: calibrate template raw file call back info
// 2019/09/03
[StructLayout(LayoutKind.Sequential)]
public struct ECALLBACK_RAW_INFO
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
char[] szRawName; // 返回数据文件名称
double dMean; // 灰度均值
};
// lxm0712
[StructLayout(LayoutKind.Sequential)]
public struct GainInfo
{
int id;
int dosvalue; //剂量值
int groupnum; //获取测试组总数
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
char[] offsetpath; //亮场offset文件路径
int averagegray; //该剂量下所有帧的平均灰度
};
#endregion
// Notice: calibrate lxm0712
// System Manufacture Information:50
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct SysBaseInfo
{
// Register_1
public char m_byProductType; //01 //01-Flat Panel Detector; 02-Linear Array Detector
// Register_2
public char m_byXRaySensorType; //01 //01-Amorphous Silicon; 02-CMOS; 03-IGZO; 04-LTPS; 05-Amorphous Selenium
// Register_3
public char m_byPanelSize; //01 //01-1717 inch Panel Size; 02-1417; 03-1414; 04-1212;
//05-1012; 06-0912; 07-0910; 08-0909; 09-0506; 10-0505; 11-0503
// Register_4
public char m_byPixelPitch; //01 //01-27 um; 02-50; 03-75; 04-85; 05-100; 06-127; 07-140; 08-150; 09-180; 10-200 11-205; 12-400; 13-1000
// Register_5
public char m_byPixelMatrix; //01 //01-"3072 x 3072"; 02-"2536 x 3528"; 03-"2800 x 2304"; 04-"2304 x 2304"; 05-"2048 x 2048"; 06-"1536 x 1536";
//07-"1024 x 1536"; 08-"1024 x 1024"; 09-"1024 x 0768"; 10-"1024 x 0512"; 11-"0768 x 0768";
//12-"0512 x 0512"; 13-"0512 x 0256"; 14-"0256 x 0256"
// Register_6
public char m_byScintillatorType; //01 //01-DRZ Standard; 02-DRZ High; 03-DRZ Plus; 04-PI-200; 05-Structured GOS; 06-CSI Evaporation; 07-CSI Attach;
// Register_7
public char m_byScanLineFanoutMode; //01 //01-Single Side Single Gate; 02-Dual Side Single Gate; 03-Single Side Dual Gate; 04-Dual Side Dual Gate;
// Register_8
public char m_byReadoutLineFanoutMode; //01 //01-Single Side Single Read; 02-Dual Side Single Read; 03-Single Side Dual Read; 04-Dual Side Dual Read;
// Register_9
public char m_byFPDMode; //01 //01-Static; 02-Dynamic;
// Register_10
public char m_byFPDStyle; //01 //01-Fixed; 02-Wireless; 03-Portable;
// Register_11
public char m_byApplicationMode; //01 //01-Medical; 02-Industry;
// Register_12
public char m_byGateChannel; //01 //01-"600 Channel"; 02-"512 Channel"; 03-"384 Channel"; 04-"256 Channel"; 05-"128 Channel"; 06-"064 Channel"
// Register_13
public char m_byGateType; //01 //01-"HX8677"; 02-"HX8698D"; 03-"NT39565D"
// Register_14
public char m_byAFEChannel; //01 //01-"64 Channel"; 02-"128 Channel"; 03-"256 Channel"; 04-"512 Channel";
// Register_15
public char m_byAFEType; //01 //01-"AFE0064"; 02-"TI COF 2256"; 03-"AD8488"; 04-"ADI COF 2256";
// Register_16~Register_17
public ushort m_sGateNumber; //02 //Gate Number
// Register_18~Register_19
public ushort m_sAFENumber; //02 //AFE Number
////////// Register_20~Register_100.
////////[MarshalAs(UnmanagedType.ByValArray, SizeConst = 81)]
////////public char[] m_abyReservedFrom20To100; //03//////Registers 20To100(include) Are Reserved;
// Register_20~Register_21
public ushort m_sImageWidth; //02 //Image Width // modified by mhyang 20191220
// Register_22~Register_23
public ushort m_sImageHeight; //02 //Image Height
// Register_24~Register_37
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
public char[] m_cSnNumber; //14 //sn number // modified by mhyang 20200401
// Register_38~Register_100.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 63)]
public char[] m_abyReservedFrom20To100; //63//////Registers 38To100(include) Are Reserved;
};
// System Manufacture Information:50
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct SysManuInfo
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_5~Register_16
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public char[] m_abyFPDSerialNumber; //12 //FPD SN Byte 01-12;
// Register_17~Register_18
public short m_sYear; //02 //Year
// Register_19~Register_20
public short m_sMouth; //02 //Month
// Register_21~Register_22
public short m_sDay; //02 //Day
// Register_23~Register_24
public short m_sEOSFirmwareVersion; //02 //EOS Firmware Version
// Register_25~Register_26
public short m_sEOSFirmwareBuildingTime; //02 //EOS Firmware Building Time
// Register_27~Register_28
public short m_sMasterFPGAFirmwareVersion; //02 //Master FPGA Firmware Version
////// Register_29~Register_30
////public short m_sMasterFPGAFirmwareBuildingTime; //02 //Master FPGA Firmware Building Time
////// Register_31~Register_32
////public short m_sSlaveFPGAFirmwareVersion; //02 //Slave FPGA Firmware Version(Register 0043-0044)
////// Register_33~Register_34
////public short m_sSlaveFPGAFirmwareBuildingTime; //02 //Slave FPGA Firmware Building Time
// Register_29~Register_31
public char m_byMasterFPGAFirmwareBuildingTime1; //01 //Master FPGA Firmware Building Time1
public char m_byMasterFPGAFirmwareBuildingTime2; //01 //Master FPGA Firmware Building Time2
public char m_byMasterFPGAFirmwareBuildingTime3; //01 //Master FPGA Firmware Building Time3
// Register_32~Register_34
public char m_byMasterFPGAFirmwareStatus1; //01 //Master FPGA Firmware status1
public char m_byMasterFPGAFirmwareStatus2; //01 //Master FPGA Firmware status2
public char m_byMasterFPGAFirmwareStatus3; //01 //Master FPGA Firmware status3
// Register_35~Register_36
public short m_sMCUFirmwareVersion; //02 //MCU Firmware Version
// Register_37~Register_38
public short m_sMCUFirmwareBuildingTime; //02 //MCU Firmware Building Time
// Register_39~Register_50
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public char[] m_abySysManuInfoReserved;
};
// System Status Information:28
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct SysStatusInfo
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_5~Register_8
public int m_unTemperature; //04 //Temperature
// Register_9~Register_12
public int m_unHumidity; //04 //Humidity
// Register_13~Register_16
public int m_unDose; //04 //Dose
// Register_17~Register_28
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public char[] m_abySysStatusInfoReserved;
};
// Gigabit Ethernet Information:40
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct EtherInfo
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_9~Register_14
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] m_bySourceMAC; //06 //Source MAC
// Register_15~Register_18
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] m_bySourceIP; //04 //Source IP
// Register_5~Register_6
public ushort m_sSourceUDPPort; //02 //Source UDP Port
// Register_19~Register_24
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] m_byDestMAC; //06 //Dest MAC
// Register_25~Register_28
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] m_byDestIP; //04 //Dest IP
// Register_7~Register_8
public ushort m_sDestUDPPort; //02 //Dest UDP Port
// Register_29~Register_40
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public char[] m_abyEtherInfoReserved;
};
// High Voltage Generator Interface Trigger Mode Information:21
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct HiVolTriggerModeInfo
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_5
public char m_byPrepSignalValidTrigger; //01 //01-"High Level Trigger, Low Level Invalid"; 02-"Low Level Trigger, High Level Invalid"
//03-"Positive Edge Trigger, Negative Edge Invalid"; 04-"Negative Edge Trigger, Positive Edge Invalid"
// Register_6
public char m_byExposureEnableSignal; //01 //01-"High Level Trigger, Low Level Invalid"; 02-"Low Level Trigger, High Level Invalid"
//03-"Positive Edge Trigger, Negative Edge Invalid"; 04-"Negative Edge Trigger, Positive Edge Invalid"
// Register_7
public char m_byXRayExposureSignalValid; //01 //01-"High Level Trigger, Low Level Invalid"; 02-"Low Level Trigger, High Level Invalid"
//03-"Positive Edge Trigger, Negative Edge Invalid"; 04-"Negative Edge Trigger, Positive Edge Invalid"
// Register_8
public char m_bySyncInSignalValidTrigger; //01 //01-"High Level Trigger, Low Level Invalid"; 02-"Low Level Trigger, High Level Invalid"
//03-"Positive Edge Trigger, Negative Edge Invalid"; 04-"Negative Edge Trigger, Positive Edge Invalid";
// Register_9
public char m_bySyncOutSignalValidTrigger; //01 //01-"High Level Trigger, Low Level Invalid"; 02-"Low Level Trigger, High Level Invalid";
// Register_10~Register_21
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]//wss
public char[] m_abyEtherInfoReserved;
};
// System Configuration Information:127
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct SysCfgInfo
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_5
public char m_byWorkMode; //01 // 01-"Static: Software Mode" 02-"Static: Prep Mode"; 03-"Static Hvg Trigger Mode";
// 04-Static AED Trigger Mode, 05-Dynamic Hvg In Mode,06-Dynamic Fpd Out Mode.
// Register_6
public char m_byPreviewModeTransmission; //01 //00-"Just transmmit full resolution image matrix"; 01-"Just transmmit the preview image";
//02-"Transmmit the preview image and full resolution image"
// Register_7
public char m_byPositiveVsNegativeIntegrate; //01 //01-"Electron"; 02-"Hole" //04-"Static: Inner Trigger Mode"; 05-"Dynamic: Sync In Mode"; 06-"Dynamic: Sync Out Mode"
// Register_8
public char m_byBinning; //01 //01-"1x1"; 02-"2x2 Binning"; 03-"3x3 Binning"; 04-"4x4 Binning";
// Register_9
public char m_byIntegratorCapacitorSelection; //01 //01-"Integrator Capacitor PGA0"; 02-"Integrator Capacitor PGA1"; 03-"PGA2";......;08-"Integrator Capacitor PGA7"
// Register_10
public char m_byAmplifierGainSelection; //01 //01-"Amplifier Gain AMP0"; 02-"Amplifier Gain AMP1"; 03-"Amplifier Gain AMP2"; 04-"Amplifier Gain AMP3";
//05-"Amplifier Gain AMP4"; 06-"Amplifier Gain AMP5"; 07-"Amplifier Gain AMP6"; 08-"Amplifier Gain AMP7";
// Register_11
public char m_bySelfDumpingEnable; //01 //01-"Enable Dumping Process"; 02-"Disable Dumping Process";
// Register12
public char m_bySelfDumpingProcessing; //01 //01-"Clear Process for Dumping"; 02-"Acquisition Process for Dumping";
// add 20190705
public char m_byClearFrameNumber; //01 //01-"Clear Frame"; 02-"Clear Frame";03-"Clear Frame";04-"Clear Frame";
// Register_13
public char m_byPDZ; //01 //01-"Disable PDZ"; 02-"Enable PDZ"
// Register_14
public char m_byNAPZ; //01 //01-"Disable NAPZ"; 02-"Enable NAPZ"
// Register15
public char m_byInnerTriggerSensorSelection; //01 //00-"No Selection"; 01-"I Sensor Selection"; 02-"II Sensor Selection";
//03-"III Sensor Selection"; 04-"IV Sensor Selection"; 05-"V Sensor Selection"
// Register_16~Register_17
public short m_sZoomBeginRowNumber; //02 //Zoom Begin Row Number
// Register_18~Register_19
public short m_sZoomEndRowNumber; //02 //Zoom End Row Number
// Register_20~Register_21
public short m_sZoomBeginColumnNumber; //02 //Zoom Begin Column Number
// Register_22~Register_23
public short m_sZoomEndColumnNumber; //02 //Zoom End Column Number
// Register24~Register27
public int m_unSelfDumpingSpanTime; //04 //unit: ms
// Register28~Register31
public int m_unContinuousAcquisitionSpanTime; //04 //unit: ms
// Register32~Register35
public int m_unPreDumpingDelayTime; //04 //unit: ms
// Register36~Register39
public int m_unPreAcquisitionDelayTime; //04 //unit: ms
// Register40~Register43
public int m_unPostDumpingDelayTime; //04 //unit: ms
// Register44~Register47
public int m_unPostAcquisitionDelayTime; //04 //unit: ms
// Register48~Register51
public int m_unSyncInExposureWindowTime; //04 //unit: ms
// Register52~Register55
public int m_unSyncOutExposureWindowTime; //04 //unit: ms
// Register56~Register59
public int m_unTFTOffToIntegrateOffTimeSpan; //04 //unit: ms
// Register_60~Register_63
public int m_unIntegrateTime; //04 //unit: ms
// Register_64~Register_67
public int m_unPreFrameDelay; //04 //unit: ms
// Register_68~Register_71
public int m_unPostFrameDelay; //04 //unit: ms
// Register_72~Register_75
public int m_unPreRowDelay; //04 //unit: ms
// Register_76~Register_79
public int m_unPostRowDelay; //04 //unit: ms
////// Register_80~Register_127
////[MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
////public char[] m_abySysCfgInfoReserved;
// Register_80~Register_127
public char m_byHvgRdyMode; //01 //00-"Auto"; 01-"自定义"
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 47)]
public char[] m_abySysCfgInfoReserved;
};
// Image Calibration Configuration:20
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct ImgCaliCfg
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
public byte m_byOffsetCorrection;
//[FieldOffset(1)]
public byte m_byGainCorrection;
//[FieldOffset(2)]
public byte m_byDefectCorrection;
// Register_8
//[FieldOffset(3)]
public byte m_byDummyCorrection;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public char[] m_abyImgCaliCfgReserved;
};
// Voltage Adjust Configuration:48
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct VolAdjustCfg
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_5~Register_8
public int m_unVCOM; //04 //VCOM
// Register_9~Register_12
public int m_unVGG; //04 //VGG
// Register_13~Register_16
public int m_unVEE; //04 //VEE
// Register_17~Register_20
public int m_unVbias; //04 //Vbias
// Register_21~Register_36
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public int[] m_unComp; //04 //Comp1 // Register114
// Register_37~Register_48
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public char[] m_abyVolAdjustCfgReserved; //12//////Registers 114(include) Are Reserved;
};
// TI COF Parameter Configuration:84
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct TICOFCfg
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_5~Register_64
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public short[] m_sTICOFRegister;
// Register_65~Register_84
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public char[] m_abyTICOFCfgReserved;
};
//CMOS Parameter Configuration:116
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct CMOSCfg
{
// Register_1~Register_4
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public char[] m_byHead;
// Register_5~Register_68
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public short[] m_sCMOSRegister;
// Register_69~Register_116
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
public char[] m_abyCMOSCfgReserved;
};
// ADI COF Parameter Configuration:390
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct ADICOFCfg
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
// Register_1~Register_4
public char[] m_byHead;
// Register_5~Register_19
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
public short[] m_sADICOFRegister;
// Register_20~Register_375 355
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 355)]
public char[] m_abyADICOFCfgReserved;
};
// 1024 byte regedit
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct RegCfgInfo
{
// System base Information:100,Register_1~Register_100
public SysBaseInfo m_SysBaseInfo;
// System Manufacture Information:50,Register_101~Register_150
public SysManuInfo m_SysManuInfo;
// System Status Information:28,Register_151~Register_178
public SysStatusInfo m_SysStatusInfo;
// Gigabit Ethernet Information:40,Register_179~Register_218
public EtherInfo m_EtherInfo;
// High Voltage Generator Interface Trigger Mode Information:21,Register_219~Register_239
public HiVolTriggerModeInfo m_HiVolTriggerModeInfo;
// System Configuration Information:127,Register_240~Register_366
public SysCfgInfo m_SysCfgInfo;
// Image Calibration Configuration:20,Register_367~Register_386
public ImgCaliCfg m_ImgCaliCfg;
// Voltage Adjust Configuration:48,Register_387~Register_434
public VolAdjustCfg m_VolAdjustCfg;
// TI COF Parameter Configuration:84,Register_435~Register_518
public TICOFCfg m_TICOFCfg;
// CMOS Parameter Configuration:116,Register_519~Register_634
public CMOSCfg m_CMOSCfg;
// ADI COF Parameter Configuration:390,Register_635~Register_1024
public ADICOFCfg m_ADICOFCfg;
};
#endregion
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("CarerayImage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CarerayImage")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("bfcb03f8-cd69-4f02-8336-65ddff73d385")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.2.1")]
[assembly: AssemblyFileVersion("1.1.2.1")]
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using static Asa.eyemLib;
namespace Asa
{
//using eyemLib = eyemLib_old;
/// <summary>
/// Careray平板图像
/// </summary>
public class XrayImage : XrayImageInterface
{
private readonly XrayImageInterface device;
//加载模板到内存
static IntPtr hModelIDs = IntPtr.Zero;
static XrayImage(){
if (!Directory.Exists("CountTemplate"))
Directory.CreateDirectory("CountTemplate");
var flag = eyemInitModel("CountTemplate", out hModelIDs);
}
/// <summary>
/// 16位窗位
/// </summary>
public int WindowLevel
{
get
{
return device.WindowLevel;
}
set
{
device.WindowLevel = value;
}
}
/// <summary>
/// 16位窗宽
/// </summary>
public int WindowWidth
{
get
{
return device.WindowWidth;
}
set
{
device.WindowWidth = value;
}
}
/// <summary>
/// Careray平板图像
/// </summary>
public XrayImage(string logName = "CarerayImage",DeviceType deviceType=DeviceType.CARREY)
{
if (deviceType == DeviceType.CARREY)
device = new CarerayImage(logName);
else
device = new haobo(logName);
}
/// <summary>
/// 打开设备
/// </summary>
/// <returns></returns>
public bool Open()
{
return device.Open();
}
/// <summary>
/// 关闭设备
/// </summary>
/// <returns></returns>
public bool Close()
{
return device.Close();
}
/// <summary>
/// 获取图像
/// </summary>
/// <returns></returns>
public bool GetImage(int _MaxFrameCount = 3, int MaxDelay = 5000)
{
return device.GetImage(_MaxFrameCount, MaxDelay);
}
/// <summary>
/// 获取48位RGB图像
/// </summary>
/// <returns></returns>
public Bitmap Get48bImage()
{
return device.Get48bImage();
}
/// <summary>
/// 获取raw数据指针
/// </summary>
/// <returns></returns>
public EyemImage GetRawBufferHandle()
{
return device.GetRawBufferHandle();
}
/// <summary>
/// 释放raw指针
/// </summary>
public void FreeRawBufferHandle()
{
device.FreeRawBufferHandle();
}
/// <summary>
/// 本地文件普通器件点料
/// </summary>
/// <param name="path"></param>
/// <param name="ShrinkOffset"></param>
/// <param name="count"></param>
/// <param name="tpDstImg"></param>
/// <returns></returns>
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCount(string path, int ShrinkOffset, out string count, out EyemImage tpDstImg)
{
count = "";
tpDstImg = new EyemImage();
string fileName = System.IO.Path.GetFileNameWithoutExtension(path);
int flag = eyemImageRead(path, -1, out EyemImage eyem);
if (flag != 0) return -1;
int n = GetLocalCount(eyem, ShrinkOffset, fileName, out count, out tpDstImg);
eyemImageFree(ref eyem);
return n;
}
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCount(EyemImage eyem, int ShrinkOffset, string outfilename, out string count, out EyemImage tpDstImg)
{
var tpRoi = new EyemRect();
tpRoi.iXs = 0 + ShrinkOffset;
tpRoi.iYs = 0 + ShrinkOffset;
tpRoi.iWidth = eyem.iWidth - ShrinkOffset * 2;
tpRoi.iHeight = eyem.iHeight - ShrinkOffset * 2;
int n;
string pNumObj = null;
setSkipProcessID(-1);
n = eyemCountObject(eyem, tpRoi, outfilename, 0, 0, 0, 0, ref pNumObj, out tpDstImg);
count = pNumObj;
return n;
}
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCountE(EyemImage eyem, EyemRect? tpRoi, string outfilename, double dOffset, int iWinSize, out string count, out EyemImage tpDstImg)
{
if (tpRoi == null) {
var ntpRoi = new EyemRect();
ntpRoi.iXs = 0;
ntpRoi.iYs = 0;
ntpRoi.iWidth = eyem.iWidth;
ntpRoi.iHeight = eyem.iHeight;
}
count = "";
int n;
tpDstImg = new EyemImage();
string pNumObj = null;
setSkipProcessID(-1);
n = eyemCountObject(eyem, tpRoi.Value, outfilename, dOffset, 0, 100, iWinSize, ref pNumObj, out tpDstImg);
//int eyemCountObjectE(EyemImage tpImage, string fileName, ref string pNumObj, out EyemImage tpDstImg);
count = pNumObj;
return n;
}
/// <summary>
/// 本地文件异性器件点料
/// </summary>
/// <param name="path"></param>
/// <param name="ShrinkOffset"></param>
/// <param name="type"></param>
/// <param name="count"></param>
/// <param name="tpDstImg"></param>
/// <returns></returns>
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCountIrregular(string path, int ShrinkOffset, string type, out string count, out EyemImage tpDstImg)
{
count = "";
tpDstImg = new EyemImage();
string fileName = System.IO.Path.GetFileNameWithoutExtension(path);
int flag = eyemImageRead(path, -1, out EyemImage eyem);
if (flag != 0) return -1;
int n = GetLocalCountIrregular(eyem, ShrinkOffset, fileName, type, out count, out tpDstImg);
eyemImageFree(ref eyem);
return n;
}
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCountIrregular(EyemImage eyem, int ShrinkOffset, string outfilename, string type, out string count, out EyemImage tpDstImg)
{
int n;
string pNumObj = null;
var tpRoi = new EyemRect();
tpRoi.iXs = 0 + ShrinkOffset;
tpRoi.iYs = 0 + ShrinkOffset;
tpRoi.iWidth = eyem.iWidth - ShrinkOffset * 2;
tpRoi.iHeight = eyem.iHeight - ShrinkOffset * 2;
setSkipProcessID(-1);
n = eyemCountObjectIrregularParts(eyem, tpRoi, outfilename, 0, type, 0, 0, ref pNumObj, out tpDstImg);
count = pNumObj;
return n;
}
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCountTemplate(string path, int ShrinkOffset,string template, out string count, out Bitmap BmpDstImg)
{
count = "";
BmpDstImg = null;
string fileName = System.IO.Path.GetFileNameWithoutExtension(path);
int flag = eyemImageRead(path, -1, out EyemImage eyem);
if (flag != 0) return -1;
int n = GetLocalCountTemplate(eyem, ShrinkOffset, fileName,template, out count, out BmpDstImg);
eyemImageFree(ref eyem);
return n;
}
[HandleProcessCorruptedStateExceptions]
public static int GetLocalCountTemplate(EyemImage eyem, int ShrinkOffset, string outfilename,string template, out string count, out Bitmap BmpDstImg)
{
setSkipProcessID(-1);
EyemImage tpDstImg;
BmpDstImg = null;
int n, flag;
string pNumObj = null;
count = "";
var tpRoi = new EyemRect();
tpRoi.iXs = 0 + ShrinkOffset;
tpRoi.iYs = 0 + ShrinkOffset;
tpRoi.iWidth = eyem.iWidth - ShrinkOffset * 2;
tpRoi.iHeight = eyem.iHeight - ShrinkOffset * 2;
//获取用于制作模板的图像
flag = eyemAchvTemplateImage(eyem, tpRoi, out tpDstImg);
string selectModel = "";
if (string.IsNullOrEmpty(template))
{
//可以选择使用自动匹配或者指定模板文件
flag = eyemMatchTemplateModel(tpDstImg, hModelIDs, ref selectModel);
eyemImageFree(ref tpDstImg);
if (selectModel == "")
return flag;
}
else {
selectModel = template;
}
n = eyemCountObjectIrregularPartsE(eyem, tpRoi, outfilename, selectModel, hModelIDs, ref pNumObj, out tpDstImg);
count = pNumObj;
if (n == 0)
{
BmpDstImg = eyemCvtToBitmap(tpDstImg);
}
eyemImageFree(ref tpDstImg);
return n;
}
[HandleProcessCorruptedStateExceptions]
public static Bitmap GetTemplateBitmap(string bitmapfile, int ShrinkOffset, out string selectModel)
{
EyemImage tpDstImg;
Bitmap BmpDstImg;
int flag = eyemImageRead(bitmapfile, -1, out EyemImage eyem);
var tpRoi = new EyemRect();
tpRoi.iXs = 0 + ShrinkOffset;
tpRoi.iYs = 0 + ShrinkOffset;
tpRoi.iWidth = eyem.iWidth - ShrinkOffset * 2;
tpRoi.iHeight = eyem.iHeight - ShrinkOffset * 2;
//获取用于制作模板的图像
flag = eyemAchvTemplateImage(eyem, tpRoi, out tpDstImg);
BmpDstImg = eyemCvtToBitmap(tpDstImg);
//可以选择使用自动匹配或者指定模板文件
selectModel = "";
flag = eyemMatchTemplateModel(tpDstImg, hModelIDs, ref selectModel);
eyemImageFree(ref tpDstImg);
eyemImageFree(ref eyem);
return BmpDstImg;
}
[HandleProcessCorruptedStateExceptions]
public static bool SaveTemplate(string bitmapfile, Rectangle rect, int ShrinkOffset, double matchDeg,out string selectModel,out string count, out Bitmap BmpDstImg)
{
setSkipProcessID(-1);
EyemImage tpDstImg;
BmpDstImg = null;
int flag = eyemImageRead(bitmapfile, -1, out EyemImage eyem);
var tpRoi = new EyemRect();
tpRoi.iXs = 0 + ShrinkOffset;
tpRoi.iYs = 0 + ShrinkOffset;
tpRoi.iWidth = eyem.iWidth- ShrinkOffset*2;
tpRoi.iHeight = eyem.iHeight - ShrinkOffset * 2;
//获取用于制作模板的图像
flag = eyemAchvTemplateImage(eyem, tpRoi, out tpDstImg);
//创建模板匹配模型
EyemRect tpRoi2 = new EyemRect();
tpRoi2.iXs = rect.X;
tpRoi2.iYs = rect.Y;
tpRoi2.iWidth = rect.Width;
tpRoi2.iHeight = rect.Height;
string filename = Guid.NewGuid().ToString();
Directory.CreateDirectory("CountTemplate_temp\\");
string file = "CountTemplate_temp\\" + filename + ".tpl";
flag = eyemCreateTemplateModel(tpDstImg, tpRoi2, matchDeg, file);
//测试插入模板
eyemInsertModel(hModelIDs, file);
//可以选择使用自动匹配或者指定模板文件
selectModel = file;
string pNumObj = "";
int n = eyemCountObjectIrregularPartsE(eyem, tpRoi, "123", selectModel, hModelIDs, ref pNumObj, out tpDstImg);
BmpDstImg = eyemCvtToBitmap(tpDstImg);
eyemImageFree(ref tpDstImg);
eyemImageFree(ref eyem);
count = pNumObj;
return true;
}
//测试移除模板
public static void RemoveModelByName(string file){
//测试移除模板
eyemRemoveModelByName(hModelIDs, file);
}
public static Bitmap tplToBitmap(string tplfile,out double MatchDeg)
{
//根据名称获取模板
EyemModelID tpModelID = new EyemModelID();
var flag = eyemAchvModelByName(tplfile, hModelIDs, ref tpModelID);
EyemImage tpModeImg = new EyemImage();
tpModeImg.iChannels = 1; tpModeImg.iDepth = 0;
tpModeImg.iWidth = tpModelID.iWidth; tpModeImg.iHeight = tpModelID.iHeight; tpModeImg.ucpImage = tpModelID.vpImage;
MatchDeg = tpModelID.dMatchDeg;
var BmpDstImg = eyemCvtToBitmap(tpModeImg);
//eyemImageFree(ref tpModeImg);
return BmpDstImg;
}
public static void ReloadTpl()
{
eyemReleaseModel(ref hModelIDs);
var flag = eyemInitModel("CountTemplate", out hModelIDs);
}
public static Action SkipCounting() {
return () => { eyemLib.setSkipProcessID(0);
System.Threading.Thread.Sleep(200);
};
}
public void LoadRAW(string filePath)
{
device.LoadRAW(filePath);
}
public void SaveRAW(string filePath)
{
device.SaveRAW(filePath);
}
public enum DeviceType
{
HAOBO,
CARREY
}
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Asa.eyemLib;
namespace Asa
{
interface XrayImageInterface
{
bool Open();
bool Close();
bool GetImage(int _MaxFrameCount = 3, int MaxDelay = 5000);
Bitmap Get48bImage();
EyemImage GetRawBufferHandle();
void FreeRawBufferHandle();
void LoadRAW(string filePath);
void SaveRAW(string filePath);
/// <summary>
/// 窗宽
/// </summary>
int WindowWidth { set; get; }
/// <summary>
/// 窗位
/// </summary>
int WindowLevel { set; get; }
}
}
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Asa
{
/// <summary>
/// 点料和解码
/// </summary>
public static unsafe class eyemLib
{
/// <summary>
/// 读取图像
/// </summary>
/// <param name="filename"></param>
/// <param name="iFalgs">填 -1</param>
/// <param name="ucpImage"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern int eyemImageRead(string filename, int iFalgs, out EyemImage ucpImage);
/// <summary>
/// 释放图像资源
/// </summary>
/// <param name="eyemImage"></param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern void eyemImageFree(ref EyemImage eyemImage);
/// <summary>
/// 普通器件
/// </summary>
/// <param name="tpSrcImg"></param>
/// <param name="tpRoi"></param>
/// <param name="fileName"></param>
/// <param name="dOffset"></param>
/// <param name="iMinArea"></param>
/// <param name="iMaxArea"></param>
/// <param name="iWinSize"></param>
/// <param name="pNumObj"></param>
/// <param name="tpDstImg"></param>
/// <returns></returns>
//[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
//internal static extern int eyemCountObject(EyemImage tpSrcImg, string fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, ref IntPtr pNumObj, out EyemImage tpDstImg);
/// <summary>
/// 异型器件
/// </summary>
/// <param name="tpSrcImg"></param>
/// <param name="fileName"></param>
/// <param name="dOffset"></param>
/// <param name="strType"></param>
/// <param name="iMaxArea"></param>
/// <param name="iWinSize"></param>
/// <param name="pNumObj"></param>
/// <param name="tpDstImg"></param>
/// <returns></returns>
//[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
//internal static extern int eyemCountObjectIrregularParts(EyemImage tpSrcImg, string fileName, double dOffset, string strType, int iMaxArea, int iWinSize, ref IntPtr pNumObj, out EyemImage tpDstImg);
/// <summary>
/// 普通器件
/// </summary>
/// <param name="tpSrcImg"></param>
/// <param name="tpRoi"></param>
/// <param name="fileName"></param>
/// <param name="dOffset"></param>
/// <param name="iMinArea"></param>
/// <param name="iMaxArea"></param>
/// <param name="iWinSize"></param>
/// <param name="pNumObj"></param>
/// <param name="tpDstImg"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemCountObject(EyemImage tpSrcImg, EyemRect tpRoi, string fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, ref string pNumObj, out EyemImage tpDstImg);
/// <summary>
/// 异型器件
/// </summary>
/// <param name="tpSrcImg"></param>
/// <param name="tpRoi"></param>
/// <param name="fileName"></param>
/// <param name="dOffset"></param>
/// <param name="strType"></param>
/// <param name="iMaxArea"></param>
/// <param name="iWinSize"></param>
/// <param name="pNumObj"></param>
/// <param name="tpDstImg"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemCountObjectIrregularParts(EyemImage tpSrcImg, EyemRect tpRoi, string fileName, double dOffset, string strType, int iMaxArea, int iWinSize, ref string pNumObj, out EyemImage tpDstImg);
//普通器件(新版本)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, string fileName, ref string pNumObj, out EyemImage tpDstImg);
//异型器件(新版本)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, string fileName, string ccTplName, IntPtr hModelIDs, ref string pNumObj, out EyemImage tpDstImg);
//创建模板匹配模型
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, string ccTplName);
//获取模板图像
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//选取模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemMatchTemplateModel(EyemImage tpImage, IntPtr hModelIDs, ref string lpszTplName);
//加载模板到内存
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemInitModel(string ccTplName, out IntPtr hModelID);
//通过名称获取模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemAchvModelByName(string ccTplName, IntPtr hModelID, ref EyemModelID tpEyemModelID);
//释放模板内存
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemReleaseModel(ref IntPtr hModelID);
//插入模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemInsertModel(IntPtr hModelID, string ccTplName);
//通过名称移除模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemRemoveModelByName( IntPtr hModelID, string ccTplName);
//跳过程序执行
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int setSkipProcessID(int pid);
// 设定日志回调
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void setLogCallback(TCallBack cb);
// 日志回调
private delegate void TCallBack(string msg);
private static TCallBack sld = new TCallBack(TLogCallback);
private static log4net.ILog LOG;
private static void TLogCallback(string msg)
{
LOG.Info(msg);
}
static eyemLib() {
setLogCallback(sld);
LOG = log4net.LogManager.GetLogger("eyemlog");
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemModelID
{
public IntPtr vpImage; // 地址
public int iXs; // 图像X坐标
public int iYs; // 图像Y坐标
public int iWidth; // 图像内存X方向大小
public int iHeight; // 图像内存Y方向大小
public double dMatchDeg; // 匹配度
public IntPtr lpszName; // 名称
}
/// <summary>
/// 图像信息
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct EyemImage
{
/// <summary>
/// 地址
/// </summary>
public IntPtr ucpImage;
/// <summary>
/// 图像内存 x 方向大小
/// </summary>
public int iWidth;
/// <summary>
/// 图像内存 y 方向大小
/// </summary>
public int iHeight;
/// <summary>
/// iDepth:
/// uint8_t 取值范围[0, 255], iDepth = 0(常用,解码图像一般为此种格式)
/// int8_t 取值范围[-128, 127], iDepth = 1
/// uint16_t 取值范围[0, 56635], iDepth = 2(常用,点料机图像一般为此种格式)
/// int16_t 取值范围[-32768, 32767], iDepth = 3
/// int32_t 取值范围[-2147483648, 2147483647], iDepth = 4
/// float_t 取值范围[-3.4028235E38, 3.4028235E38], iDepth = 5
/// double_t 取值范围[-1.7E-308, 1.7E+308], iDepth = 6
/// </summary>
public int iDepth;
/// <summary>
/// 彩色图 iChannels=3或4(比RGB多了Alpha通道),一般为3
/// 灰度图 iChannels = 1
/// </summary>
public int iChannels; // 图像通道数
}
/// <summary>
/// 扫码接口
/// </summary>
/// <param name="tpImage"></param>
/// <param name="tpRoi">扫码区域</param>
/// <param name="fileName"></param>
/// <param name="strCodeType"></param>
/// <param name="hObject"></param>
/// <param name="tpResults"></param>
/// <param name="ipNum"></param>
/// <param name="bUseNiBlack"></param>
/// <param name="iBlockSize"></param>
/// <param name="iRangeC"></param>
/// <param name="iSymbolMin"></param>
/// <param name="iSymbolMax"></param>
/// <param name="dScaleUpAndDown">缩放值</param>
/// <param name="dToleErr"></param>
/// <param name="dMinorStep"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 1, double dToleErr = 0.5, double dMinorStep = 1.0);
#region EyemImage转换成Bitmap
public static Bitmap eyemCvtToBitmap(EyemImage tpImage)
{
if (tpImage.ucpImage == IntPtr.Zero)
throw new ArgumentNullException("图像不存在");
if (tpImage.iDepth != 0)
throw new ArgumentException("图像必须是8位无符号整型");
PixelFormat format;
switch (tpImage.iChannels)
{
case 1:
format = PixelFormat.Format8bppIndexed;
break;
case 3:
format = PixelFormat.Format24bppRgb;
break;
case 4:
format = PixelFormat.Format32bppArgb;
break;
default:
return null;
}
Bitmap bitmap = new Bitmap(tpImage.iWidth, tpImage.iHeight, format);
//对于输出灰度图像
if (format == PixelFormat.Format8bppIndexed)
{
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < 256; i++)
{
palette.Entries[i] = Color.FromArgb(i, i, i);
}
bitmap.Palette = palette;
}
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, tpImage.iWidth, tpImage.iHeight),
ImageLockMode.WriteOnly, format);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = (y * tpImage.iWidth * tpImage.iChannels);
long offsetDst = (y * pd);
Buffer.MemoryCopy((byte*)(tpImage.ucpImage.ToPointer()) + offsetSrc, (byte*)(bd.Scan0.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return bitmap;
}
#endregion
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode
{
public double dAngle; // 角度
public int iCenterX; // y坐标
public int iCenterY; // y坐标
public IntPtr hType; // 码类型
public IntPtr hText; // 码内容
}
/// <summary>
/// 释放工具
/// </summary>
/// <param name="hObject"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
[DllImport("Kernel32.dll")]
private static extern void CopyMemory(IntPtr dest, IntPtr source, int size);
/// <summary>
/// 释放
/// </summary>
public class DataCodeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public DataCodeHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemDetectAndDecodeFree(handle);
}
}
}
}
using Asa.HaoboSDK;
using ConfigHelper;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Asa.eyemLib;
namespace Asa
{
class haobo : XrayImageInterface
{
private readonly log4net.ILog LOG;
RegCfgInfo m_pLastRegCfg;
static int nPrepareTm = 3000;
static USER_CALLBACK_HANDLE_ENVENT _dUserCallbackHandleEnvent;
IMAGE_CORRECT_ENABLE m_pCorrect = new IMAGE_CORRECT_ENABLE();
byte[] buffer;
public haobo(string logName = "CarerayImage") {
LOG = log4net.LogManager.GetLogger(logName);
//1 初始化DLL
HBI_FPD_DLL._handel = HBI_FPD_DLL.HBI_Init();
_dUserCallbackHandleEnvent = DataCallBack;
//2 注册回调函数
int _ret = HBI_FPD_DLL.HBI_RegEventCallBackFun(HBI_FPD_DLL._handel, _dUserCallbackHandleEnvent);
if (_ret != 0) WriteLog("HBI_RegEventCallBackFun" + _ret.ToString());
}
public bool Open()
{
var HB_Remote_IP = Config.Get("HB_Remote_IP");
var HB_Remote_PORT = Config.Get<ushort>("HB_Remote_PORT");
var HB_Local_IP = Config.Get("HB_Local_IP");
var HB_Local_PORT = Config.Get<ushort>("HB_Local_PORT");
int _ret = HBI_FPD_DLL.HBI_ConnectDetector(HBI_FPD_DLL._handel, HB_Remote_IP, HB_Remote_PORT, HB_Local_IP, HB_Local_PORT, 20); //4 连接
if (_ret != 0)
{
LOG.Error("HBI_ConnectDetector" + _ret.ToString());
}
else
{
GetFirmwareCfg();
btnSetCorrectEnable();
_ret = HBI_FPD_DLL.HBI_UpdateTriggerMode(HBI_FPD_DLL._handel, 1);
if (_ret != 0) WriteLog("HBI_UpdateTriggerMode" + _ret.ToString());
else WriteLog("success HBI_UpdateTriggerMode" + _ret.ToString());
_ret = HBI_FPD_DLL.HBI_SetPreAcqTm(HBI_FPD_DLL._handel, 1000);
if (0 != _ret)
{
WriteLog("HBI_SetPreAcqTm failed!");
return false;
}
}
return _ret == 0;
}
public bool Close()
{
int ret = HBI_FPD_DLL.HBI_DisConnectDetector(HBI_FPD_DLL._handel);
if (ret != 0)
{
LOG.Error("HBI_DisConnectDetector" + ret.ToString());
}
return ret == 0;
}
/// <summary>
/// 图像宽度
/// </summary>
public int ImageWidth { private set; get; } = 3072;
/// <summary>
/// 图像高度
/// </summary>
public int ImageHeight { private set; get; } = 3072;
/// <summary>
/// 窗宽
/// </summary>
public int WindowWidth { set; get; } = 65535;
/// <summary>
/// 窗位
/// </summary>
public int WindowLevel { set; get; } = 32768;
public Bitmap Get48bImage()
{
if (buffer == null) return null;
if (ImageWidth <= 0 || ImageHeight <= 0)
{
LOG.Info("宽高不正确,ImageWidth=" + ImageWidth + ", ImageHeight=" + ImageHeight);
return null;
}
int count = ImageWidth * ImageHeight;
byte[] gray = new byte[count * 2];
Array.Copy(buffer, 0, gray, 0, gray.Length);
int idx1 = 0;
int idx2 = 0;
int half = WindowWidth / 2;
byte[] buff = new byte[gray.Length * 3];
for (int i = 0; i < count; i++)
{
short point = BitConverter.ToInt16(gray, idx1);
//point += 20000;
if (point < WindowLevel - half)
{
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
buff[idx2++] = 0;
}
else if (point > WindowLevel + half)
{
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
buff[idx2++] = 255;
}
else
{
byte[] bb = BitConverter.GetBytes(point);
buff[idx2++] = bb[0];
buff[idx2++] = bb[1];
buff[idx2++] = bb[0];
buff[idx2++] = bb[1];
buff[idx2++] = bb[0];
buff[idx2++] = bb[1];
}
idx1 += 2;
}
/*
//var bufferGCHandle = GCHandle.Alloc(buffer);
IntPtr intPtr = Marshal.UnsafeAddrOfPinnedArrayElement<byte>(buff, 0);
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, ImageWidth * 6, System.Drawing.Imaging.PixelFormat.Format48bppRgb, intPtr);
//bufferGCHandle.Free();
*/
Bitmap bmp = new Bitmap(ImageWidth, ImageHeight, System.Drawing.Imaging.PixelFormat.Format48bppRgb);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, ImageWidth, ImageHeight), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
Marshal.Copy(buff, 0, bmpData.Scan0, bmpData.Stride * ImageHeight);
bmp.UnlockBits(bmpData);
return bmp;
}
CancellationTokenSource WaitstopToken = new CancellationTokenSource();
bool buffgetted = false;
public bool GetImage(int _MaxFrameCount = 3, int MaxDelay = 5000)
{
WaitstopToken = new CancellationTokenSource();
buffer = null;
/*
FPD_AQC_MODE stMode = new FPD_AQC_MODE();
stMode.aqc_mode = EnumIMAGE_ACQ_MODE.STATIC_ACQ_DEFAULT_MODE;
stMode.ndiscard = 0;
stMode.nframeid = stMode.nframesum = stMode.ngroupno = 0;
int ret = HBI_FPD_DLL.HBI_SingleAcquisition(HBI_FPD_DLL._handel, stMode); //6
if (ret != 0) WriteLog("HBI_SingleAcquisition" + ret.ToString());
else WriteLog("0x03 SingleAcquisition成功");
if (m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode != 0x01)
{
LOG.Error("需要将触发模式改成software mode才能上图");
return false;
}*/
buffgetted = false;
int ret = HBI_FPD_DLL.HBI_Prepare(HBI_FPD_DLL._handel); //5
if (ret != 0) WriteLog("HBI_Prepare" + ret.ToString());
else WriteLog("0x02 prepare成功");
Task a = Task.Delay(MaxDelay);
Task b = Task.Run(()=> {
while (true)
{
Thread.Sleep(100);
if (buffgetted)
break;
}
});
Task.WaitAny(a, b);
Thread.Sleep(500);
/*
if (buffer != null)
{
using (FileStream fileStream = File.OpenWrite("logs\\raw.raw"))
{
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Close();
fileStream.Dispose();
}
}*/
return buffer != null;
}
IntPtr BufferPtr;
public EyemImage GetRawBufferHandle()
{
EyemImage eyemImage = new EyemImage();
if (buffer == null)
throw new Exception("图像buffer为空");
if (ImageWidth <= 0 || ImageHeight <= 0)
{
LOG.Info("宽高不正确,ImageWidth=" + ImageWidth + ", ImageHeight=" + ImageHeight);
throw new Exception("图像宽高不正确");
}
BufferPtr = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, BufferPtr, buffer.Length);
eyemImage.ucpImage = BufferPtr;
eyemImage.iWidth = ImageWidth;
eyemImage.iHeight = ImageHeight;
eyemImage.iChannels = 1;
eyemImage.iDepth = 2;
return eyemImage;
}
public void FreeRawBufferHandle()
{
try
{
Marshal.FreeHGlobal(BufferPtr);
}
catch { }
}
// 设置软触发清空时间
private void SetPrepareTime()
{
WriteLog(string.Format("Set Prepare time.:[{0}]\n", nPrepareTm));
int _ret = HBI_FPD_DLL.HBI_SetPreAcqTm(HBI_FPD_DLL._handel, nPrepareTm);
if (0 != _ret)
{
LOG.Error("HBI_SetPreAcqTm failed!");
return;
}
else
{
WriteLog("HBI_SetPreAcqTm success!\n");
if (nPrepareTm == 3000) nPrepareTm = 0;
else nPrepareTm = 3000;
}
}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////// 回调函数 //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
private int DataCallBack(byte cmd, IntPtr buff, int len, int id)
{
int status = 0;
switch (cmd)
{
case (byte)(eCallbackEventCommType.ECALLBACK_TYPE_NET_ERR_MSG):
WriteLog(string.Format("ECALLBACK_TYPE_NET_ERR_MSG,recode={0}\n", len));
if (len <= 0 && len >= -7)
{
if (len == 0)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,Err:网络未连接!\n");
else if (len == -1)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,Err:参数异常!\n");
else if (len == -2)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,Err:准备就绪的描述符数返回失败!\n");
else if (len == -3)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,Err:接收超时!\n");
else if (len == -4)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,Err:接收失败!\n");
else if (len == -5)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,Err:端口不可读!\n");
else if (len == -6)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,network card unusual!\n");
else if (len == -7)
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,network card ok!\n");
status = (int)EFpdStatusType.FPD_STATUS_DISCONN;
}
else if (len == 1)
{ // connect
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,开始监听!\n");
status = (int)EFpdStatusType.FPD_STATUS_CONN;
}
else if (len == 2)
{ // ready
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,ready!\n");
status = (int)EFpdStatusType.FPD_STATUS_READY;
}
else if (len == 3)
{ // busy
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,busy!\n");
status = (int)EFpdStatusType.FPD_STATUS_BUSY;
}
else if (len == 4)
{ // prepare
WriteLog("ECALLBACK_TYPE_NET_ERR_MSG,prepare!\n");
status = (int)EFpdStatusType.FPD_STATUS_PREPARE;
}
else
WriteLog(string.Format("ECALLBACK_TYPE_NET_ERR_MSG,Err:other error={0}\n", len));
//
if (status != -1)
{
////// 更新图标
////theDemo->PostMessage(WM_USER_CONNECT_STATUS_ICON, (WPARAM)status, (LPARAM)0);
////// 更新状态信息
if (len <= 0 && len >= -6)
{
//触发断开消息
HBI_FPD_DLL.HBI_DisConnectDetector(HBI_FPD_DLL._handel);
// 更新平板断开信息
Close();
//btnDisconnect_Click(null, null);
}
}
break;
case (byte)(eCallbackEventCommType.ECALLBACK_TYPE_ROM_UPLOAD):
WriteLog("ECALLBACK_TYPE_ROM_UPLOAD!\n");
// 当前反馈固件参数,转化为结构体
m_pLastRegCfg = (RegCfgInfo)Marshal.PtrToStructure(buff, typeof(RegCfgInfo));
////#if 0
//// PrintFirmwrae(); // 打印结构体信息
////#endif
break;
case (byte)(eCallbackEventCommType.ECALLBACK_TYPE_SET_CFG_OK):
WriteLog("ECALLBACK_TYPE_SET_CFG_OK!\n");
break;
//----------------图像-------------------
case (byte)(eCallbackEventCommType.ECALLBACK_TYPE_SINGLE_IMAGE):
case (byte)(eCallbackEventCommType.ECALLBACK_TYPE_MULTIPLE_IMAGE):
#if savebmp8
//byte[] bytess = new byte[len];
//Marshal.Copy(buff, bytess, 0, len);
//////
////WriteLog("success,ECALLBACK_TYPE_MULTIPLE_IMAGE or ECALLBACK_TYPE_SINGLE_IMAGE!\n");
////if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\raw_dir")) Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\raw_dir");
////string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".raw";
////FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\raw_dir\\" + fileName, FileMode.CreateNew);
////BinaryWriter bw = new BinaryWriter(fs);
////bw.Write(bytess, 0, bytess.Length);
////bw.Close();
////fs.Close();
#else
WriteLog($"success,IMAGE!ww={m_pLastRegCfg.m_SysBaseInfo.m_sImageWidth},hh={m_pLastRegCfg.m_SysBaseInfo.m_sImageHeight},len={len}");
buffer = new byte[len];
Marshal.Copy(buff, buffer, 0, len);
buffgetted = true;
WaitstopToken.Cancel(false);
if (false && 0 == HBI_FPD_DLL.HBI_16UCConvertTo8UC(HBI_FPD_DLL._handel, buff, ref len))
{
WriteLog("success,ECALLBACK_TYPE_MULTIPLE_IMAGE or ECALLBACK_TYPE_SINGLE_IMAGE!\n");
if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\raw_dir")) Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\raw_dir");
string fileName = Directory.GetCurrentDirectory() + "\\raw_dir\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp";
int ww = m_pLastRegCfg.m_SysBaseInfo.m_sImageWidth;
int hh = m_pLastRegCfg.m_SysBaseInfo.m_sImageHeight;
ImageWidth = ww;
ImageHeight = hh;
SaveBmp8(ww, hh, buff, fileName);
}
#endif
break;
#region
case (byte)(eCallbackEventCommType.ECALLBACK_TYPE_THREAD_EVENT):
if (len == 100)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,start recv data!\n");
else if (len == 101)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,end recv data!\n");
else if (len == 104)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,Packet Retransmission:start recv data!\n");
else if (len == 105)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,Frame Retransmission:start recv data!\n");
else if (len == 106)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,Frame loss retransmission over,end recv data!\n");
else if (len == 107)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,image buff is null:end recv data!\n");
else if (len == 108)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,Generate Offset Template:start thread!\n");
else if (len == 109)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,Generate Offset Template:end thread!\n");
else if (len == 110)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,Generate Gain Template:start thread!\n");
else if (len == 111)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,Generate Gain Template:end thread!\n");
else if (len == 112)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,offset calibrate:success!\n");
else if (len == 113)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,offset calibrate:failed!\n");
else if (len == 114)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,gain calibrate:success!\n");
else if (len == 115)
WriteLog("ECALLBACK_TYPE_THREAD_EVENT,gain calibrate:failed!\n");
else
WriteLog(string.Format("ECALLBACK_TYPE_THREAD_EVENT,Err:未知错误[{0}]\n", len));
break;
#endregion
default:
WriteLog(string.Format("ECALLBACK_TYPE_THREAD_EVENT,ECALLBACK_TYPE_INVALVE,command=[{0}]\n", cmd));
break;
}
return 1;
}
private void GetFirmwareCfg()
{
m_pLastRegCfg = new RegCfgInfo();//RegCfgInfo 1024
int _ret = Marshal.SizeOf(m_pLastRegCfg);
_ret = HBI_FPD_DLL.HBI_GetDevCfgInfo(HBI_FPD_DLL._handel, ref m_pLastRegCfg); //获取固件参数,连接后即可获取参数
if (_ret != 0) { WriteLog("Error,HBI_GetDevCfgInfo" + _ret.ToString()); return; } // WriteLog("HBI_GetDevCfgInfo:\n", img_pro.nwidth, img_pro.nheight);
// 测试,置零,检查结果
ushort usValue = (ushort)(((m_pLastRegCfg.m_EtherInfo.m_sDestUDPPort & 0xff) << 8) | ((m_pLastRegCfg.m_EtherInfo.m_sDestUDPPort >> 8) & 0xff));// 高低位需要转换
WriteLog(string.Format("\tSourceIP:{0}.{1}.{2}.{3}:{4}\n",
(int)(m_pLastRegCfg.m_EtherInfo.m_byDestIP[0]), (int)(m_pLastRegCfg.m_EtherInfo.m_byDestIP[1]),
(int)(m_pLastRegCfg.m_EtherInfo.m_byDestIP[2]), (int)(m_pLastRegCfg.m_EtherInfo.m_byDestIP[3]), (ushort)(usValue)));
usValue = (ushort)(((m_pLastRegCfg.m_EtherInfo.m_sSourceUDPPort & 0xff) << 8) | ((m_pLastRegCfg.m_EtherInfo.m_sSourceUDPPort >> 8) & 0xff));
WriteLog(string.Format("\tDestIP:{0}.{1}.{2}.{3}:{4}\n", (int)(m_pLastRegCfg.m_EtherInfo.m_bySourceIP[0]), (int)(m_pLastRegCfg.m_EtherInfo.m_bySourceIP[1]),
(int)(m_pLastRegCfg.m_EtherInfo.m_bySourceIP[2]),
(int)(m_pLastRegCfg.m_EtherInfo.m_bySourceIP[3]), (ushort)(usValue)));
if (m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize >= 0x01 && m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize <= 0x06)
{
if (m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize == 0x01)
WriteLog(string.Format("\tPanelSize:0x{0:X000},fpd type:4343\n", (int)m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize));
else if (m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize == 0x02)
WriteLog(string.Format("\tPanelSize:0x{0:X000},fpd type:3543\n", (int)m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize));
else if (m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize == 0x03)
WriteLog(string.Format("\tPanelSize:0x{0:X000},fpd type:1613\n", (int)m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize));
else if (m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize == 0x04)
WriteLog(string.Format("\tPanelSize:0x{0:X000},fpd type:3030\n", (int)m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize));
else if (m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize == 0x05)
WriteLog(string.Format("\tPanelSize:0x{0:X000},fpd type:2530\n", (int)m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize));
else
WriteLog(string.Format("\tPanelSize:0x{0:X000},fpd type:3025\n", (int)m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize));
}
else
{
WriteLog(string.Format("\tErr:fpd property:Do not know!fpd type:0x{0:X000}\n", (int)m_pLastRegCfg.m_SysBaseInfo.m_byPanelSize));
}
WriteLog(string.Format("\twidth={0},hight={1}\n", m_pLastRegCfg.m_SysBaseInfo.m_sImageWidth, m_pLastRegCfg.m_SysBaseInfo.m_sImageHeight));
WriteLog("\tdatatype is unsigned char.\n");
WriteLog("\tdatabit is 16bits.\n");
WriteLog("\tdata is little endian.\n");
//cboxWorkMode.Enabled = true;
#region workmode 等值显示
if (m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode == 0x01)//workmode
{
WriteLog(string.Format("\tstatic software trigger.{0:X}\n", (int)(m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode)));
//cboxWorkMode.SelectedIndex = 1;
}
else if (m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode == 0x03)
{
//cboxWorkMode.SelectedIndex = 0;
WriteLog(string.Format("\tstatic hvg trigger.{0:X000}\n", (int)(m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode)));
}
else if (m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode == 0x04)
{
//cboxWorkMode.SelectedIndex = 2;
WriteLog(string.Format("\tstatic hvg trigger.{0:X000}\n", (int)(m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode)));
}
else WriteLog(string.Format("\tother trigger mode.{0:X000}\n", (int)(m_pLastRegCfg.m_SysCfgInfo.m_byWorkMode)));
//
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection <= 3)
// cboxOffsetEnable.SelectedIndex = m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection;
//else
// cboxOffsetEnable.SelectedIndex = 0;
WriteLog(string.Format("\tOffset correction disenable.0x{0:X000}\n", (int)(m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection)));
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection <= 2)
// cboxGainEnable.SelectedIndex = m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection;
//else
// cboxGainEnable.SelectedIndex = 0;
WriteLog(string.Format("\tGain correction disenable.0x{0:X000}\n", (int)(m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection)));
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byDefectCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byDefectCorrection <= 2)
// cboxDefectEnable.SelectedIndex = m_pLastRegCfg.m_ImgCaliCfg.m_byDefectCorrection;
//else
// cboxDefectEnable.SelectedIndex = 0;
WriteLog(string.Format("\tDefect correction disenable.0x{0:X000}\n", (int)(m_pLastRegCfg.m_ImgCaliCfg.m_byDefectCorrection)));
//if (m_pLastRegCfg.m_ImgCaliCfg.m_byDummyCorrection >= 0x00 && m_pLastRegCfg.m_ImgCaliCfg.m_byDummyCorrection <= 3)
// cboxDummyEnable.SelectedIndex = m_pLastRegCfg.m_ImgCaliCfg.m_byDummyCorrection;
//else
// cboxDummyEnable.SelectedIndex = 0;
WriteLog(string.Format("\tDummy correction disenable.0x{0:X000}\n", (int)(m_pLastRegCfg.m_ImgCaliCfg.m_byDummyCorrection)));
//// 更新显示信息
//PostMessage(WM_USER_CURR_FPD_INFO, (WPARAM)0, (LPARAM)0);
#endregion
}
private void btnSetCorrectEnable()
{
WriteLog("set correct enable begin!\n");
//m_pCorrect.bFeedbackCfg = false; // false - ECALLBACK_TYPE_SET_CFG_OK Event
m_pCorrect.bFeedbackCfg = true; // true - ECALLBACK_TYPE_ROM_UPLOAD Event
m_pCorrect.ucOffsetCorrection = (char)m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection;
m_pCorrect.ucGainCorrection = (char)m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection;
m_pCorrect.ucDefectCorrection = (char)m_pLastRegCfg.m_ImgCaliCfg.m_byDefectCorrection;
m_pCorrect.ucDummyCorrection = (char)0/*cboxDummyEnable.SelectedIndex*/; // 暂时不支持
// 打印软触发使能参数
WriteLog("HBI_UpdateCorrectEnable\n");
WriteLog(String.Format("\tm_pCorrect.ucOffsetCorrection={0}\n", (int)m_pCorrect.ucOffsetCorrection));
WriteLog(String.Format("\tm_pCorrect.ucGainCorrection={0}\n", (int)m_pCorrect.ucGainCorrection));
WriteLog(String.Format("\tm_pCorrect.ucDefectCorrection={0}\n", (int)m_pCorrect.ucDefectCorrection));
WriteLog(String.Format("\tm_pCorrect.ucDummyCorrection={0}\n", (int)m_pCorrect.ucDummyCorrection));
int _ret = HBI_FPD_DLL.HBI_UpdateCorrectEnable(HBI_FPD_DLL._handel, ref m_pCorrect);
if (_ret == 0)
{
WriteLog("\tHBI_UpdateCorrectEnable success!\n");
}
else
{
WriteLog("HBI_UpdateCorrectEnable failed!");
}
}
public static void SaveBmp8(int width, int height, IntPtr buff, string savePath)
{
int nwidth = width;
int nheight = height;
short fiBitCount = 8;
int iLineByteCnt = (((width * fiBitCount) + 31) >> 5) << 2;
int dataSize = iLineByteCnt * height;
//byte[] fsbytes = new byte[14];//文件头
//byte[] fibytes = new byte[40];//信息头
byte[] pbytes = new byte[256 * 4];//调色板
byte[] bfType = new byte[2];
bfType[0] = (int)'B';
bfType[1] = (int)'M';
byte[] bfSize = BitConverter.GetBytes(dataSize + 14 + 40 + 1024);
byte[] bfReserved = new byte[4] { 0, 0, 0, 0 };
byte[] biOffbits = BitConverter.GetBytes(1024 + 14 + 40);
byte[] biSize = BitConverter.GetBytes(40);
byte[] biWidth = BitConverter.GetBytes(width);
byte[] biHeight = BitConverter.GetBytes(-1 * height);
byte[] biPlanes = new byte[] { 0, 1 };
byte[] biBitCount = BitConverter.GetBytes(fiBitCount);
byte[] biCompression = new byte[] { 0, 0, 0, 0 };
byte[] biSizeImage = new byte[] { 0, 0, 0, 0 };
byte[] biXYPelsPerMeter = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] biClrUsed = BitConverter.GetBytes(256);
byte[] biClrImportant = BitConverter.GetBytes(256);
//调色版
for (int i = 0; i < 256; i++)
{
pbytes[i * 4] = (byte)i;
pbytes[i * 4 + 1] = (byte)i;
pbytes[i * 4 + 2] = (byte)i;
pbytes[i * 4 + 3] = 255;
}
byte[] data = new byte[dataSize];
Marshal.Copy(buff, data, 0, width * height);
using (FileStream fileStream = File.OpenWrite(savePath))
{
fileStream.Write(bfType, 0, 2);
fileStream.Write(bfSize, 0, 4);
fileStream.Write(bfReserved, 0, 4);
fileStream.Write(biOffbits, 0, 4);
//
fileStream.Write(biSize, 0, 4);
fileStream.Write(biWidth, 0, 4);
fileStream.Write(biHeight, 0, 4);
fileStream.Write(biPlanes, 0, 2);
fileStream.Write(biBitCount, 0, 2);
fileStream.Write(biCompression, 0, 4);
fileStream.Write(biSizeImage, 0, 4);
fileStream.Write(biXYPelsPerMeter, 0, 8);
fileStream.Write(biClrUsed, 0, 4);
fileStream.Write(biClrImportant, 0, 4);
//
fileStream.Write(pbytes, 0, pbytes.Length);
//
fileStream.Write(data, 0, data.Length);
//
fileStream.Close();
fileStream.Dispose();
}
}
/// <summary>
/// 加载本地RAW图片,64字节头
/// </summary>
/// <param name="filePath">图片路径</param>
public void LoadRAW(string filePath)
{
buffer = System.IO.File.ReadAllBytes(filePath);
}
/// <summary>
/// 保存本地RAW图片
/// </summary>
/// <param name="filePath">图片路径</param>
public void SaveRAW(string filePath)
{
if (buffer == null) return;
System.IO.File.WriteAllBytes(filePath, buffer);
}
void WriteLog(string log) {
LOG.Info(log);
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<log4net>
<appender name="CarerayImage" type="log4net.Appender.RollingFileAppender">
<file value="logs/CarerayImage.log"/>
<param name="Encoding" value="UTF-8"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM-dd"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date][%t]%-5p %m%n"/>
</layout>
</appender>
<root>
<level value="Debug"/>
<appender-ref ref="CarerayImage"/>
</root>
</log4net>
</configuration>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{01B38047-138C-45CB-A5F8-7F472E92A43A}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>CarerayImage_Test</RootNamespace>
<AssemblyName>CarerayImage_Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\..\..\..\DLL\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarerayImage\CarerayImage.csproj">
<Project>{bfcb03f8-cd69-4f02-8336-65ddff73d385}</Project>
<Name>CarerayImage</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file \ No newline at end of file
namespace CarerayImage_Test
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 165);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(97, 26);
this.button1.TabIndex = 0;
this.button1.Text = "打开文件";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Location = new System.Drawing.Point(115, 12);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(673, 426);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(12, 77);
this.numericUpDown1.Maximum = new decimal(new int[] {
65536,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(97, 21);
this.numericUpDown1.TabIndex = 2;
this.numericUpDown1.Value = new decimal(new int[] {
65535,
0,
0,
0});
this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(12, 116);
this.numericUpDown2.Maximum = new decimal(new int[] {
65536,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(97, 21);
this.numericUpDown2.TabIndex = 3;
this.numericUpDown2.Value = new decimal(new int[] {
32768,
0,
0,
0});
this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 62);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 12);
this.label1.TabIndex = 4;
this.label1.Text = "窗宽";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 101);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(29, 12);
this.label2.TabIndex = 5;
this.label2.Text = "窗位";
//
// button2
//
this.button2.Location = new System.Drawing.Point(12, 197);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(97, 26);
this.button2.TabIndex = 6;
this.button2.Text = "打开设备";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(12, 229);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(97, 26);
this.button3.TabIndex = 7;
this.button3.Text = "关闭设备";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(12, 261);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(97, 26);
this.button4.TabIndex = 8;
this.button4.Text = "获取图像";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(12, 293);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(97, 26);
this.button5.TabIndex = 9;
this.button5.Text = "保存图像";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(24, 415);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(75, 23);
this.button6.TabIndex = 10;
this.button6.Text = "button6";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(12, 325);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(97, 26);
this.button7.TabIndex = 11;
this.button7.Text = "保存RAW";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button8
//
this.button8.Location = new System.Drawing.Point(24, 12);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(75, 23);
this.button8.TabIndex = 12;
this.button8.Text = "点料测试";
this.button8.UseVisualStyleBackColor = true;
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// button9
//
this.button9.Location = new System.Drawing.Point(12, 357);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(97, 23);
this.button9.TabIndex = 13;
this.button9.Text = "点料";
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.numericUpDown2);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
}
}
using Asa;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Asa.eyemLib;
namespace CarerayImage_Test
{
public partial class Form1 : Form
{
private Asa.XrayImage xrayImage;
private Bitmap bmp;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
xrayImage = new Asa.XrayImage("123", Asa.XrayImage.DeviceType.CARREY);
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog { Filter = "RAW|*.raw" };
if (dlg.ShowDialog() == DialogResult.Cancel) return;
xrayImage.LoadRAW(dlg.FileName);
//careray.RemoveCircle();
bmp = xrayImage.Get48bImage();
pictureBox1.Image = bmp;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
xrayImage.WindowWidth = Convert.ToInt32(numericUpDown1.Value);
pictureBox1.Image = xrayImage.Get48bImage();
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
xrayImage.WindowLevel = Convert.ToInt32(numericUpDown2.Value);
pictureBox1.Image = xrayImage.Get48bImage();
}
private void button2_Click(object sender, EventArgs e)
{
bool rtn = xrayImage.Open();
MessageBox.Show(rtn.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
bool rtn = xrayImage.Close();
MessageBox.Show(rtn.ToString());
}
private void button4_Click(object sender, EventArgs e)
{
xrayImage.GetImage(3,3500);
xrayImage.WindowWidth = Convert.ToInt32(numericUpDown1.Value);
xrayImage.WindowLevel = Convert.ToInt32(numericUpDown2.Value);
bmp = xrayImage.Get48bImage();
pictureBox1.Image = bmp;
}
private void button5_Click(object sender, EventArgs e)
{
bmp.Save(Application.StartupPath + string.Format("\\png\\{0:HHmmss}", DateTime.Now) + ".png", System.Drawing.Imaging.ImageFormat.Png);
}
private void button6_Click(object sender, EventArgs e)
{
int w = 200;
int h = 100;
int count = w * h;
byte[] buff = new byte[count * 4 * 2];
int n = 0;
int color = 65535;
byte[] bb = BitConverter.GetBytes(color);
for (int i = 0; i < count; i++)
{
buff[n++] = bb[0];
buff[n++] = bb[1];
buff[n++] = bb[0];
buff[n++] = bb[1];
buff[n++] = bb[0];
buff[n++] = bb[1];
}
bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format48bppRgb);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
System.Runtime.InteropServices.Marshal.Copy(buff, 0, bmpData.Scan0, bmpData.Stride * h);
bmp.UnlockBits(bmpData);
pictureBox1.Image = bmp;
}
private void button7_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "RAW文件|*.raw";
if (dlg.ShowDialog() == DialogResult.OK)
xrayImage.SaveRAW(dlg.FileName);
}
private void button8_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "PNG文件|*.png";
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
foreach (string path in openFileDialog.FileNames)
{
Task.Run(() => {
//int n = XrayImage.GetLocalCount(path,200, out string count, out EyemImage tpDstImg);
//Console.WriteLine(count);
//int n = XrayImage.GetLocalCountTemplate(path, 20, out string count, out Bitmap BmpDstImg);
//Console.WriteLine(count);
//pictureBox1.Image = BmpDstImg;
Bitmap bitmap = new Bitmap(path);
BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
var eyem = new EyemImage();
eyem.ucpImage = bmpData.Scan0;
eyem.iWidth = bitmap.Width;
eyem.iHeight = bitmap.Height;
eyem.iDepth = 2;
eyem.iChannels = 2;
int n = XrayImage.GetLocalCount(eyem, 200,"123", out string count, out EyemImage tpDstImg);
Console.WriteLine(count);
});
//MessageBox.Show(count);
}
}
//int m = careray.GetLocalCountIrregular(path, 35, "4", 5, out string count, out Asa.API.EyemImage tpDstImg);
//int n = careray.GetCount(2, 3, out int iObjCount, out Asa.API.EyemImage tpDstImg);
}
private void button9_Click(object sender, EventArgs e)
{
for (int i = 0; i < 20; i++)
{
eyemLib.EyemImage eyemImage = xrayImage.GetRawBufferHandle();
int n = XrayImage.GetLocalCount(eyemImage,10, "123.png", out string count, out _);
xrayImage.FreeRawBufferHandle();
Console.WriteLine(count);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
using log4net.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CarerayImage_Test
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
XmlConfigurator.Configure();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("CarerayImage_Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CarerayImage_Test")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("01b38047-138c-45cb-a5f8-7f472e92a43a")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace CarerayImage_Test.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CarerayImage_Test.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace CarerayImage_Test.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!