Commit 43f333cc 刘韬

优化eyemDecode

1 个父辈 1cbbaf0f
......@@ -41,11 +41,13 @@
<Reference Include="halcondotnet">
<HintPath>..\dll\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\dll\log4net.dll</HintPath>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\增广夹爪\log4net.dll</HintPath>
</Reference>
<Reference Include="MvCameraControl.Net">
<HintPath>..\dll\MvCameraControl.Net.dll</HintPath>
<Reference Include="MvCameraControl.Net, Version=2.4.1.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\dll\MvCameraControl.Net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
......
......@@ -407,43 +407,7 @@ namespace CodeLibrary
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)
{
......@@ -485,8 +449,6 @@ namespace CodeLibrary
}
return hoImage;
}
[DllImport("Kernel32.dll")]
private static extern void CopyMemory(IntPtr dest, IntPtr source, int size);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);
......
......@@ -57,7 +57,7 @@ namespace CodeLibrary
DataCodeHandle hObject = null;
try
{
int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, 11, 5, 128, 215);
int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, 19, 5, 128, 215);
HDLogUtil.info($"eyemDetectAndDecode:{result},ipNum:{ipNum}");
if (result != 0 || ipNum == 0)
return codelist;
......@@ -97,8 +97,30 @@ namespace CodeLibrary
}
}
[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 dScaleUpAndDown = 1, double dToleErr = 0.5, double dMinorStep = 1.0);
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 dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
/*
* 参数说明
tpImage 输入图像,可使用”eyemImageRead“接口读取图片(需与“eyemImageFree”配合使用),也可直接创建EyemImage对象。
tpRoi 感兴趣区域,尺寸不能小于iSymbolMax。
fileName 文件名,可不填。
strCodeType 所要识别条码类型,“QRCode|DataMatrix|CODE_128”等等。
hObject 结果释放句柄,配合eyemDetectAndDecodeFree使用
tpResults 识别结果
ipNum 结果数量
bUseNiBlack 使用NiBlack二值化,默认值 false。
iBlockSize 定位块大小(奇数),略大于最大定位块(只二维码),佳世达一般设置为11。
iRangeC 搜索范围,范围越大识别越好时间也相应越长,佳世达一般设置为5。
iSymbolMin 最小二维码尺寸,默认128。
iSymbolMax 最大二维码尺寸,佳世达一般设置为215。
dScaleUpAndDown 缩放,<1表示缩小,>1表示放大,=1表示不缩放
dToleErr 最大允许误差默认50%,越小越严格但可能会识别不到。
dMinorStep 步进,默认1.0。
//返回值
-3 图像不存在
-1 内存不足
0 正常
-100 未识别到条码或参数设置不正确
*/
/// <summary>
/// 读取图像
/// </summary>
......
......@@ -48,7 +48,7 @@
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\log4net.dll</HintPath>
<HintPath>..\..\..\增广夹爪\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
......
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!