Commit 5c989fcf LN

1

2 个父辈 7ab790ee 21c3fca6
...@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "CodeLibraryProjec ...@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "CodeLibraryProjec
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeLibrary", "CodeLibraryProject\CodeLibrary\CodeLibrary.csproj", "{2E0D9598-CB37-46DC-9C9B-D36D4D344451}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeLibrary", "CodeLibraryProject\CodeLibrary\CodeLibrary.csproj", "{2E0D9598-CB37-46DC-9C9B-D36D4D344451}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeToolClinet", "CodeToolClinet\CodeToolClinet.csproj", "{87075EC9-91E4-4EF1-9B35-E220DA7C937C}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -27,6 +29,10 @@ Global ...@@ -27,6 +29,10 @@ Global
{2E0D9598-CB37-46DC-9C9B-D36D4D344451}.Debug|Any CPU.Build.0 = Debug|Any CPU {2E0D9598-CB37-46DC-9C9B-D36D4D344451}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E0D9598-CB37-46DC-9C9B-D36D4D344451}.Release|Any CPU.ActiveCfg = Release|Any CPU {2E0D9598-CB37-46DC-9C9B-D36D4D344451}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E0D9598-CB37-46DC-9C9B-D36D4D344451}.Release|Any CPU.Build.0 = Release|Any CPU {2E0D9598-CB37-46DC-9C9B-D36D4D344451}.Release|Any CPU.Build.0 = Release|Any CPU
{87075EC9-91E4-4EF1-9B35-E220DA7C937C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87075EC9-91E4-4EF1-9B35-E220DA7C937C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87075EC9-91E4-4EF1-9B35-E220DA7C937C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87075EC9-91E4-4EF1-9B35-E220DA7C937C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
...@@ -58,7 +58,12 @@ namespace CodeLibrary ...@@ -58,7 +58,12 @@ namespace CodeLibrary
/// </summary> /// </summary>
public string[] CameraName public string[] CameraName
{ {
get { return cameraName.ToArray(); } get {
if (cameraName == null)
{
cameraName = new List<string>();
}
return cameraName.ToArray(); }
} }
/// <summary> /// <summary>
...@@ -100,10 +105,17 @@ namespace CodeLibrary ...@@ -100,10 +105,17 @@ namespace CodeLibrary
/// </summary> /// </summary>
public void Load() public void Load()
{ {
cameraAll = CameraFinder.Enumerate(); try
cameraName = new List<string>(); {
foreach (ICameraInfo info in cameraAll) cameraAll = CameraFinder.Enumerate();
cameraName.Add(info[CameraInfoKey.ModelName].ToString() + " (" + info[CameraInfoKey.SerialNumber].ToString() + ")"); cameraName = new List<string>();
foreach (ICameraInfo info in cameraAll)
cameraName.Add(info[CameraInfoKey.ModelName].ToString() + " (" + info[CameraInfoKey.SerialNumber].ToString() + ")");
}
catch (Exception ex)
{
HDLogUtil.error("Basler Load Error:" + ex.StackTrace);
}
} }
/// <summary> /// <summary>
......
...@@ -82,7 +82,8 @@ namespace CodeLibrary ...@@ -82,7 +82,8 @@ namespace CodeLibrary
{ {
System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog(); System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
openDialog.Title = selImage; openDialog.Title = selImage;
openDialog.Filter = "(*.jpg)|*.jpg|(*.png)|*.png|(*.bmp)|*.bmp"; openDialog.Filter = "(*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp";
// openDialog.Filter = "All Supported Images (*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png)|*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*";
//openDialog.DefaultExt = "png"; //openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = openDialog.ShowDialog(); System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel) if (result == System.Windows.Forms.DialogResult.Cancel)
...@@ -153,9 +154,16 @@ namespace CodeLibrary ...@@ -153,9 +154,16 @@ namespace CodeLibrary
stopwatch.Restart(); stopwatch.Restart();
HDCodeHelper.HalconWindow = this.hWindowControl1.HalconWindow; HDCodeHelper.HalconWindow = this.hWindowControl1.HalconWindow;
Bitmap map = new Bitmap(pictureBox1.Image); Bitmap map = new Bitmap(pictureBox1.Image);
List<CodeInfo> result = HDCodeHelper.DecodeBarCode(map); if (chbZxing.Checked)
ShowCode(result); {
txtResult.Text += "\r\n elapsed time:" + stopwatch.Elapsed.ToString(); zxingDecode(map, "barcode");
}
else
{
List<CodeInfo> result = HDCodeHelper.DecodeBarCode(map);
ShowCode(result);
txtResult.Text += "\r\n elapsed time:" + stopwatch.Elapsed.ToString();
}
} }
public void ShowImage(HObject ho_Image) public void ShowImage(HObject ho_Image)
{ {
...@@ -198,20 +206,45 @@ namespace CodeLibrary ...@@ -198,20 +206,45 @@ namespace CodeLibrary
{ {
codeParamPath = ""; codeParamPath = "";
} }
List<CodeInfo> codeList = new List<CodeInfo>(); if (chbZxing.Checked)
if (cmbCodeType.Text.ToLower().Equals("barcode")) {
{ zxingDecode(map, cmbCodeType.Text);
codeList = HDCodeHelper.DecodeBarCode(ho_image);
} }
else else
{ {
codeList = HDCodeHelper.DecodeCode(ho_image, count, codeParamPath, cmbCodeType.Text); List<CodeInfo> codeList = new List<CodeInfo>();
} if (cmbCodeType.Text.ToLower().Equals("barcode"))
ShowCode(codeList); {
codeList = HDCodeHelper.DecodeBarCode(ho_image);
}
else
{
codeList = HDCodeHelper.DecodeCode(ho_image, count, codeParamPath, cmbCodeType.Text);
}
txtResult.Text += "\r\n elapsed time:" + stopwatch.Elapsed.ToString(); //if (codeList.Count <= 0)
//{
// zxingDecode(map, cmbCodeType.Text);
//}
//else
{
ShowCode(codeList);
txtResult.Text += "\r\n elapsed time:" + stopwatch.Elapsed.ToString();
}
}
} }
private void zxingDecode(Bitmap map,string type )
{
List<string> results = ZXingCodeHelper.DeCodes(map, type);
txtResult.Text = " zxing decode:";
foreach (string code in results)
{
txtResult.Text += "\r\n" + "\r\n" + code;
}
txtResult.Text += "\r\n \r\n elapsed time:" + stopwatch.Elapsed.ToString();
}
private void btnClearLog_Click(object sender, EventArgs e) private void btnClearLog_Click(object sender, EventArgs e)
{ {
HDLogUtil.ClearLog(); HDLogUtil.ClearLog();
...@@ -462,5 +495,11 @@ namespace CodeLibrary ...@@ -462,5 +495,11 @@ namespace CodeLibrary
} }
} }
} }
private void btnCopyN_Click(object sender, EventArgs e)
{
string text = cmbCamera.Text;
Clipboard.SetDataObject(text);
}
} }
} }
...@@ -228,7 +228,7 @@ namespace CodeLibrary ...@@ -228,7 +228,7 @@ namespace CodeLibrary
{ {
System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog(); System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
openDialog.Title = selImage; openDialog.Title = selImage;
openDialog.Filter = "(*.jpg)|*.jpg|(*.png)|*.png|(*.bmp)|*.bmp"; openDialog.Filter = "(*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp";
//openDialog.DefaultExt = "png"; //openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = openDialog.ShowDialog(); System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel) if (result == System.Windows.Forms.DialogResult.Cancel)
......
...@@ -103,6 +103,8 @@ namespace CodeLibrary ...@@ -103,6 +103,8 @@ namespace CodeLibrary
} }
// HOperatorSet.SetDataCode2dParam(hv_DataCodeHandle, "timeout", 3000); // HOperatorSet.SetDataCode2dParam(hv_DataCodeHandle, "timeout", 3000);
ho_SymbolXLDs.Dispose(); ho_SymbolXLDs.Dispose();
// set_data_code_2d_param(DataCodeHandle, 'timeout', 200)
HOperatorSet.SetDataCode2dParam(hv_DataCodeHandle, "timeout", 1000);
if (codeCount <= 0) if (codeCount <= 0)
{ {
HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle, HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle,
......
...@@ -61,7 +61,7 @@ namespace CodeLibrary ...@@ -61,7 +61,7 @@ namespace CodeLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
HDLogUtil.error("解析摄像机配置出错:" + ex.ToString()); HDLogUtil.error("解析摄像机配置出错:" + ex.StackTrace);
} }
} }
private static HTuple hv_AcqHandle = null; private static HTuple hv_AcqHandle = null;
......
...@@ -54,7 +54,13 @@ namespace CodeLibrary ...@@ -54,7 +54,13 @@ namespace CodeLibrary
/// </summary> /// </summary>
public string[] CameraName public string[] CameraName
{ {
get { return cameraName.ToArray(); } get
{
if (cameraName == null)
{
cameraName = new List<string>();
}
return cameraName.ToArray(); }
} }
/// <summary> /// <summary>
...@@ -96,27 +102,34 @@ namespace CodeLibrary ...@@ -96,27 +102,34 @@ namespace CodeLibrary
/// </summary> /// </summary>
public void Load() public void Load()
{ {
int rtn = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref cameraAll); try
if (rtn != MyCamera.MV_OK) return;
cameraName.Clear();
string s = "";
for (int i = 0; i < cameraAll.nDeviceNum; i++)
{ {
MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(cameraAll.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); int rtn = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref cameraAll);
if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) if (rtn != MyCamera.MV_OK) return;
{ cameraName.Clear();
IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0); string s = "";
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 + ")"; for (int i = 0; i < cameraAll.nDeviceNum; i++)
}
else if (device.nTLayerType == MyCamera.MV_USB_DEVICE)
{ {
IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0); MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(cameraAll.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO)); if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE)
s = "USB:" + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")"; {
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 + ")";
}
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 + ")";
}
cameraName.Add(s);
} }
cameraName.Add(s); }
catch (Exception ex)
{
HDLogUtil.error("HIK Load Error:" + ex.StackTrace);
} }
} }
......
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing;
using ZXing.Common;
using ZXing.Multi.QrCode;
namespace CodeLibrary
{
public class ZXingCodeHelper
{
public static List<string> DeCodes(Bitmap map, string codeType)
{
if (codeType.ToUpper().Equals("QR CODE"))
{
return DecodeQRCodes(map);
}
else if (codeType.ToUpper().Equals("DATA MATRIX ECC 200"))
{
return DecodeCodes(map);
}
else if (codeType.ToUpper().Equals("BARCODE"))
{
return DecodeCodes(map);
}
else
{
return DecodeCodes(map);
}
}
public static List<string> DecodeCodes(Bitmap bmp)
{
MultiFormatReader mreader = new MultiFormatReader();
ZXing.Multi.GenericMultipleBarcodeReader genericMultiple = new ZXing.Multi.GenericMultipleBarcodeReader(mreader);
LuminanceSource source = new BitmapLuminanceSource(bmp);
BinaryBitmap binarybitmap = new BinaryBitmap(new HybridBinarizer(source));
Result[] rr = genericMultiple.decodeMultiple(binarybitmap);
List<string> result = new List<string>();
if (rr != null)
{
foreach (Result res in rr)
{
if (res != null)
{
string text = res.ToString();
if (!IsGBCode(text))
{
text = ConvertISO88591ToEncoding(text, Encoding.Default);
}
result.Add(text);
}
}
}
return result;
}
public static List<string> DecodeBarCodes(Bitmap bmp)
{
List<string> result = new List<string>();
BarcodeReader br = new BarcodeReader();
DecodingOptions decodeOption = new DecodingOptions();
decodeOption.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.CODE_39, BarcodeFormat.CODE_128 };
br.Options = decodeOption;
Result res = br.Decode(bmp);
if (res != null)
{
result.Add(res.ToString());
}
return result;
}
public static List<string> DecodeDMCodes(Bitmap bmp)
{
ZXing.Datamatrix.DataMatrixReader qc = new ZXing.Datamatrix.DataMatrixReader();
List<string> result = new List<string>();
LuminanceSource source = new BitmapLuminanceSource(bmp);
BinaryBitmap binarybitmap = new BinaryBitmap(new HybridBinarizer(source));
IDictionary<DecodeHintType, object> hints = new Dictionary<DecodeHintType, object>();
hints.Add(DecodeHintType.CHARACTER_SET, "UTF-8");
hints.Add(DecodeHintType.TRY_HARDER, "3");
Result res = qc.decode(binarybitmap, hints);
if (res != null)
{
result.Add(res.ToString());
}
return result;
}
public static List<string> DecodeQRCodes(Bitmap bmp)
{
QRCodeMultiReader qc = new QRCodeMultiReader();
List<string> result = new List<string>();
LuminanceSource source = new BitmapLuminanceSource(bmp);
BinaryBitmap binarybitmap = new BinaryBitmap(new HybridBinarizer(source));
IDictionary<DecodeHintType, object> hints = new Dictionary<DecodeHintType, object>();
hints.Add(DecodeHintType.CHARACTER_SET, "GB2312");
hints.Add(DecodeHintType.TRY_HARDER, "3");
Result[] r = qc.decodeMultiple(binarybitmap, hints);
if (r != null)
{
foreach (Result res in r)
{
if (res != null)
{
string text = res.ToString();
//if (!IsGBCode(text))
//{
// string chStr = "生产日期(或厂家批次):";
// int index = text.IndexOf(chStr);
// if (index > 0)
// {
// string sub1 = text.Substring(0, index);
// int sub3startIndex =index+ chStr.Length;
// string sub3 = text.Substring(sub3startIndex,text.Length- sub3startIndex);
// string sub1r = ConvertISO88591ToEncoding(sub1, Encoding.Default);
// string sub3r = ConvertISO88591ToEncoding(sub3, Encoding.Default);
// text = sub1r + chStr + sub3r;
// }
// else
// {
// text = ConvertISO88591ToEncoding(text, Encoding.Default);
// }
//}
result.Add(text);
}
}
}
return result;
}
//public static string DecodeQRCode(Bitmap bmp)
//{
// string text = "";
// DecodingOptions option = new DecodingOptions();
// //option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE, BarcodeFormat.All_1D };
// option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE };
// BarcodeReader br = new BarcodeReader();
// br.Options = option;
// Result rs = br.Decode(bmp);
// if (rs == null)
// {
// text = "";
// }
// else
// {
// text = rs.ToString();
// if (!IsGBCode(text))
// {
// text = ConvertISO88591ToEncoding(text, Encoding.Default);
// }
// }
// return text;
//}
//转换
private static string ConvertISO88591ToEncoding(string srcString, Encoding dstEncode)
{
String sResult;
Encoding ISO88591Encoding = Encoding.GetEncoding("ISO-8859-1");
Encoding GB2312Encoding = Encoding.GetEncoding("GB2312"); //这个地方很特殊,必须利用GB2312编码
byte[] srcBytes = ISO88591Encoding.GetBytes(srcString);
//将原本存储ISO-8859-1的字节数组当成GB2312转换成目标编码(关键步骤)
byte[] dstBytes = Encoding.Convert(GB2312Encoding, dstEncode, srcBytes);
char[] dstChars = new char[dstEncode.GetCharCount(dstBytes, 0, dstBytes.Length)];
dstEncode.GetChars(dstBytes, 0, dstBytes.Length, dstChars, 0);//利用char数组存储字符
sResult = new string(dstChars);
return sResult;
}
/// <summary>
/// 判断一个word是否为GB2312编码的汉字
/// </summary>
/// <param name="word"></param>
/// <returns></returns>
private static bool IsGBCode(string word)
{
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(word);
if (bytes.Length <= 1) // if there is only one byte, it is ASCII code or other code
{
return false;
}
else
{
byte byte1 = bytes[0];
byte byte2 = bytes[1];
if (byte1 >= 176 && byte1 <= 247 && byte2 >= 160 && byte2 <= 254) //判断是否是GB2312
{
return true;
}
else
{
return false;
}
}
}
}
}
using Basler.Pylon;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeLibrary
{
public class BaslerCManager
{
/// <summary>
/// 当前相机
/// </summary>
// private Camera cameraCur = null;
private static Dictionary<string, BaslerCameraBean> cameraMap = new Dictionary<string, BaslerCameraBean>();
/// <summary>
/// 所有相机列表
/// </summary>
private static List<ICameraInfo> cameraAll;
/// <summary>
/// 所有相机的名称
/// </summary>
private static List<string> cameraName;
/// <summary>
/// 获取连续图像
/// </summary>
public delegate void GrabImageEvent();
///// <summary>
///// 获取连续图像事件,需要跨线程操作
///// </summary>
//public event GrabImageEvent GrabImage;
private BaslerCManager()
{
Load();
}
/// <summary>
/// 错误信息
/// </summary>
public static string ErrInfo { set; get; }
/// <summary>
/// 相机总数
/// </summary>
public int Count
{
get { return cameraAll == null ? 0 : cameraAll.Count; }
}
/// <summary>
/// 相机名称,ModelName,SerialNumber
/// </summary>
public static string[] CameraName
{
get
{
if (cameraName == null)
{
cameraName = new List<string>();
}
return cameraName.ToArray();
}
}
public static BaslerCameraBean GetCamera(string cName)
{
if (cameraMap.ContainsKey(cName))
{
return cameraMap[cName];
}
return null;
}
public static void AddCamera(string name, BaslerCameraBean bean)
{
if (cameraMap.ContainsKey(name))
{
cameraMap.Remove(name);
}
cameraMap.Add(name, bean);
}
/// <summary>
/// 当前相机是否打开
/// </summary>
public static bool IsOpen(string name)
{
BaslerCameraBean bean = GetCamera(name);
if (bean == null)
{ return false; }
else
{
return bean.cameraCur.IsOpen;
}
}
/// <summary>
/// 加载相机
/// </summary>
public static void Load()
{
try
{
cameraAll = CameraFinder.Enumerate();
cameraName = new List<string>();
foreach (ICameraInfo info in cameraAll)
cameraName.Add(info[CameraInfoKey.ModelName].ToString() + " (" + info[CameraInfoKey.SerialNumber].ToString() + ")");
}
catch (Exception ex)
{
HDLogUtil.error("Basler Load Error:" + ex.StackTrace);
}
}
/// <summary>
/// 打开指定相机
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool Open(string name, GrabImageEvent grab=null)
{
int n = cameraName.FindIndex(s => s == name);
if (n == -1)
return false;
else
{
if (cameraMap.ContainsKey(name))
{
if (cameraMap[name].cameraCur != null)
{
cameraMap[name].cameraCur.Close();
}
cameraMap.Remove(name);
}
Camera cameraCur = null;
if (n < 0 || n >= cameraAll.Count) { return false ; }
try
{
cameraCur = new Camera(cameraAll[n]);
BaslerCameraBean bean = new BaslerCameraBean(cameraCur);
bean.Open( );
AddCamera(name, bean);
}
catch (Exception ex)
{
ErrInfo = ex.Message;
return false ;
}
return true;
}
}
/// <summary>
/// 关闭当前相机
/// </summary>
public static void Close(string name)
{
BaslerCameraBean bean = GetCamera(name);
if (bean != null && bean.cameraCur != null)
{
bean.Close();
}
}
public static void CloseAll()
{
foreach(string key in cameraMap.Keys)
{
Close(key);
}
}
/// <summary>
/// 停止抓取数据
/// </summary>
public static void Stop(string name)
{
BaslerCameraBean bean = GetCamera(name);
if (bean != null)
{
bean.Stop();
}
}
/// <summary>
/// 抓取一张图像
/// </summary>
public static Bitmap GrabOne(string name)
{
BaslerCameraBean bean = GetCamera(name);
if (bean != null && bean.cameraCur != null)
{
return bean.GrabOne();
}
return null;
}
}
}
using Basler.Pylon;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static CodeLibrary.BaslerCamera;
namespace CodeLibrary
{
public class BaslerCameraBean
{
public Camera cameraCur = null;
/// <summary>
/// 相机图像宽度
/// </summary>
public int Width { set; get; }
/// <summary>
/// 相机图像高度
/// </summary>
public int Height { set; get; }
/// <summary>
/// 相机32位缓存
/// </summary>
public byte[] Buffer { get; private set; }
/// <summary>
/// 相机32位图像
/// </summary>
public Bitmap Image { get; private set; }
/// <summary>
/// 获取连续图像事件,需要跨线程操作
/// </summary>
public event GrabImageEvent GrabImage;
/// <summary>
/// 错误信息
/// </summary>
public string ErrInfo { set; get; }
public BaslerCameraBean (Camera c)
{
this.cameraCur = c;
}
public BaslerCameraBean (Camera c ,int width,int height)
{
this.cameraCur = c;
this.Width = width;
this.Height = height;
}
public void Open()
{
cameraCur.StreamGrabber.ImageGrabbed += OnImageGrabbed;
//cameraCur.StreamGrabber.GrabStopped += OnGrabStopped;
cameraCur.Open();
int Width = Convert.ToInt32(cameraCur.Parameters[PLCamera.Width].GetValue());
int Height = Convert.ToInt32(cameraCur.Parameters[PLCamera.Height].GetValue());
cameraCur.Parameters[PLCamera.UserSetSelector].SetValue(PLCamera.UserSetSelector.UserSet1); //加载用户设置1
bool bln = cameraCur.Parameters[PLCamera.UserSetLoad].TryExecute(); //执行设置
}
/// <summary>
/// 关闭当前相机
/// </summary>
public void Close()
{
if (cameraCur != null)
{
cameraCur.Close();
cameraCur.Dispose();
cameraCur = null;
}
}
/// <summary>
/// 停止抓取数据
/// </summary>
public void Stop()
{
if (cameraCur != null)
cameraCur.StreamGrabber.Stop();
}
/// <summary>
/// 抓取一张图像
/// </summary>
public Bitmap GrabOne()
{
cameraCur.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.SingleFrame);
//cameraCur.StreamGrabber.Start();
//IGrabResult grabResult = cameraCur.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
IGrabResult grabResult = cameraCur.StreamGrabber.GrabOne(5000);
if (!grabResult.IsValid) return null ;
Image = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppRgb);
BitmapData bmpData = Image.LockBits(new Rectangle(0, 0, grabResult.Width, grabResult.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
IntPtr ptrBmp = bmpData.Scan0;
int picSize = bmpData.Stride * grabResult.Height;
PixelDataConverter conv = new PixelDataConverter();
conv.OutputPixelFormat = PixelType.BGRA8packed;
conv.Convert(ptrBmp, picSize, grabResult);
Buffer = new byte[picSize];
System.Runtime.InteropServices.Marshal.Copy(ptrBmp, Buffer, 0, picSize);
Image.UnlockBits(bmpData);
return Image;
//cameraCur.StreamGrabber.Stop();
}
/// <summary>
/// 抓取连续图像,触发GrabImage事件
/// </summary>
public void GrabContinuous()
{
cameraCur.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous);
cameraCur.StreamGrabber.Start(GrabStrategy.OneByOne, GrabLoop.ProvidedByStreamGrabber);
}
private void OnImageGrabbed(object sender, ImageGrabbedEventArgs e)
{
try
{
IGrabResult grabResult = e.GrabResult;
if (!grabResult.IsValid) return;
Image = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppRgb);
BitmapData bmpData = Image.LockBits(new Rectangle(0, 0, grabResult.Width, grabResult.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
IntPtr ptrBmp = bmpData.Scan0;
int picSize = bmpData.Stride * grabResult.Height;
PixelDataConverter conv = new PixelDataConverter();
conv.OutputPixelFormat = PixelType.BGRA8packed;
conv.Convert(ptrBmp, picSize, grabResult);
Buffer = new byte[picSize];
System.Runtime.InteropServices.Marshal.Copy(ptrBmp, Buffer, 0, picSize);
Image.UnlockBits(bmpData);
GrabImage?.Invoke();
}
catch (Exception ex)
{
ErrInfo = ex.Message;
}
finally
{
e.DisposeGrabResultIfClone();
}
}
}
}
using MvCamCtrl.NET;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace CodeLibrary
{
public class HIKCManager
{ /// <summary>
/// 当前相机
/// </summary>
// private Camera cameraCur = null;
private static Dictionary<string, HIKCameraBean> cameraMap = new Dictionary<string, HIKCameraBean>();
/// <summary>
/// 当前相机
/// </summary>
// private MyCamera cameraCurr;
/// <summary>
/// 所有相机列表
/// </summary>
private static MyCamera.MV_CC_DEVICE_INFO_LIST cameraAll;
/// <summary>
/// 所有相机的名称
/// </summary>
private static List<string> cameraName = new List<string>();
/// <summary>
/// 海康相机
/// </summary>
public HIKCManager()
{
cameraAll = new MyCamera.MV_CC_DEVICE_INFO_LIST();
Load();
}
public static HIKCameraBean GetCamera(string cName)
{
if (cameraMap.ContainsKey(cName))
{
return cameraMap[cName];
}
return null;
}
public static void AddCamera(string name, HIKCameraBean bean)
{
if (cameraMap.ContainsKey(name))
{
cameraMap.Remove(name);
}
cameraMap.Add(name, bean);
}
/// <summary>
/// 错误信息
/// </summary>
public static string ErrInfo { set; get; }
/// <summary>
/// 相机总数
/// </summary>
public static int Count
{
get { return (int)cameraAll.nDeviceNum; }
}
/// <summary>
/// 相机名称,ModelName,SerialNumber
/// </summary>
public static string[] CameraName
{
get
{
if (cameraName == null)
{
cameraName = new List<string>();
}
return cameraName.ToArray();
}
}
/// <summary>
/// 当前相机是否打开
/// </summary>
public static bool IsOpen(string cName)
{
HIKCameraBean bean = GetCamera(cName);
if (bean == null || bean.cameraCur == null)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// 加载相机
/// </summary>
public static void Load()
{
try
{
int rtn = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref cameraAll);
if (rtn != MyCamera.MV_OK) return;
cameraName.Clear();
string s = "";
for (int i = 0; i < cameraAll.nDeviceNum; i++)
{
MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(cameraAll.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE)
{
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 + ")";
}
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 + ")";
}
cameraName.Add(s);
}
}
catch (Exception ex)
{
HDLogUtil.error("HIK Load Error:" + ex.StackTrace);
}
}
/// <summary>
/// 打开指定相机
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool Open(string name)
{
int n = cameraName.FindIndex(s => s == name);
if (n == -1)
return false;
else
{
if (cameraMap.ContainsKey(name))
{
if (cameraMap[name].cameraCur != null)
{
cameraMap[name].Close();
}
cameraMap.Remove(name);
}
if (n < 0 || n >= cameraAll.pDeviceInfo.Length) { return false; }
try
{
MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(cameraAll.pDeviceInfo[n], typeof(MyCamera.MV_CC_DEVICE_INFO));
MyCamera cameraCur = new MyCamera();
HIKCameraBean bean = new HIKCameraBean(cameraCur);
bean.Open(device);
AddCamera(name, bean);
}
catch (Exception ex)
{
ErrInfo = ex.Message;
return false;
}
return true;
}
}
/// <summary>
/// 关闭当前相机
/// </summary>
public static void Close(string cName)
{
HIKCameraBean bean = GetCamera(cName);
if (bean != null && bean.cameraCur != null)
{
bean.cameraCur.MV_CC_CloseDevice_NET();
bean.cameraCur.MV_CC_DestroyDevice_NET();
bean.cameraCur = null;
}
}
public static void CloseAll()
{
foreach (string key in cameraMap.Keys)
{
Close(key);
}
}
/// <summary>
/// 停止抓取数据
/// </summary>
public static void Stop(string cName)
{
HIKCameraBean bean = GetCamera(cName);
if (bean == null || bean.cameraCur != null)
{ return; }
if (bean.cameraCur == null) return;
int rtn = bean.cameraCur.MV_CC_StopGrabbing_NET();
if (rtn != MyCamera.MV_OK) return;
}
/// <summary>
/// 抓取一张图像
/// </summary>
public static Bitmap GrabOne(string cName)
{
HIKCameraBean bean = GetCamera(cName);
if (bean == null || bean.cameraCur != null)
{ return null; }
return bean.GrabOne();
}
/// <summary>
/// 抓取连续图像,触发GrabImage事件
/// </summary>
/// <param name="hWnd"></param>
public static void GrabContinuous(string cName, IntPtr hWnd)
{
HIKCameraBean bean = GetCamera(cName);
if (bean == null || bean.cameraCur != null)
{ return ; }
int rtn = bean.cameraCur.MV_CC_StartGrabbing_NET();
if (rtn != MyCamera.MV_OK) return;
rtn = bean.cameraCur.MV_CC_Display_NET(hWnd);
if (rtn != MyCamera.MV_OK) return;
}
}
}
using MvCamCtrl.NET;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace CodeLibrary
{
public class HIKCameraBean
{
/// <summary>
/// 当前相机
/// </summary>
public MyCamera cameraCur;
/// <summary>
/// 海康相机
/// </summary>
internal HIKCameraBean(MyCamera cameraCur)
{
this.cameraCur = cameraCur;
}
/// <summary>
/// 错误信息
/// </summary>
public string ErrInfo { set; get; }
/// <summary>
/// 当前相机是否打开
/// </summary>
public bool IsOpen
{
get
{
if (cameraCur == null)
return false;
else
return true;
}
}
/// <summary>
/// 相机图像宽度
/// </summary>
public int Width { set; get; }
/// <summary>
/// 相机图像高度
/// </summary>
public int Height { set; get; }
/// <summary>
/// 相机32位缓存
/// </summary>
public byte[] Buffer { get; private set; }
/// <summary>
/// 相机32位图像
/// </summary>
public Bitmap Image { get; private set; }
/// <summary>
/// 打开指定相机
/// </summary>
/// <param name="idx">索引</param>
/// <returns></returns>
public bool Open(MyCamera.MV_CC_DEVICE_INFO device)
{
if (cameraCur == null) return false;
int nRet = cameraCur.MV_CC_CreateDevice_NET(ref device);
if (nRet != MyCamera.MV_OK) return false;
nRet = cameraCur.MV_CC_OpenDevice_NET();
if (nRet != MyCamera.MV_OK)
{
cameraCur.MV_CC_DestroyDevice_NET();
return false;
}
if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE)
{
int nPacketSize = cameraCur.MV_CC_GetOptimalPacketSize_NET();
if (nPacketSize > 0) nRet = cameraCur.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
}
cameraCur.MV_CC_SetEnumValue_NET("AcquisitionMode", 2); //工作在连续模式
cameraCur.MV_CC_SetEnumValue_NET("TriggerMode", 0); //连续模式
MyCamera.MVCC_INTVALUE pstValue = new MyCamera.MVCC_INTVALUE();
nRet = cameraCur.MV_CC_GetWidth_NET(ref pstValue);
Width = (int)pstValue.nCurValue;
nRet = cameraCur.MV_CC_GetHeight_NET(ref pstValue);
Height = (int)pstValue.nCurValue;
return true;
}
/// <summary>
/// 关闭当前相机
/// </summary>
public void Close()
{
if (cameraCur != null)
{
cameraCur.MV_CC_CloseDevice_NET();
cameraCur.MV_CC_DestroyDevice_NET();
cameraCur = null;
}
}
/// <summary>
/// 停止抓取数据
/// </summary>
public void Stop()
{
if (cameraCur == null) return;
int rtn = cameraCur.MV_CC_StopGrabbing_NET();
if (rtn != MyCamera.MV_OK) return;
}
/// <summary>
/// 抓取一张图像
/// </summary>
public Bitmap GrabOne()
{
int rtn = cameraCur.MV_CC_StartGrabbing_NET();
if (rtn != MyCamera.MV_OK) return null;
MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
rtn = cameraCur.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
if (rtn != MyCamera.MV_OK) return null;
uint dataSize = stParam.nCurValue;
byte[] dataArr = new byte[dataSize];
uint buffSize = dataSize * 3 + 2048;
byte[] buffArr = new byte[buffSize];
IntPtr pData = Marshal.UnsafeAddrOfPinnedArrayElement(dataArr, 0);
MyCamera.MV_FRAME_OUT_INFO_EX stFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
rtn = cameraCur.MV_CC_GetOneFrameTimeout_NET(pData, dataSize, ref stFrameInfo, 100000);
if (rtn != MyCamera.MV_OK) return null;
MyCamera.MvGvspPixelType enDstPixelType = stFrameInfo.enPixelType;
switch (stFrameInfo.enPixelType)
{
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12_Packed:
enDstPixelType = stFrameInfo.enPixelType; break;
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR8:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG8:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB8:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG8:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB10:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB10_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_YUYV_Packed:
case MyCamera.MvGvspPixelType.PixelType_Gvsp_YCBCR411_8_CBYYCRYY:
enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed; break;
}
IntPtr pImage = Marshal.UnsafeAddrOfPinnedArrayElement(buffArr, 0);
MyCamera.MV_PIXEL_CONVERT_PARAM stConverPixelParam = new MyCamera.MV_PIXEL_CONVERT_PARAM();
stConverPixelParam.nWidth = stFrameInfo.nWidth;
stConverPixelParam.nHeight = stFrameInfo.nHeight;
stConverPixelParam.pSrcData = pData;
stConverPixelParam.nSrcDataLen = stFrameInfo.nFrameLen;
stConverPixelParam.enSrcPixelType = stFrameInfo.enPixelType;
stConverPixelParam.enDstPixelType = enDstPixelType;
stConverPixelParam.pDstBuffer = pImage;
stConverPixelParam.nDstBufferSize = buffSize;
rtn = cameraCur.MV_CC_ConvertPixelType_NET(ref stConverPixelParam);
if (rtn != MyCamera.MV_OK) return null;
if (enDstPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
{
Image = new Bitmap(stFrameInfo.nWidth, stFrameInfo.nHeight, stFrameInfo.nWidth * 1, PixelFormat.Format8bppIndexed, pImage);
ColorPalette cp = Image.Palette;
for (int i = 0; i < 256; i++)
cp.Entries[i] = Color.FromArgb(i, i, i);
Image.Palette = cp;
int picSize = Image.Width * Image.Height;
Buffer = new byte[picSize];
Array.Copy(buffArr, Buffer, picSize);
//Rectangle rect = new Rectangle(0, 0, Image.Width, Image.Height);
//BitmapData bmpData = Image.LockBits(rect, ImageLockMode.ReadWrite, Image.PixelFormat);
//IntPtr iPtr = bmpData.Scan0;
//int picSize = Image.Width * Image.Height;
//Buffer = new byte[picSize];
//Marshal.Copy(iPtr, Buffer, 0, picSize);
//Image.UnlockBits(bmpData);
}
else
{
for (int i = 0; i < stFrameInfo.nHeight; i++)
{
for (int j = 0; j < stFrameInfo.nWidth; j++)
{
byte chRed = buffArr[i * stFrameInfo.nWidth * 3 + j * 3];
buffArr[i * stFrameInfo.nWidth * 3 + j * 3] = buffArr[i * stFrameInfo.nWidth * 3 + j * 3 + 2];
buffArr[i * stFrameInfo.nWidth * 3 + j * 3 + 2] = chRed;
}
}
Image = new Bitmap(stFrameInfo.nWidth, stFrameInfo.nHeight, stFrameInfo.nWidth * 3, PixelFormat.Format24bppRgb, pImage);
int picSize = Image.Width * Image.Height * 3;
Buffer = new byte[picSize];
Array.Copy(buffArr, Buffer, picSize);
return Image;
}
rtn = cameraCur.MV_CC_StopGrabbing_NET();
if (rtn != MyCamera.MV_OK)
{
}
return null;
}
/// <summary>
/// 抓取连续图像,触发GrabImage事件
/// </summary>
/// <param name="hWnd"></param>
public void GrabContinuous(IntPtr hWnd)
{
int rtn = cameraCur.MV_CC_StartGrabbing_NET();
if (rtn != MyCamera.MV_OK) return;
rtn = cameraCur.MV_CC_Display_NET(hWnd);
if (rtn != MyCamera.MV_OK) return;
}
}
}
...@@ -3,6 +3,7 @@ FrmCodeDecode_label4_Text,参数路径,Parameters of the path ...@@ -3,6 +3,7 @@ FrmCodeDecode_label4_Text,参数路径,Parameters of the path
FrmCodeDecode_chbUseParam_Text,使用参数,operation parameter FrmCodeDecode_chbUseParam_Text,使用参数,operation parameter
FrmCodeDecode_btnAn_Text,变暗,darken FrmCodeDecode_btnAn_Text,变暗,darken
FrmCodeDecode_btnLight_Text,提亮,brighten FrmCodeDecode_btnLight_Text,提亮,brighten
FrmCodeDecode_btnCopyN_Text,复制名称,Copy Name
FrmCodeDecode_label3_Text,条码类型:,Bar code type: FrmCodeDecode_label3_Text,条码类型:,Bar code type:
FrmCodeDecode_label2_Text,相机列表:,Camera list: FrmCodeDecode_label2_Text,相机列表:,Camera list:
FrmCodeDecode_btnExit_Text,退出,Exit FrmCodeDecode_btnExit_Text,退出,Exit
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
增加相机本身获取图片的代码,后续扫码都直接从相机中获取图片,然后扫码 增加相机本身获取图片的代码,后续扫码都直接从相机中获取图片,然后扫码
20190731
RC29西安三台料仓的二维码使用halcon无法识别,增加zxing的识别方式。
...@@ -3,6 +3,7 @@ FrmCodeDecode_label4_Text,参数路径,Parameters of the path ...@@ -3,6 +3,7 @@ FrmCodeDecode_label4_Text,参数路径,Parameters of the path
FrmCodeDecode_chbUseParam_Text,使用参数,operation parameter FrmCodeDecode_chbUseParam_Text,使用参数,operation parameter
FrmCodeDecode_btnAn_Text,变暗,darken FrmCodeDecode_btnAn_Text,变暗,darken
FrmCodeDecode_btnLight_Text,提亮,brighten FrmCodeDecode_btnLight_Text,提亮,brighten
FrmCodeDecode_btnCopyN_Text,复制名称,Copy Name
FrmCodeDecode_label3_Text,条码类型:,Bar code type: FrmCodeDecode_label3_Text,条码类型:,Bar code type:
FrmCodeDecode_label2_Text,相机列表:,Camera list: FrmCodeDecode_label2_Text,相机列表:,Camera list:
FrmCodeDecode_btnExit_Text,退出,Exit FrmCodeDecode_btnExit_Text,退出,Exit
...@@ -31,3 +32,8 @@ FrmCodeLearn_label1_Text,相机:,camera: ...@@ -31,3 +32,8 @@ FrmCodeLearn_label1_Text,相机:,camera:
FrmCodeLearn_btnExit_Text,退出,Exit FrmCodeLearn_btnExit_Text,退出,Exit
FrmCodeLearn_btnStop_Text,结束学习,End of learning FrmCodeLearn_btnStop_Text,结束学习,End of learning
FrmCodeLearn_btnOpen_Text,开始学习,start to learn FrmCodeLearn_btnOpen_Text,开始学习,start to learn
selCamera,请先选择相机,Please select camera
selImage,请先选择图片,Please select picture
title,提示,Notice
imageIsNull,获取二维码图片为空,Get the two-dimensional code picture is empty
sureDelete,确定删除文件:,Make sure to delete the file:
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{87075EC9-91E4-4EF1-9B35-E220DA7C937C}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>CodeToolClinet</RootNamespace>
<AssemblyName>CodeToolClinet</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FrmMain.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmMain.Designer.cs">
<DependentUpon>FrmMain.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="FrmMain.resx">
<DependentUpon>FrmMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodeLibraryProject\Common\Common.csproj">
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file \ No newline at end of file
namespace CodeToolClinet
{
partial class FrmMain
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtData = new System.Windows.Forms.TextBox();
this.btnChange = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lblResult = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// txtData
//
this.txtData.Location = new System.Drawing.Point(162, 38);
this.txtData.Name = "txtData";
this.txtData.Size = new System.Drawing.Size(430, 26);
this.txtData.TabIndex = 8;
//
// btnChange
//
this.btnChange.BackColor = System.Drawing.SystemColors.Control;
this.btnChange.Location = new System.Drawing.Point(613, 35);
this.btnChange.Name = "btnChange";
this.btnChange.Size = new System.Drawing.Size(131, 36);
this.btnChange.TabIndex = 7;
this.btnChange.Text = "查看名称";
this.btnChange.UseVisualStyleBackColor = false;
this.btnChange.Click += new System.EventHandler(this.btnChange_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(51, 41);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(93, 20);
this.label1.TabIndex = 6;
this.label1.Text = "程序字符串:";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lblResult);
this.groupBox1.Controls.Add(this.btnChange);
this.groupBox1.Controls.Add(this.txtData);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(776, 155);
this.groupBox1.TabIndex = 9;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "程序名查看";
//
// lblResult
//
this.lblResult.AutoSize = true;
this.lblResult.Location = new System.Drawing.Point(317, 98);
this.lblResult.Name = "lblResult";
this.lblResult.Size = new System.Drawing.Size(136, 20);
this.lblResult.TabIndex = 9;
this.lblResult.Text = "CodeLibraryProject";
//
// FrmMain
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.groupBox1);
this.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Name = "FrmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "软件工具";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.FrmMain_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TextBox txtData;
private System.Windows.Forms.Button btnChange;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label lblResult;
}
}
using Common;
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 CodeToolClinet
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void btnChange_Click(object sender, EventArgs e)
{
string data = txtData.Text;
byte[] dataA = new byte[] { };
dataA = SerialBean.StringToByte(data);
string result = System.Text.Encoding.ASCII.GetString(dataA);
lblResult.Text = result;
}
private void FrmMain_Load(object sender, EventArgs e)
{
string codeName = "CodeLibraryProject";
byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(codeName);
string result = "";
result = AcSerialBean.ByteToString(byteArray);
txtData.Text = result;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CodeToolClinet
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("CodeToolClinet")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CodeToolClinet")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("87075ec9-91e4-4ef1-9b35-e220da7c937c")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace CodeToolClinet.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CodeToolClinet.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace CodeToolClinet.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
//
// File generated by HDevelop for HALCON/DOTNET (C#) Version 12.0
//
// This file is intended to be used with the HDevelopTemplate or
// HDevelopTemplateWPF projects located under %HALCONEXAMPLES%\c#
using System;
using System.Windows.Forms;
using HalconDotNet;
public partial class HDevelopExport
{
public HTuple hv_ExpDefaultWinHandle;
public void HDevelopStop()
{
MessageBox.Show("Press button to continue", "Program stop");
}
// Main procedure
private void action()
{
// Local iconic variables
HObject ho_Image=null, ho_SymbolXLDs=null;
// Local control variables
HTuple hv_code_type = null, hv_model_path = null;
HTuple hv_train_first = null, hv_AcqHandle = null, hv_DataCodeHandle = null;
HTuple hv_ResultHandles = new HTuple(), hv_DecodedDataStrings = new HTuple();
HTuple hv_GenParamNames = new HTuple(), hv_ModelBeforeTraining = new HTuple();
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_SymbolXLDs);
//Image Acquisition 04: Code generated by Image Acquisition 04
//Image Acquisition 01: Code generated by Image Acquisition 01
hv_code_type = "Data Matrix ECC 200";
hv_model_path = ("E:/BaiduNetdiskDownload/"+hv_code_type)+".dcm";
hv_train_first = 1;
HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1,
"default", -1, "false", "default", "RivetingCode", 0, -1, out hv_AcqHandle);
HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
HOperatorSet.CreateDataCode2dModel(hv_code_type, new HTuple(), new HTuple(),
out hv_DataCodeHandle);
//set_data_code_2d_param (DataCodeHandle, 'strict_model', 'yes')
//set_data_code_2d_param (DataCodeHandle, 'persistence', 0)
//set_data_code_2d_param (DataCodeHandle, 'polarity', 'light_on_dark')
if ((int)(hv_train_first) != 0)
{
while ((int)(1) != 0)
{
ho_Image.Dispose();
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
//Image Acquisition 04: Do something
//write_image (Image, 'jpeg', 0, 'E:/BaiduNetdiskDownload/fuba2.jpg')
ho_SymbolXLDs.Dispose();
HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle,
"train", "all", out hv_ResultHandles, out hv_DecodedDataStrings);
if ((int)(new HTuple((new HTuple(hv_DecodedDataStrings.TupleLength())).TupleNotEqual(
0))) != 0)
{
HOperatorSet.QueryDataCode2dParams(hv_DataCodeHandle, "get_model_params",
out hv_GenParamNames);
HOperatorSet.GetDataCode2dParam(hv_DataCodeHandle, hv_GenParamNames, out hv_ModelBeforeTraining);
HDevelopStop();
}
}
//*参数写入文件
HOperatorSet.WriteDataCode2dModel(hv_DataCodeHandle, hv_model_path);
HOperatorSet.ClearDataCode2dModel(hv_DataCodeHandle);
}
//Read the previously saved data code model
HOperatorSet.ReadDataCode2dModel(hv_model_path, out hv_DataCodeHandle);
while ((int)(1) != 0)
{
ho_Image.Dispose();
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
//Image Acquisition 04: Do something
//write_image (Image, 'jpeg', 0, 'E:/BaiduNetdiskDownload/fuba2.jpg')
ho_SymbolXLDs.Dispose();
HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle,
"stop_after_result_num", 5, out hv_ResultHandles, out hv_DecodedDataStrings);
}
HOperatorSet.ClearDataCode2dModel(hv_DataCodeHandle);
HOperatorSet.CloseFramegrabber(hv_AcqHandle);
ho_Image.Dispose();
ho_SymbolXLDs.Dispose();
}
public void InitHalcon()
{
// Default settings used in HDevelop
HOperatorSet.SetSystem("width", 512);
HOperatorSet.SetSystem("height", 512);
}
public void RunHalcon(HTuple Window)
{
hv_ExpDefaultWinHandle = Window;
action();
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!