Commit cbdaf239 刘韬

添加昊博平板校准功能, 优化康众平板取图

1 个父辈 53e99e79
......@@ -149,14 +149,17 @@ namespace Asa
CancellationTokenSource AcquisitionWaitstopToken = new CancellationTokenSource();
int addFrameCount = 0;
int MaxFrameCount = 3;
bool imageGet = false;
/// <summary>
/// 获取图像
/// </summary>
/// <returns></returns>
public bool GetImage(int _MaxFrameCount=3,int MaxDelay=5000)
{
imageGet = false;
MaxFrameCount = _MaxFrameCount;
AcquisitionWaitstopToken = new CancellationTokenSource();
//AcquisitionWaitstopToken = new CancellationTokenSource();
addFrameCount = 0;
buffer = new byte[ImageWidth * ImageHeight * 2 + HEAD];
for (int i = 0; i < buffer.Length; i++)
......@@ -167,7 +170,15 @@ namespace Asa
LOG.Info("CR_StartAcquisition Return " + rtn);
if (rtn != 0) return false;
Task.Delay(MaxDelay, AcquisitionWaitstopToken.Token).Wait();
//Task.Delay(MaxDelay, AcquisitionWaitstopToken.Token).Wait();
int timeout = 0;
while (!imageGet) {
Task.Delay(100).Wait();
timeout += 100;
if (timeout > MaxDelay)
break;
}
rtn = API.CR_StopAcquisition(DEV_INDEX);
LOG.Info("CR_StopAcquisition Return " + rtn);
......@@ -321,7 +332,8 @@ namespace Asa
LOG.Debug(string.Format("nEventID={0} {1} {2}", nEventID, eventID, addFrameCount));
if (addFrameCount > MaxFrameCount)
{
AcquisitionWaitstopToken.Cancel();
//AcquisitionWaitstopToken.Cancel();
imageGet = true;
LOG.Debug("AcquisitionWaitstopToken.Cancel");
}
}
......@@ -330,6 +342,11 @@ namespace Asa
}
}
public Task<bool> GenerateTemplate(int mode)
{
throw new NotImplementedException();
}
}
......
......@@ -344,6 +344,27 @@ namespace Asa.HaoboSDK
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#endregion
/*********************************************************
* 函 数 名: HBI_ImmediateGenerateTemplate
* 功能描述: 一键生成模板
* 参数说明:
In: void *handle - 句柄(无符号指针)
EnumIMAGE_ACQ_MODE _mode - 生成模板类型
OFFSET_TEMPLATE_MODE 连续采集一组暗场图 - offset
GAIN_TEMPLATE_MODE 连续采集一组亮场图 - gain
DEFECT_ACQ_GROUP1, 连续采集一组亮场图 - defect group1
DEFECT_ACQ_GROUP2, 连续采集一组亮场图 - defect group2
DEFECT_ACQ_AND_TEMPLATE 连续采集一组亮场图 - defect group3 and generate template
Out: 无
* 返 回 值:int
0 - 成功
非0 - 失败
* 备 注:
*********************************************************/
[DllImport("HBI_FPD.dll", EntryPoint = "HBI_ImmediateGenerateTemplate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int HBI_ImmediateGenerateTemplate(IntPtr handle, EnumIMAGE_ACQ_MODE aqc_mode);
}
#region delegate
......@@ -380,18 +401,19 @@ namespace Asa.HaoboSDK
// 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模板-连续采集亮场图
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模板-连续采集亮场图
// ADD BY MHYANG 20201013
OFFSET_TEMPLATE_MODE, // 连续采集一组暗场图 - offset
GAIN_TEMPLATE_MODE, // 连续采集一组亮场图 - gain
DEFECT_ACQ_GROUP1, // 连续采集一组亮场图 - defect group1
DEFECT_ACQ_GROUP2, // 连续采集一组亮场图 - defect group2
DEFECT_ACQ_AND_TEMPLATE // 连续采集一组亮场图 - defect group3 and generate template
};
// Notice: After Each Member Variables, show Variables enum ,
// before '-' is variables' value, after '-' is the meaning of the value;
......@@ -440,8 +462,11 @@ namespace Asa.HaoboSDK
ECALLBACK_TYPE_FACTORY_UPLOAD = 0X12,
ECALLBACK_TYPE_SINGLE_IMAGE = 0X51,
ECALLBACK_TYPE_MULTIPLE_IMAGE = 0X52,
ECALLBACK_TYPE_PREVIEW_IMAGE = 0X53,
ECALLBACK_TYPE_PACKET_MISS = 0X5B,
ECALLBACK_TYPE_LIVE_ACQ_OK = 0XA0,
ECALLBACK_TYPE_OFFSET_TMP = 0X5C,
ECALLBACK_TYPE_PREVIEW_OFFSET_TMP = 0X5D,
ECALLBACK_TYPE_SENDTO_WIZARD = 0XA0,
ECALLBACK_TYPE_ADMIN_CFG_UPDATA = 0XA1,
ECALLBACK_TYPE_USER_CFG_UPDATA = 0XA2,
ECALLBACK_TYPE_PACKET_MISS_MSG = 0XA4,
......@@ -451,7 +476,10 @@ namespace Asa.HaoboSDK
ECALLBACK_TYPE_GAIN_ERR_MSG = 0XA8,
ECALLBACK_TYPE_DEFECT_ERR_MSG = 0XA9,
ECALLBACK_TYPE_NET_ERR_MSG = 0XAA,
ECALLBACK_TYPE_SET_CFG_OK = 0XAB // 设置参数成功
ECALLBACK_TYPE_SET_CFG_OK = 0XAB, // 设置参数成功
ECALLBACK_TYPE_ACQ_SUCCESS = 0XAC, // 反馈采集到一帧图像成功
ECALLBACK_TYPE_GENERATE_TEMPLATE = 0XAD, // 生成模板
ECALLBACK_TYPE_FILE_NOTEXIST = 0XAE // 文件不存在
};
public enum eCallbackUpdateFirmwareStatus
......
using System;
using Asa.HaoboSDK;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
......@@ -121,6 +122,8 @@ namespace Asa
device.FreeRawBufferHandle();
}
/// <summary>
/// 本地文件普通器件点料
/// </summary>
......@@ -403,6 +406,15 @@ namespace Asa
{
device.SaveRAW(filePath);
}
/// <summary>
/// 校准平板
/// </summary>
/// <param name="mode">1:暗场校准,2亮场校准</param>
/// <returns></returns>
public Task<bool> GenerateTemplate(int mode)
{
return device.GenerateTemplate(mode);
}
public enum DeviceType
{
......
......@@ -29,5 +29,7 @@ namespace Asa
/// 窗位
/// </summary>
int WindowLevel { set; get; }
Task<bool> GenerateTemplate(int mode);
}
}
......@@ -397,6 +397,36 @@ namespace Asa
WriteLog(string.Format("ECALLBACK_TYPE_THREAD_EVENT,Err:未知错误[{0}]\n", len));
break;
#endregion
case (byte)(eCallbackEventCommType.ECALLBACK_TYPE_GENERATE_TEMPLATE):
int ECALLBACK_TEMPLATE_RESULT = 0X09;
if (len == ECALLBACK_TEMPLATE_RESULT)
{
//if (theDoc->m_templateHwnd != NULL)
// PostMessage(theDoc->m_templateHwnd, WM_USER_NOTICE_TEMPLATE_TOOL, (WPARAM)nid, (LPARAM)0);
if (id == -1)
WriteLog("offset template generate failed!");
else if (id == 1)
WriteLog("offset template generate success!");
else if (id == -2)
WriteLog("gain template generate failed!");
else if (id == 2)
WriteLog("gain template generate success!");
else if (id == -3)
WriteLog("defect template generate failed!");
else if (id == 3)
WriteLog("defect template generate success!");
else if (id == 4)
WriteLog("defect acq light image success!");
else if (id == -4)
WriteLog("defect acq light image failed!");
else
WriteLog("err:other error!");
inState = id;
}
break;
default:
WriteLog(string.Format("ECALLBACK_TYPE_THREAD_EVENT,ECALLBACK_TYPE_INVALVE,command=[{0}]\n", cmd));
break;
......@@ -500,8 +530,8 @@ namespace Asa
//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.ucOffsetCorrection = (char)1;//(char)m_pLastRegCfg.m_ImgCaliCfg.m_byOffsetCorrection;
m_pCorrect.ucGainCorrection = (char)1;//(char)m_pLastRegCfg.m_ImgCaliCfg.m_byGainCorrection;
m_pCorrect.ucDefectCorrection = (char)m_pLastRegCfg.m_ImgCaliCfg.m_byDefectCorrection;
m_pCorrect.ucDummyCorrection = (char)0/*cboxDummyEnable.SelectedIndex*/; // 暂时不支持
......@@ -611,6 +641,49 @@ namespace Asa
}
int inState = int.MinValue;
/// <summary>
/// 校准平板
/// </summary>
/// <param name="mode">1:暗场校准,2亮场校准</param>
/// <returns></returns>
public async Task<bool> GenerateTemplate(int mode)
{
inState = int.MinValue;
EnumIMAGE_ACQ_MODE tmode;
if (mode == 1)
{
tmode = EnumIMAGE_ACQ_MODE.OFFSET_TEMPLATE_MODE;
}
else
{
tmode = EnumIMAGE_ACQ_MODE.GAIN_TEMPLATE_MODE;
}
int ret = HBI_FPD_DLL.HBI_ImmediateGenerateTemplate(HBI_FPD_DLL._handel, tmode);
WriteLog($"ret:{ret},tmode:{tmode}");
if (ret != 0)
return false;
Task a = Task.Delay(60*1000);
Task b = Task.Run(() => {
while (true)
{
Thread.Sleep(100);
//WriteLog($"inState:{inState}");
if (inState==2 || inState==1)
break;
}
});
var result = await Task.WhenAny(a, b);
if (result == a) {
WriteLog($"{tmode}: time out");
return false;
}
return true;
}
void WriteLog(string log) {
LOG.Info(log);
}
......
......@@ -77,6 +77,12 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form2.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form2.Designer.cs">
<DependentUpon>Form2.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
......
......@@ -42,6 +42,7 @@
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
......@@ -64,7 +65,7 @@
| 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.Size = new System.Drawing.Size(736, 497);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
......@@ -203,11 +204,22 @@
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button10
//
this.button10.Location = new System.Drawing.Point(14, 469);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(95, 23);
this.button10.TabIndex = 14;
this.button10.Text = "昊博平板校准";
this.button10.UseVisualStyleBackColor = true;
this.button10.Click += new System.EventHandler(this.button10_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.ClientSize = new System.Drawing.Size(863, 521);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
......@@ -249,6 +261,7 @@
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
}
}
......@@ -144,7 +144,7 @@ namespace CarerayImage_Test
eyem.iHeight = bitmap.Height;
eyem.iDepth = 2;
eyem.iChannels = 2;
int n = XrayImage.GetLocalCount(eyem, 200,"123", out string count, out EyemImage tpDstImg);
int n = XrayImage.GetLocalCount(eyem, 200,"123", out int[] count, out Bitmap tpDstImg);
Console.WriteLine(count);
});
//MessageBox.Show(count);
......@@ -160,10 +160,16 @@ namespace CarerayImage_Test
for (int i = 0; i < 20; i++)
{
eyemLib.EyemImage eyemImage = xrayImage.GetRawBufferHandle();
int n = XrayImage.GetLocalCount(eyemImage,10, "123.png", out string count, out _);
int n = XrayImage.GetLocalCount(eyemImage,10, "123.png", out int[] count, out _);
xrayImage.FreeRawBufferHandle();
Console.WriteLine(count);
}
}
private void button10_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
}
}

namespace CarerayImage_Test
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form2";
}
#endregion
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CarerayImage_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!