/// <summary> /// 第一帧条码图像需要setconfig /// </summary> public void SetConfig() { MvSMattingConfigParam omConfigParam = MvSMattingConfigParam.GetInstance(); MVAPI.mattingGetConfig(m_handle, ref omConfigParam); omConfigParam.isEmphasis = 2; //参数可自定义 omConfigParam.isNewPackage = 1; //参数可自定义 omConfigParam.offsetHorizon = 0; //参数可自定义 omConfigParam.offsetVertical = 0; //参数可自定义 MVAPI.mattingSetConfig(m_handle, ref omConfigParam); }
/// <summary> /// 主处理函数 /// </summary> /// <param name="bmp">传入图片</param> /// <param name="mcList">条码信息</param> /// <returns>传出图片</returns> public void MattingProcess(System.Drawing.Bitmap bmp, List <MvBarCode.MvCodeInfo> mcList) { MvSMattingProcessParam omParam = MvSMattingProcessParam.GetInstance(); _omResult = MvSMattingProcessResult.GetInstance(); Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); var ptrImage = bmpData.Scan0; MvsCommon.MvSImage img = MvsCommon.MvSImage.GetInstance(); img.Height = bmp.Height; img.Width = bmp.Width; img.ImageData = ptrImage; img.DataType = Convert.ToInt32(MvsImgDataType.MVS_IMGDTP_U8); img.Type = Convert.ToInt32(MvsImgType.MVS_IMGTP_UITL_Y); omParam.pSrcImg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvsCommon.MvSImage))); Marshal.StructureToPtr(img, omParam.pSrcImg, false); var ptrPoint = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvsCommon.MvSPoint)) * 12); for (int j = 0; j < mcList.Count; j++) { for (int i = 0; i < mcList[j].Region.PtArray.Length; i++) { MvsCommon.MvSPoint pt; pt.x = mcList[j].Region.PtArray[i].X; pt.y = mcList[j].Region.PtArray[i].Y; Marshal.StructureToPtr(pt, ptrPoint + Marshal.SizeOf(typeof(MvsCommon.MvSPoint)) * i, false); } } omParam.pCodePos = ptrPoint; omParam.nCode = 1; MVAPI.mattingProcess(m_handle, ref omParam, ref _omResult); bmp.UnlockBits(bmpData); }
/// <summary> /// 初始化 /// </summary> /// <param name="width">图像宽</param> /// <param name="height">图像高</param> /// <returns></returns> public bool InitAlgorithm(Int32 width, Int32 height) { MvSMattingChannelParam omChannelParam = MvSMattingChannelParam.GetInstance(); omChannelParam.imgWidth = width; omChannelParam.imgHeight = height; //计算所需内存大小 int memChannelSize = MVAPI.mattingCalMemSize(ref omChannelParam); m_handle = Marshal.AllocHGlobal(memChannelSize); //初始化 int nResult = MVAPI.mattingInit(m_handle, ref omChannelParam); if (nResult > memChannelSize) { MVAPI.mattingExit(m_handle); return(false); } return(true); }
/// <summary> /// dispose /// </summary> public void Dispose() { MVAPI.mattingExit(m_handle); Marshal.FreeHGlobal(m_handle); }
public void SaveMattingPicture(string path, int ResizeRate) { MVAPI.mattingCompress(m_handle, _omResult.pSheetImg, ResizeRate, path); }