http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 9045|回复: 4

[C#皮肤] try -catch -throw 与全局变量传值问题

[复制链接]
发表于 2013-6-5 11:19:58 | 显示全部楼层 |阅读模式
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();  ///需要 传值出来,,,
    }


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-6-20 00:51:47 | 显示全部楼层
不错。值得学习啊,顶一个
发表于 2013-6-27 16:32:57 | 显示全部楼层
我也想听大家的建议!谢
发表于 2013-7-4 12:11:52 | 显示全部楼层
我不懂的,来学习
发表于 2013-7-5 14:42:11 | 显示全部楼层
正在学try -catch用法
受教了,学习中……
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-12-22 14:53

© 2014-2021

快速回复 返回顶部 返回列表