Commit d543ae03 刘韬

1

1 个父辈 ed43b30d
此文件类型无法预览
此文件太大,无法显示。
......@@ -153,16 +153,20 @@ namespace Asa.Barcode
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
HOperatorSet.Rgb1ToGray(hObj, out HObject grayImage);
//HOperatorSet.ScaleImage(grayImage1, out HObject grayImage, 1.2, -45);
//grayImage1.Dispose();
HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out HTuple hv_BarCode); //创建条码模型
HOperatorSet.SetBarCodeParam(hv_BarCode, "num_scanlines", 5); //扫描线的最大数量
HOperatorSet.SetBarCodeParam(hv_BarCode, "min_identical_scanlines", 3); //成功解码最少扫描线数量
HOperatorSet.SetBarCodeParam(hv_BarCode, "start_stop_tolerance", "high"); //扫描线的起点和终点的容许误差,high误差大,low误差小
//HOperatorSet.SetBarCodeParam(hv_BarCode, "start_stop_tolerance", "high"); //扫描线的起点和终点的容许误差,high误差大,low误差小
HOperatorSet.SetBarCodeParam(hv_BarCode, "max_diff_orient", 5); //条码相邻两条竖条边缘扭曲的最大角度容差
HOperatorSet.FindBarCode(grayImage, out HObject symbolRegions, hv_BarCode, "auto", out HTuple hv_String); //寻找条码
HOperatorSet.GetBarCodeResult(hv_BarCode, "all", "decoded_types", out HTuple hv_Type); //获取条码类型
HOperatorSet.GetBarCodeResult(hv_BarCode, "all", "orientation", out HTuple hv_Orientation); //获取条码方向,x轴逆时针[0,180],顺时针[0,-180]
HOperatorSet.SmallestRectangle2(symbolRegions, out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2);
HOperatorSet.ClearBarCodeModel(hv_BarCode); //清除条码模型
symbolRegions.Dispose();
grayImage.Dispose();
stopwatch.Stop();
Common.log.Info("Halcon Extract1DCode Count=" + hv_String.Length + " time:" + stopwatch.ElapsedMilliseconds);
......
......@@ -236,6 +236,18 @@ namespace Asa.Camera
}
return result.ToArray();
}
/// <summary>
/// 按索引获取当前图像
/// </summary>
/// <returns></returns>
public Bitmap GetImage(int index)
{
if (cameraAll[0].Count == 0)
return null;
cameraAll[0].GrabOne(index, out Bitmap bmp);
return bmp;
}
/// <summary>
/// 获取当前图像
......
......@@ -6,6 +6,9 @@ using System.Drawing;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using CameraVisionLib.Model;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
namespace Asa.HIK
{
......@@ -305,8 +308,6 @@ namespace Asa.HIK
private bool LoginDevice(int idx)
{
try
......@@ -450,19 +451,22 @@ namespace Asa.HIK
private bool GrabDevice(int idx, out Bitmap bmp)
{
if (info[idx].Preview == IntPtr.Zero)
{
bmp = null;
try
{
uint lpSizeReturned = 0;
uint dwPicSize = 800000;
uint dwPicSize = 10000000;
byte[] sJpegPicBuffer = new byte[dwPicSize];
IPCameraAPI.NET_DVR_JPEGPARA lpJpegPara = new() { wPicQuality = 0, wPicSize = 0xff };
bool rtn = IPCameraAPI.NET_DVR_CaptureJPEGPicture_NEW(info[idx].ID, 1, ref lpJpegPara, sJpegPicBuffer, dwPicSize, ref lpSizeReturned);
if (rtn)
{
System.IO.MemoryStream ms = new(sJpegPicBuffer, 0, (int)lpSizeReturned);
byte[] newbuf = new byte[(int)lpSizeReturned];
Buffer.BlockCopy(sJpegPicBuffer, 0, newbuf, 0, newbuf.Count());
System.IO.MemoryStream ms = new(newbuf, 0, newbuf.Count());
bmp = new Bitmap(System.Drawing.Image.FromStream(ms));
info[idx].Width = bmp.Width;
info[idx].Height = bmp.Height;
......@@ -479,48 +483,78 @@ namespace Asa.HIK
Common.log.Error(className + " GrabDevice", ex);
return false;
}
}
else
{
//以下为使用保存文件的方式读取
//bmp = null;
//string path = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName();
bmp = null;
string path = System.IO.Path.GetTempPath() + "HIK" + System.IO.Path.GetRandomFileName();
//try
//{
// IPCameraAPI.NET_DVR_JPEGPARA lpJpegPara = new()
// {
// wPicQuality = 0, //图片质量系数 0最好 1较好 2一般
// wPicSize = 0xff //Auto使用当前码流分辨率
// };
// bool rtn = IPCameraAPI.NET_DVR_CaptureJPEGPicture(info[idx].ID, 1, ref lpJpegPara, path);
// if (rtn)
// {
// System.IO.FileStream fs = new(path, System.IO.FileMode.Open);
// byte[] array = new byte[fs.Length];
// fs.Read(array, 0, array.Length);
// System.IO.MemoryStream ms = new(array);
// bmp = new Bitmap(System.Drawing.Image.FromStream(ms));
// info[idx].Width = bmp.Width;
// info[idx].Height = bmp.Height;
// fs.Dispose();
// System.IO.File.Delete(path);
// Common.log.Info(string.Format("{0} GrabOne OK, IP={1}", className, info[idx].IP));
// }
// else
// {
// uint err = IPCameraAPI.NET_DVR_GetLastError();
// Common.log.Info(string.Format("{0} GrabOne failed, IP={1}, errorcode={2}", className, info[idx].IP, err));
// }
// return rtn;
//}
//catch (Exception ex)
//{
// Common.log.Error(className + " GrabDevice", ex);
// return false;
//}
}
try
{
IPCameraAPI.NET_DVR_JPEGPARA lpJpegPara = new()
{
wPicQuality = 0, //图片质量系数 0最好 1较好 2一般
wPicSize = 0xff //Auto使用当前码流分辨率
};
bool rtn = IPCameraAPI.NET_DVR_CapturePicture(info[idx].ID, path);
if (rtn)
{
Thread.Sleep(100);
int i = 0;
for (i = 0; i < 100; i++)
{
try
{
var a = new Bitmap(path);
bmp = DeepClone(a);
a.Dispose();
break;
}
catch
{
Thread.Sleep(100);
}
}
//System.IO.FileStream fs = new(path, System.IO.FileMode.Open);
//byte[] array = new byte[fs.Length];
//fs.Read(array, 0, array.Length);
//System.IO.MemoryStream ms = new(array);
//bmp = new Bitmap(System.Drawing.Image.FromStream(ms));
//info[idx].Width = bmp.Width;
//info[idx].Height = bmp.Height;
//fs.Dispose();
System.IO.File.Delete(path);
Common.log.Info(string.Format("{0} GrabOne OK, IP={1}", className, info[idx].IP) + ",i:" + i);
}
else
{
uint err = IPCameraAPI.NET_DVR_GetLastError();
Common.log.Info(string.Format("{0} GrabOne failed, IP={1}, errorcode={2}", className, info[idx].IP, err));
}
return rtn;
}
catch (Exception ex)
{
Common.log.Error(className + " GrabDevice", ex);
return false;
}
}
}
public static T DeepClone<T>(T _object)
{
T dstobject;
using (MemoryStream mStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, _object);
mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
dstobject = (T)bf.Deserialize(mStream);
mStream.Close();
}
return dstobject;
}
private bool GrabDevice(int idx, out byte[] buff, out PixelFormat format)
{
buff = null;
......
......@@ -415,7 +415,7 @@ namespace Asa.HIK
byte[] buffArr = new byte[buffSize];
IntPtr pData = Marshal.UnsafeAddrOfPinnedArrayElement(dataArr, 0);
MyCamera.MV_FRAME_OUT_INFO_EX stFrameInfo = new();
result = cameraCurr[idx].MV_CC_GetOneFrameTimeout_NET(pData, dataSize, ref stFrameInfo, 100000);
result = cameraCurr[idx].MV_CC_GetOneFrameTimeout_NET(pData, dataSize, ref stFrameInfo, 5000);
if (result != MyCamera.MV_OK)
{
Common.log.Info(string.Format("{0} MV_CC_GetOneFrameTimeout_NET failed,{1}", cameraName[idx], result));
......
......@@ -289,6 +289,12 @@
</summary>
<returns></returns>
</member>
<member name="M:Asa.Camera.VisionLib.GetImage(System.Int32)">
<summary>
按索引获取当前图像
</summary>
<returns></returns>
</member>
<member name="M:Asa.Camera.VisionLib.GetImage(System.String)">
<summary>
获取当前图像
......
......@@ -289,6 +289,12 @@
</summary>
<returns></returns>
</member>
<member name="M:Asa.Camera.VisionLib.GetImage(System.Int32)">
<summary>
按索引获取当前图像
</summary>
<returns></returns>
</member>
<member name="M:Asa.Camera.VisionLib.GetImage(System.String)">
<summary>
获取当前图像
......
此文件太大,无法显示。
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!