Commit 7ce5a30d LN

相机获取图片修改

1 个父辈 ca0df4ec
......@@ -57,14 +57,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="camera\Basler.cs" />
<Compile Include="camera\Common.cs" />
<Compile Include="camera\HIK.cs" />
<Compile Include="FrmBase.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmBase.Designer.cs">
<DependentUpon>FrmBase.cs</DependentUpon>
</Compile>
<Compile Include="HIKCamera.cs" />
<Compile Include="BaslerCamera.cs" />
<Compile Include="FrmCodeLearn.cs">
<SubType>Form</SubType>
</Compile>
......
......@@ -55,13 +55,14 @@
this.label4 = new System.Windows.Forms.Label();
this.btnLight = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.btnScanTest = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// txtPath
//
this.txtPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.txtPath.Location = new System.Drawing.Point(864, 92);
this.txtPath.Location = new System.Drawing.Point(1047, 92);
this.txtPath.Name = "txtPath";
this.txtPath.Size = new System.Drawing.Size(321, 21);
this.txtPath.TabIndex = 0;
......@@ -82,7 +83,7 @@
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.Location = new System.Drawing.Point(734, 115);
this.pictureBox1.Location = new System.Drawing.Point(917, 115);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(451, 313);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
......@@ -92,7 +93,7 @@
// txtResult
//
this.txtResult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.txtResult.Location = new System.Drawing.Point(734, 431);
this.txtResult.Location = new System.Drawing.Point(917, 431);
this.txtResult.Multiline = true;
this.txtResult.Name = "txtResult";
this.txtResult.Size = new System.Drawing.Size(450, 290);
......@@ -132,9 +133,9 @@
this.hWindowControl1.ImagePart = new System.Drawing.Rectangle(0, 0, 640, 480);
this.hWindowControl1.Location = new System.Drawing.Point(11, 115);
this.hWindowControl1.Name = "hWindowControl1";
this.hWindowControl1.Size = new System.Drawing.Size(717, 606);
this.hWindowControl1.Size = new System.Drawing.Size(900, 606);
this.hWindowControl1.TabIndex = 8;
this.hWindowControl1.WindowSize = new System.Drawing.Size(717, 606);
this.hWindowControl1.WindowSize = new System.Drawing.Size(900, 606);
//
// btnbarCode
//
......@@ -151,7 +152,7 @@
//
this.btnLearn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnLearn.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnLearn.Location = new System.Drawing.Point(1066, 12);
this.btnLearn.Location = new System.Drawing.Point(1249, 12);
this.btnLearn.Name = "btnLearn";
this.btnLearn.Size = new System.Drawing.Size(109, 33);
this.btnLearn.TabIndex = 10;
......@@ -238,7 +239,7 @@
//
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(1066, 50);
this.btnExit.Location = new System.Drawing.Point(1249, 50);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(109, 33);
this.btnExit.TabIndex = 18;
......@@ -250,7 +251,7 @@
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
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(731, 95);
this.label1.Location = new System.Drawing.Point(914, 95);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(127, 17);
this.label1.TabIndex = 19;
......@@ -330,7 +331,7 @@
this.txtParamPath.Enabled = false;
this.txtParamPath.Location = new System.Drawing.Point(205, 92);
this.txtParamPath.Name = "txtParamPath";
this.txtParamPath.Size = new System.Drawing.Size(523, 21);
this.txtParamPath.Size = new System.Drawing.Size(706, 21);
this.txtParamPath.TabIndex = 28;
//
// label4
......@@ -367,11 +368,23 @@
this.button1.Visible = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// btnScanTest
//
this.btnScanTest.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnScanTest.Location = new System.Drawing.Point(1069, 12);
this.btnScanTest.Name = "btnScanTest";
this.btnScanTest.Size = new System.Drawing.Size(167, 33);
this.btnScanTest.TabIndex = 30;
this.btnScanTest.Text = "扫码测试";
this.btnScanTest.UseVisualStyleBackColor = true;
this.btnScanTest.Click += new System.EventHandler(this.btnScanTest_Click);
//
// FrmCodeDecode
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1192, 729);
this.ClientSize = new System.Drawing.Size(1375, 729);
this.Controls.Add(this.btnScanTest);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtParamPath);
this.Controls.Add(this.label4);
......@@ -403,6 +416,7 @@
this.Name = "FrmCodeDecode";
this.Text = "二维码识别";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmCodeDecode_FormClosing);
this.Load += new System.EventHandler(this.FrmMain_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
......@@ -438,6 +452,7 @@
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnLight;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button btnScanTest;
}
}
......@@ -37,20 +37,21 @@ 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();
}
//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;
}
private void btnOpen_Click(object sender, EventArgs e)
......@@ -106,21 +107,21 @@ namespace CodeLibrary
}
private void LoadCamera()
{
string[] camerName = BaslerCamera.Instance.CameraName;
baslerNameList.AddRange(camerName);
//string[] camerName = BaslerCamera.Instance.CameraName;
//baslerNameList.AddRange(camerName);
cmbCamera.Items.Clear();
foreach (string str in camerName)
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 (camerName.Length > 0)
//camerName = HIKCamera.Instance.CameraName;
//hikNameList.AddRange(camerName);
//foreach (string str in camerName)
//{
// cmbCamera.Items.Add(str);
//}
if (cmbCamera.Items.Count > 0)
{
cmbCamera.SelectedIndex = 0;
}
......
......@@ -80,6 +80,7 @@ namespace CodeLibrary
}
public static List<CodeInfo> DecodeCode(HObject ho_Image, string symbolType, string hv_model_path, int codeCount)
{
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 开始");
List<CodeInfo> codeList = new List<CodeInfo>();
try
{
......@@ -138,11 +139,13 @@ namespace CodeLibrary
}
}
}
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:"+codeList.Count);
return codeList;
}
catch (Exception ex)
{
HDLogUtil.error("DecodeCode出错:" + ex.ToString());
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 结束,返回数量:" + codeList.Count);
return codeList;
}
......@@ -195,7 +198,7 @@ namespace CodeLibrary
ho_Image.Dispose();
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
BitmapData srcBmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
BitmapData srcBmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, bmp.PixelFormat);
HOperatorSet.GenImageInterleaved(out ho_Image, srcBmpData.Scan0, "bgrx", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0);
bmp.UnlockBits(srcBmpData);
......
......@@ -34,12 +34,12 @@ namespace CodeLibrary
public static void info(string msg)
{
LOGGER.Info(LOGGER.Logger.Name + " - " + msg);
LOGGER.Info("HDLogUtil" + " - " + msg);
AddToBox(msg);
}
public static void debug(string msg)
{
LOGGER.Debug(LOGGER.Logger.Name + " - " + msg);
LOGGER.Debug("HDLogUtil" + " - " + msg);
if (debug_opened)
{
AddToBox(msg);
......@@ -48,7 +48,7 @@ namespace CodeLibrary
public static void error(string errorMsg)
{
LOGGER.Error(LOGGER.Logger.Name + " - " + errorMsg);
LOGGER.Error("HDLogUtil" + " - " + errorMsg);
AddToBox(errorMsg);
}
private static void AddToBox(string msg)
......
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace CodeLibrary
{
/// <summary>
/// 相机
/// </summary>
public class Camera : ClsCamera
{
public static ClsCamera _cam;
private static CameraType _type;
/// <summary>
/// 连续采集事件
/// </summary>
public static event Continuous Continuous_Event;
/// <summary>
/// 相机
/// </summary>
private Camera()
{ }
/// <summary>
/// 相机类型
/// </summary>
public static CameraType Type
{
set
{
if (_cam != null)
{
return ;
// _cam.CloseAll();
}
_type = value;
switch (_type)
{
case CameraType.HIK:
_cam = new HIK();
((HIK)_cam).Continuous_Event += Camera_Continuous_Event;
break;
case CameraType.Basler:
_cam = new Basler();
((Basler)_cam).Continuous_Event += Camera_Continuous_Event;
break;
}
}
get
{
return _type;
}
}
/// <summary>
/// 错误信息
/// </summary>
public override string ErrInfo => _cam.ErrInfo;
/// <summary>
/// 相机是否打开
/// </summary>
public override bool[] IsOpen => _cam.IsOpen;
/// <summary>
/// 相机总数
/// </summary>
public override int Count => _cam.Count;
/// <summary>
/// 相机名称
/// </summary>
public override string[] Name => _cam.Name;
/// <summary>
/// 图像宽度
/// </summary>
public override int[] Width => _cam.Width;
/// <summary>
/// 图像高度
/// </summary>
public override int[] Height => _cam.Height;
/// <summary>
/// 图像缓存
/// </summary>
public override byte[] Buffer => _cam.Buffer;
/// <summary>
/// 图像
/// </summary>
public override Bitmap Image => _cam.Image;
/// <summary>
/// 加载
/// </summary>
/// <returns></returns>
public override bool Load()
{
if (_cam == null)
return false;
else
return _cam.Load();
}
/// <summary>
/// 打开相机
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public override bool Open(int index)
{
return _cam.Open(index);
}
/// <summary>
/// 打开相机
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public override bool Open(string name)
{
return _cam.Open(name);
}
/// <summary>
/// 打开所有相机
/// </summary>
/// <returns></returns>
public override bool OpenAll()
{
return _cam.OpenAll();
}
///// <summary>
///// 连续抓取图像
///// </summary>
///// <returns></returns>
//public override bool GrabContinuous(int index)
//{
// return _cam.GrabContinuous( index);
//}
/// <summary>
/// 抓取一次图像
/// </summary>
/// <returns></returns>
public override bool GrabOne(int index)
{
return _cam.GrabOne( index);
}
///// <summary>
///// 抓取一次图像
///// </summary>
///// <param name="index"></param>
///// <returns></returns>
//public override bool GrabOne(int index)
//{
// return _cam.GrabOne(index);
//}
/// <summary>
/// 抓取一次图像
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public override bool GrabOne(string name)
{
return _cam.GrabOne(name);
}
/// <summary>
/// 停止连续抓取
/// </summary>
public override void GrabStop(int index)
{
_cam.GrabStop( index);
}
/// <summary>
/// 关闭所有相机
/// </summary>
public override void CloseAll()
{
_cam.CloseAll();
}
/// <summary>
/// 关闭相机
/// </summary>
public override void Close(int index)
{
_cam.Close( index);
}
public override void Close(string name)
{
_cam.Close(name);
}
private static void Camera_Continuous_Event()
{
Continuous_Event?.Invoke();
}
public override Bitmap GrabOneImage(string name)
{
return _cam.GrabOneImage(name);
}
}
/// <summary>
/// 相机类型
/// </summary>
public enum CameraType
{
/// <summary>
/// 海康
/// </summary>
HIK,
/// <summary>
/// Basle
/// </summary>
Basler
}
public abstract class ClsCamera
{
/// <summary>
/// 所有相机的名称
/// </summary>
protected List<string> cameraName;
protected string _errInfo;
protected bool[] _isOpen;
protected int _count;
protected string[] _name;
protected int[] _width;
protected int[] _height;
protected byte[] _buffer;
protected Bitmap _image;
// protected int _index;
public delegate void Continuous();
public virtual string ErrInfo => _errInfo;
public virtual bool[] IsOpen => _isOpen;
public virtual int Count => _count;
public virtual string[] Name => _name;
public virtual int[] Width => _width;
public virtual int[] Height => _height;
public virtual byte[] Buffer => _buffer;
public virtual Bitmap Image => _image;
public abstract bool Load();
public abstract bool OpenAll();
public abstract bool Open(int index);
public abstract bool Open(string name);
public abstract void CloseAll();
public abstract void Close(int index);
public abstract void Close(string name);
// public abstract bool GrabOne();
public abstract bool GrabOne(int index);
public abstract bool GrabOne(string name);
// public abstract bool GrabContinuous(int index);
public abstract void GrabStop(int index);
public abstract Bitmap GrabOneImage(string name);
}
}
......@@ -25,7 +25,7 @@ namespace CodeTest
}
for (int i = 100000; i <= 100000+count; i++)
{
string name = "pn;" + i.ToString().PadLeft(6, '0') + ";1000";
string name = "TRAY" + i.ToString().PadLeft(6, '0') + "";
Bitmap map = ZXingCode(name, 200, BarcodeFormat.QR_CODE);
if (map != null)
{
......
......@@ -18,12 +18,12 @@ namespace CodeTest
[STAThread]
static void Main()
{
//CodeCreater.CreateCode(100);
// CodeCreater.CreateCode(10);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
HDCodeLearnHelper.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName), ConfigAppSettings.GetValue(Setting_Init.CodeType));
Application.Run(new FrmCodeDecode());
//Application.Run(new FrmTest());
////Application.Run(new FrmTest());
}
}
......
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!