Commit dc2183db LN

增加扫码源码

1 个父辈 fa6e6336
......@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CodeLibrary</RootNamespace>
<AssemblyName>CodeLibrary</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
......@@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -30,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Basler.Pylon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e389355f398382ab, processorArchitecture=x86">
......@@ -55,6 +57,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="zxing">
<HintPath>..\dll\zxing.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="camera\Basler.cs" />
......@@ -84,6 +89,7 @@
<Compile Include="ImageHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CodeResourceControl.cs" />
<Compile Include="ZXingCodeHelper.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FrmBase.resx">
......
......@@ -85,6 +85,10 @@ namespace CodeLibrary
NoIdLog(id, defaultStr);
}
}
if (strCurLanguage == null)
{
strCurLanguage = "";
}
return strCurLanguage;
}
public static string GetString(string id, string defaultStr, params object[] param)
......
......@@ -66,9 +66,9 @@
//
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.Location = new System.Drawing.Point(949, 51);
this.btnStop.Location = new System.Drawing.Point(949, 49);
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.Text = "结束学习";
this.btnStop.UseVisualStyleBackColor = true;
......@@ -78,9 +78,9 @@
//
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.Location = new System.Drawing.Point(949, 13);
this.btnOpen.Location = new System.Drawing.Point(949, 12);
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.Text = "开始学习";
this.btnOpen.UseVisualStyleBackColor = true;
......@@ -104,9 +104,9 @@
//
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.Location = new System.Drawing.Point(1096, 51);
this.btnExit.Location = new System.Drawing.Point(1096, 49);
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.Text = "退出";
this.btnExit.UseVisualStyleBackColor = true;
......@@ -115,7 +115,7 @@
// label1
//
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.Size = new System.Drawing.Size(110, 20);
this.label1.TabIndex = 7;
......@@ -138,16 +138,16 @@
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.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.Size = new System.Drawing.Size(186, 25);
this.cmbCodeType.Size = new System.Drawing.Size(163, 25);
this.cmbCodeType.TabIndex = 10;
this.cmbCodeType.SelectedIndexChanged += new System.EventHandler(this.cmbCodeType_SelectedIndexChanged);
//
// label2
//
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.Size = new System.Drawing.Size(110, 20);
this.label2.TabIndex = 9;
......@@ -177,7 +177,7 @@
// lblCount
//
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.Size = new System.Drawing.Size(112, 20);
this.lblCount.TabIndex = 13;
......@@ -210,7 +210,7 @@
"18",
"19",
"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.Size = new System.Drawing.Size(64, 25);
this.cmbCount.TabIndex = 14;
......@@ -228,9 +228,9 @@
//
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.Location = new System.Drawing.Point(1096, 13);
this.btnClearLog.Location = new System.Drawing.Point(1096, 12);
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.Text = "清理日志";
this.btnClearLog.UseVisualStyleBackColor = true;
......@@ -242,7 +242,7 @@
this.chbTest.Checked = true;
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.Location = new System.Drawing.Point(531, 56);
this.chbTest.Location = new System.Drawing.Point(532, 55);
this.chbTest.Name = "chbTest";
this.chbTest.Size = new System.Drawing.Size(147, 21);
this.chbTest.TabIndex = 17;
......@@ -253,7 +253,7 @@
// btnSelImage
//
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.Size = new System.Drawing.Size(160, 32);
this.btnSelImage.TabIndex = 19;
......@@ -286,7 +286,7 @@
//
this.chbUseCamera.AutoSize = true;
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.Size = new System.Drawing.Size(123, 21);
this.chbUseCamera.TabIndex = 21;
......@@ -297,7 +297,7 @@
// btnDelOld
//
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.Size = new System.Drawing.Size(160, 32);
this.btnDelOld.TabIndex = 22;
......@@ -320,12 +320,13 @@
//
this.chbHalcon.AutoSize = true;
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.Size = new System.Drawing.Size(115, 21);
this.chbHalcon.TabIndex = 24;
this.chbHalcon.Text = "Halcon获取图片";
this.chbHalcon.UseVisualStyleBackColor = true;
this.chbHalcon.Visible = false;
this.chbHalcon.CheckedChanged += new System.EventHandler(this.chbHalcon_CheckedChanged);
//
// cmbCamera
......@@ -333,9 +334,9 @@
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.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.Size = new System.Drawing.Size(186, 25);
this.cmbCamera.Size = new System.Drawing.Size(351, 25);
this.cmbCamera.TabIndex = 25;
//
// FrmCodeLearn
......
......@@ -27,9 +27,10 @@ namespace CodeLibrary
private string title = CodeResourceControl.GetString(CodeResourceControl.title, "提示");
private string imageIsNull = CodeResourceControl.GetString(CodeResourceControl.imageIsNull, "获取二维码图片为空");
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;
string camerName = cmbCamera.Text;
if (index < 0)
......@@ -37,22 +38,8 @@ namespace CodeLibrary
MessageBox.Show(selCamera);
return null;
}
//if (baslerNameList.Contains(camerName))
//{
// 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;
ho_image= Camera._cam.CaptureOnImage(camerName );
return ho_image;
}
private void btnOpen_Click(object sender, EventArgs e)
{
......@@ -73,14 +60,16 @@ namespace CodeLibrary
}
else
{
Bitmap bitmap = GetCameraBitmap();
if (bitmap != null)
// Bitmap bitmap = GetCameraBitmap();
HObject ho_Image = GetCameraImg();
if (ho_Image != null)
{
HDLogUtil.info("从相机【" + cmbCamera.Text + "】获取到一张图片");
ClearPicImg();
pictureBox1.Image = (Image)bitmap.Clone();
HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HDCodeLearnHelper.DefaultImage = hoImage;
//pictureBox1.Image = (Image)bitmap.Clone();
//HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HDCodeLearnHelper.DefaultImage = ho_Image;
ShowImage(ho_Image);
}
else
{
......@@ -97,8 +86,10 @@ namespace CodeLibrary
return;
}
Bitmap bitmap = new Bitmap( pictureBox1.Image);
HObject Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HObject Image;
HDCodeHelper.Bitmap2HObjectBpp24(bitmap,out Image);
HDCodeLearnHelper.DefaultImage = Image;
ShowImage(Image);
}
Task.Factory.StartNew(delegate ()
{
......@@ -108,20 +99,11 @@ namespace CodeLibrary
}
private void LoadCamera()
{
//string[] camerName = BaslerCamera.Instance.CameraName;
//baslerNameList.AddRange(camerName);
cmbCamera.Items.Clear();
foreach (string str in Camera._cam.Name)
{
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)
{
cmbCamera.SelectedIndex = 0;
......@@ -306,5 +288,15 @@ namespace CodeLibrary
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);
}
}
}
......@@ -219,7 +219,7 @@ namespace CodeLibrary
CodeResultAdd(hv_DecodedDataStrings, codeType, "学习");
}
ShowImage(hv_ExpDefaultWinHandle, ho_Image, ho_SymbolXLDs);
ho_Image.Dispose();
}
if (findCode.Count >= codeCount || stopWatch.ElapsedMilliseconds > timeOutMs)
{
......@@ -251,6 +251,7 @@ namespace CodeLibrary
{
CodeResultAdd(hv_DecodedDataStrings, codeType, "识别");
}
ho_Image.Dispose();
}
if (findCode.Count >= codeCount || stopWatch.ElapsedMilliseconds > timeOutMs)
{
......@@ -264,7 +265,40 @@ namespace CodeLibrary
CloseCamera(cameraName);
ho_SymbolXLDs.Dispose();
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;
}
catch (Exception ex)
......
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using ZXing;
using ZXing.Common;
......@@ -202,5 +203,8 @@ namespace CodeLibrary
}
}
}
}
......@@ -4,6 +4,7 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
using HalconDotNet;
using System.Runtime.InteropServices;
namespace CodeLibrary
{
......@@ -227,9 +228,65 @@ namespace CodeLibrary
}
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
// public abstract bool GrabContinuous(int index);
// public abstract void GrabStop(int index);
public abstract Bitmap GrabOneImage(string name);
public abstract HObject CaptureOnImage(string name);
public abstract HObject CaptureOnImage(string name );
}
}
......@@ -110,6 +110,7 @@ namespace CodeLibrary
if (rtn != MyCamera.MV_OK)
{
_errInfo = "Load failed";
HDLogUtil.error(" Load camera error : " + _errInfo);
return false;
}
......@@ -123,12 +124,14 @@ namespace CodeLibrary
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));
s = "GigE:" + gigeInfo.chModelName + " (" + gigeInfo.chSerialNumber + ")";
//Marshal.FreeHGlobal(buffer);
}
else if (device.nTLayerType == MyCamera.MV_USB_DEVICE)
{
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));
s = "USB:" + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")";
//Marshal.FreeHGlobal(buffer);
}
cameraName.Add(s);
}
......@@ -155,6 +158,7 @@ namespace CodeLibrary
if (index < 0 || index >= _count)
{
_errInfo = "Not find";
HDLogUtil.error("open camera " + index + " error : " + _errInfo);
return false;
}
if (cameraCurr[index] != null) Close(index);
......@@ -171,6 +175,7 @@ namespace CodeLibrary
{
cameraCurr[index].MV_CC_DestroyDevice_NET();
_errInfo = "Can not open";
HDLogUtil.error("open camera " + index + " error : " + _errInfo);
return false;
}
......@@ -189,6 +194,7 @@ namespace CodeLibrary
_isOpen[index] = true;
_errInfo = "OK";
HDLogUtil.info("open camera " + index + _errInfo);
return true;
}
catch (Exception ex)
......@@ -204,7 +210,7 @@ namespace CodeLibrary
int n = cameraName.FindIndex(s => s == name);
if (n == -1)
{
_errInfo = name + "Not find";
_errInfo = name + " Not find";
return false;
}
else
......@@ -215,7 +221,8 @@ namespace CodeLibrary
int n = cameraName.FindIndex(s => s == name);
if (n == -1)
{
_errInfo = name + "Not find";
_errInfo = name + " Not find";
HDLogUtil.error("GrabOneImage ["+name+"] error : " + _errInfo);
return null;
}
if (cameraCurr[n] != null)
......@@ -335,66 +342,90 @@ namespace CodeLibrary
return _image;
}
}
public override HObject CaptureOnImage(string name)
public override HObject CaptureOnImage(string name )
{
HObject hoImage = null;
int index = cameraName.FindIndex(s => s == name);
if (index == -1)
{
_errInfo = name + "Not find";
return null;
HDLogUtil.error("CaptureOnImage [" + name + "] error : " + _errInfo);
return hoImage;
}
if (cameraCurr[index] != null)
{
}
else
{
HDLogUtil.info("CaptureOnImage [" + name + "] 先打开相机 ");
Open(name);
}
MyCamera.MV_FRAME_OUT FrameInfo = new MyCamera.MV_FRAME_OUT();
try
{
int rtn = cameraCurr[index].MV_CC_StartGrabbing_NET();
if (rtn != MyCamera.MV_OK)
{
_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);
// ch:获取一帧图像 | en:Get one image
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) + "]");
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);
//HOperatorSet.GenImage1Extern(out hoImage, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr, Marshal.GetFunctionPointerForDelegate(callback));
if (FrameInfo.pBufAddr != IntPtr.Zero)
{
nRet = cameraCurr[index].MV_CC_FreeImageBuffer_NET(ref FrameInfo);
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
{
Console.WriteLine("No data:{0:x8}", nRet);
HDLogUtil.error(" [" + name + "] MV_CC_GetImageBuffer_NET No data: " + nRet);
}
}
catch (Exception ex)
{
_errInfo = ex.Message;
return null;
return hoImage;
}
finally
{
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;
}
HalconDotNet.HalconAPI.HClearProcCallBack callback = __OnFreeCallBack;
private static void __OnFreeCallBack(IntPtr pImg)
{
Marshal.FreeHGlobal(pImg);
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!