| | |
| | | image = bmp; |
| | | return true; |
| | | } |
| | | else if (InputImage is HObject ho_image) |
| | | { |
| | | if (!ho_image.IsInitialized()) |
| | | return false; |
| | | |
| | | if (Params.Fixture == null) |
| | | Params.Fixture = new Fixture(); |
| | | |
| | | HObject hoDomainImage = null; |
| | | |
| | | switch (Params.ROI?.GetType().Name) |
| | | { |
| | | case "HRectangle2": |
| | | HOperatorSet.GenRectangle2(out HObject hRectangle2, (HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)(Params.ROI.Phi + Params.Fixture.Phi), (HTuple)((HRectangle2)Params.ROI).SemiLength1, (HTuple)((HRectangle2)Params.ROI).SemiLength2); |
| | | HOperatorSet.ReduceDomain(ho_image, hRectangle2, out hoDomainImage); |
| | | break; |
| | | case "HCircle": |
| | | HOperatorSet.GenCircle(out HObject hCircle, (HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)((HCircle)Params.ROI).Radius); |
| | | HOperatorSet.ReduceDomain(ho_image, hCircle, out hoDomainImage); |
| | | break; |
| | | case "ROI": |
| | | default: |
| | | image = ho_image.CopyObj(1, -1); |
| | | return true; |
| | | } |
| | | |
| | | image = hoDomainImage; |
| | | return true; |
| | | } |
| | | else if (InputImage is Mat) |
| | | { |
| | | Mat src = ((Mat)InputImage); |
| | |
| | | } |
| | | } |
| | | |
| | | public virtual bool ReduceDomainImage(object InputImage, ref HImage image) |
| | | { |
| | | image = null; |
| | | if (InputImage == null) |
| | | { |
| | | image = null; |
| | | Msg = "输入图片为空"; |
| | | Result = false; |
| | | return false; |
| | | } |
| | | |
| | | lock (InputImage) |
| | | { |
| | | try |
| | | { |
| | | if (InputImage is HImage ho_image) |
| | | { |
| | | if (!ho_image.IsInitialized()) |
| | | return false; |
| | | |
| | | if (Params.Fixture == null) |
| | | Params.Fixture = new Fixture(); |
| | | |
| | | HImage hoDomainImage = null; |
| | | |
| | | switch (Params.ROI?.GetType().Name) |
| | | { |
| | | case "HRectangle2": |
| | | using (HRegion hRectangle2 = new HRegion()) |
| | | { |
| | | hRectangle2.GenRectangle2((HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)(Params.ROI.Phi + Params.Fixture.Phi), (HTuple)((HRectangle2)Params.ROI).SemiLength1, (HTuple)((HRectangle2)Params.ROI).SemiLength2); |
| | | hoDomainImage = ho_image.ReduceDomain(hRectangle2); |
| | | } |
| | | break; |
| | | case "HCircle": |
| | | using (HRegion hCircle = new HRegion()) |
| | | { |
| | | hCircle.GenCircle((HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)((HCircle)Params.ROI).Radius); |
| | | hoDomainImage = ho_image.ReduceDomain(hCircle); |
| | | } |
| | | break; |
| | | case "ROI": |
| | | default: |
| | | image = ho_image.CopyObj(1, -1); |
| | | return true; |
| | | } |
| | | |
| | | image = hoDomainImage; |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | image = null; |
| | | Msg = $"输入格式不正确{InputImage.GetType()}"; |
| | | Result = false; |
| | | return false; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | image = null; |
| | | Msg = $"裁剪区域失败,原因是:{ex.ToString()}"; |
| | | Result = false; |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public override void Dispose() |
| | | { |
| | | if (InputImage != null) |
| | |
| | | Result = true; |
| | | bCompleted = false; |
| | | Msg = string.Empty; |
| | | 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 (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 (Record != null) |
| | | { |
| | | Record.Dispose(); |
| | |
| | | HImage image = null; |
| | | try |
| | | { |
| | | if (bmp == null || bmp.Width == 0 || bmp.Height == 0) |
| | | if (bmp.Tag != null && bmp == null || bmp.Width == 0 || bmp.Height == 0) |
| | | { |
| | | image = null; |
| | | return image; |
| | | } |
| | | |
| | | lock (bmp) |
| | | { |
| | | image = new HImage(); |