|
class Caokuanshang
{
#region 槽宽上测量图像处理
public static HTuple hv_ExpDefaultWinHandle;
// Chapter: Graphics / Text
// Short Description: This procedure writes a text message.
public static void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
{
。。。。。。
//reset changed window settings
HOperatorSet.SetRgb(hv_ExpDefaultWinHandle, hv_Red, hv_Green, hv_Blue);
HOperatorSet.SetPart(hv_ExpDefaultWinHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part,
hv_Column2Part);
return;
}
// Chapter: Graphics / Text
// Short Description: Set font independent of OS
public static void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font,
HTuple hv_Bold, HTuple hv_Slant)
{
。。。。。。
return;
}
// Procedures
// Main procedure
public static string action(HTuple Window1)
{
hv_ExpDefaultWinHandle = Window1;
// Local iconic variables
HObject ho_Image, ho_Region1, ho_RegionOpening;
HObject ho_ConnectedRegions, ho_RegionFillUp, ho_SelectedRegions;
HObject ho_Rectangle, ho_RegionBorder, ho_RegionDilation;
HObject ho_ImageReduced, ho_Region2, ho_RegionOpening1;
HObject ho_ConnectedRegions1, ho_RegionFillUp1, ho_Region3;
HObject ho_SelectedRegions1, ho_Rectangle1;
// Local control variables
HTuple hv_AcqHandle, hv_Width, hv_Height, hv_WindowHandle = new HTuple();
HTuple hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2;
HTuple hv_Row1, hv_Column1, hv_Row2, hv_Column2, hv_C;
HTuple hv_RowLine1, hv_ColLine1, hv_RowLine2, hv_ColLine2;
。。。
HOperatorSet.GenEmptyObj(out ho_Region3);
HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
HOperatorSet.GenEmptyObj(out ho_Rectangle1);
try
{
//Code generated by Image Acquisition 01
HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8,
"rgb", -1, "false", "default", "USB2.0 Camera", 0, -1, out hv_AcqHandle);
HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
ho_Image.Dispose();
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
HOperatorSet.CloseFramegrabber(hv_AcqHandle);
//Do something
//read_image (Image, 'C:/Documents and Settings/Administrator/桌面/图片 029.jpg')
HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
//dev_close_window(...);
//dev_open_window(...);
HOperatorSet.SetPart(hv_ExpDefaultWinHandle, 0, 0, hv_Width, hv_Height);
HOperatorSet.SetLineWidth(hv_ExpDefaultWinHandle, 3);
HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "white");
HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "margin");
HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
set_display_font(hv_ExpDefaultWinHandle, 16, "mono", "true", "false");
HOperatorSet.SetLineWidth(hv_ExpDefaultWinHandle, 2);
HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "fill");
ho_Region1.Dispose();
HOperatorSet.FastThreshold(ho_Image, out ho_Region1, 150, 255, 20);
ho_RegionOpening.Dispose();
HOperatorSet.OpeningRectangle1(ho_Region1, out ho_RegionOpening, 1, 1);
ho_ConnectedRegions.Dispose();
HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
ho_RegionFillUp.Dispose();
HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp);
ho_SelectedRegions.Dispose();
HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions, "area", "and",
2000, 999999);
HOperatorSet.SmallestRectangle2(ho_SelectedRegions, out hv_Row, out hv_Column,
out hv_Phi, out hv_Length1, out hv_Length2);
ho_Rectangle.Dispose();
HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1,
hv_Length2);
ho_RegionBorder.Dispose();
HOperatorSet.Boundary(ho_Rectangle, out ho_RegionBorder, "inner_filled");
ho_RegionDilation.Dispose();
HOperatorSet.DilationRectangle1(ho_RegionBorder, out ho_RegionDilation, 50,
1);
ho_ImageReduced.Dispose();
HOperatorSet.ReduceDomain(ho_Image, ho_RegionDilation, out ho_ImageReduced);
HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);
HOperatorSet.DispObj(ho_ImageReduced, hv_ExpDefaultWinHandle);
ho_Region2.Dispose();
HOperatorSet.FastThreshold(ho_ImageReduced, out ho_Region2, 150, 255, 20);
ho_RegionOpening1.Dispose();
HOperatorSet.OpeningRectangle1(ho_Region2, out ho_RegionOpening1, 1, 1);
ho_ConnectedRegions1.Dispose();
HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions1);
ho_RegionFillUp1.Dispose();
HOperatorSet.FillUp(ho_ConnectedRegions1, out ho_RegionFillUp1);
ho_Region3.Dispose();
HOperatorSet.SelectShape(ho_RegionFillUp1, out ho_Region3, "area", "and", 1000,
3000);
HOperatorSet.InnerRectangle1(ho_Region3, out hv_Row1, out hv_Column1, out hv_Row2,
out hv_Column2);
ho_Rectangle1.Dispose();
HOperatorSet.GenRectangle1(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Row2,
hv_Column2);
HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);
HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
hv_C = 480-hv_Row1;
hv_RowLine1 = hv_Row1-4;
hv_ColLine1 = hv_Column1.Clone();
hv_RowLine2 = hv_Row1-4;
hv_ColLine2 = hv_Column1+55;
HOperatorSet.DispLine(hv_ExpDefaultWinHandle, hv_RowLine1, hv_ColLine1, hv_RowLine2,
hv_ColLine2);
HOperatorSet.DispArrow(hv_ExpDefaultWinHandle, hv_RowLine1, hv_ColLine1+50,
480, hv_ColLine1+50, 3);
disp_message(hv_ExpDefaultWinHandle, "槽的上部分:"+hv_C, "window", hv_Row1-30,
hv_Column1-70, "black", "true");
//return hv_C.ToString(); ///需要 传值出来,,,
}
catch (HalconException HDevExpDefaultException)
{
ho_Image.Dispose();
ho_Region1.Dispose();
。。。
ho_Rectangle1.Dispose();
throw HDevExpDefaultException;
}
ho_Image.Dispose();
ho_Region1.Dispose();
。。
ho_Region2.Dispose();
ho_RegionOpening1.Dispose();
ho_ConnectedRegions1.Dispose();
ho_RegionFillUp1.Dispose();
ho_Region3.Dispose();
ho_Rectangle1.Dispose();
}
return hv_C.ToString(); ///需要 传值出来,,,
}
#endregion
----- //return hv_C.ToString(); ///需要 传值出来,,,配合try -catch-throw---怎么实现,,return hv_C.ToString(); ///需要 传值出来,,,
}
|
|