| | |
| | | using Newtonsoft.Json; |
| | | using HalconDotNet; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using OpenCvSharp; |
| | | using OpenCvSharp.Extensions; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Diagnostics; |
| | | using System.Text; |
| | |
| | | |
| | | Mat src = Cv2.ImRead(SN); |
| | | if (src != null && !src.Empty()) |
| | | OutputImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src); |
| | | OutputImage = src.ToBitmap(); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | times--; |
| | | if (TriggerSource == TriggerSource.Software) |
| | | { |
| | | Camera.GetImageWithSoftTrigger(out bitmap, timeout); |
| | | } |
| | | else |
| | | { |
| | | Camera.GetImage(out bitmap, timeout); |
| | | |
| | | } |
| | | if (bitmap != null) |
| | | { |
| | | break; |
| | | } |
| | | else if (isRegrab) |
| | | { |
| | | Debug.WriteLine($"取图失败,重新取图,剩余次数:{times}"); |
| | |
| | | } while (times > 0 && isRegrab); |
| | | |
| | | if (isUpParams) |
| | | { |
| | | Camera.SetCamConfig(oriConfig); |
| | | |
| | | } |
| | | OutputImage = bitmap; |
| | | } |
| | | |
| | |
| | | { |
| | | Result = true; |
| | | Msg = ""; |
| | | OutputImage = null; |
| | | if (OutputImage != null) |
| | | { |
| | | if (OutputImage is HObject) |
| | | ((HObject)OutputImage).Dispose(); |
| | | else if (OutputImage is Mat) |
| | | ((Mat)OutputImage).Dispose(); |
| | | else if (OutputImage is Bitmap) |
| | | ((Bitmap)OutputImage).Dispose(); |
| | | |
| | | OutputImage = null; |
| | | } |
| | | if (Record != null) |
| | | { |
| | | Record.Dispose(); |
| | | Record = null; |
| | | } |
| | | } |
| | | |
| | | public override void Dispose() |
| | | { |
| | | if (InputImage != null) |
| | | { |
| | | if (InputImage is HObject) |
| | | ((HObject)InputImage).Dispose(); |
| | | else if (InputImage is Mat) |
| | | ((Mat)InputImage).Dispose(); |
| | | else if (InputImage is Bitmap) |
| | | ((Bitmap)InputImage).Dispose(); |
| | | |
| | | InputImage = null; |
| | | } |
| | | |
| | | if (OutputImage != null) |
| | | { |
| | | if (OutputImage is HObject) |
| | | ((HObject)OutputImage).Dispose(); |
| | | else if (OutputImage is Mat) |
| | | ((Mat)OutputImage).Dispose(); |
| | | else if (OutputImage is Bitmap) |
| | | ((Bitmap)OutputImage).Dispose(); |
| | | |
| | | OutputImage = null; |
| | | } |
| | | return; |
| | | } |
| | | |
| | |
| | | if (OutputImage != null) |
| | | { |
| | | if (OutputImage is Bitmap) |
| | | { |
| | | obj.OutputImage = ((Bitmap)OutputImage).Clone(); |
| | | } |
| | | } |
| | | |
| | | return obj; |