| | |
| | | /// <summary> |
| | | /// 读写锁 |
| | | /// </summary> |
| | | public readonly object lockObj = new object(); |
| | | public static readonly object lockObj = new object(); |
| | | |
| | | /// <summary> |
| | | /// 裁切图片为hoDomainImage(保留原坐标系,其余填充为空) |
| | |
| | | Result = true; |
| | | bCompleted = false; |
| | | 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(); |
| | |
| | | else |
| | | { |
| | | throw new ArgumentException($"Mat2HObject不支持的图像格式:{mat.Type()}"); |
| | | return; |
| | | } |
| | | return; |
| | | } |
| | |
| | | HOperatorSet.GenImageConst(out image, "real", hv_xMax + 1, hv_yMax + 1); |
| | | HOperatorSet.SetGrayval(image, hv_y, hv_x, hv_z); |
| | | |
| | | //hoperatorset.getimagesize(ho_image, out htuple hv_width, out htuple hv_height); |
| | | //hoperatorset.genrectangle1(out hobject ho_rectangle, 0, 0, hv_height - 1, hv_width - 1); |
| | | //hoperatorset.getregionpoints(ho_rectangle, out htuple hv_rows, out htuple hv_columns); |
| | | //hoperatorset.getgrayval(ho_image, hv_rows, hv_columns, out htuple hv_z); |
| | | //HOperatorSet.GetImageSize(ho_Image, out HTuple hv_Width, out HTuple hv_Height); |
| | | //HOperatorSet.GenRectangle1(out HObject ho_Rectangle, 0, 0, hv_Height - 1, hv_Width - 1); |
| | | //HOperatorSet.GetRegionPoints(ho_Rectangle, out HTuple hv_Rows, out HTuple hv_Columns); |
| | | //HOperatorSet.GetGrayval(ho_Image, hv_Rows, hv_Columns, out HTuple hv_Z); |
| | | } |
| | | catch { image = null; } |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 图像增强算法-边缘增强 |
| | | /// </summary> |
| | | /// <param name="ho_Image">待测图片</param> |
| | | /// <param name="hv_Wid">掩膜宽</param> |
| | | /// <param name="hv_High">掩膜高</param> |
| | | /// <param name="hv_Fac">增强因子</param> |
| | | /// <param name="hv_Row1">起始纵坐标</param> |
| | | /// <param name="hv_Column1">起始横坐标</param> |
| | | /// <param name="hv_Row2">结束纵坐标</param> |
| | | /// <param name="hv_Column2">结束横坐标</param> |
| | | public static void ImageEnhancement(HObject ho_Image, out HObject ho_OutImage, HTuple hv_ImageEnhancementType, HTuple hv_Wid, HTuple hv_High, HTuple hv_Fac) |
| | | { |
| | | HOperatorSet.GenEmptyObj(out ho_OutImage); |
| | | try |
| | | { |
| | | HTuple hv_ImageEnhancementTypeOut = new HTuple(); |
| | | hv_ImageEnhancementTypeOut.Dispose(); |
| | | hv_ImageEnhancementTypeOut = new HTuple(hv_ImageEnhancementType); |
| | | |
| | | hv_Wid.Dispose(); |
| | | hv_High.Dispose(); |
| | | ho_OutImage.Dispose(); |
| | | |
| | | //设置图像增强算法 |
| | | if ((int)(new HTuple(hv_ImageEnhancementTypeOut.TupleEqual("emphasize"))) != 0) |
| | | { |
| | | hv_ImageEnhancementTypeOut.Dispose(); |
| | | hv_ImageEnhancementTypeOut = "emphasize"; |
| | | HOperatorSet.Emphasize(ho_Image, out ho_OutImage, hv_Wid, hv_High, hv_Fac); |
| | | } |
| | | else if ((int)(new HTuple(hv_ImageEnhancementTypeOut.TupleEqual("equHisto"))) != 0) |
| | | { |
| | | hv_ImageEnhancementTypeOut.Dispose(); |
| | | hv_ImageEnhancementTypeOut = "equHisto"; |
| | | HOperatorSet.ScaleImageMax(ho_Image, out ho_OutImage); |
| | | } |
| | | else |
| | | { |
| | | hv_ImageEnhancementTypeOut.Dispose(); |
| | | hv_ImageEnhancementTypeOut = "scaleMax"; |
| | | HOperatorSet.EquHistoImage(ho_Image, out ho_OutImage); |
| | | } |
| | | return; |
| | | } |
| | | catch (HalconException HDevExpDefaultException) |
| | | { |
| | | |
| | | hv_Wid.Dispose(); |
| | | hv_High.Dispose(); |
| | | |
| | | throw HDevExpDefaultException; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 卡尺算法 |
| | | /// </summary> |
| | | /// <param name="ho_Image">待测图片</param> |