Commit fee2767d LN

二维码学习功能修改

1 个父辈 12cebded
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CodeLibrary</RootNamespace> <RootNamespace>CodeLibrary</RootNamespace>
<AssemblyName>CodeLibrary</AssemblyName> <AssemblyName>CodeLibrary</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Basler.Pylon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e389355f398382ab, processorArchitecture=x86"> <Reference Include="Basler.Pylon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e389355f398382ab, processorArchitecture=x86">
...@@ -55,6 +57,9 @@ ...@@ -55,6 +57,9 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="zxing">
<HintPath>..\dll\zxing.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="camera\Basler.cs" /> <Compile Include="camera\Basler.cs" />
...@@ -84,6 +89,7 @@ ...@@ -84,6 +89,7 @@
<Compile Include="ImageHelper.cs" /> <Compile Include="ImageHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CodeResourceControl.cs" /> <Compile Include="CodeResourceControl.cs" />
<Compile Include="ZXingCodeHelper.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="FrmBase.resx"> <EmbeddedResource Include="FrmBase.resx">
......
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
// //
this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnStop.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnStop.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnStop.Location = new System.Drawing.Point(949, 51); this.btnStop.Location = new System.Drawing.Point(949, 49);
this.btnStop.Name = "btnStop"; this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(144, 35); this.btnStop.Size = new System.Drawing.Size(144, 32);
this.btnStop.TabIndex = 3; this.btnStop.TabIndex = 3;
this.btnStop.Text = "结束学习"; this.btnStop.Text = "结束学习";
this.btnStop.UseVisualStyleBackColor = true; this.btnStop.UseVisualStyleBackColor = true;
...@@ -78,9 +78,9 @@ ...@@ -78,9 +78,9 @@
// //
this.btnOpen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnOpen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnOpen.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnOpen.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpen.Location = new System.Drawing.Point(949, 13); this.btnOpen.Location = new System.Drawing.Point(949, 12);
this.btnOpen.Name = "btnOpen"; this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(144, 35); this.btnOpen.Size = new System.Drawing.Size(144, 32);
this.btnOpen.TabIndex = 1; this.btnOpen.TabIndex = 1;
this.btnOpen.Text = "开始学习"; this.btnOpen.Text = "开始学习";
this.btnOpen.UseVisualStyleBackColor = true; this.btnOpen.UseVisualStyleBackColor = true;
...@@ -104,9 +104,9 @@ ...@@ -104,9 +104,9 @@
// //
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnExit.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnExit.Location = new System.Drawing.Point(1096, 51); this.btnExit.Location = new System.Drawing.Point(1096, 49);
this.btnExit.Name = "btnExit"; this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(110, 35); this.btnExit.Size = new System.Drawing.Size(110, 32);
this.btnExit.TabIndex = 6; this.btnExit.TabIndex = 6;
this.btnExit.Text = "退出"; this.btnExit.Text = "退出";
this.btnExit.UseVisualStyleBackColor = true; this.btnExit.UseVisualStyleBackColor = true;
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
// label1 // label1
// //
this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(3, 19); this.label1.Location = new System.Drawing.Point(3, 18);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(110, 20); this.label1.Size = new System.Drawing.Size(110, 20);
this.label1.TabIndex = 7; this.label1.TabIndex = 7;
...@@ -138,16 +138,16 @@ ...@@ -138,16 +138,16 @@
this.cmbCodeType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbCodeType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCodeType.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.cmbCodeType.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbCodeType.FormattingEnabled = true; this.cmbCodeType.FormattingEnabled = true;
this.cmbCodeType.Location = new System.Drawing.Point(131, 53); this.cmbCodeType.Location = new System.Drawing.Point(117, 53);
this.cmbCodeType.Name = "cmbCodeType"; this.cmbCodeType.Name = "cmbCodeType";
this.cmbCodeType.Size = new System.Drawing.Size(186, 25); this.cmbCodeType.Size = new System.Drawing.Size(163, 25);
this.cmbCodeType.TabIndex = 10; this.cmbCodeType.TabIndex = 10;
this.cmbCodeType.SelectedIndexChanged += new System.EventHandler(this.cmbCodeType_SelectedIndexChanged); this.cmbCodeType.SelectedIndexChanged += new System.EventHandler(this.cmbCodeType_SelectedIndexChanged);
// //
// label2 // label2
// //
this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(3, 57); this.label2.Location = new System.Drawing.Point(3, 55);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(110, 20); this.label2.Size = new System.Drawing.Size(110, 20);
this.label2.TabIndex = 9; this.label2.TabIndex = 9;
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
// lblCount // lblCount
// //
this.lblCount.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblCount.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblCount.Location = new System.Drawing.Point(323, 58); this.lblCount.Location = new System.Drawing.Point(286, 55);
this.lblCount.Name = "lblCount"; this.lblCount.Name = "lblCount";
this.lblCount.Size = new System.Drawing.Size(112, 20); this.lblCount.Size = new System.Drawing.Size(112, 20);
this.lblCount.TabIndex = 13; this.lblCount.TabIndex = 13;
...@@ -210,7 +210,7 @@ ...@@ -210,7 +210,7 @@
"18", "18",
"19", "19",
"20"}); "20"});
this.cmbCount.Location = new System.Drawing.Point(441, 54); this.cmbCount.Location = new System.Drawing.Point(404, 53);
this.cmbCount.Name = "cmbCount"; this.cmbCount.Name = "cmbCount";
this.cmbCount.Size = new System.Drawing.Size(64, 25); this.cmbCount.Size = new System.Drawing.Size(64, 25);
this.cmbCount.TabIndex = 14; this.cmbCount.TabIndex = 14;
...@@ -228,9 +228,9 @@ ...@@ -228,9 +228,9 @@
// //
this.btnClearLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnClearLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnClearLog.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnClearLog.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnClearLog.Location = new System.Drawing.Point(1096, 13); this.btnClearLog.Location = new System.Drawing.Point(1096, 12);
this.btnClearLog.Name = "btnClearLog"; this.btnClearLog.Name = "btnClearLog";
this.btnClearLog.Size = new System.Drawing.Size(110, 35); this.btnClearLog.Size = new System.Drawing.Size(110, 32);
this.btnClearLog.TabIndex = 16; this.btnClearLog.TabIndex = 16;
this.btnClearLog.Text = "清理日志"; this.btnClearLog.Text = "清理日志";
this.btnClearLog.UseVisualStyleBackColor = true; this.btnClearLog.UseVisualStyleBackColor = true;
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
this.chbTest.Checked = true; this.chbTest.Checked = true;
this.chbTest.CheckState = System.Windows.Forms.CheckState.Checked; this.chbTest.CheckState = System.Windows.Forms.CheckState.Checked;
this.chbTest.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.chbTest.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbTest.Location = new System.Drawing.Point(531, 56); this.chbTest.Location = new System.Drawing.Point(532, 55);
this.chbTest.Name = "chbTest"; this.chbTest.Name = "chbTest";
this.chbTest.Size = new System.Drawing.Size(147, 21); this.chbTest.Size = new System.Drawing.Size(147, 21);
this.chbTest.TabIndex = 17; this.chbTest.TabIndex = 17;
...@@ -253,7 +253,7 @@ ...@@ -253,7 +253,7 @@
// btnSelImage // btnSelImage
// //
this.btnSelImage.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnSelImage.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnSelImage.Location = new System.Drawing.Point(783, 15); this.btnSelImage.Location = new System.Drawing.Point(783, 12);
this.btnSelImage.Name = "btnSelImage"; this.btnSelImage.Name = "btnSelImage";
this.btnSelImage.Size = new System.Drawing.Size(160, 32); this.btnSelImage.Size = new System.Drawing.Size(160, 32);
this.btnSelImage.TabIndex = 19; this.btnSelImage.TabIndex = 19;
...@@ -286,7 +286,7 @@ ...@@ -286,7 +286,7 @@
// //
this.chbUseCamera.AutoSize = true; this.chbUseCamera.AutoSize = true;
this.chbUseCamera.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.chbUseCamera.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbUseCamera.Location = new System.Drawing.Point(531, 18); this.chbUseCamera.Location = new System.Drawing.Point(532, 18);
this.chbUseCamera.Name = "chbUseCamera"; this.chbUseCamera.Name = "chbUseCamera";
this.chbUseCamera.Size = new System.Drawing.Size(123, 21); this.chbUseCamera.Size = new System.Drawing.Size(123, 21);
this.chbUseCamera.TabIndex = 21; this.chbUseCamera.TabIndex = 21;
...@@ -297,7 +297,7 @@ ...@@ -297,7 +297,7 @@
// btnDelOld // btnDelOld
// //
this.btnDelOld.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnDelOld.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnDelOld.Location = new System.Drawing.Point(783, 53); this.btnDelOld.Location = new System.Drawing.Point(783, 49);
this.btnDelOld.Name = "btnDelOld"; this.btnDelOld.Name = "btnDelOld";
this.btnDelOld.Size = new System.Drawing.Size(160, 32); this.btnDelOld.Size = new System.Drawing.Size(160, 32);
this.btnDelOld.TabIndex = 22; this.btnDelOld.TabIndex = 22;
...@@ -320,12 +320,13 @@ ...@@ -320,12 +320,13 @@
// //
this.chbHalcon.AutoSize = true; this.chbHalcon.AutoSize = true;
this.chbHalcon.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.chbHalcon.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbHalcon.Location = new System.Drawing.Point(344, 19); this.chbHalcon.Location = new System.Drawing.Point(374, 18);
this.chbHalcon.Name = "chbHalcon"; this.chbHalcon.Name = "chbHalcon";
this.chbHalcon.Size = new System.Drawing.Size(115, 21); this.chbHalcon.Size = new System.Drawing.Size(115, 21);
this.chbHalcon.TabIndex = 24; this.chbHalcon.TabIndex = 24;
this.chbHalcon.Text = "Halcon获取图片"; this.chbHalcon.Text = "Halcon获取图片";
this.chbHalcon.UseVisualStyleBackColor = true; this.chbHalcon.UseVisualStyleBackColor = true;
this.chbHalcon.Visible = false;
this.chbHalcon.CheckedChanged += new System.EventHandler(this.chbHalcon_CheckedChanged); this.chbHalcon.CheckedChanged += new System.EventHandler(this.chbHalcon_CheckedChanged);
// //
// cmbCamera // cmbCamera
...@@ -333,9 +334,9 @@ ...@@ -333,9 +334,9 @@
this.cmbCamera.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbCamera.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCamera.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.cmbCamera.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbCamera.FormattingEnabled = true; this.cmbCamera.FormattingEnabled = true;
this.cmbCamera.Location = new System.Drawing.Point(131, 17); this.cmbCamera.Location = new System.Drawing.Point(117, 16);
this.cmbCamera.Name = "cmbCamera"; this.cmbCamera.Name = "cmbCamera";
this.cmbCamera.Size = new System.Drawing.Size(186, 25); this.cmbCamera.Size = new System.Drawing.Size(351, 25);
this.cmbCamera.TabIndex = 25; this.cmbCamera.TabIndex = 25;
// //
// FrmCodeLearn // FrmCodeLearn
......
...@@ -27,32 +27,19 @@ namespace CodeLibrary ...@@ -27,32 +27,19 @@ namespace CodeLibrary
private string title = CodeResourceControl.GetString(CodeResourceControl.title, "提示"); private string title = CodeResourceControl.GetString(CodeResourceControl.title, "提示");
private string imageIsNull = CodeResourceControl.GetString(CodeResourceControl.imageIsNull, "获取二维码图片为空"); private string imageIsNull = CodeResourceControl.GetString(CodeResourceControl.imageIsNull, "获取二维码图片为空");
private string sureDelete = CodeResourceControl.GetString(CodeResourceControl.sureDelete, "确定删除文件:"); private string sureDelete = CodeResourceControl.GetString(CodeResourceControl.sureDelete, "确定删除文件:");
private Bitmap GetCameraBitmap() private HObject GetCameraImg()
{ {
Bitmap bitmap = null; HObject ho_image = null;
//Bitmap bitmap = null;
int index = cmbCamera.SelectedIndex; int index = cmbCamera.SelectedIndex;
string camerName = cmbCamera.Text; string camerName = cmbCamera.Text;
if (index < 0) if (index < 0)
{ {
MessageBox.Show(selCamera); MessageBox.Show(selCamera);
return null; return null;
} }
//if (baslerNameList.Contains(camerName)) ho_image = Camera._cam.CaptureOnImage(camerName);
//{ return ho_image;
// BaslerCamera.Instance.Open(camerName);
// BaslerCamera.Instance.GrabOne();
// bitmap = BaslerCamera.Instance.Image;
// BaslerCamera.Instance.Close();
//}
//else
//{
// HIKCamera.Instance.Open(camerName);
// HIKCamera.Instance.GrabOne();
// bitmap = HIKCamera.Instance.Image;
// HIKCamera.Instance.Close();
//}
bitmap = Camera._cam.GrabOneImage(camerName);
return bitmap;
} }
private void btnOpen_Click(object sender, EventArgs e) private void btnOpen_Click(object sender, EventArgs e)
{ {
...@@ -73,14 +60,16 @@ namespace CodeLibrary ...@@ -73,14 +60,16 @@ namespace CodeLibrary
} }
else else
{ {
Bitmap bitmap = GetCameraBitmap(); // Bitmap bitmap = GetCameraBitmap();
if (bitmap != null) HObject ho_Image = GetCameraImg();
if (ho_Image != null)
{ {
HDLogUtil.info("从相机【" + cmbCamera.Text + "】获取到一张图片"); HDLogUtil.info("从相机【" + cmbCamera.Text + "】获取到一张图片");
ClearPicImg(); ClearPicImg();
pictureBox1.Image = (Image)bitmap.Clone(); //pictureBox1.Image = (Image)bitmap.Clone();
HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap); //HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HDCodeLearnHelper.DefaultImage = hoImage; HDCodeLearnHelper.DefaultImage = ho_Image;
ShowImage(ho_Image);
} }
else else
{ {
...@@ -99,6 +88,7 @@ namespace CodeLibrary ...@@ -99,6 +88,7 @@ namespace CodeLibrary
Bitmap bitmap = new Bitmap( pictureBox1.Image); Bitmap bitmap = new Bitmap( pictureBox1.Image);
HObject Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap); HObject Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HDCodeLearnHelper.DefaultImage = Image; HDCodeLearnHelper.DefaultImage = Image;
ShowImage(Image);
} }
Task.Factory.StartNew(delegate () Task.Factory.StartNew(delegate ()
{ {
...@@ -107,21 +97,12 @@ namespace CodeLibrary ...@@ -107,21 +97,12 @@ namespace CodeLibrary
FormStatus(true); FormStatus(true);
} }
private void LoadCamera() private void LoadCamera()
{ {
//string[] camerName = BaslerCamera.Instance.CameraName;
//baslerNameList.AddRange(camerName);
cmbCamera.Items.Clear(); cmbCamera.Items.Clear();
foreach (string str in Camera._cam.Name) foreach (string str in Camera._cam.Name)
{ {
cmbCamera.Items.Add(str); cmbCamera.Items.Add(str);
} }
//camerName = HIKCamera.Instance.CameraName;
//hikNameList.AddRange(camerName);
//foreach (string str in camerName)
//{
// cmbCamera.Items.Add(str);
//}
if (cmbCamera.Items.Count > 0) if (cmbCamera.Items.Count > 0)
{ {
cmbCamera.SelectedIndex = 0; cmbCamera.SelectedIndex = 0;
...@@ -306,5 +287,15 @@ namespace CodeLibrary ...@@ -306,5 +287,15 @@ namespace CodeLibrary
cmbCamera.Visible = true ; cmbCamera.Visible = true ;
} }
} }
public void ShowImage(HObject ho_Image)
{
HTuple width, height;
HOperatorSet.GetImageSize(ho_Image, out width, out height);
int dWidth = (int)width.D;
int dHeight = (int)height.D;
this.hWindowControl1.HalconWindow.SetPart(0, 0, dHeight, dWidth);
HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
}
} }
} }
...@@ -78,9 +78,9 @@ namespace CodeLibrary ...@@ -78,9 +78,9 @@ namespace CodeLibrary
} }
return codeList; return codeList;
} }
public static List<CodeInfo> DecodeCode(HObject ho_Image, string symbolType, string hv_model_path, int codeCount,int timeOut=2000) public static List<CodeInfo> DecodeCode(HObject ho_Image, string symbolType, string hv_model_path, int codeCount,int timeOut=1500)
{ {
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 开始"); HDLogUtil.debug(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 开始");
List<CodeInfo> codeList = new List<CodeInfo>(); List<CodeInfo> codeList = new List<CodeInfo>();
try try
{ {
...@@ -141,13 +141,13 @@ namespace CodeLibrary ...@@ -141,13 +141,13 @@ namespace CodeLibrary
} }
} }
} }
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:"+codeList.Count); HDLogUtil.debug(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:"+codeList.Count);
return codeList; return codeList;
} }
catch (Exception ex) catch (Exception ex)
{ {
HDLogUtil.error("DecodeCode出错:" + ex.ToString()); HDLogUtil.error("DecodeCode出错:" + ex.ToString());
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:" + codeList.Count); HDLogUtil.debug(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:" + codeList.Count);
return codeList; return codeList;
} }
......
...@@ -204,3 +204,4 @@ namespace CodeLibrary ...@@ -204,3 +204,4 @@ namespace CodeLibrary
} }
} }
...@@ -4,6 +4,7 @@ using System.Drawing; ...@@ -4,6 +4,7 @@ using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Collections.Generic; using System.Collections.Generic;
using HalconDotNet; using HalconDotNet;
using System.Runtime.InteropServices;
namespace CodeLibrary namespace CodeLibrary
{ {
...@@ -68,7 +69,7 @@ namespace CodeLibrary ...@@ -68,7 +69,7 @@ namespace CodeLibrary
} }
} }
} }
public override Bitmap GrabOne(int index) public override Bitmap GrabOne(int index)
{ {
...@@ -168,7 +169,7 @@ namespace CodeLibrary ...@@ -168,7 +169,7 @@ namespace CodeLibrary
//cameraCur.CameraOpened += OnCameraOpened; //cameraCur.CameraOpened += OnCameraOpened;
//cameraCur.CameraClosed += OnCameraClosed; //cameraCur.CameraClosed += OnCameraClosed;
//cameraCur.StreamGrabber.GrabStarted += OnGrabStarted; //cameraCur.StreamGrabber.GrabStarted += OnGrabStarted;
// cameraCurr[index].StreamGrabber.ImageGrabbed += OnImageGrabbed; // cameraCurr[index].StreamGrabber.ImageGrabbed += OnImageGrabbed;
//cameraCur.StreamGrabber.GrabStopped += OnGrabStopped; //cameraCur.StreamGrabber.GrabStopped += OnGrabStopped;
cameraCurr[index].Open(); cameraCurr[index].Open();
_width[index] = Convert.ToInt32(cameraCurr[index].Parameters[PLCamera.Width].GetValue()); _width[index] = Convert.ToInt32(cameraCurr[index].Parameters[PLCamera.Width].GetValue());
...@@ -210,7 +211,7 @@ namespace CodeLibrary ...@@ -210,7 +211,7 @@ namespace CodeLibrary
} }
return rtn; return rtn;
} }
public override Bitmap GrabOneImage(string name) public override Bitmap GrabOneImage(string name)
{ {
...@@ -229,6 +230,61 @@ namespace CodeLibrary ...@@ -229,6 +230,61 @@ namespace CodeLibrary
} }
public override HObject CaptureOnImage(string name) public override HObject CaptureOnImage(string name)
{ {
int index = cameraName.FindIndex(s => s == name);
if (index == -1)
{
_errInfo = name + "Not find";
return null;
}
if (cameraCurr[index] != null)
{
}
else
{
Open(index);
}
try
{
if (cameraCurr[index] != null)
{
cameraCurr[index].Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.SingleFrame);
//cameraCur.StreamGrabber.Start();
//IGrabResult grabResult = cameraCur.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
IGrabResult grabResult = cameraCurr[index].StreamGrabber.GrabOne(5000);
if (!grabResult.IsValid || !grabResult.GrabSucceeded)
{
_errInfo = grabResult.ErrorDescription;
return null;
}
//相机像素数据
byte[] buffer = grabResult.PixelData as byte[];
//锁定像素数据
GCHandle hand = GCHandle.Alloc(buffer, GCHandleType.Pinned);
//获取像素数据的指针
IntPtr pr = hand.AddrOfPinnedObject();
HalconDotNet.HObject image;
//转成灰度图HOjbect
HalconDotNet.HOperatorSet.GenImage1(out image, new HalconDotNet.HTuple("byte"), grabResult.Width, grabResult.Height, pr);
//释放内存
if (hand.IsAllocated) hand.Free();
_errInfo = "OK";
return image;
}
}
catch (Exception ex)
{
_errInfo = ex.Message;
return null;
}
finally
{
// cameraCurr[index].MV_CC_StopGrabbing_NET();
}
return null; return null;
} }
} }
......
此文件类型无法预览
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!