Commit 8f00002c 刘韬

增加Qrcode识别算法,优化x光部分失败流程,优化入料失败流程,优化贴标错位问题

1 个父辈 14cf1502
......@@ -57,14 +57,16 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="zxing">
<HintPath>..\..\..\..\GeneralClassLibrary\CodeLibraryProject\CodeLibrary\bin\Debug\zxing.dll</HintPath>
<Reference Include="zxing, Version=0.14.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\GeneralClassLibrary\CodeLibraryProject\CodeTest\bin\Debug\zxing.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="camera\Basler.cs" />
<Compile Include="camera\Common.cs" />
<Compile Include="camera\HIK.cs" />
<Compile Include="eyemDecode.cs" />
<Compile Include="FrmBase.cs">
<SubType>Form</SubType>
</Compile>
......
......@@ -82,6 +82,8 @@ namespace CodeLibrary
cmbCamera.Items.Clear();
Camera.Type = CameraType.HIK;
Camera._cam.Load();
if (Camera._cam.Name == null)
return;
foreach (string str in Camera._cam.Name)
{
cmbCamera.Items.Add(str);
......@@ -248,6 +250,15 @@ namespace CodeLibrary
}
if (chbZxing.Checked)
{
if (HDCodeLearnHelper.DefaultBitmap != null) {
List<CodeInfo> codeList = eyemDecode.Decoder(ref HDCodeLearnHelper.DefaultBitmap);
HDCodeLearnHelper.DefaultBitmap.Dispose();
ShowCode(codeList);
return;
}
if (pictureBox1.Image == null)
{
MessageBox.Show(selImage, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
......@@ -278,6 +289,7 @@ namespace CodeLibrary
}
private void zxingDecode(Bitmap map, string type)
{
/*
List<string> results = ZXingCodeHelper.DeCodes(map, type);
txtResult.Text = " zxing decode:";
......@@ -286,6 +298,16 @@ namespace CodeLibrary
txtResult.Text += "\r\n" + "\r\n" + code;
}
txtResult.Text += "\r\n \r\n elapsed time:" + stopwatch.Elapsed.ToString();
*/
List<CodeInfo> codeList = new List<CodeInfo>(); ;
//for (int i = 0; i < 1000; i++)
//{
Bitmap b = (Bitmap)pictureBox1.Image.Clone();
codeList = eyemDecode.Decoder(ref b);
b.Dispose();
Thread.Sleep(10);
//}
ShowCode(codeList);
}
private void btnClearLog_Click(object sender, EventArgs e)
......@@ -293,8 +315,9 @@ namespace CodeLibrary
HDLogUtil.ClearLog();
txtResult.Text = "";
}
private HObject GetCameraBitmap()
private HObject GetCameraBitmap(out Bitmap bitmap)
{
bitmap = null;
try
{
int index = cmbCamera.SelectedIndex;
......@@ -305,11 +328,11 @@ namespace CodeLibrary
return null;
}
HObject map;
map = Camera._cam.CaptureOnImage(camerName );
map = Camera._cam.CaptureOnImage(camerName,out bitmap);
if ( map == null)
{
Camera._cam.Close(camerName);
map = Camera._cam.CaptureOnImage(camerName );
map = Camera._cam.CaptureOnImage(camerName, out bitmap);
}
return map;
}
......@@ -325,7 +348,7 @@ namespace CodeLibrary
{
if (!chbZxing.Checked)
{
HObject bitmap = GetCameraBitmap();
HObject bitmap = GetCameraBitmap(out Bitmap b);
if (bitmap != null)
{
HDLogUtil.info("从相机【" + cmbCamera.Text + "】获取到一张图片");
......@@ -333,6 +356,7 @@ namespace CodeLibrary
//pictureBox1.Image = (Image)bitmap.Clone();
//HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HDCodeLearnHelper.DefaultImage = bitmap;
HDCodeLearnHelper.DefaultBitmap = b;
ShowImage(bitmap);
}
}
......
......@@ -437,7 +437,7 @@ namespace CodeLibrary
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 1500);
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 2500);
}
foreach (CodeInfo c in cc)
{
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
......@@ -17,6 +18,7 @@ namespace CodeLibrary
/// 图片对象,学习时如果使用图片学习,需要先设置此属性
/// </summary>
public static HObject DefaultImage = null;
public static Bitmap DefaultBitmap = null;
/// <summary>
/// 学习后是否自动测试,默认是
/// </summary>
......
......@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
......@@ -35,11 +36,13 @@ namespace CodeLibrary
public static void info(string msg)
{
LOGGER.Info("HDLogUtil" + " - " + msg);
OutputDebugString("HDLogUtil" + " - " + msg);
AddToBox(msg);
}
public static void debug(string msg)
{
LOGGER.Debug("HDLogUtil" + " - " + msg);
OutputDebugString("HDLogUtil" + " - " + msg);
if (debug_opened)
{
AddToBox(msg);
......@@ -49,6 +52,7 @@ namespace CodeLibrary
public static void error(string errorMsg)
{
LOGGER.Error("HDLogUtil" + " - " + errorMsg);
OutputDebugString("HDLogUtil" + " - " + errorMsg);
AddToBox(errorMsg);
}
private static void AddToBox(string msg)
......@@ -94,5 +98,7 @@ namespace CodeLibrary
count = 0;
}
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);
}
}
......@@ -228,9 +228,14 @@ namespace CodeLibrary
}
return null;
}
public override HObject CaptureOnImage(string name )
public override HObject CaptureOnImage(string name)
{
return CaptureOnImage(name, out _);
}
public override HObject CaptureOnImage(string name, out Bitmap bmp)
{
HObject hoImage = null;
bmp = null;
int index = cameraName.FindIndex(s => s == name);
if (index == -1)
{
......
......@@ -113,6 +113,7 @@ namespace CodeLibrary
// public abstract void GrabStop(int index);
public abstract Bitmap GrabOneImage(string name);
public abstract HObject CaptureOnImage(string name );
public abstract HObject CaptureOnImage(string name,out Bitmap bitmap);
}
}
......@@ -224,7 +224,7 @@ namespace CodeLibrary
if (n == -1)
{
_errInfo = name + " Not find";
HDLogUtil.error("GrabOneImage ["+name+"] error : " + _errInfo);
HDLogUtil.error("GrabOneImage [" + name + "] error : " + _errInfo);
return null;
}
if (cameraCurr[n] != null)
......@@ -344,9 +344,17 @@ namespace CodeLibrary
return _image;
}
}
public override HObject CaptureOnImage(string name )
public override HObject CaptureOnImage(string name)
{
HObject hoImage = null;
var r = CaptureOnImage(name, out Bitmap bmp);
bmp.Dispose();
return r;
}
public override HObject CaptureOnImage(string name, out Bitmap bmp)
{
HObject hoImage = null;
bmp = null;
int index = cameraName.FindIndex(s => s == name);
if (index == -1)
{
......@@ -380,11 +388,63 @@ namespace CodeLibrary
{
HDLogUtil.debug("Get Image Buffer:" + "Width[" + Convert.ToString(FrameInfo.stFrameInfo.nWidth) + "] , Height[" + Convert.ToString(FrameInfo.stFrameInfo.nHeight)
+ "] , FrameNum[" + Convert.ToString(FrameInfo.stFrameInfo.nFrameNum) + "]");
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));
//HObject ho_Imagetemp;
HOperatorSet.GenImage1(out hoImage, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr);
try
{
HDLogUtil.info(FrameInfo.stFrameInfo.enPixelType.ToString());
bmp = new Bitmap(FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.stFrameInfo.nWidth * 1, PixelFormat.Format8bppIndexed, FrameInfo.pBufAddr);
ColorPalette pal = bmp.Palette;
for (int i = 0; i <= 255; i++)
{
pal.Entries[i] = Color.FromArgb(i, i, i);
}
bmp.Palette = pal;
/*
var width = FrameInfo.stFrameInfo.nWidth;
var height = FrameInfo.stFrameInfo.nHeight;
const int Alpha = 255;
IntPtr[] ptr = new IntPtr[2];
bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
ColorPalette pal = bmp.Palette;
for (int i = 0; i <= 255; i++)
{
pal.Entries[i] = Color.FromArgb(Alpha, i, i, i);
}
bmp.Palette = pal;
Rectangle rect = new Rectangle(0, 0, width, height);
BitmapData bitmapData = bmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
ptr[0] = bitmapData.Scan0;
ptr[1] = FrameInfo.pBufAddr;
//Marshal.Copy()
if (width % 4 == 0)
{
HDLogUtil.info("CopyMemory1");
CopyMemory((IntPtr)ptr[0], (IntPtr)ptr[1], width * height * PixelSize);
}
else
{
HDLogUtil.info("CopyMemory2");
for (int i = 0; i < height - 1; i++)
{
ptr[1] += width;
CopyMemory((IntPtr)ptr[0], (IntPtr)ptr[1], width * PixelSize);
ptr[0] += bitmapData.Stride;
}
}
bmp.UnlockBits(bitmapData);
HDLogUtil.debug("UnlockBits");
//bmp.Save(@"D:\image\"+DateTime.Now.Ticks.ToString() + "test.bmp");
*/
}
catch (Exception ex)
{
HDLogUtil.error(ex.ToString());
}
if (FrameInfo.pBufAddr != IntPtr.Zero)
{
nRet = cameraCurr[index].MV_CC_FreeImageBuffer_NET(ref FrameInfo);
......@@ -399,6 +459,7 @@ namespace CodeLibrary
else
{
HDLogUtil.error(" [" + name + "] MV_CC_GetImageBuffer_NET No data: " + nRet);
}
}
catch (Exception ex)
......@@ -420,15 +481,16 @@ namespace CodeLibrary
}
return hoImage;
}
HalconDotNet.HalconAPI.HClearProcCallBack callback = __OnFreeCallBack;
[DllImport("Kernel32.dll")]
private static extern void CopyMemory(IntPtr dest, IntPtr source, int size);
private static void __OnFreeCallBack(IntPtr pImg)
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);
HalconDotNet.HalconAPI.HClearProcCallBack callback = __OnFreeCallBack;
private static void __OnFreeCallBack(IntPtr pImg)
{
Marshal.FreeHGlobal(pImg);
}
}
}
\ No newline at end of file
using Microsoft.Win32.SafeHandles;
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.Text.RegularExpressions;
using System.Threading.Tasks;
namespace CodeLibrary
{
public unsafe class eyemDecode
{
public static object DecoderLocker = new object();
public static List<CodeInfo> Decoder(ref Bitmap bmap)
{
List<CodeInfo> codelist = new List<CodeInfo>();
lock (DecoderLocker)
{
try
{
Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height);
EyemImage eyemImage = new EyemImage();
BitmapData bitmapData = bmap.LockBits(rect, ImageLockMode.ReadOnly, bmap.PixelFormat);
eyemImage.ucpImage = bitmapData.Scan0;
eyemImage.iWidth = rect.Width;
eyemImage.iHeight = rect.Height;
eyemImage.iChannel = 0;// Bitmap.GetPixelFormatSize(bitmapData.PixelFormat);
EyemRect eyemRect = new EyemRect();
eyemRect.iXs = 0;
eyemRect.iYs = 0;
eyemRect.iWidth = eyemImage.iWidth;
eyemRect.iHeight = eyemImage.iHeight;
//string strDecodeResult = "";
string codeType = "DataMatrix";//QRCode
codeType = "QRCode";
int ipNum;
EyemBarCode* tpResults;
DataCodeHandle hObject = null;
try
{
//int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, ref strDecodeResult, false, 11, 3, 128, 215);
int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, 11, 5, 128, 215);
HDLogUtil.info($"eyemDetectAndDecode:{result},ipNum:{ipNum}");
if (result != 0 || ipNum == 0)
return codelist;
for (int i = 0; i < ipNum; i++)
{
CodeInfo ci = new CodeInfo(Marshal.PtrToStringAnsi(tpResults[i].hText), tpResults[i].iCenterX, tpResults[i].iCenterY);
ci.CodeType = Marshal.PtrToStringAnsi(tpResults[i].hType);
codelist.Add(ci);
//Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + "");
}
}
finally
{
if (hObject != null)
hObject.Dispose();
bmap.UnlockBits(bitmapData);
//bmap.Dispose();
}
}
catch (Exception ex)
{
HDLogUtil.error(ex.ToString());
}
}
//eyemImageFree(eyemImage.ucpImage);
return codelist;
}
//释放解码句柄
public class DataCodeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public DataCodeHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemDetectAndDecodeFree(handle);
}
}
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, ref string strDecodeResult, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dToleErr = 0.5, double dMinorStep = 1.0);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dToleErr = 0.5, double dMinorStep = 1.0);
/// <summary>
/// 读取图像
/// </summary>
/// <param name="filename"></param>
/// <param name="iFalgs"></param>
/// <param name="ucpImage"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemImageRead(string filename, int iFalgs, out EyemImage ucpImage);
/// <summary>
/// 释放图像资源
/// </summary>
/// <param name="ipImage"></param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern void eyemImageFree(IntPtr ipImage);
//释放工具
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
[StructLayout(LayoutKind.Sequential)]
public struct EyemImage
{
public IntPtr ucpImage; // 地址
public int iWidth; // 图像内存 x 方向大小
public int iHeight; // 图像内存 y 方向大小
public int iChannel; // 图像通道数
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode
{
public int iCenterX; // y坐标
public int iCenterY; // y坐标
public IntPtr hType; // 码类型
public IntPtr hText; // 码内容
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode2
{
public int iCenterX; // y坐标
public int iCenterY; // y坐标
public string hType; // 码类型
public string hText; // 码内容
}
}
}
......@@ -366,6 +366,7 @@ namespace OnlineStore.DeviceLibrary
WorkLog("放料完成:进出轴返回P1,升降轴返回P1");
InOutAxis.AbsMove(MoveInfo, Config.InoutAxis_P1, Config.InoutAxis_P1Speed);
UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1Speed);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
}
else if (MoveInfo.IsStep(StepEnum.IW42_InoutToP1))
{
......
......@@ -160,6 +160,7 @@ namespace OnlineStore.DeviceLibrary
public void SecMoveReset()
{
SecMoveInfo.NextMoveStep(StepEnum.OLR01_LabelZHome);
RobotManager.LastPrintStatus=Asa.PrintLabel.PrinterStatus.Unknown;
SecMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
SecWorkLog("贴标Z轴原点返回,标签吸码停止输出,贴标气缸后退");
LabelZAxis.HomeMove(SecMoveInfo);
......
......@@ -828,7 +828,7 @@ namespace OnlineStore.DeviceLibrary
}
else if (SecMoveInfo.IsStep(StepEnum.OL20_LableCancel))
{
ShelfMoveInfo.NextMoveStep(StepEnum.OL21_LableCancel2);
SecMoveInfo.NextMoveStep(StepEnum.OL21_LableCancel2);
IOMove(IO_Type.Nozzle_Work, IO_VALUE.LOW);
LabelZAxis.AbsMove(SecMoveInfo, Config.LabelZ_P1, Config.LabelZ_P1Speed);
CylinderMove(SecMoveInfo, IO_Type.LablePaste_Forward, IO_Type.PasteCode_Back);
......
......@@ -438,7 +438,7 @@ namespace OnlineStore.DeviceLibrary
if (!isFirst)
{
targetP3 = StartMovePosition+Config.Height_ChangeValue * 40;
targetP3 = StartMovePosition+Config.Height_ChangeValue * 55;
if (targetP3 > Config.BatchAxisP3) {
targetP3 = Config.BatchAxisP3;
}
......
......@@ -109,12 +109,12 @@ namespace OnlineStore.DeviceLibrary
WorkLog("料盘处理:等待扫描区域信号检测", 0);
//IOMove(IO_Type.X_InLine_Run, IO_VALUE.HIGH);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
}
else if (MoveInfo.IsStep(StepEnum.XW02_InDoorOpen))
{
}
else if (MoveInfo.IsStep(StepEnum.XW04_InLineRun))
{
......@@ -132,17 +132,29 @@ namespace OnlineStore.DeviceLibrary
In_ReelInfo = new ReelInfo();
WorkLog("料盘处理:更新Work_ReelInfo【" + Work_ReelInfo.ToStr() + "】,清空 In_ReelInfo,左侧皮带线先停止,右侧皮带线再转动4秒钟");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
//IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
}
else if (MoveInfo.IsStep(StepEnum.XW06_WaitTime))
{
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:停止入口皮带线,中间皮带线");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW);
if (IOValue(IO_Type.X_ReelCheck).Equals(IO_VALUE.HIGH))
{
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:停止入口皮带线,中间皮带线");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH,800);
}
else if (MoveInfo.IsTimeOut(20))
{
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:未检测到料盘,直接执行送出动作");
Work_ReelInfo.IsNgReel = true;
Work_ReelInfo.NgMsg = "未检测到料盘";
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW);
}
}
else if (MoveInfo.IsStep(StepEnum.XW07_InLineStop))
{
......@@ -173,6 +185,7 @@ namespace OnlineStore.DeviceLibrary
CylinderMove(MoveInfo, IO_Type.X_OutDoor_Down, IO_Type.X_OutDoor_Up);
CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Down, IO_Type.X_StopCylinder_Up);
}
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
......@@ -234,12 +247,13 @@ namespace OnlineStore.DeviceLibrary
}
else if (MoveInfo.IsStep(StepEnum.XW12_XRayStart))
{
TickLog("打开xray",true);
TickLog("打开xray", true);
MoveInfo.NextMoveStep(StepEnum.XW13_GetXRayImage);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(8000));
WorkLog("点料:清理" + path1_tif + "内容,开始获取X射线图形 ");
if (string.IsNullOrEmpty(CapImage())) {
if (string.IsNullOrEmpty(CapImage()))
{
//Alarm(AlarmType.IoSingleTimeOut);
}
MoveInfo.EndStepWait();
......@@ -371,7 +385,7 @@ namespace OnlineStore.DeviceLibrary
TickLog("点料完成");
WorkLog("料盘处理:料盘处理结束,耗时(" + FormUtil.GetSpanStr(span) + ")");
MoveInfo.EndMove();
}
}
......
......@@ -100,7 +100,7 @@ namespace OnlineStore.DeviceLibrary
private static int ScanCount = 0;
private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount);
public static List<string> CameraScan(string deviceName, params string[] cameraList) {
return CameraScan(deviceName, out _, false, cameraList);
return CameraScan(deviceName, out _, true, cameraList);
}
[HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(string deviceName, out List<CodeInfo> ccall, bool nosave,params string[] cameraList)
......@@ -112,6 +112,7 @@ namespace OnlineStore.DeviceLibrary
{
return codeList;
}
Bitmap bmp=null;
try
{
foreach (string cameraName in cameraList)
......@@ -130,48 +131,75 @@ namespace OnlineStore.DeviceLibrary
bool findRightCode = false;
try
{
ho_Image = Camera._cam.CaptureOnImage(cameraName);
ho_Image = Camera._cam.CaptureOnImage(cameraName,out bmp);
if (ho_Image == null)
{
LogUtil.error(deviceName + " 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName);
continue;
}
LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码");
//cc = new List<CodeInfo>();
string r = "";
foreach (string codeType in codeTypeList)
{
//判断是否是一维码
if (codeType.ToLower().Equals("barcode"))
List<CodeInfo> tlci = eyemDecode.Decoder(ref bmp);
foreach (CodeInfo code in tlci) {
LogUtil.info(deviceName + " 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr);
string str = CodeManager.ReplaceCode(code.CodeStr);
if (!codeList.Contains(str))
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 1500);
codeList.Add(str);
r = r + "##eyemDecode|" + code.CodeType + "|" + str;
if (!findRightCode)
{
findRightCode = HasRightCode(str);
if (findRightCode)
ccall.Add(code);
}
}
foreach (CodeInfo c in cc)
}
if (!findRightCode)
{
foreach (string codeType in codeTypeList)
{
string str = CodeManager.ReplaceCode(c.CodeStr);
if (!codeList.Contains(str))
//判断是否是一维码
if (codeType.ToLower().Equals("barcode"))
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{
codeList.Add(str);
r = r + "##" + str;
if (!findRightCode)
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 2500);
}
foreach (CodeInfo c in cc)
{
string str = CodeManager.ReplaceCode(c.CodeStr);
if (!codeList.Contains(str))
{
findRightCode = HasRightCode(str);
if (findRightCode)
ccall.Add(c);
codeList.Add(str);
r = r + "##Halcon|" + codeType + "|" + str;
if (!findRightCode)
{
findRightCode = HasRightCode(str);
if (findRightCode)
{
ccall.Add(c);
if (codeType == "QR Code")
nosave = false;
}
}
}
}
}
}
//bmp.Save(@"D:\image\" + DateTime.Now.Ticks.ToString() + "test.bmp");
if (!findRightCode || !nosave)
{
SaveImageToFile(deviceName, cameraName, ho_Image);
//SaveImageToFile(deviceName, cameraName, ho_Image);
SaveImageToFile(deviceName, cameraName, bmp);
}
if (deviceName != "" || r != "")
{
......@@ -190,10 +218,18 @@ namespace OnlineStore.DeviceLibrary
}
finally
{
LogUtil.info("回收");
if (ho_Image != null)
{
HalconDotNet.HOperatorSet.ClearObj(ho_Image);
}
HalconDotNet.HOperatorSet.ClearObj(ho_Image);
LogUtil.info("回收ho_Image");
}
if (bmp != null)
{
bmp.Dispose();
LogUtil.info("回收bmp");
}
}
}
}
......@@ -232,17 +268,17 @@ namespace OnlineStore.DeviceLibrary
}
private static void SaveImageToFile(string deviceName, string cameraName, Bitmap bitmap)
{
string date = deviceName.Trim().Replace('_', '-') + "-" + DateTime.Now.ToString("HH-mm-ss-") + DateTime.Now.Millisecond;
string date = deviceName.Trim().Replace('_', '-') + "-" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "-" + DateTime.Now.Millisecond.ToString().PadLeft(4, '0');
string dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp";
try
{
Bitmap bit = (Bitmap)bitmap.Clone();
if (Directory.Exists(dire).Equals(false))
//Bitmap bit = (Bitmap)bitmap.Clone();
if (!Directory.Exists(dire))
{
Directory.CreateDirectory(dire);
}
bit.Save(dire + iamgeName, ImageFormat.Bmp);
bitmap.Save(dire + iamgeName, ImageFormat.Bmp);
LogUtil.info(deviceName + " 【" + cameraName + "】扫码失败,保存图片到【" + dire + iamgeName + "】成功");
}
catch (Exception ex)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!