private static HTuple TupleFind2(HTuple t1, HTuple t2) { HTuple htuple = t1.TupleFind(t2); if (htuple.Length > 0 && htuple[0].I == -1) { htuple = new HTuple(); } return(htuple); }
/// <summary> /// Returns an HTuple with only unique elements. /// </summary> /// <param name="input">The input HTuple.</param> /// <returns>The output HTuple.</returns> public static HTuple Unique(HTuple input) { HTuple output = new HTuple(); int count = input.Length; if (input.Length > 0) { output = output.TupleConcat(input[0]); for (int i = 0; i < count; i++) { if (output.TupleFind(input[i]) == -1) { output = output.TupleConcat(input[i]); } } } return(output); }
// Chapter: Graphics / Text // Short Description: Set font independent of OS public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold, HTuple hv_Slant) { // Local control variables HTuple hv_OS, hv_Exception = new HTuple(); HTuple hv_AllowedFontSizes = new HTuple(), hv_Distances = new HTuple(); HTuple hv_Indices = new HTuple(); HTuple hv_Bold_COPY_INP_TMP = hv_Bold.Clone(); HTuple hv_Font_COPY_INP_TMP = hv_Font.Clone(); HTuple hv_Size_COPY_INP_TMP = hv_Size.Clone(); HTuple hv_Slant_COPY_INP_TMP = hv_Slant.Clone(); // Initialize local and output iconic variables //This procedure sets the text font of the current window with //the specified attributes. //It is assumed that following fonts are installed on the system: //Windows: Courier New, Arial Times New Roman //Linux: courier, helvetica, times //Because fonts are displayed smaller on Linux than on Windows, //a scaling factor of 1.25 is used the get comparable results. //For Linux, only a limited number of font sizes is supported, //to get comparable results, it is recommended to use one of the //following sizes: 9, 11, 14, 16, 20, 27 //(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34) // //input parameters: //WindowHandle: The graphics window for which the font will be set //Size: The font size. If Size=-1, the default of 16 is used. //Bold: If set to 'true', a bold font is used //Slant: If set to 'true', a slanted font is used // HOperatorSet.GetSystem("operating_system", out hv_OS); if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0) { hv_Size_COPY_INP_TMP = 16; } if ((int)(new HTuple((((hv_OS.TupleStrFirstN(2)).TupleStrLastN(0))).TupleEqual( "Win"))) != 0) { //set font on Windows systems if ((int)((new HTuple((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr( new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual( "courier")))) != 0) { hv_Font_COPY_INP_TMP = "Courier New"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Font_COPY_INP_TMP = "Arial"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Font_COPY_INP_TMP = "Times New Roman"; } if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Bold_COPY_INP_TMP = 1; } else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Bold_COPY_INP_TMP = 0; } else { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Slant_COPY_INP_TMP = 1; } else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Slant_COPY_INP_TMP = 0; } else { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } try { HOperatorSet.SetFont(hv_WindowHandle, ((((((("-" + hv_Font_COPY_INP_TMP) + "-") + hv_Size_COPY_INP_TMP) + "-*-") + hv_Slant_COPY_INP_TMP) + "-*-*-") + hv_Bold_COPY_INP_TMP) + "-"); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); throw new HalconException(hv_Exception); } } else { //set font for UNIX systems hv_Size_COPY_INP_TMP = hv_Size_COPY_INP_TMP * 1.25; hv_AllowedFontSizes = new HTuple(); hv_AllowedFontSizes[0] = 11; hv_AllowedFontSizes[1] = 14; hv_AllowedFontSizes[2] = 17; hv_AllowedFontSizes[3] = 20; hv_AllowedFontSizes[4] = 25; hv_AllowedFontSizes[5] = 34; if ((int)(new HTuple(((hv_AllowedFontSizes.TupleFind(hv_Size_COPY_INP_TMP))).TupleEqual( -1))) != 0) { hv_Distances = ((hv_AllowedFontSizes - hv_Size_COPY_INP_TMP)).TupleAbs(); HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_Size_COPY_INP_TMP = hv_AllowedFontSizes.TupleSelect(hv_Indices.TupleSelect( 0)); } if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual( "Courier")))) != 0) { hv_Font_COPY_INP_TMP = "courier"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Font_COPY_INP_TMP = "helvetica"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Font_COPY_INP_TMP = "times"; } if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Bold_COPY_INP_TMP = "bold"; } else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Bold_COPY_INP_TMP = "medium"; } else { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0) { if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("times"))) != 0) { hv_Slant_COPY_INP_TMP = "i"; } else { hv_Slant_COPY_INP_TMP = "o"; } } else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Slant_COPY_INP_TMP = "r"; } else { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } try { HOperatorSet.SetFont(hv_WindowHandle, ((((((("-adobe-" + hv_Font_COPY_INP_TMP) + "-") + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*"); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); throw new HalconException(hv_Exception); } } return; }
public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold, HTuple hv_Slant) { // Local iconic variables // Local control variables HTuple hv_OS = null, hv_Fonts = new HTuple(); HTuple hv_Style = null, hv_Exception = new HTuple(), hv_AvailableFonts = null; HTuple hv_Fdx = null, hv_Indices = new HTuple(); HTuple hv_Font_COPY_INP_TMP = hv_Font.Clone(); HTuple hv_Size_COPY_INP_TMP = hv_Size.Clone(); // Initialize local and output iconic variables //This procedure sets the text font of the current window with //the specified attributes. // //Input parameters: //WindowHandle: The graphics window for which the font will be set //Size: The font size. If Size=-1, the default of 16 is used. //Bold: If set to 'true', a bold font is used //Slant: If set to 'true', a slanted font is used // HOperatorSet.GetSystem("operating_system", out hv_OS); // dev_get_preferences(...); only in hdevelop // dev_set_preferences(...); only in hdevelop if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0) { hv_Size_COPY_INP_TMP = 16; } if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0) { //Restore previous behaviour hv_Size_COPY_INP_TMP = ((1.13677 * hv_Size_COPY_INP_TMP)).TupleInt(); } if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "Courier"; hv_Fonts[1] = "Courier 10 Pitch"; hv_Fonts[2] = "Courier New"; hv_Fonts[3] = "CourierNew"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "Consolas"; hv_Fonts[1] = "Menlo"; hv_Fonts[2] = "Courier"; hv_Fonts[3] = "Courier 10 Pitch"; hv_Fonts[4] = "FreeMono"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "Luxi Sans"; hv_Fonts[1] = "DejaVu Sans"; hv_Fonts[2] = "FreeSans"; hv_Fonts[3] = "Arial"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "Times New Roman"; hv_Fonts[1] = "Luxi Serif"; hv_Fonts[2] = "DejaVu Serif"; hv_Fonts[3] = "FreeSerif"; hv_Fonts[4] = "Utopia"; } else { hv_Fonts = hv_Font_COPY_INP_TMP.Clone(); } hv_Style = ""; if ((int)(new HTuple(hv_Bold.TupleEqual("true"))) != 0) { hv_Style = hv_Style + "Bold"; } else if ((int)(new HTuple(hv_Bold.TupleNotEqual("false"))) != 0) { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant.TupleEqual("true"))) != 0) { hv_Style = hv_Style + "Italic"; } else if ((int)(new HTuple(hv_Slant.TupleNotEqual("false"))) != 0) { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Style.TupleEqual(""))) != 0) { hv_Style = "Normal"; } HOperatorSet.QueryFont(hv_WindowHandle, out hv_AvailableFonts); hv_Font_COPY_INP_TMP = ""; for (hv_Fdx = 0; (int)hv_Fdx <= (int)((new HTuple(hv_Fonts.TupleLength())) - 1); hv_Fdx = (int)hv_Fdx + 1) { hv_Indices = hv_AvailableFonts.TupleFind(hv_Fonts.TupleSelect(hv_Fdx)); if ((int)(new HTuple((new HTuple(hv_Indices.TupleLength())).TupleGreater(0))) != 0) { if ((int)(new HTuple(((hv_Indices.TupleSelect(0))).TupleGreaterEqual(0))) != 0) { hv_Font_COPY_INP_TMP = hv_Fonts.TupleSelect(hv_Fdx); break; } } } if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(""))) != 0) { throw new HalconException("Wrong value of control parameter Font"); } hv_Font_COPY_INP_TMP = (((hv_Font_COPY_INP_TMP + "-") + hv_Style) + "-") + hv_Size_COPY_INP_TMP; HOperatorSet.SetFont(hv_WindowHandle, hv_Font_COPY_INP_TMP); // dev_set_preferences(...); only in hdevelop return; }
public void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth) { HObject[] OTemp = new HObject[20]; HObject ho_TempArrow = null; HTuple hv_Length = null, hv_ZeroLengthIndices = null; HTuple hv_DR = null, hv_DC = null, hv_HalfHeadWidth = null; HTuple hv_RowP1 = null, hv_ColP1 = null, hv_RowP2 = null; HTuple hv_ColP2 = null, hv_Index = null; HOperatorSet.GenEmptyObj(out ho_Arrow); HOperatorSet.GenEmptyObj(out ho_TempArrow); ho_Arrow.Dispose(); HOperatorSet.GenEmptyObj(out ho_Arrow); HOperatorSet.DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Length); hv_ZeroLengthIndices = hv_Length.TupleFind(0); if ((int)(new HTuple(hv_ZeroLengthIndices.TupleNotEqual(-1))) != 0) { if (hv_Length == null) { hv_Length = new HTuple(); } hv_Length[hv_ZeroLengthIndices] = -1; } hv_DR = (1.0 * (hv_Row2 - hv_Row1)) / hv_Length; hv_DC = (1.0 * (hv_Column2 - hv_Column1)) / hv_Length; hv_HalfHeadWidth = hv_HeadWidth / 2.0; hv_RowP1 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) + (hv_HalfHeadWidth * hv_DC); hv_ColP1 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) - (hv_HalfHeadWidth * hv_DR); hv_RowP2 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) - (hv_HalfHeadWidth * hv_DC); hv_ColP2 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) + (hv_HalfHeadWidth * hv_DR); for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Length.TupleLength())) - 1); hv_Index = (int)hv_Index + 1) { if ((int)(new HTuple(((hv_Length.TupleSelect(hv_Index))).TupleEqual(-1))) != 0) { ho_TempArrow.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_TempArrow, hv_Row1.TupleSelect(hv_Index), hv_Column1.TupleSelect(hv_Index)); } else { ho_TempArrow.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_TempArrow, ((((((((((hv_Row1.TupleSelect( hv_Index))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat( hv_RowP1.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat( hv_RowP2.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)), ((((((((((hv_Column1.TupleSelect(hv_Index))).TupleConcat(hv_Column2.TupleSelect( hv_Index)))).TupleConcat(hv_ColP1.TupleSelect(hv_Index)))).TupleConcat( hv_Column2.TupleSelect(hv_Index)))).TupleConcat(hv_ColP2.TupleSelect( hv_Index)))).TupleConcat(hv_Column2.TupleSelect(hv_Index))); } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_Arrow, ho_TempArrow, out ExpTmpOutVar_0); ho_Arrow.Dispose(); ho_Arrow = ExpTmpOutVar_0; } } ho_TempArrow.Dispose(); return; }
// Chapter: Graphics / Text // Short Description: Set font independent of OS public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold, HTuple hv_Slant) { // Local iconic variables // Local control variables HTuple hv_OS = null, hv_BufferWindowHandle = new HTuple(); HTuple hv_Ascent = new HTuple(), hv_Descent = new HTuple(); HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); HTuple hv_Scale = new HTuple(), hv_Exception = new HTuple(); HTuple hv_SubFamily = new HTuple(), hv_Fonts = new HTuple(); HTuple hv_SystemFonts = new HTuple(), hv_Guess = new HTuple(); HTuple hv_I = new HTuple(), hv_Index = new HTuple(), hv_AllowedFontSizes = new HTuple(); HTuple hv_Distances = new HTuple(), hv_Indices = new HTuple(); HTuple hv_FontSelRegexp = new HTuple(), hv_FontsCourier = new HTuple(); HTuple hv_Bold_COPY_INP_TMP = hv_Bold.Clone(); HTuple hv_Font_COPY_INP_TMP = hv_Font.Clone(); HTuple hv_Size_COPY_INP_TMP = hv_Size.Clone(); HTuple hv_Slant_COPY_INP_TMP = hv_Slant.Clone(); // Initialize local and output iconic variables //This procedure sets the text font of the current window with //the specified attributes. //It is assumed that following fonts are installed on the system: //Windows: Courier New, Arial Times New Roman //Mac OS X: CourierNewPS, Arial, TimesNewRomanPS //Linux: courier, helvetica, times //Because fonts are displayed smaller on Linux than on Windows, //a scaling factor of 1.25 is used the get comparable results. //For Linux, only a limited number of font sizes is supported, //to get comparable results, it is recommended to use one of the //following sizes: 9, 11, 14, 16, 20, 27 //(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34) // //Input parameters: //WindowHandle: The graphics window for which the font will be set //Size: The font size. If Size=-1, the default of 16 is used. //Bold: If set to 'true', a bold font is used //Slant: If set to 'true', a slanted font is used // HOperatorSet.GetSystem("operating_system", out hv_OS); // dev_get_preferences(...); only in hdevelop // dev_set_preferences(...); only in hdevelop if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0) { hv_Size_COPY_INP_TMP = 16; } if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0) { //Set font on Windows systems try { //Check, if font scaling is switched on //open_window(...); HOperatorSet.SetFont(hv_ExpDefaultWinHandle, "-Consolas-16-*-0-*-*-1-"); HOperatorSet.GetStringExtents(hv_ExpDefaultWinHandle, "test_string", out hv_Ascent, out hv_Descent, out hv_Width, out hv_Height); //Expected width is 110 hv_Scale = 110.0 / hv_Width; hv_Size_COPY_INP_TMP = ((hv_Size_COPY_INP_TMP * hv_Scale)).TupleInt(); //close_window(...); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); //throw (Exception) } if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))).TupleOr( new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("courier")))) != 0) { hv_Font_COPY_INP_TMP = "Courier New"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0) { hv_Font_COPY_INP_TMP = "Consolas"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Font_COPY_INP_TMP = "Arial"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Font_COPY_INP_TMP = "Times New Roman"; } if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Bold_COPY_INP_TMP = 1; } else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Bold_COPY_INP_TMP = 0; } else { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Slant_COPY_INP_TMP = 1; } else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Slant_COPY_INP_TMP = 0; } else { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } try { HOperatorSet.SetFont(hv_ExpDefaultWinHandle, ((((((("-" + hv_Font_COPY_INP_TMP) + "-") + hv_Size_COPY_INP_TMP) + "-*-") + hv_Slant_COPY_INP_TMP) + "-*-*-") + hv_Bold_COPY_INP_TMP) + "-"); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); //throw (Exception) } } else if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Dar"))) != 0) { //Set font on Mac OS X systems. Since OS X does not have a strict naming //scheme for font attributes, we use tables to determine the correct font //name. hv_SubFamily = 0; if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_SubFamily = hv_SubFamily.TupleBor(1); } else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleNotEqual("false"))) != 0) { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_SubFamily = hv_SubFamily.TupleBor(2); } else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleNotEqual("false"))) != 0) { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "Menlo-Regular"; hv_Fonts[1] = "Menlo-Italic"; hv_Fonts[2] = "Menlo-Bold"; hv_Fonts[3] = "Menlo-BoldItalic"; } else if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))).TupleOr( new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("courier")))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "CourierNewPSMT"; hv_Fonts[1] = "CourierNewPS-ItalicMT"; hv_Fonts[2] = "CourierNewPS-BoldMT"; hv_Fonts[3] = "CourierNewPS-BoldItalicMT"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "ArialMT"; hv_Fonts[1] = "Arial-ItalicMT"; hv_Fonts[2] = "Arial-BoldMT"; hv_Fonts[3] = "Arial-BoldItalicMT"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Fonts = new HTuple(); hv_Fonts[0] = "TimesNewRomanPSMT"; hv_Fonts[1] = "TimesNewRomanPS-ItalicMT"; hv_Fonts[2] = "TimesNewRomanPS-BoldMT"; hv_Fonts[3] = "TimesNewRomanPS-BoldItalicMT"; } else { //Attempt to figure out which of the fonts installed on the system //the user could have meant. HOperatorSet.QueryFont(hv_ExpDefaultWinHandle, out hv_SystemFonts); hv_Fonts = new HTuple(); hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP); hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP); hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP); hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP); hv_Guess = new HTuple(); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Regular"); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "MT"); for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1) { HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index); if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0) { if (hv_Fonts == null) { hv_Fonts = new HTuple(); } hv_Fonts[0] = hv_Guess.TupleSelect(hv_I); break; } } //Guess name of slanted font hv_Guess = new HTuple(); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Italic"); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-ItalicMT"); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Oblique"); for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1) { HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index); if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0) { if (hv_Fonts == null) { hv_Fonts = new HTuple(); } hv_Fonts[1] = hv_Guess.TupleSelect(hv_I); break; } } //Guess name of bold font hv_Guess = new HTuple(); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Bold"); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldMT"); for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1) { HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index); if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0) { if (hv_Fonts == null) { hv_Fonts = new HTuple(); } hv_Fonts[2] = hv_Guess.TupleSelect(hv_I); break; } } //Guess name of bold slanted font hv_Guess = new HTuple(); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldItalic"); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldItalicMT"); hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldOblique"); for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1) { HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index); if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0) { if (hv_Fonts == null) { hv_Fonts = new HTuple(); } hv_Fonts[3] = hv_Guess.TupleSelect(hv_I); break; } } } hv_Font_COPY_INP_TMP = hv_Fonts.TupleSelect(hv_SubFamily); try { HOperatorSet.SetFont(hv_ExpDefaultWinHandle, (hv_Font_COPY_INP_TMP + "-") + hv_Size_COPY_INP_TMP); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); //throw (Exception) } } else { //Set font for UNIX systems hv_Size_COPY_INP_TMP = hv_Size_COPY_INP_TMP * 1.25; hv_AllowedFontSizes = new HTuple(); hv_AllowedFontSizes[0] = 11; hv_AllowedFontSizes[1] = 14; hv_AllowedFontSizes[2] = 17; hv_AllowedFontSizes[3] = 20; hv_AllowedFontSizes[4] = 25; hv_AllowedFontSizes[5] = 34; if ((int)(new HTuple(((hv_AllowedFontSizes.TupleFind(hv_Size_COPY_INP_TMP))).TupleEqual( -1))) != 0) { hv_Distances = ((hv_AllowedFontSizes - hv_Size_COPY_INP_TMP)).TupleAbs(); HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_Size_COPY_INP_TMP = hv_AllowedFontSizes.TupleSelect(hv_Indices.TupleSelect( 0)); } if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual( "Courier")))) != 0) { hv_Font_COPY_INP_TMP = "courier"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Font_COPY_INP_TMP = "helvetica"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Font_COPY_INP_TMP = "times"; } if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Bold_COPY_INP_TMP = "bold"; } else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Bold_COPY_INP_TMP = "medium"; } else { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0) { if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("times"))) != 0) { hv_Slant_COPY_INP_TMP = "i"; } else { hv_Slant_COPY_INP_TMP = "o"; } } else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Slant_COPY_INP_TMP = "r"; } else { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } try { HOperatorSet.SetFont(hv_ExpDefaultWinHandle, ((((((("-adobe-" + hv_Font_COPY_INP_TMP) + "-") + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*"); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); if ((int)((new HTuple(((hv_OS.TupleSubstr(0, 4))).TupleEqual("Linux"))).TupleAnd( new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("courier")))) != 0) { HOperatorSet.QueryFont(hv_ExpDefaultWinHandle, out hv_Fonts); hv_FontSelRegexp = (("^-[^-]*-[^-]*[Cc]ourier[^-]*-" + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP; hv_FontsCourier = ((hv_Fonts.TupleRegexpSelect(hv_FontSelRegexp))).TupleRegexpMatch( hv_FontSelRegexp); if ((int)(new HTuple((new HTuple(hv_FontsCourier.TupleLength())).TupleEqual( 0))) != 0) { hv_Exception = "Wrong font name"; //throw (Exception) } else { try { HOperatorSet.SetFont(hv_ExpDefaultWinHandle, (((hv_FontsCourier.TupleSelect( 0)) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*"); } // catch (Exception) catch (HalconException HDevExpDefaultException2) { HDevExpDefaultException2.ToHTuple(out hv_Exception); //throw (Exception) } } } //throw (Exception) } } // dev_set_preferences(...); only in hdevelop return; }
static public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold, HTuple hv_Slant) { // Local control variables HTuple hv_OS, hv_Exception = new HTuple(); HTuple hv_AllowedFontSizes = new HTuple(), hv_Distances = new HTuple(); HTuple hv_Indices = new HTuple(); HTuple hv_Bold_COPY_INP_TMP = hv_Bold.Clone(); HTuple hv_Font_COPY_INP_TMP = hv_Font.Clone(); HTuple hv_Size_COPY_INP_TMP = hv_Size.Clone(); HTuple hv_Slant_COPY_INP_TMP = hv_Slant.Clone(); // Initialize local and output iconic variables //Slant: If set to 'true', a slanted font is used // HOperatorSet.GetSystem("operating_system", out hv_OS); if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr( new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0) { hv_Size_COPY_INP_TMP = 16; } if ((int)(new HTuple((((hv_OS.TupleStrFirstN(2)).TupleStrLastN(0))).TupleEqual( "Win"))) != 0) { //set font on Windows systems if ((int)((new HTuple((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr( new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual( "courier")))) != 0) { hv_Font_COPY_INP_TMP = "Courier New"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Font_COPY_INP_TMP = "Arial"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Font_COPY_INP_TMP = "Times New Roman"; } if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Bold_COPY_INP_TMP = 1; } else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Bold_COPY_INP_TMP = 0; } else { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Slant_COPY_INP_TMP = 1; } else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Slant_COPY_INP_TMP = 0; } else { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } try { HOperatorSet.SetFont(hv_WindowHandle, ((((((("-" + hv_Font_COPY_INP_TMP) + "-") + hv_Size_COPY_INP_TMP) + "-*-") + hv_Slant_COPY_INP_TMP) + "-*-*-") + hv_Bold_COPY_INP_TMP) + "-"); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); throw new HalconException(hv_Exception); } } else { //set font for UNIX systems hv_Size_COPY_INP_TMP = hv_Size_COPY_INP_TMP * 1.25; hv_AllowedFontSizes = new HTuple(); hv_AllowedFontSizes[0] = 11; hv_AllowedFontSizes[1] = 14; hv_AllowedFontSizes[2] = 17; hv_AllowedFontSizes[3] = 20; hv_AllowedFontSizes[4] = 25; hv_AllowedFontSizes[5] = 34; if ((int)(new HTuple(((hv_AllowedFontSizes.TupleFind(hv_Size_COPY_INP_TMP))).TupleEqual( -1))) != 0) { hv_Distances = ((hv_AllowedFontSizes - hv_Size_COPY_INP_TMP)).TupleAbs(); HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices); hv_Size_COPY_INP_TMP = hv_AllowedFontSizes.TupleSelect(hv_Indices.TupleSelect( 0)); } if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual( "Courier")))) != 0) { hv_Font_COPY_INP_TMP = "courier"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0) { hv_Font_COPY_INP_TMP = "helvetica"; } else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0) { hv_Font_COPY_INP_TMP = "times"; } if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0) { hv_Bold_COPY_INP_TMP = "bold"; } else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Bold_COPY_INP_TMP = "medium"; } else { hv_Exception = "Wrong value of control parameter Bold"; throw new HalconException(hv_Exception); } if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0) { if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("times"))) != 0) { hv_Slant_COPY_INP_TMP = "i"; } else { hv_Slant_COPY_INP_TMP = "o"; } } else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0) { hv_Slant_COPY_INP_TMP = "r"; } else { hv_Exception = "Wrong value of control parameter Slant"; throw new HalconException(hv_Exception); } try { HOperatorSet.SetFont(hv_WindowHandle, ((((((("-adobe-" + hv_Font_COPY_INP_TMP) + "-") + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*"); } // catch (Exception) catch (HalconException HDevExpDefaultException1) { HDevExpDefaultException1.ToHTuple(out hv_Exception); throw new HalconException(hv_Exception); } } return; }
public static bool InspectPinPos(St_InspectPinParam InspectPinParamIn, HObject ImgIn, out HTuple OffSetRows, out HTuple OffSetCols, out HTuple OffSetDist, out HObject PinContour, out HObject ErrorContour) { //1.0获得最新图片PIN针的中心坐标 OffSetRows = new HTuple(); OffSetCols = new HTuple(); OffSetDist = new HTuple(); ErrorContour = new HObject(); PinContour = new HObject(); #region //定义参数 if (InspectPinParamIn.Elements.Count() == 0 || InspectPinParamIn.Elements == null) { return(false); } double Element = InspectPinParamIn.Elements[0]; double DetectHight = InspectPinParamIn.DetectHeights[0]; double DtetectWidth = InspectPinParamIn.DetectWidths[0]; double LineRow1 = InspectPinParamIn.Row1s[0]; double LineCol1 = InspectPinParamIn.Col1s[0]; double LineRow2 = InspectPinParamIn.Row2s[0]; double LineCol2 = InspectPinParamIn.Col2s[0]; HObject DetectRegions = new HObject(); HObject RoiContour = new HObject(); double DnThreshold = InspectPinParamIn.DnThresholds[0]; double UpThreshold = InspectPinParamIn.UpThresholds[0]; double MinArea = InspectPinParamIn.MinAreas[0]; double MaxArea = InspectPinParamIn.MaxAreas[0]; #endregion HTuple PinRows = new HTuple(), PinCols = new HTuple(); for (int i = 0; i < InspectPinParamIn.Elements.Count(); i++) { #region 参数赋值 Element = InspectPinParamIn.Elements[i]; DetectHight = InspectPinParamIn.DetectHeights[i]; DtetectWidth = InspectPinParamIn.DetectWidths[i]; LineRow1 = InspectPinParamIn.Row1s[i]; LineCol1 = InspectPinParamIn.Col1s[i]; LineRow2 = InspectPinParamIn.Row2s[i]; LineCol2 = InspectPinParamIn.Col2s[i]; DnThreshold = InspectPinParamIn.DnThresholds[i]; UpThreshold = InspectPinParamIn.UpThresholds[i]; MinArea = InspectPinParamIn.MinAreas[i]; MaxArea = InspectPinParamIn.MaxAreas[i]; #endregion //1.1 生成单行Pin针ROI MyVisionBase.gen_rake_ROI1(ImgIn, out DetectRegions, out RoiContour, Element, DetectHight, DtetectWidth, LineRow1, LineCol1, LineRow2, LineCol2); HObject ReduceImg; HTuple area = new HTuple(), row = new HTuple(), col = new HTuple(); HObject CircleObj = new HObject(); HOperatorSet.GenCircle(out CircleObj, 10, 10, 5); #region 找出每行Pin针的中心坐标 for (int j = 0; j < DetectRegions.CountObj(); j++) //计算每根针的中心 { HObject RegionI = new HObject(); HOperatorSet.CopyObj(DetectRegions, out RegionI, j + 1, 1); HOperatorSet.ReduceDomain(ImgIn, RegionI, out ReduceImg); RegionI.Dispose(); //获取目标区域的图像 HObject ThrdRegion; HOperatorSet.Threshold(ReduceImg, out ThrdRegion, DnThreshold, UpThreshold); ReduceImg.Dispose(); //阈值分割 HObject ExpandRegion = new HObject(); HOperatorSet.ExpandRegion(ThrdRegion, CircleObj, out ExpandRegion, 3, "image"); //膨胀 ThrdRegion.Dispose();; HObject ConnectRegion; HOperatorSet.Connection(ExpandRegion, out ConnectRegion); ExpandRegion.Dispose(); //链接 HObject SelectRegion = new HObject(); HOperatorSet.SelectShape(ConnectRegion, out SelectRegion, "area", "and", MinArea, MaxArea); ConnectRegion.Dispose(); //挑出目标区域 HTuple areaI, RowI, ColI; HOperatorSet.AreaCenter(SelectRegion, out areaI, out RowI, out ColI); //获取Pin针中心坐标 if (RowI.Length > 0) { HTuple MaxValue = areaI.TupleMax(); int MaxIndex = areaI.TupleFind(MaxValue); row[j] = RowI[MaxIndex].D; col[j] = ColI[MaxIndex].D; } else { row[j] = 0; col[j] = 0; } } #endregion PinRows = PinRows.TupleConcat(row); PinCols = PinCols.TupleConcat(col); CircleObj.Dispose(); } HTuple TeachPinRows = new HTuple(), TeachPinCols = new HTuple(); for (int i = 0; i < InspectPinParamIn.Elements.Count(); i++) { HTuple row0 = new HTuple(), col0 = new HTuple(); MyVisionBase.ListToHTuple(InspectPinParamIn.ListRows[i], out row0); MyVisionBase.ListToHTuple(InspectPinParamIn.ListCols[i], out col0); TeachPinRows = TeachPinRows.TupleConcat(row0); TeachPinCols = TeachPinCols.TupleConcat(col0); } HTuple HomMat = new HTuple(); HOperatorSet.VectorToHomMat2d(TeachPinCols, TeachPinRows, PinCols, PinRows, out HomMat); //计算平移矩阵 HTuple TargetRows = new HTuple(), TargetCols = new HTuple(); HOperatorSet.AffineTransPixel(HomMat, TeachPinCols, TeachPinRows, out TargetCols, out TargetRows); //平移示教点的坐标 if (TargetRows.Length != TeachPinRows.Length) { return(false); } HTuple OffSetRows0 = new HTuple(), OffSetCols0 = new HTuple(), OffSetDist0 = new HTuple(); OffSetCols0 = PinCols - TargetCols; OffSetRows0 = PinRows - TargetRows; HOperatorSet.DistancePp(TargetRows, TargetCols, PinRows, PinCols, out OffSetDist0); //计算出偏移量 HTuple Max = OffSetDist0.TupleMax(); HTuple MaxIndex0 = OffSetDist0.TupleFind(Max); HOperatorSet.GenCircleContourXld(out ErrorContour, PinRows[MaxIndex0[0].I], PinCols[MaxIndex0[0].I], 50, 0, Math.PI * 2, "positive", 1.0); HOperatorSet.GenCrossContourXld(out PinContour, PinRows, PinCols, 50, 0); OffSetRows = OffSetRows0; OffSetCols = OffSetCols0; OffSetDist = OffSetDist0; return(true); }
// Main procedure private void action() { // Local iconic variables HObject ho_Image, ho_SymbolRegions = null, ho_CandidateRegions = null; HObject ho_ScanlinesAll = null, ho_ScanlinesValid = null; // Local control variables HTuple hv_UserDefinedMessages, hv_StatusID = new HTuple(); HTuple hv_Status = new HTuple(), hv_ImagePrefix, hv_ImageSuffix; HTuple hv_WindowHandle, hv_BarCodeHandle, hv_CodeType; HTuple hv_Count, hv_IndexExposure, hv_DecodedDataStrings = new HTuple(); HTuple hv_NumInterestingCand = new HTuple(), hv_IndexCandidate = new HTuple(); HTuple hv_String = new HTuple(), hv_StatusIDSplit = new HTuple(); HTuple hv_CenterRows = new HTuple(), hv_CenterColumns = new HTuple(); HTuple hv_Box = new HTuple(), hv_IndexStatus = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_SymbolRegions); HOperatorSet.GenEmptyObj(out ho_CandidateRegions); HOperatorSet.GenEmptyObj(out ho_ScanlinesAll); HOperatorSet.GenEmptyObj(out ho_ScanlinesValid); try { //This example presents the bar code parameters 'status' //and 'status_id' that can be used within get_bar_code_result //to get additional information about possibly occuring //errors when reading a bar code. // //Remark: UserDefinedMessages set to false disables additional //diagnostic messages (overexposure) in this example program hv_UserDefinedMessages = 1; if ((int)(new HTuple(hv_UserDefinedMessages.TupleEqual(0))) != 0) { hv_StatusID = "-1"; } if (HDevWindowStack.IsOpen()) { HOperatorSet.CloseWindow(HDevWindowStack.Pop()); } // dev_close_inspect_ctrl(...); only in hdevelop // dev_update_pc(...); only in hdevelop // dev_update_window(...); only in hdevelop hv_ImagePrefix = "barcode/25interleaved/25interleaved_exposure_"; hv_ImageSuffix = ".png"; ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, (hv_ImagePrefix + "01") + hv_ImageSuffix); dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle); set_display_font(hv_WindowHandle, 14, "mono", "true", "false"); if (HDevWindowStack.IsOpen()) { HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 2); } // //If get_bar_code_result is called with the parameter 'status', //'persistence' must be set for the bar code model HOperatorSet.CreateBarCodeModel("persistence", 1, out hv_BarCodeHandle); // //For the visualization, the number of scanlines is reduced //(default is 10) HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "num_scanlines", 5); HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "check_char", "present"); // // hv_CodeType = "2/5 Interleaved"; hv_Count = 5; for (hv_IndexExposure = 1; hv_IndexExposure.Continue(hv_Count, 1); hv_IndexExposure = hv_IndexExposure.TupleAdd(1)) { ho_Image.Dispose(); HOperatorSet.ReadImage(out ho_Image, (hv_ImagePrefix + (hv_IndexExposure.TupleString( "02"))) + hv_ImageSuffix); // //Try decoding the bar code in the input image ho_SymbolRegions.Dispose(); HOperatorSet.FindBarCode(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, hv_CodeType, out hv_DecodedDataStrings); ho_CandidateRegions.Dispose(); HOperatorSet.GetBarCodeObject(out ho_CandidateRegions, hv_BarCodeHandle, "all", "candidate_regions"); if ((int)(new HTuple((new HTuple(hv_DecodedDataStrings.TupleLength())).TupleGreater( 0))) != 0) { //If a bar code was found, display only scanlines of //successfully decoded regions (which are the first //regions of all candidate regions) HOperatorSet.CountObj(ho_SymbolRegions, out hv_NumInterestingCand); } else { //If no bar code could be found, display the error //information for all candidate regions HOperatorSet.CountObj(ho_CandidateRegions, out hv_NumInterestingCand); } // //Iterate over all symbol regions or candidate regions //if no symbol could be decoded for (hv_IndexCandidate = 0; hv_IndexCandidate.Continue(hv_NumInterestingCand - 1, 1); hv_IndexCandidate = hv_IndexCandidate.TupleAdd(1)) { // //Display valid scanlines in green, invalid //scanlines in red ho_ScanlinesAll.Dispose(); HOperatorSet.GetBarCodeObject(out ho_ScanlinesAll, hv_BarCodeHandle, hv_IndexCandidate, "scanlines_all"); ho_ScanlinesValid.Dispose(); HOperatorSet.GetBarCodeObject(out ho_ScanlinesValid, hv_BarCodeHandle, hv_IndexCandidate, "scanlines_valid"); if (HDevWindowStack.IsOpen()) { HOperatorSet.ClearWindow(HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_ScanlinesAll, HDevWindowStack.GetActive()); } if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_ScanlinesValid, HDevWindowStack.GetActive()); } // //Display the index number of the current candidate disp_message(hv_WindowHandle, (("Candidate " + (hv_IndexCandidate + 1)) + " of ") + hv_NumInterestingCand, "image", 72, 12, "forest green", "true"); // if ((int)(hv_UserDefinedMessages) != 0) { // //Get a tuple of strings containing multiple status //identifiers, separated by a semicolon HOperatorSet.GetBarCodeResult(hv_BarCodeHandle, hv_IndexCandidate, "status_id", out hv_StatusID); // //This user-defined procedure can be modified to //translate status identifiers to customized status //messages translate_bar_code_status_id(hv_StatusID, out hv_Status); } else { // //Get tuple of strings containing status messages HOperatorSet.GetBarCodeResult(hv_BarCodeHandle, hv_IndexCandidate, "status", out hv_Status); } // //Show decoded bar code data if ((int)(new HTuple((new HTuple(hv_DecodedDataStrings.TupleLength())).TupleGreater( 0))) != 0) { if (HDevWindowStack.IsOpen()) { HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green"); } if (HDevWindowStack.IsOpen()) { HOperatorSet.DispObj(ho_ScanlinesValid, HDevWindowStack.GetActive() ); } hv_String = "Decoded data strings: " + hv_DecodedDataStrings; // //Combinations of status IDs can be combined to //give further hints for the image acquisition, // e.g. about a possible overexposure HOperatorSet.TupleNumber(hv_StatusID.TupleSplit(";"), out hv_StatusIDSplit); if ((int)((new HTuple(((hv_StatusIDSplit.TupleFind(1000))).TupleNotEqual( -1))).TupleAnd(new HTuple(((hv_StatusIDSplit.TupleFind(1004))).TupleNotEqual( -1)))) != 0) { hv_String = hv_String.TupleConcat("Possible overexposure detected."); } disp_message(hv_WindowHandle, hv_String, "image", 12, 12, "forest green", "true"); } else { disp_message(hv_WindowHandle, "Could not decode bar code", "image", 12, 12, "red", "true"); } // //Display the index number of each scanline at its center scanline_centers(ho_ScanlinesAll, out hv_CenterRows, out hv_CenterColumns); // //If the scanlines lie to close to each other, omit the //background boxes if ((int)(new HTuple(((((((hv_CenterRows.TupleSelect((new HTuple(hv_CenterRows.TupleLength() )) - 2)) - (hv_CenterRows.TupleSelect((new HTuple(hv_CenterRows.TupleLength() )) - 1)))).TuplePow(2)) + ((((hv_CenterColumns.TupleSelect((new HTuple(hv_CenterColumns.TupleLength() )) - 2)) - (hv_CenterColumns.TupleSelect((new HTuple(hv_CenterColumns.TupleLength() )) - 1)))).TuplePow(2)))).TupleGreater(200 * 200))) != 0) { hv_Box = "true"; } else { hv_Box = "false"; } for (hv_IndexStatus = 0; (int)hv_IndexStatus <= (int)((new HTuple(hv_Status.TupleLength() )) - 1); hv_IndexStatus = (int)hv_IndexStatus + 1) { disp_message(hv_WindowHandle, "" + hv_IndexStatus, "image", hv_CenterRows.TupleSelect( hv_IndexStatus), hv_CenterColumns.TupleSelect(hv_IndexStatus), "green", hv_Box); } // dev_inspect_ctrl(...); only in hdevelop if ((int)((new HTuple(hv_IndexCandidate.TupleLess(hv_NumInterestingCand - 1))).TupleOr( new HTuple(hv_IndexExposure.TupleLess(hv_Count)))) != 0) { disp_continue_message(hv_WindowHandle, "black", "true"); HDevelopStop(); } } } // //Free all memory of the bar code model HOperatorSet.ClearBarCodeModel(hv_BarCodeHandle); } catch (HalconException HDevExpDefaultException) { ho_Image.Dispose(); ho_SymbolRegions.Dispose(); ho_CandidateRegions.Dispose(); ho_ScanlinesAll.Dispose(); ho_ScanlinesValid.Dispose(); throw HDevExpDefaultException; } ho_Image.Dispose(); ho_SymbolRegions.Dispose(); ho_CandidateRegions.Dispose(); ho_ScanlinesAll.Dispose(); ho_ScanlinesValid.Dispose(); }
public void translate_bar_code_status_id(HTuple hv_StatusID, out HTuple hv_MessageText) { // Local control variables HTuple hv_Messages, hv_IndexStatus, hv_Msg = new HTuple(); HTuple hv_StatusIDSplit = new HTuple(), hv_IndexSplit = new HTuple(); HTuple hv_IndexMessage = new HTuple(); // Initialize local and output iconic variables hv_MessageText = new HTuple(); hv_Messages = new HTuple(); hv_Messages = hv_Messages.TupleConcat(0); hv_Messages = hv_Messages.TupleConcat("unknown decoding status."); hv_Messages = hv_Messages.TupleConcat(1); hv_Messages = hv_Messages.TupleConcat("success."); hv_Messages = hv_Messages.TupleConcat(2); hv_Messages = hv_Messages.TupleConcat("edges: not enough edges detected."); hv_Messages = hv_Messages.TupleConcat(3); hv_Messages = hv_Messages.TupleConcat("edges: not enough edges for a start, a stop and at least one data character."); hv_Messages = hv_Messages.TupleConcat(4); hv_Messages = hv_Messages.TupleConcat("edges: too many edges detected."); hv_Messages = hv_Messages.TupleConcat(5); hv_Messages = hv_Messages.TupleConcat("edges: center of scanline not within image domain."); hv_Messages = hv_Messages.TupleConcat(6); hv_Messages = hv_Messages.TupleConcat("decoding: could not find stop character."); hv_Messages = hv_Messages.TupleConcat(7); hv_Messages = hv_Messages.TupleConcat("decoding: could not find start and stop characters."); hv_Messages = hv_Messages.TupleConcat(8); hv_Messages = hv_Messages.TupleConcat("decoding: internal error when estimating the maximum string length."); hv_Messages = hv_Messages.TupleConcat(9); hv_Messages = hv_Messages.TupleConcat("decoding: internal error when decoding a single character."); hv_Messages = hv_Messages.TupleConcat(10); hv_Messages = hv_Messages.TupleConcat("decoding: number of wide bars of a single character is not equal to 2."); hv_Messages = hv_Messages.TupleConcat(11); hv_Messages = hv_Messages.TupleConcat("decoding: invalid encoding pattern."); hv_Messages = hv_Messages.TupleConcat(12); hv_Messages = hv_Messages.TupleConcat("decoding: invalid mix of character sets."); hv_Messages = hv_Messages.TupleConcat(13); hv_Messages = hv_Messages.TupleConcat("decoding: error decoding the reference to a human readable string."); hv_Messages = hv_Messages.TupleConcat(14); hv_Messages = hv_Messages.TupleConcat("decoding: could not detect center guard pattern."); hv_Messages = hv_Messages.TupleConcat(15); hv_Messages = hv_Messages.TupleConcat("decoding: could not detect left and/or right guard patterns."); hv_Messages = hv_Messages.TupleConcat(16); hv_Messages = hv_Messages.TupleConcat("decoding: could not detect add-on guard pattern."); hv_Messages = hv_Messages.TupleConcat(17); hv_Messages = hv_Messages.TupleConcat("decoding: could not detect enough finder patterns."); hv_Messages = hv_Messages.TupleConcat(18); hv_Messages = hv_Messages.TupleConcat("decoding: no segment found."); hv_Messages = hv_Messages.TupleConcat(19); hv_Messages = hv_Messages.TupleConcat("check: checksum test failed."); hv_Messages = hv_Messages.TupleConcat(20); hv_Messages = hv_Messages.TupleConcat("check: check of add-on symbol failed."); hv_Messages = hv_Messages.TupleConcat(21); hv_Messages = hv_Messages.TupleConcat("check: detected EAN-13 bar code type instead of specified type."); hv_Messages = hv_Messages.TupleConcat(22); hv_Messages = hv_Messages.TupleConcat("check: symbol region overlaps with another symbol region."); hv_Messages = hv_Messages.TupleConcat(1000); hv_Messages = hv_Messages.TupleConcat("White spaces too wide."); hv_Messages = hv_Messages.TupleConcat(1001); hv_Messages = hv_Messages.TupleConcat("White spaces too narrow."); hv_Messages = hv_Messages.TupleConcat(1002); hv_Messages = hv_Messages.TupleConcat("Bars too wide."); hv_Messages = hv_Messages.TupleConcat(1003); hv_Messages = hv_Messages.TupleConcat("Bars too narrow."); hv_Messages = hv_Messages.TupleConcat(1004); hv_Messages = hv_Messages.TupleConcat("Possible saturation of gray values."); hv_Messages = hv_Messages.TupleConcat(1005); hv_Messages = hv_Messages.TupleConcat("No composite component found."); // for (hv_IndexStatus = 0; (int)hv_IndexStatus <= (int)((new HTuple(hv_StatusID.TupleLength() )) - 1); hv_IndexStatus = (int)hv_IndexStatus + 1) { hv_Msg = ""; HOperatorSet.TupleNumber(((hv_StatusID.TupleSelect(hv_IndexStatus))).TupleSplit( ";"), out hv_StatusIDSplit); for (hv_IndexSplit = 0; (int)hv_IndexSplit <= (int)((new HTuple(hv_StatusIDSplit.TupleLength() )) - 1); hv_IndexSplit = (int)hv_IndexSplit + 1) { hv_IndexMessage = hv_Messages.TupleFind(hv_StatusIDSplit.TupleSelect(hv_IndexSplit)); if ((int)(new HTuple(hv_IndexMessage.TupleEqual(-1))) != 0) { //This should not happen! Just in case, the default //message for an unknown status is returned. hv_IndexMessage = 0; } hv_Msg = (hv_Msg + (hv_Messages.TupleSelect(hv_IndexMessage + 1))) + " "; } //Remove the leading space hv_MessageText[hv_IndexStatus] = (hv_Msg.TupleStrFirstN((hv_Msg.TupleStrlen() ) - 2)).TupleStrLastN(0); } return; }
private void FindLineBtn_Click(object sender, EventArgs e) { txtFindTime.Clear(); Stopwatch sw = new Stopwatch(); sw.Start(); if (GrabedImg == null) { Logger.PopError("请先采集图片!", true); return; } //1.0模板匹配 St_TemplateParam TemplateParam = VisionPara0.localPara.Template; RectangleF roi = new RectangleF(); LocalSettingPara Setting = VisionPara0.localPara.localSetting; roi.X = Setting.SearchAreaX; roi.Y = Setting.SearchAreaY; roi.Width = Setting.SearchWidth; roi.Height = Setting.SearchHeight; MatchingResult result; TemplateParam.FindSharpTemplate(GrabedImg, roi, TemplateParam, out result); //2.0调整图像位置 St_VectorAngle VectorAngle0 = new St_VectorAngle(VisionPara0.localPara.Template.CenterY, VisionPara0.localPara.Template.CenterX, VisionPara0.localPara.Template.TemplateAngle); St_VectorAngle TempFindVectorAngle = new St_VectorAngle(result.mRow, result.mCol, result.mAngle);//找到的模板坐标 HTuple HomMat = new HTuple(); HOperatorSet.VectorAngleToRigid(result.mRow, result.mCol, result.mAngle, VisionPara0.localPara.Template.CenterY, VisionPara0.localPara.Template.CenterX, VisionPara0.localPara.Template.TemplateAngle, out HomMat); HObject AffineImg = new HObject(); HOperatorSet.AffineTransImage(GrabedImg, out AffineImg, HomMat, "constant", "false"); HOperatorSet.ClearWindow(ShowWindow); MyVisionBase.hDispObj(ShowWindow, GrabedImg); //3.0找出Pin针坐标 HObject RoiContour = new HObject(); MyVisionBase.hDispObj(ShowWindow, AffineImg); HTuple PinRows = new HTuple(), PinCols = new HTuple(); PinInsepct.FindPinPos(TeachInspectPinParam, AffineImg, out PinRows, out PinCols); HObject ShowContour = new HObject(); HOperatorSet.GenCrossContourXld(out ShowContour, PinRows, PinCols, 50, 0); MyVisionBase.hSetColor(ShowWindow, "red"); MyVisionBase.hDispObj(ShowWindow, ShowContour); //4.0 计算出Pin针偏移量 HTuple OffSetRows = new HTuple(), OffSetCols = new HTuple(), OffSetDists = new HTuple();; PinInsepct.CalculatePinOffset(TeachInspectPinParam, PinRows, PinCols, out OffSetRows, out OffSetCols, out OffSetDists); HTuple Max = OffSetDists.TupleMax(); HTuple MaxIndex = OffSetDists.TupleFind(Max); HOperatorSet.GenCircleContourXld(out ShowContour, PinRows[MaxIndex[0].I], PinCols[MaxIndex[0].I], 50, 0, Math.PI * 2, "positive", 1.0); MyVisionBase.hSetColor(ShowWindow, "red"); MyVisionBase.hDispObj(ShowWindow, ShowContour); txtFindTime.Text = sw.ElapsedMilliseconds.ToString(); }
// Short Description: Creates an arrow shaped XLD contour. public void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_TempArrow = null; // Local control variables HTuple hv_Length = null, hv_ZeroLengthIndices = null; HTuple hv_DR = null, hv_DC = null, hv_HalfHeadWidth = null; HTuple hv_RowP1 = null, hv_ColP1 = null, hv_RowP2 = null; HTuple hv_ColP2 = null, hv_Index = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Arrow); HOperatorSet.GenEmptyObj(out ho_TempArrow); //This procedure generates arrow shaped XLD contours, ho_Arrow.Dispose(); HOperatorSet.GenEmptyObj(out ho_Arrow); // //Calculate the arrow length HOperatorSet.DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Length); // //Mark arrows with identical start and end point //(set Length to -1 to avoid division-by-zero exception) hv_ZeroLengthIndices = hv_Length.TupleFind(0); if ((int)(new HTuple(hv_ZeroLengthIndices.TupleNotEqual(-1))) != 0) { if (hv_Length == null) { hv_Length = new HTuple(); } hv_Length[hv_ZeroLengthIndices] = -1; } // //Calculate auxiliary variables. hv_DR = (1.0 * (hv_Row2 - hv_Row1)) / hv_Length; hv_DC = (1.0 * (hv_Column2 - hv_Column1)) / hv_Length; hv_HalfHeadWidth = hv_HeadWidth / 2.0; // //Calculate end points of the arrow head. hv_RowP1 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) + (hv_HalfHeadWidth * hv_DC); hv_ColP1 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) - (hv_HalfHeadWidth * hv_DR); hv_RowP2 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) - (hv_HalfHeadWidth * hv_DC); hv_ColP2 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) + (hv_HalfHeadWidth * hv_DR); // //Finally create output XLD contour for each input point pair for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Length.TupleLength())) - 1); hv_Index = (int)hv_Index + 1) { if ((int)(new HTuple(((hv_Length.TupleSelect(hv_Index))).TupleEqual(-1))) != 0) { //Create_ single points for arrows with identical start and end point ho_TempArrow.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_TempArrow, hv_Row1.TupleSelect(hv_Index), hv_Column1.TupleSelect(hv_Index)); } else { //Create arrow contour ho_TempArrow.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_TempArrow, ((((((((((hv_Row1.TupleSelect( hv_Index))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat( hv_RowP1.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat( hv_RowP2.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)), ((((((((((hv_Column1.TupleSelect(hv_Index))).TupleConcat(hv_Column2.TupleSelect( hv_Index)))).TupleConcat(hv_ColP1.TupleSelect(hv_Index)))).TupleConcat( hv_Column2.TupleSelect(hv_Index)))).TupleConcat(hv_ColP2.TupleSelect( hv_Index)))).TupleConcat(hv_Column2.TupleSelect(hv_Index))); } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_Arrow, ho_TempArrow, out ExpTmpOutVar_0); ho_Arrow.Dispose(); ho_Arrow = ExpTmpOutVar_0; } } ho_TempArrow.Dispose(); return; }
public string RunMaxPoint(HObject Image, HObject orgionImage, HWindow_Final hWindow_Final, HTuple Homat, out FindMaxResult fResult) { fResult = new FindMaxResult(); try { HObject Line = new HObject(); //PreHandle(Image, out ScaleImage); FitLine(Image, null, out Line, Homat); //Image = hWindow_Final.Image; double xResolution = 0.006; if (MyGlobal.GoSDK.context.xResolution != 0) { xResolution = MyGlobal.GoSDK.context.xResolution; } double MoveLeft = (inParam.PlateWidth) / xResolution; double BaseOffset = inParam.BaseOffset / xResolution; HTuple baseZ = new HTuple(); List <ROI> _roiList = new List <ROI>(); if (Homat.Length != 0) { for (int i = 0; i < roiList.Count; i++) { _roiList.Add(new ROI()); HTuple coord = roiList[i].getModelData(); HTuple affinePx, affinePy, affinePx1, affinePy1; HOperatorSet.AffineTransPoint2d(Homat, coord[0], coord[1], out affinePx, out affinePy); HOperatorSet.AffineTransPoint2d(Homat, coord[2], coord[3], out affinePx1, out affinePy1); ROI roi = new ROIRectangle1(affinePx, affinePy, affinePx1, affinePy1); _roiList[i] = roi; } } else { _roiList = roiList; } if (_roiList.Count > 2) { HTuple grayValue = new HTuple(); for (int i = 0; i < 2; i++) { HTuple recR, recC; HRegion temp = _roiList[i].getRegion(); HOperatorSet.GetRegionPoints(temp, out recR, out recC); hWindow_Final.viewWindow.displayHobject(temp, "green", true); HTuple GrayValue = new HTuple(); HTuple width, height; HOperatorSet.GetImageSize(Image, out width, out height); HTuple newReq = recR.TupleLessElem(height); HTuple newCeq = recC.TupleLessElem(width); HTuple Rid = newReq.TupleFind(1); HTuple Cid = newCeq.TupleFind(1); HTuple id = Rid.TupleIntersection(Cid); if (id.Length != 0) { recR = recR[id]; recC = recC[id]; HOperatorSet.GetGrayval(orgionImage, recR, recC, out GrayValue); HTuple newGray = GrayValue.TupleGreaterElem(-30); HTuple NeqId = new HTuple(); HOperatorSet.TupleFind(newGray, 1, out NeqId); GrayValue = GrayValue[NeqId]; HOperatorSet.TupleSort(GrayValue, out GrayValue); int len = GrayValue.Length; int len10 = (int)(len * 0.05); GrayValue = GrayValue.TupleSelectRange(len10, len - 1); GrayValue = GrayValue.TupleSelectRange(0, GrayValue.Length - len10); HTuple mean = GrayValue.TupleMean(); grayValue = grayValue.TupleConcat(mean); } else { return("基准区域超出图像"); } } baseZ = grayValue.TupleMean(); } HTuple MaxZ = new HTuple(); for (int i = 2; i < _roiList.Count; i++) { HRegion temp = _roiList[i].getRegion(); HObject regionContour = new HObject(); HOperatorSet.GenContourRegionXld(temp, out regionContour, "border"); HTuple intersectR, intersectC, isOverlapping; //hWindow_Final.viewWindow.displayHobject(regionContour, "red", true); HOperatorSet.IntersectionContoursXld(regionContour, Line, "mutual", out intersectR, out intersectC, out isOverlapping); if (intersectR.Length > 1) { HTuple Coord = _roiList[i].getModelData(); HTuple colLeft = intersectC[0] - MoveLeft; HTuple rowLeft = Coord[0]; HTuple colRight = intersectC[1] + BaseOffset; HTuple rowRight = Coord[2]; HObject rec = new HObject(); if (colRight.D <= colLeft.D) { colRight = colLeft.D + 1; } HOperatorSet.GenRectangle1(out rec, rowLeft, colLeft, rowRight, colRight); //HOperatorSet.SetColor(hWindow_Final.HWindowHalconID, "red"); //HOperatorSet.SetDraw(hWindow_Final.HWindowHalconID, "fill"); //HOperatorSet.DispObj(rec, hWindow_Final.HWindowHalconID); hWindow_Final.viewWindow.displayHobject(rec, "red", true); HTuple recR, recC; HOperatorSet.GetRegionPoints(rec, out recR, out recC); HTuple GrayValue = new HTuple(); HTuple width, height; HOperatorSet.GetImageSize(Image, out width, out height); HTuple newReq = recR.TupleLessElem(height); HTuple newCeq = recC.TupleLessElem(width); HTuple Rid = newReq.TupleFind(1); HTuple Cid = newCeq.TupleFind(1); HTuple id = Rid.TupleIntersection(Cid); if (id.Length != 0) { recR = recR[id]; recC = recC[id]; HOperatorSet.GetGrayval(orgionImage, recR, recC, out GrayValue); } else { return("感光片区域超出图像"); } HTuple newGray = GrayValue.TupleFind(-30); GrayValue = GrayValue.TupleRemove(newGray); HOperatorSet.TupleSort(GrayValue, out GrayValue); int len = GrayValue.Length; int len10 = (int)(len * 0.05); //GrayValue = GrayValue.TupleSelectRange(len10, len - 1); GrayValue = GrayValue.TupleSelectRange(GrayValue.Length - len10 * 3 - 1, GrayValue.Length - len10); HTuple max = GrayValue.TupleMean(); HTuple subMax = max.D - baseZ.D; double maxSub = Math.Round(subMax.D, 3); MaxZ = MaxZ.TupleConcat(maxSub); HOperatorSet.SetColor(hWindow_Final.HWindowHalconID, "blue"); HOperatorSet.SetFont(hWindow_Final.HWindowHalconID, "-Arial - 20 -"); HOperatorSet.SetTposition(hWindow_Final.HWindowHalconID, i * 10, 10); HOperatorSet.WriteString(hWindow_Final.HWindowHalconID, maxSub.ToString()); } } if (MaxZ.Length == 0) { return("遮光片区域未找到"); } fResult.Max = MaxZ; HTuple maxAll = MaxZ.TupleMax(); if (maxAll.D > inParam.DownLimits && maxAll.D < inParam.UpLimits) { fResult.DetectOK = true; HOperatorSet.SetColor(hWindow_Final.HWindowHalconID, "green"); HOperatorSet.SetFont(hWindow_Final.HWindowHalconID, "-Arial - 50 -"); HOperatorSet.SetTposition(hWindow_Final.HWindowHalconID, 0, 10); HOperatorSet.WriteString(hWindow_Final.HWindowHalconID, "OK"); } else { fResult.DetectOK = false; HOperatorSet.SetColor(hWindow_Final.HWindowHalconID, "red"); HOperatorSet.SetFont(hWindow_Final.HWindowHalconID, "-Arial - 50 -"); HOperatorSet.SetTposition(hWindow_Final.HWindowHalconID, 0, 10); HOperatorSet.WriteString(hWindow_Final.HWindowHalconID, "NG"); } return("OK"); } catch (Exception ex) { return("RunMaxPoint" + ex.Message); } }
/// <summary> /// Creates an arrow shaped XLD contour. /// </summary> /// <param name="ho_Arrow">生成的箭头</param> /// <param name="hv_Row1">箭头起点Row</param> /// <param name="hv_Column1">箭头起点Column</param> /// <param name="hv_Row2">箭头终点Row</param> /// <param name="hv_Column2">箭头终点Column</param> /// <param name="hv_HeadLength">头长度</param> /// <param name="hv_HeadWidth">头宽度</param> public static void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth) { // Stack for temporary objects HObject[] OTemp = new HObject[20]; // Local iconic variables HObject ho_TempArrow = null; // Local control variables HTuple hv_Length = new HTuple(), hv_ZeroLengthIndices = new HTuple(); HTuple hv_DR = new HTuple(), hv_DC = new HTuple(), hv_HalfHeadWidth = new HTuple(); HTuple hv_RowP1 = new HTuple(), hv_ColP1 = new HTuple(); HTuple hv_RowP2 = new HTuple(), hv_ColP2 = new HTuple(); HTuple hv_Index = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Arrow); HOperatorSet.GenEmptyObj(out ho_TempArrow); //This procedure generates arrow shaped XLD contours, //pointing from (Row1, Column1) to (Row2, Column2). //If starting and end point are identical, a contour consisting //of a single point is returned. // //input parameteres: //Row1, Column1: Coordinates of the arrows' starting points //Row2, Column2: Coordinates of the arrows' end points //HeadLength, HeadWidth: Size of the arrow heads in pixels // //output parameter: //Arrow: The resulting XLD contour // //The input tuples Row1, Column1, Row2, and Column2 have to be of //the same length. //HeadLength and HeadWidth either have to be of the same length as //Row1, Column1, Row2, and Column2 or have to be a single element. //If one of the above restrictions is violated, an error will occur. // // //Init ho_Arrow.Dispose(); HOperatorSet.GenEmptyObj(out ho_Arrow); // //Calculate the arrow length hv_Length.Dispose(); HOperatorSet.DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Length); // //Mark arrows with identical start and end point //(set Length to -1 to avoid division-by-zero exception) hv_ZeroLengthIndices.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_ZeroLengthIndices = hv_Length.TupleFind( 0); } if ((int)(new HTuple(hv_ZeroLengthIndices.TupleNotEqual(-1))) != 0) { if (hv_Length == null) { hv_Length = new HTuple(); } hv_Length[hv_ZeroLengthIndices] = -1; } // //Calculate auxiliary variables. hv_DR.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_DR = (1.0 * (hv_Row2 - hv_Row1)) / hv_Length; } hv_DC.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_DC = (1.0 * (hv_Column2 - hv_Column1)) / hv_Length; } hv_HalfHeadWidth.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_HalfHeadWidth = hv_HeadWidth / 2.0; } // //Calculate end points of the arrow head. hv_RowP1.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_RowP1 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) + (hv_HalfHeadWidth * hv_DC); } hv_ColP1.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_ColP1 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) - (hv_HalfHeadWidth * hv_DR); } hv_RowP2.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_RowP2 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) - (hv_HalfHeadWidth * hv_DC); } hv_ColP2.Dispose(); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_ColP2 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) + (hv_HalfHeadWidth * hv_DR); } // //Finally create output XLD contour for each input point pair for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Length.TupleLength())) - 1); hv_Index = (int)hv_Index + 1) { if ((int)(new HTuple(((hv_Length.TupleSelect(hv_Index))).TupleEqual(-1))) != 0) { //Create_ single points for arrows with identical start and end point using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_TempArrow.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_TempArrow, hv_Row1.TupleSelect(hv_Index), hv_Column1.TupleSelect(hv_Index)); } } else { //Create arrow contour using (HDevDisposeHelper dh = new HDevDisposeHelper()) { ho_TempArrow.Dispose(); HOperatorSet.GenContourPolygonXld(out ho_TempArrow, ((((((((((hv_Row1.TupleSelect( hv_Index))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat( hv_RowP1.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat( hv_RowP2.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)), ((((((((((hv_Column1.TupleSelect(hv_Index))).TupleConcat(hv_Column2.TupleSelect( hv_Index)))).TupleConcat(hv_ColP1.TupleSelect(hv_Index)))).TupleConcat( hv_Column2.TupleSelect(hv_Index)))).TupleConcat(hv_ColP2.TupleSelect( hv_Index)))).TupleConcat(hv_Column2.TupleSelect(hv_Index))); } } { HObject ExpTmpOutVar_0; HOperatorSet.ConcatObj(ho_Arrow, ho_TempArrow, out ExpTmpOutVar_0); ho_Arrow.Dispose(); ho_Arrow = ExpTmpOutVar_0; } } ho_TempArrow.Dispose(); hv_Length.Dispose(); hv_ZeroLengthIndices.Dispose(); hv_DR.Dispose(); hv_DC.Dispose(); hv_HalfHeadWidth.Dispose(); hv_RowP1.Dispose(); hv_ColP1.Dispose(); hv_RowP2.Dispose(); hv_ColP2.Dispose(); hv_Index.Dispose(); return; }