Commit 89781f01 LN

扫码代码更新

1 个父辈 db900060
...@@ -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,11 +31,11 @@ ...@@ -30,11 +31,11 @@
<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">
<SpecificVersion>False</SpecificVersion> <HintPath>..\..\dll\Basler.Pylon.dll</HintPath>
<HintPath>..\dll\Basler.Pylon.dll</HintPath>
</Reference> </Reference>
<Reference Include="halcondotnet"> <Reference Include="halcondotnet">
<HintPath>..\dll\halcondotnet.dll</HintPath> <HintPath>..\dll\halcondotnet.dll</HintPath>
...@@ -55,6 +56,9 @@ ...@@ -55,6 +56,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 +88,7 @@ ...@@ -84,6 +88,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">
......
...@@ -85,6 +85,10 @@ namespace CodeLibrary ...@@ -85,6 +85,10 @@ namespace CodeLibrary
NoIdLog(id, defaultStr); NoIdLog(id, defaultStr);
} }
} }
if (strCurLanguage == null)
{
strCurLanguage = "";
}
return strCurLanguage; return strCurLanguage;
} }
public static string GetString(string id, string defaultStr, params object[] param) public static string GetString(string id, string defaultStr, params object[] param)
......
...@@ -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,9 +27,10 @@ namespace CodeLibrary ...@@ -27,9 +27,10 @@ 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)
...@@ -37,22 +38,8 @@ namespace CodeLibrary ...@@ -37,22 +38,8 @@ namespace CodeLibrary
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
{ {
...@@ -97,8 +86,10 @@ namespace CodeLibrary ...@@ -97,8 +86,10 @@ namespace CodeLibrary
return; return;
} }
Bitmap bitmap = new Bitmap( pictureBox1.Image); Bitmap bitmap = new Bitmap( pictureBox1.Image);
HObject Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap); HObject Image;
HDCodeHelper.Bitmap2HObjectBpp24(bitmap,out Image);
HDCodeLearnHelper.DefaultImage = Image; HDCodeLearnHelper.DefaultImage = Image;
ShowImage(Image);
} }
Task.Factory.StartNew(delegate () Task.Factory.StartNew(delegate ()
{ {
...@@ -108,20 +99,11 @@ namespace CodeLibrary ...@@ -108,20 +99,11 @@ namespace CodeLibrary
} }
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 +288,15 @@ namespace CodeLibrary ...@@ -306,5 +288,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);
}
} }
} }
...@@ -6,6 +6,7 @@ using System.Drawing.Imaging; ...@@ -6,6 +6,7 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace CodeLibrary namespace CodeLibrary
...@@ -41,19 +42,20 @@ namespace CodeLibrary ...@@ -41,19 +42,20 @@ namespace CodeLibrary
} }
return DecodeCode(ho_Image, codeCount, codeParamPath, paramType); return DecodeCode(ho_Image, codeCount, codeParamPath, paramType);
} }
/// <summary> ///// <summary>
/// 根据图片解析二维码 ///// 根据图片解析二维码
/// </summary> ///// </summary>
/// <param name="map">图片对象</param> ///// <param name="map">图片对象</param>
/// <param name="codeCount">二维码数量</param> ///// <param name="codeCount">二维码数量</param>
/// <param name="codeParamPath">二维码参数路径,""表示不使用参数</param> ///// <param name="codeParamPath">二维码参数路径,""表示不使用参数</param>
/// <param name="paramType">二维码类型,不传类型默认Data Matrix ECC 200</param> ///// <param name="paramType">二维码类型,不传类型默认Data Matrix ECC 200</param>
/// <returns>解析到的二维码</returns> ///// <returns>解析到的二维码</returns>
public static List<CodeInfo> DecodeCode(Bitmap map, int codeCount, string codeParamPath, params string[] paramType) //public static List<CodeInfo> DecodeCode(Bitmap map, int codeCount, string codeParamPath, params string[] paramType)
{ //{
HObject ho_image = Bitmap2HObjectBpp24(map); // HObject ho_image;
return DecodeCode(ho_image, codeCount, codeParamPath, paramType); // Bitmap2HObjectBpp24(map,out ho_image);
} // return DecodeCode(ho_image, codeCount, codeParamPath, paramType);
//}
/// <summary> /// <summary>
/// 根据图片解析二维码 /// 根据图片解析二维码
/// </summary> /// </summary>
...@@ -78,9 +80,9 @@ namespace CodeLibrary ...@@ -78,9 +80,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 +143,48 @@ namespace CodeLibrary ...@@ -141,13 +143,48 @@ namespace CodeLibrary
} }
} }
} }
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:"+codeList.Count); HDLogUtil.debug(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:"+codeList.Count);
if (hv_Area != null)
{
hv_Area.UnPinTuple();
}
if (hv_Row1 != null)
{
hv_Row1.UnPinTuple();
}
if (hv_Column != null)
{
hv_Column.UnPinTuple();
}
if (hv_PointOrder != null)
{
hv_PointOrder.UnPinTuple();
}
if (hv_ResultHandles != null)
{
hv_ResultHandles.UnPinTuple();
}
if (hv_DecodedDataStrings != null)
{
hv_DecodedDataStrings.UnPinTuple();
}
if (hv_DataCodeHandle != null)
{
hv_DataCodeHandle.UnPinTuple();
}
if (ho_SymbolXLDs != null)
{
ho_SymbolXLDs.Dispose();
ho_SymbolXLDs = null;
}
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;
} }
...@@ -191,9 +228,9 @@ namespace CodeLibrary ...@@ -191,9 +228,9 @@ namespace CodeLibrary
/// <summary> /// <summary>
/// 将BitMap转换为HObject对象 /// 将BitMap转换为HObject对象
/// </summary> /// </summary>
public static HObject Bitmap2HObjectBpp24(Bitmap bmp) public static bool Bitmap2HObjectBpp24(Bitmap bmp,out HObject ho_Image)
{ {
HObject ho_Image = null; ho_Image = null;
try try
{ {
HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_Image);
...@@ -204,13 +241,14 @@ namespace CodeLibrary ...@@ -204,13 +241,14 @@ namespace CodeLibrary
HOperatorSet.GenImageInterleaved(out ho_Image, srcBmpData.Scan0, "bgrx", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0); HOperatorSet.GenImageInterleaved(out ho_Image, srcBmpData.Scan0, "bgrx", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0);
bmp.UnlockBits(srcBmpData); bmp.UnlockBits(srcBmpData);
return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
HDLogUtil.error("将BitMap转换为HObject对象出错:" + ex.ToString()); HDLogUtil.error("将BitMap转换为HObject对象出错:" + ex.ToString());
ho_Image = null; ho_Image = null;
} }
return ho_Image; return false ;
} }
internal static string GetCodeParamFilePath(string codeType) internal static string GetCodeParamFilePath(string codeType)
...@@ -236,11 +274,12 @@ namespace CodeLibrary ...@@ -236,11 +274,12 @@ namespace CodeLibrary
HOperatorSet.ReadImage(out ho_Image, filePath); HOperatorSet.ReadImage(out ho_Image, filePath);
return DecodeBarCode(ho_Image); return DecodeBarCode(ho_Image);
} }
public static List<CodeInfo> DecodeBarCode(Bitmap bitmap) //public static List<CodeInfo> DecodeBarCode(Bitmap bitmap)
{ //{
HObject ho_image = Bitmap2HObjectBpp24(bitmap); // HObject ho_image;
return DecodeBarCode(ho_image); // Bitmap2HObjectBpp24(bitmap,out ho_image);
} // return DecodeBarCode(ho_image);
//}
public static List<CodeInfo> DecodeBarCode(HObject ho_Image) public static List<CodeInfo> DecodeBarCode(HObject ho_Image)
{ {
...@@ -300,6 +339,32 @@ namespace CodeLibrary ...@@ -300,6 +339,32 @@ namespace CodeLibrary
} }
} }
HOperatorSet.ClearBarCodeModel(hv_BarCodeHandle); HOperatorSet.ClearBarCodeModel(hv_BarCodeHandle);
if (hv_Area != null)
{
hv_Area.UnPinTuple();
}
if (hv_Row1 != null)
{
hv_Row1.UnPinTuple();
}
if (hv_Column != null)
{
hv_Column.UnPinTuple();
}
if (hv_Orientation != null)
{
hv_Orientation.UnPinTuple();
}
if (ho_GrayImage != null)
{
ho_GrayImage.Dispose();
ho_GrayImage = null;
}
if (ho_SymbolRegions != null)
{
ho_SymbolRegions.Dispose();
ho_SymbolRegions = null;
}
return codeList; return codeList;
} }
...@@ -332,5 +397,41 @@ public class CodeInfo ...@@ -332,5 +397,41 @@ public class CodeInfo
this.X = x; this.X = x;
this.Y = y; this.Y = y;
} }
public string GetCodeStr()
{
return Gb2312Correct(CodeStr);
}
/// <summary>
/// 判断字符串中是否包含中文
/// </summary>
/// <param name="str">需要判断的字符串</param>
/// <returns>判断结果</returns>
public static bool HasChinese(string str)
{
return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
}
/// <summary>
/// utf8文字用gb2312格式显示时候乱码,需要转换为gb2312
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Gb2312Correct(string text)
{
if (HasChinese(text) == false)
{
return text;
}
//声明字符集
System.Text.Encoding utf8, gb2312;
//utf8
utf8 = System.Text.Encoding.GetEncoding("utf-8");
//gb2312
gb2312 = System.Text.Encoding.GetEncoding("gb2312");
byte[] gb;
gb = utf8.GetBytes(text);
gb = System.Text.Encoding.Convert(utf8, gb2312, gb);
//返回转换后的字符
return gb2312.GetString(gb);
}
} }
} }
...@@ -219,7 +219,7 @@ namespace CodeLibrary ...@@ -219,7 +219,7 @@ namespace CodeLibrary
CodeResultAdd(hv_DecodedDataStrings, codeType, "学习"); CodeResultAdd(hv_DecodedDataStrings, codeType, "学习");
} }
ShowImage(hv_ExpDefaultWinHandle, ho_Image, ho_SymbolXLDs); ShowImage(hv_ExpDefaultWinHandle, ho_Image, ho_SymbolXLDs);
ho_Image.Dispose();
} }
if (findCode.Count >= codeCount || stopWatch.ElapsedMilliseconds > timeOutMs) if (findCode.Count >= codeCount || stopWatch.ElapsedMilliseconds > timeOutMs)
{ {
...@@ -251,6 +251,7 @@ namespace CodeLibrary ...@@ -251,6 +251,7 @@ namespace CodeLibrary
{ {
CodeResultAdd(hv_DecodedDataStrings, codeType, "识别"); CodeResultAdd(hv_DecodedDataStrings, codeType, "识别");
} }
ho_Image.Dispose();
} }
if (findCode.Count >= codeCount || stopWatch.ElapsedMilliseconds > timeOutMs) if (findCode.Count >= codeCount || stopWatch.ElapsedMilliseconds > timeOutMs)
{ {
...@@ -264,7 +265,40 @@ namespace CodeLibrary ...@@ -264,7 +265,40 @@ namespace CodeLibrary
CloseCamera(cameraName); CloseCamera(cameraName);
ho_SymbolXLDs.Dispose(); ho_SymbolXLDs.Dispose();
StopLearn(); StopLearn();
if (hv_code_type != null)
{
hv_code_type.UnPinTuple();
}
if (hv_model_path != null)
{
hv_model_path.UnPinTuple();
}
if (hv_train_first != null)
{
hv_train_first.UnPinTuple();
}
if (hv_ResultHandles != null)
{
hv_ResultHandles.UnPinTuple();
}
if (hv_DataCodeHandle != null)
{
hv_DataCodeHandle.UnPinTuple();
}
if (hv_DecodedDataStrings != null)
{
hv_DecodedDataStrings.UnPinTuple();
}
if (hv_GenParamNames != null)
{
hv_GenParamNames.UnPinTuple();
}
if (hv_ModelBeforeTraining != null)
{
hv_ModelBeforeTraining.UnPinTuple();
}
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -3,6 +3,7 @@ using System.Collections.Generic; ...@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZXing; using ZXing;
using ZXing.Common; using ZXing.Common;
...@@ -202,5 +203,8 @@ namespace CodeLibrary ...@@ -202,5 +203,8 @@ 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
{ {
...@@ -227,9 +228,65 @@ namespace CodeLibrary ...@@ -227,9 +228,65 @@ namespace CodeLibrary
} }
return null; return null;
} }
public override HObject CaptureOnImage(string name) public override HObject CaptureOnImage(string name )
{ {
return null; HObject hoImage = null;
int index = cameraName.FindIndex(s => s == name);
if (index == -1)
{
_errInfo = name + "Not find";
return hoImage;
}
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 hoImage;
}
//相机像素数据
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 hoImage, new HalconDotNet.HTuple("byte"), grabResult.Width, grabResult.Height, pr);
//释放内存
if (hand.IsAllocated) hand.Free();
_errInfo = "OK";
return hoImage;
}
}
catch (Exception ex)
{
_errInfo = ex.Message;
return hoImage;
}
finally
{
// cameraCurr[index].MV_CC_StopGrabbing_NET();
}
return hoImage;
} }
} }
......
...@@ -112,7 +112,7 @@ namespace CodeLibrary ...@@ -112,7 +112,7 @@ namespace CodeLibrary
// public abstract bool GrabContinuous(int index); // public abstract bool GrabContinuous(int index);
// public abstract void GrabStop(int index); // public abstract void GrabStop(int index);
public abstract Bitmap GrabOneImage(string name); public abstract Bitmap GrabOneImage(string name);
public abstract HObject CaptureOnImage(string name); public abstract HObject CaptureOnImage(string name );
} }
} }
...@@ -110,6 +110,7 @@ namespace CodeLibrary ...@@ -110,6 +110,7 @@ namespace CodeLibrary
if (rtn != MyCamera.MV_OK) if (rtn != MyCamera.MV_OK)
{ {
_errInfo = "Load failed"; _errInfo = "Load failed";
HDLogUtil.error(" Load camera error : " + _errInfo);
return false; return false;
} }
...@@ -123,12 +124,14 @@ namespace CodeLibrary ...@@ -123,12 +124,14 @@ namespace CodeLibrary
IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0); IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0);
MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
s = "GigE:" + gigeInfo.chModelName + " (" + gigeInfo.chSerialNumber + ")"; s = "GigE:" + gigeInfo.chModelName + " (" + gigeInfo.chSerialNumber + ")";
//Marshal.FreeHGlobal(buffer);
} }
else if (device.nTLayerType == MyCamera.MV_USB_DEVICE) else if (device.nTLayerType == MyCamera.MV_USB_DEVICE)
{ {
IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0); IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0);
MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO)); MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO));
s = "USB:" + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")"; s = "USB:" + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")";
//Marshal.FreeHGlobal(buffer);
} }
cameraName.Add(s); cameraName.Add(s);
} }
...@@ -155,6 +158,7 @@ namespace CodeLibrary ...@@ -155,6 +158,7 @@ namespace CodeLibrary
if (index < 0 || index >= _count) if (index < 0 || index >= _count)
{ {
_errInfo = "Not find"; _errInfo = "Not find";
HDLogUtil.error("open camera " + index + " error : " + _errInfo);
return false; return false;
} }
if (cameraCurr[index] != null) Close(index); if (cameraCurr[index] != null) Close(index);
...@@ -171,6 +175,7 @@ namespace CodeLibrary ...@@ -171,6 +175,7 @@ namespace CodeLibrary
{ {
cameraCurr[index].MV_CC_DestroyDevice_NET(); cameraCurr[index].MV_CC_DestroyDevice_NET();
_errInfo = "Can not open"; _errInfo = "Can not open";
HDLogUtil.error("open camera " + index + " error : " + _errInfo);
return false; return false;
} }
...@@ -189,6 +194,7 @@ namespace CodeLibrary ...@@ -189,6 +194,7 @@ namespace CodeLibrary
_isOpen[index] = true; _isOpen[index] = true;
_errInfo = "OK"; _errInfo = "OK";
HDLogUtil.info("open camera " + index + _errInfo);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
...@@ -204,7 +210,7 @@ namespace CodeLibrary ...@@ -204,7 +210,7 @@ namespace CodeLibrary
int n = cameraName.FindIndex(s => s == name); int n = cameraName.FindIndex(s => s == name);
if (n == -1) if (n == -1)
{ {
_errInfo = name + "Not find"; _errInfo = name + " Not find";
return false; return false;
} }
else else
...@@ -215,7 +221,8 @@ namespace CodeLibrary ...@@ -215,7 +221,8 @@ namespace CodeLibrary
int n = cameraName.FindIndex(s => s == name); int n = cameraName.FindIndex(s => s == name);
if (n == -1) if (n == -1)
{ {
_errInfo = name + "Not find"; _errInfo = name + " Not find";
HDLogUtil.error("GrabOneImage ["+name+"] error : " + _errInfo);
return null; return null;
} }
if (cameraCurr[n] != null) if (cameraCurr[n] != null)
...@@ -335,66 +342,80 @@ namespace CodeLibrary ...@@ -335,66 +342,80 @@ namespace CodeLibrary
return _image; return _image;
} }
} }
public override HObject CaptureOnImage(string name) public override HObject CaptureOnImage(string name )
{ {
HObject hoImage = null;
int index = cameraName.FindIndex(s => s == name); int index = cameraName.FindIndex(s => s == name);
if (index == -1) if (index == -1)
{ {
_errInfo = name + "Not find"; _errInfo = name + "Not find";
return null; HDLogUtil.error("CaptureOnImage [" + name + "] error : " + _errInfo);
return hoImage;
} }
if (cameraCurr[index] != null) if (cameraCurr[index] != null)
{ {
} }
else else
{ {
HDLogUtil.info("CaptureOnImage [" + name + "] 先打开相机 ");
Open(name); Open(name);
} }
MyCamera.MV_FRAME_OUT FrameInfo = new MyCamera.MV_FRAME_OUT();
try try
{ {
int rtn = cameraCurr[index].MV_CC_StartGrabbing_NET(); int rtn = cameraCurr[index].MV_CC_StartGrabbing_NET();
if (rtn != MyCamera.MV_OK) if (rtn != MyCamera.MV_OK)
{ {
_errInfo = "Can not grab one : " + rtn; _errInfo = "Can not grab one : " + rtn;
return null; HDLogUtil.error("CaptureOnImage [" + name + "] error : " + _errInfo);
return hoImage;
} }
MyCamera.MV_FRAME_OUT FrameInfo = new MyCamera.MV_FRAME_OUT();
int nRet = cameraCurr[index].MV_CC_GetImageBuffer_NET(ref FrameInfo, 1000); int nRet = cameraCurr[index].MV_CC_GetImageBuffer_NET(ref FrameInfo, 1000);
// ch:获取一帧图像 | en:Get one image // ch:获取一帧图像 | en:Get one image
if (MyCamera.MV_OK == nRet) if (MyCamera.MV_OK == nRet)
{ {
Console.WriteLine("Get Image Buffer:" + "Width[" + Convert.ToString(FrameInfo.stFrameInfo.nWidth) + "] , Height[" + Convert.ToString(FrameInfo.stFrameInfo.nHeight) HDLogUtil.debug("Get Image Buffer:" + "Width[" + Convert.ToString(FrameInfo.stFrameInfo.nWidth) + "] , Height[" + Convert.ToString(FrameInfo.stFrameInfo.nHeight)
+ "] , FrameNum[" + Convert.ToString(FrameInfo.stFrameInfo.nFrameNum) + "]"); + "] , FrameNum[" + Convert.ToString(FrameInfo.stFrameInfo.nFrameNum) + "]");
HObject ho_Imagetemp; //HObject ho_Imagetemp;
HOperatorSet.GenImage1(out ho_Imagetemp, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr); HOperatorSet.GenImage1(out hoImage, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr);
if (FrameInfo.pBufAddr != IntPtr.Zero) if (FrameInfo.pBufAddr != IntPtr.Zero)
{ {
nRet = cameraCurr[index].MV_CC_FreeImageBuffer_NET(ref FrameInfo); nRet = cameraCurr[index].MV_CC_FreeImageBuffer_NET(ref FrameInfo);
if (nRet != MyCamera.MV_OK) if (nRet != MyCamera.MV_OK)
{ {
Console.WriteLine("Free Image Buffer fail:{0:x8}", nRet); HDLogUtil.error(" [" + name + "] Free Image Buffer fail:" + nRet);
} }
} }
return ho_Imagetemp; //return ho_Imagetemp;
return hoImage;
} }
else else
{ {
Console.WriteLine("No data:{0:x8}", nRet); HDLogUtil.error(" [" + name + "] MV_CC_GetImageBuffer_NET No data: " + nRet);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_errInfo = ex.Message; _errInfo = ex.Message;
return null; return hoImage;
} }
finally finally
{ {
cameraCurr[index].MV_CC_StopGrabbing_NET(); cameraCurr[index].MV_CC_StopGrabbing_NET();
try
{
cameraCurr[index].MV_CC_FreeImageBuffer_NET(ref FrameInfo);
} }
return null; catch (Exception ex)
{
HDLogUtil.error(" [" + name + "] MV_CC_FreeImageBuffer_NET 出错:" + ex.ToString());
}
}
return hoImage;
} }
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!