C#实现Halcon中绘制矩形并解码
图像结果
说明
- 原图像显示在PictureBox控件中,并把绘制区域显示在另外的PictureBox控件中
- 绘制二维码存在区域,对区域内容进行解码,根据区域区分二维码先后
- 能够区分镜像码、区分码版本、区分容错率、解码时间、设置超时时间
绘制矩形
public void Draw_Reactangle2(HObject ho_Image, out HObject ho_Rectangle)
{
HTuple hv_Row3 = null, hv_Column3 = null, hv_Phi = null;
HTuple hv_Length1 = null, hv_Length2 = null;
HOperatorSet.GenEmptyObj(out ho_Rectangle);
HOperatorSet.DrawRectangle1(hv_WindowHandle, out hv_Row3, out hv_Column3, out hv_Length1, out hv_Length2);
ho_Rectangle.Dispose();
HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row3, hv_Column3, hv_Length1,
hv_Length2);
HOperatorSet.DispObj(ho_Rectangle, hv_WindowHandle);
}
解码Halcon可直接导出C#
public void Vision_Inspection(HObject ho_Image, HObject ho_Rectangle, HTuple hv_DataCodeHandle, HTuple hv_row, HTuple hv_col, string type, HTuple hv_other_window = null)
{
//HOperatorSet.DispObj(ho_Image, hv_WindowHandle);
HTuple hv_ResultHandles = new HTuple(), hv_DecodedDataStrings = new HTuple();
HObject ho_TemplateImage = null, ho_SymbolXLDs = null;
HTuple hv_T2 = new HTuple(), hv_Time = new HTuple(), hv_ResultMessage = new HTuple(), hv_T1 = new HTuple();
HTuple hv_i = new HTuple(), hv_ResultVariousNames = new HTuple();
HTuple hv_ResultVariousNames_cn = new HTuple(), hv_ResultVariousValues = new HTuple();
HTuple hv_c = new HTuple(), hv_VariousResults = new HTuple();
HOperatorSet.CountSeconds(out hv_T1);
HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_TemplateImage);
HOperatorSet.FindDataCode2d(ho_TemplateImage, out ho_SymbolXLDs, hv_DataCodeHandle, new HTuple(),new HTuple(), out hv_ResultHandles, out hv_DecodedDataStrings);
HOperatorSet.CountSeconds(out hv_T2);
hv_Time = 1000 * (hv_T2 - hv_T1);
hv_ResultMessage = ("Time: " + (hv_Time.TupleString(".2f"))) + " ms";
string decode = hv_DecodedDataStrings.S;
}