Halcon 代码
* board.hdev: Detection of missing solder
*
get_system ('clip_region', Information)
set_system ('clip_region', 'true')
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowID)
read_image (Images, ['ic0','ic1','ic2','ic3'])
channels_to_image (Images, Ic)
select_obj (Images, Input1, 1)
dev_display (Input1)
set_display_font (WindowID, 14, 'mono', 'false', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
select_obj (Images, Input2, 2)
dev_display (Input2)
disp_continue_message (WindowID, 'black', 'true')
stop ()
select_obj (Images, Input3, 3)
dev_display (Input3)
disp_continue_message (WindowID, 'black', 'true')
stop ()
select_obj (Images, Input4, 4)
dev_display (Input4)
*disp_continue_message (WindowID, 'black', 'true')
stop ()
*对1图像平均
mean_n(Input4, Imagemean)
dev_display(Imagemean)
*对4幅图像做平均
mean_n (Ic, ImageMean)
dev_display (ImageMean)
*阈值分割,找出暗区域
threshold (Images, Darks, 0, 40)
*把暗区域连接到一块,暗区域就是焊锡的内部,偏暗
union1 (Darks, Dark)
*把区域里面的孔填满
fill_up (Dark, DarkFilled)
dev_set_color ('green')
dev_display (DarkFilled)
*disp_continue_message (WindowID, 'black', 'true')
stop ()
*阈值分割,找出亮区域
threshold (Images, Lights, 100, 255)
*把亮区域连接到一起
union1 (Lights, Light)
*计算暗区域和亮区域的交点,可以得到焊锡的边缘Intersection
intersection (DarkFilled, Light, Intersection)
dev_display (ImageMean)
dev_display (Intersection)
*disp_continue_message (WindowID, 'black', 'true')
stop ()
*返回暗色(焊锡)区域的补数Back。黑色区域的补数不就是包含亮色区域的地方?
complement (DarkFilled, Back)
dev_set_color ('red')
dev_display (Back)
*disp_continue_message (WindowID, 'black', 'true')
stop ()
*填补并扩展边缘区域之间的空白或分裂重叠区域,计算迭代10次。Back作为禁止区域不参与计算
expand_region (Intersection, Back, RegionExpanded, 10, 'image')
*把区域里面的孔全部填了,返回没有孔的区域Good,这是先找的背景区域,然后反向找的焊锡区域
fill_up (RegionExpanded, Good)
dev_display (ImageMean)
dev_set_color ('green')
dev_display (Good)
*disp_continue_message (WindowID, 'black', 'true')
stop ()
difference (DarkFilled, Good, Rest)
dev_set_color ('red')
dev_display (Rest)
*disp_continue_message (WindowID, 'black', 'true')
stop ()
*看一下没有扩展灰度之前的图像,填充两个区域之间的空白部分
dev_display(Rest)
expand_gray (Rest, Ic, Good, Bad, 6, 'image', 5)
dev_display (Bad)
*看一下把ok区域填充一下的效果,就是把现有区域附近的5个灰度值内的像素扩展一下
dev_display(Good)
expand_gray (Good, Ic, Rest, Good_expand, 6, 'image', 5)
dev_display(Good_expand)
*disp_continue_message (WindowID, 'black', 'true'
stop ()
connection (Bad, ConnectedBad)
select_shape (ConnectedBad, BigBad, 'area', 'and', 150, 99999)
area_center (BigBad, AreaBad, Row, Column)
count_obj (BigBad, NumMissingSolder)
AreaMissingSolder := sum(AreaBad)
dev_display (Images)
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Good)
dev_set_color ('red')
dev_display (BigBad)
dev_set_draw ('fill')
dev_set_line_width (1)
dev_update_window ('on')
set_system ('clip_region', Information)
C#代码
//
// File generated by HDevelop for HALCON/.NET (C#) Version 19.11.0.0
// Non-ASCII strings in this file are encoded in local-8-bit encoding (cp936).
//
// Please note that non-ASCII characters in string constants are exported
// as octal codes in order to guarantee that the strings are correctly
// created on all systems, independent on any compiler settings.
//
// Source files with different encoding should not be mixed in one project.
//
using HalconDotNet;
public partial class HDevelopExport
{
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public HDevelopExport()
{
// Default settings used in HDevelop
HOperatorSet.SetSystem("width", 512);
HOperatorSet.SetSystem("height", 512);
if (HalconAPI.isWindows)
HOperatorSet.SetSystem("use_window_thread","true");
action();
}
#endif
// Procedures
// External procedures
// Chapter: Graphics / Text
// Short Description: This procedure displays 'Click 'Run' to continue' in the lower right corner of the screen.
public void disp_continue_message (HTuple hv_WindowHandle, HTuple hv_Color, HTuple hv_Box)
{
// Local iconic variables
// Local control variables
HTuple hv_GenParamName = new HTuple(), hv_GenParamValue = new HTuple();
HTuple hv_ContinueMessage = new HTuple();
HTuple hv_Color_COPY_INP_TMP = new HTuple(hv_Color);
// Initialize local and output iconic variables
try
{
//This procedure displays 'Press Run (F5) to continue' in the
//lower right corner of the screen.
//It uses the procedure disp_message.
//
//Input parameters:
//WindowHandle: The window, where the text shall be displayed
//Color: defines the text color.
// If set to '' or 'auto', the currently set color is used.
//Box: If set to 'true', the text is displayed in a box.
//
//Convert the parameter Box to generic parameters.
hv_GenParamName.Dispose();
hv_GenParamName = new HTuple();
hv_GenParamValue.Dispose();
hv_GenParamValue = new HTuple();
if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(0))) != 0)
{
if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleEqual("false"))) != 0)
{
//Display no box
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"box");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
"false");
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
else if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleNotEqual(
"true"))) != 0)
{
//Set a color other than the default.
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"box_color");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
hv_Box.TupleSelect(0));
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
}
if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(1))) != 0)
{
if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleEqual("false"))) != 0)
{
//Display no shadow.
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"shadow");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
"false");
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
else if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleNotEqual(
"true"))) != 0)
{
//Set a shadow color other than the default.
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"shadow_color");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
hv_Box.TupleSelect(1));
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
}
//
if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(""))) != 0)
{
//disp_text does not accept an empty string for Color.
hv_Color_COPY_INP_TMP.Dispose();
hv_Color_COPY_INP_TMP = new HTuple();
}
//
//Display the message.
hv_ContinueMessage.Dispose();
hv_ContinueMessage = "Press Run (F5) to continue";
HOperatorSet.DispText(hv_WindowHandle, hv_ContinueMessage, "window", "bottom",
"right", hv_Color_COPY_INP_TMP, hv_GenParamName, hv_GenParamValue);
hv_Color_COPY_INP_TMP.Dispose();
hv_GenParamName.Dispose();
hv_GenParamValue.Dispose();
hv_ContinueMessage.Dispose();
return;
}
catch (HalconException HDevExpDefaultException)
{
hv_Color_COPY_INP_TMP.Dispose();
hv_GenParamName.Dispose();
hv_GenParamValue.Dispose();
hv_ContinueMessage.Dispose();
throw HDevExpDefaultException;
}
}
// 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 = new HTuple(), hv_Fonts = new HTuple();
HTuple hv_Style = new HTuple(), hv_Exception = new HTuple();
HTuple hv_AvailableFonts = new HTuple(), hv_Fdx = new HTuple();
HTuple hv_Indices = new HTuple();
HTuple hv_Font_COPY_INP_TMP = new HTuple(hv_Font);
HTuple hv_Size_COPY_INP_TMP = new HTuple(hv_Size);
// Initialize local and output iconic variables
try
{
//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
//
hv_OS.Dispose();
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.Dispose();
hv_Size_COPY_INP_TMP = 16;
}
if ((int)(new HTuple(((hv_OS.TupleSubstr(0,2))).TupleEqual("Win"))) != 0)
{
//Restore previous behaviour
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_Size = ((1.13677*hv_Size_COPY_INP_TMP)).TupleInt()
;
hv_Size_COPY_INP_TMP.Dispose();
hv_Size_COPY_INP_TMP = ExpTmpLocalVar_Size;
}
}
}
else
{
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_Size = hv_Size_COPY_INP_TMP.TupleInt()
;
hv_Size_COPY_INP_TMP.Dispose();
hv_Size_COPY_INP_TMP = ExpTmpLocalVar_Size;
}
}
}
if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))) != 0)
{
hv_Fonts.Dispose();
hv_Fonts = new HTuple();
hv_Fonts[0] = "Courier";
hv_Fonts[1] = "Courier 10 Pitch";
hv_Fonts[2] = "Courier New";
hv_Fonts[3] = "CourierNew";
hv_Fonts[4] = "Liberation Mono";
}
else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0)
{
hv_Fonts.Dispose();
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";
hv_Fonts[5] = "Liberation Mono";
}
else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
{
hv_Fonts.Dispose();
hv_Fonts = new HTuple();
hv_Fonts[0] = "Luxi Sans";
hv_Fonts[1] = "DejaVu Sans";
hv_Fonts[2] = "FreeSans";
hv_Fonts[3] = "Arial";
hv_Fonts[4] = "Liberation Sans";
}
else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
{
hv_Fonts.Dispose();
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";
hv_Fonts[5] = "Liberation Serif";
}
else
{
hv_Fonts.Dispose();
hv_Fonts = new HTuple(hv_Font_COPY_INP_TMP);
}
hv_Style.Dispose();
hv_Style = "";
if ((int)(new HTuple(hv_Bold.TupleEqual("true"))) != 0)
{
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_Style = hv_Style+"Bold";
hv_Style.Dispose();
hv_Style = ExpTmpLocalVar_Style;
}
}
}
else if ((int)(new HTuple(hv_Bold.TupleNotEqual("false"))) != 0)
{
hv_Exception.Dispose();
hv_Exception = "Wrong value of control parameter Bold";
throw new HalconException(hv_Exception);
}
if ((int)(new HTuple(hv_Slant.TupleEqual("true"))) != 0)
{
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_Style = hv_Style+"Italic";
hv_Style.Dispose();
hv_Style = ExpTmpLocalVar_Style;
}
}
}
else if ((int)(new HTuple(hv_Slant.TupleNotEqual("false"))) != 0)
{
hv_Exception.Dispose();
hv_Exception = "Wrong value of control parameter Slant";
throw new HalconException(hv_Exception);
}
if ((int)(new HTuple(hv_Style.TupleEqual(""))) != 0)
{
hv_Style.Dispose();
hv_Style = "Normal";
}
hv_AvailableFonts.Dispose();
HOperatorSet.QueryFont(hv_WindowHandle, out hv_AvailableFonts);
hv_Font_COPY_INP_TMP.Dispose();
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.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
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.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
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");
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_Font = (((hv_Font_COPY_INP_TMP+"-")+hv_Style)+"-")+hv_Size_COPY_INP_TMP;
hv_Font_COPY_INP_TMP.Dispose();
hv_Font_COPY_INP_TMP = ExpTmpLocalVar_Font;
}
}
HOperatorSet.SetFont(hv_WindowHandle, hv_Font_COPY_INP_TMP);
hv_Font_COPY_INP_TMP.Dispose();
hv_Size_COPY_INP_TMP.Dispose();
hv_OS.Dispose();
hv_Fonts.Dispose();
hv_Style.Dispose();
hv_Exception.Dispose();
hv_AvailableFonts.Dispose();
hv_Fdx.Dispose();
hv_Indices.Dispose();
return;
}
catch (HalconException HDevExpDefaultException)
{
hv_Font_COPY_INP_TMP.Dispose();
hv_Size_COPY_INP_TMP.Dispose();
hv_OS.Dispose();
hv_Fonts.Dispose();
hv_Style.Dispose();
hv_Exception.Dispose();
hv_AvailableFonts.Dispose();
hv_Fdx.Dispose();
hv_Indices.Dispose();
throw HDevExpDefaultException;
}
}
#if !NO_EXPORT_MAIN
// Main procedure
private void action()
{
// Local iconic variables
HObject ho_Images, ho_Ic, ho_Input1, ho_Input2;
HObject ho_Input3, ho_Input4, ho_ImageMean, ho_Darks, ho_Dark;
HObject ho_DarkFilled, ho_Lights, ho_Light, ho_Intersection;
HObject ho_Back, ho_RegionExpanded, ho_Good, ho_Rest, ho_Bad;
HObject ho_Good_expand, ho_ConnectedBad, ho_BigBad;
// Local control variables
HTuple hv_Information = new HTuple(), hv_WindowID = new HTuple();
HTuple hv_AreaBad = new HTuple(), hv_Row = new HTuple();
HTuple hv_Column = new HTuple(), hv_NumMissingSolder = new HTuple();
HTuple hv_AreaMissingSolder = new HTuple();
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Images);
HOperatorSet.GenEmptyObj(out ho_Ic);
HOperatorSet.GenEmptyObj(out ho_Input1);
HOperatorSet.GenEmptyObj(out ho_Input2);
HOperatorSet.GenEmptyObj(out ho_Input3);
HOperatorSet.GenEmptyObj(out ho_Input4);
HOperatorSet.GenEmptyObj(out ho_ImageMean);
HOperatorSet.GenEmptyObj(out ho_Darks);
HOperatorSet.GenEmptyObj(out ho_Dark);
HOperatorSet.GenEmptyObj(out ho_DarkFilled);
HOperatorSet.GenEmptyObj(out ho_Lights);
HOperatorSet.GenEmptyObj(out ho_Light);
HOperatorSet.GenEmptyObj(out ho_Intersection);
HOperatorSet.GenEmptyObj(out ho_Back);
HOperatorSet.GenEmptyObj(out ho_RegionExpanded);
HOperatorSet.GenEmptyObj(out ho_Good);
HOperatorSet.GenEmptyObj(out ho_Rest);
HOperatorSet.GenEmptyObj(out ho_Bad);
HOperatorSet.GenEmptyObj(out ho_Good_expand);
HOperatorSet.GenEmptyObj(out ho_ConnectedBad);
HOperatorSet.GenEmptyObj(out ho_BigBad);
try
{
//board.hdev: Detection of missing solder
//
hv_Information.Dispose();
HOperatorSet.GetSystem("clip_region", out hv_Information);
HOperatorSet.SetSystem("clip_region", "true");
// dev_update_window(...); only in hdevelop
if (HDevWindowStack.IsOpen())
{
HOperatorSet.CloseWindow(HDevWindowStack.Pop());
}
HOperatorSet.SetWindowAttr("background_color","black");
HOperatorSet.OpenWindow(0,0,512,512,0,"visible","",out hv_WindowID);
HDevWindowStack.Push(hv_WindowID);
ho_Images.Dispose();
HOperatorSet.ReadImage(out ho_Images, (((new HTuple("ic0")).TupleConcat("ic1")).TupleConcat(
"ic2")).TupleConcat("ic3"));
ho_Ic.Dispose();
HOperatorSet.ChannelsToImage(ho_Images, out ho_Ic);
ho_Input1.Dispose();
HOperatorSet.SelectObj(ho_Images, out ho_Input1, 1);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Input1, HDevWindowStack.GetActive());
}
set_display_font(hv_WindowID, 14, "mono", "false", "false");
disp_continue_message(hv_WindowID, "black", "true");
// stop(...); only in hdevelop
ho_Input2.Dispose();
HOperatorSet.SelectObj(ho_Images, out ho_Input2, 2);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Input2, HDevWindowStack.GetActive());
}
disp_continue_message(hv_WindowID, "black", "true");
// stop(...); only in hdevelop
ho_Input3.Dispose();
HOperatorSet.SelectObj(ho_Images, out ho_Input3, 3);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Input3, HDevWindowStack.GetActive());
}
disp_continue_message(hv_WindowID, "black", "true");
// stop(...); only in hdevelop
ho_Input4.Dispose();
HOperatorSet.SelectObj(ho_Images, out ho_Input4, 4);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Input4, HDevWindowStack.GetActive());
}
//disp_continue_message (WindowID, 'black', 'true')
// stop(...); only in hdevelop
//对4幅图像做平均
ho_ImageMean.Dispose();
HOperatorSet.MeanN(ho_Ic, out ho_ImageMean);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_ImageMean, HDevWindowStack.GetActive());
}
//阈值分割,找出暗区域
ho_Darks.Dispose();
HOperatorSet.Threshold(ho_Images, out ho_Darks, 0, 40);
//把暗区域连接到一块,暗区域就是焊锡的内部,偏暗
ho_Dark.Dispose();
HOperatorSet.Union1(ho_Darks, out ho_Dark);
//把区域里面的孔填满
ho_DarkFilled.Dispose();
HOperatorSet.FillUp(ho_Dark, out ho_DarkFilled);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_DarkFilled, HDevWindowStack.GetActive());
}
//disp_continue_message (WindowID, 'black', 'true')
// stop(...); only in hdevelop
//阈值分割,找出亮区域
ho_Lights.Dispose();
HOperatorSet.Threshold(ho_Images, out ho_Lights, 100, 255);
//把亮区域连接到一起
ho_Light.Dispose();
HOperatorSet.Union1(ho_Lights, out ho_Light);
//计算暗区域和亮区域的交点,可以得到焊锡的边缘Intersection
ho_Intersection.Dispose();
HOperatorSet.Intersection(ho_DarkFilled, ho_Light, out ho_Intersection);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_ImageMean, HDevWindowStack.GetActive());
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Intersection, HDevWindowStack.GetActive());
}
//disp_continue_message (WindowID, 'black', 'true')
// stop(...); only in hdevelop
//返回暗色(焊锡)区域的补数Back。黑色区域的补数不就是包含亮色区域的地方?
ho_Back.Dispose();
HOperatorSet.Complement(ho_DarkFilled, out ho_Back);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Back, HDevWindowStack.GetActive());
}
//disp_continue_message (WindowID, 'black', 'true')
// stop(...); only in hdevelop
//填补并扩展边缘区域之间的空白或分裂重叠区域,计算迭代10次。Back作为禁止区域不参与计算
ho_RegionExpanded.Dispose();
HOperatorSet.ExpandRegion(ho_Intersection, ho_Back, out ho_RegionExpanded,
10, "image");
//把区域里面的孔全部填了,返回没有孔的区域Good,这是先找的背景区域,然后反向找的焊锡区域
ho_Good.Dispose();
HOperatorSet.FillUp(ho_RegionExpanded, out ho_Good);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_ImageMean, HDevWindowStack.GetActive());
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Good, HDevWindowStack.GetActive());
}
//disp_continue_message (WindowID, 'black', 'true')
// stop(...); only in hdevelop
ho_Rest.Dispose();
HOperatorSet.Difference(ho_DarkFilled, ho_Good, out ho_Rest);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Rest, HDevWindowStack.GetActive());
}
//disp_continue_message (WindowID, 'black', 'true')
// stop(...); only in hdevelop
//看一下没有扩展灰度之前的图像,填充两个区域之间的空白部分
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Rest, HDevWindowStack.GetActive());
}
ho_Bad.Dispose();
HOperatorSet.ExpandGray(ho_Rest, ho_Ic, ho_Good, out ho_Bad, 6, "image", 5);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Bad, HDevWindowStack.GetActive());
}
//看一下把ok区域填充一下的效果,就是把现有区域附近的5个灰度值内的像素扩展一下
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Good, HDevWindowStack.GetActive());
}
ho_Good_expand.Dispose();
HOperatorSet.ExpandGray(ho_Good, ho_Ic, ho_Rest, out ho_Good_expand, 6, "image",
5);
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Good_expand, HDevWindowStack.GetActive());
}
//disp_continue_message (WindowID, 'black', 'true'
// stop(...); only in hdevelop
ho_ConnectedBad.Dispose();
HOperatorSet.Connection(ho_Bad, out ho_ConnectedBad);
ho_BigBad.Dispose();
HOperatorSet.SelectShape(ho_ConnectedBad, out ho_BigBad, "area", "and", 150,
99999);
hv_AreaBad.Dispose();hv_Row.Dispose();hv_Column.Dispose();
HOperatorSet.AreaCenter(ho_BigBad, out hv_AreaBad, out hv_Row, out hv_Column);
hv_NumMissingSolder.Dispose();
HOperatorSet.CountObj(ho_BigBad, out hv_NumMissingSolder);
hv_AreaMissingSolder.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_AreaMissingSolder = hv_AreaBad.TupleSum()
;
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Images, HDevWindowStack.GetActive());
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 3);
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Good, HDevWindowStack.GetActive());
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_BigBad, HDevWindowStack.GetActive());
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "fill");
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 1);
}
// dev_update_window(...); only in hdevelop
HOperatorSet.SetSystem("clip_region", hv_Information);
}
catch (HalconException HDevExpDefaultException)
{
ho_Images.Dispose();
ho_Ic.Dispose();
ho_Input1.Dispose();
ho_Input2.Dispose();
ho_Input3.Dispose();
ho_Input4.Dispose();
ho_ImageMean.Dispose();
ho_Darks.Dispose();
ho_Dark.Dispose();
ho_DarkFilled.Dispose();
ho_Lights.Dispose();
ho_Light.Dispose();
ho_Intersection.Dispose();
ho_Back.Dispose();
ho_RegionExpanded.Dispose();
ho_Good.Dispose();
ho_Rest.Dispose();
ho_Bad.Dispose();
ho_Good_expand.Dispose();
ho_ConnectedBad.Dispose();
ho_BigBad.Dispose();
hv_Information.Dispose();
hv_WindowID.Dispose();
hv_AreaBad.Dispose();
hv_Row.Dispose();
hv_Column.Dispose();
hv_NumMissingSolder.Dispose();
hv_AreaMissingSolder.Dispose();
throw HDevExpDefaultException;
}
ho_Images.Dispose();
ho_Ic.Dispose();
ho_Input1.Dispose();
ho_Input2.Dispose();
ho_Input3.Dispose();
ho_Input4.Dispose();
ho_ImageMean.Dispose();
ho_Darks.Dispose();
ho_Dark.Dispose();
ho_DarkFilled.Dispose();
ho_Lights.Dispose();
ho_Light.Dispose();
ho_Intersection.Dispose();
ho_Back.Dispose();
ho_RegionExpanded.Dispose();
ho_Good.Dispose();
ho_Rest.Dispose();
ho_Bad.Dispose();
ho_Good_expand.Dispose();
ho_ConnectedBad.Dispose();
ho_BigBad.Dispose();
hv_Information.Dispose();
hv_WindowID.Dispose();
hv_AreaBad.Dispose();
hv_Row.Dispose();
hv_Column.Dispose();
hv_NumMissingSolder.Dispose();
hv_AreaMissingSolder.Dispose();
}
#endif
}
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public class HDevelopExportApp
{
static void Main(string[] args)
{
new HDevelopExport();
}
}
#endif