当前位置: 首页 > news >正文

网站开发 策划是干嘛的关键词林俊杰歌词

网站开发 策划是干嘛的,关键词林俊杰歌词,推广运营方案,怎么样创建网站产品检测 这段代码是一个基于HalconDotNet的Windows窗体应用程序,主要用于图像处理和测量。以下是对代码的一些总结: 1. **图像显示与加载:** - 使用HalconDotNet库进行图像处理。 - 通过OpenFileDialog实现图像文件的选择和加载。 …

产品检测

这段代码是一个基于HalconDotNet的Windows窗体应用程序,主要用于图像处理和测量。以下是对代码的一些总结:
1. **图像显示与加载:**
   - 使用`HalconDotNet`库进行图像处理。
   - 通过`OpenFileDialog`实现图像文件的选择和加载。
   - 使用`HImage`对象存储和显示图像。
2. **图像处理方法:**
   - 实现了图像的灰度化、二值化、连接区域等处理。
   - 提供了一系列图像处理的参数,如二值化阈值、区域筛选参数等。
3. **测量功能:**
   - 实现了对图像中物体宽度、高度的测量。
   - 计算了内外圈直径,并显示在界面上。
   - 提供了上下高度、左右宽度等测量按钮。
4. **界面交互:**
   - 通过按钮触发不同的图像处理和测量操作。
   - 提供了清除窗口和退出程序的功能。
5. **界面设计:**
   - 使用Windows窗体(`Form`)设计应用程序界面。
   - 包含了图像显示窗口(`HalconWindow`)和多个按钮用于触发不同操作。
6. **代码结构:**
   - 使用了命名空间(`WindowsFormsApp1`)。
   - 包含了一个`Form`类,其中定义了图像处理的方法和界面上的各个控件事件处理方法。
7. **需要改进的地方:**
   - 部分注释是中文,但整体注释较少,可以进一步添加注释以提高代码可读性。
   - 代码中使用了一些硬编码的路径,可以考虑使用相对路径或配置文件来管理。
总体而言,这是一个用于图像处理和测量的简单Windows应用程序,可以根据具体需求进一步扩展和优化。

using HalconDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApp1
{public partial class Form1 : Form{public Form1(){InitializeComponent();}public static HImage hImage = new HImage();public HRegion hRegion = new HRegion();public void HImageShow(HImage hImage, string filePath){hImage.ReadImage(filePath);hImage.GetImageSize(out HTuple width, out HTuple height);HOperatorSet.CountChannels(hImage, out HTuple channels);HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, height + 1, width + 1);//hImage.DispImage(hWindowControl1.HalconWindow);  //灰度图像hImage.DispObj(hWindowControl1.HalconWindow);}//二值化参数HTuple MinValue = 4;HTuple MaxValue = 88;//ROI筛选1HTuple feature1 = "area";string operation = "and";HTuple min1 = 150.0;HTuple max1 = 99999.0;// 照片位深int dpi = 72;public HRegion hImage1Process(HImage hImage){HImage grayImage = hImage.Rgb1ToGray();HRegion Region1 = grayImage.Threshold(MinValue, MaxValue);HRegion connectionRegion = Region1.Connection();HRegion selectRegion = connectionRegion.SelectShape(feature1, operation, min1, max1);HRegion regionUnion = selectRegion.Union1();HRegion closingRegion = regionUnion.ClosingCircle(7.5);HRegion opeingRegion = closingRegion.OpeningCircle(3.5);return opeingRegion;}//显示图片private void button1_Click(object sender, EventArgs e){OpenFileDialog openFileDialog2 = new OpenFileDialog();openFileDialog2.Multiselect = true;  //该值确定是否可以选择多个文件//openFileDialog2.Title = "请选择文件";openFileDialog2.Filter = "(*.PNG)|*.PNG|(*.jpg)|*.jpg|(*.txt)|*.txt";//openFileDialog2.Filter = "文档(*.doc;*.docx)|*.doc;*.docx";string filePath = "";if (openFileDialog2.ShowDialog() == DialogResult.OK){if (openFileDialog2.FileName != ""){filePath = openFileDialog2.FileName;HImageShow(hImage, filePath);}}}//清除窗口private void button2_Click(object sender, EventArgs e){hWindowControl1.HalconWindow.ClearWindow();hImage.Dispose();}//退出程序private void button9_Click(object sender, EventArgs e){System.Environment.Exit(0);}//宽度计算public void objWidth(HImage hImage){hRegion = hImage1Process(hImage);hRegion.SmallestRectangle2(out HTuple row, out HTuple column, out HTuple Phi, out HTuple Length1, out HTuple Length2);hRegion.SmallestCircle(out HTuple Row, out HTuple Column, out HTuple Radius);HTuple MaxLength1 = Length1.TupleMax();textBox2.Text = (MaxLength1 / dpi * 25.4).ToString() + "mm\n";hWindowControl1.HalconWindow.SetDraw("margin");hRegion.GenRegionLine(row, column - Length1, row, column + Length1);hRegion.DispObj(hWindowControl1.HalconWindow);hRegion.Dispose();}//高度计算public void objHeigth(HImage hImage){hRegion = hImage1Process(hImage);hRegion.SmallestRectangle2(out HTuple row, out HTuple column, out HTuple Phi, out HTuple Length1, out HTuple Length2);hRegion.SmallestCircle(out HTuple Row, out HTuple Column, out HTuple Radius);double MaxLength2 = 0;HTuple MaxLength1 = Length1.TupleMax();textBox1.Text = (Length1[0] == MaxLength1[0]).ToString();for (int Index = 0; Index < Length1.Length; Index++){if (Length1[Index] - MaxLength1[Index] <= 0.000001){MaxLength2 = Length2[Index];}}textBox1.Text = (MaxLength2 / dpi * 25.4).ToString() + "mm\n";hWindowControl1.HalconWindow.SetDraw("margin");hRegion.GenRectangle2(row, column, Phi, Length1, Length2);hRegion.GenRegionLine(row - Length2, column, row + Length2, column);hRegion.DispObj(hWindowControl1.HalconWindow);hRegion.Dispose();}//上下高度private void button3_Click(object sender, EventArgs e){objHeigth(hImage);}//左右宽度private void button4_Click(object sender, EventArgs e){objWidth(hImage);}//内圈直径private void button5_Click(object sender, EventArgs e){objCicle1(hImage);}//内圈直径计算public void objCicle1(HImage hImage){hRegion = hImage1Process(hImage);hRegion.SmallestRectangle2(out HTuple row, out HTuple column, out HTuple Phi, out HTuple Length1, out HTuple Length2);hRegion.SmallestCircle(out HTuple Row, out HTuple Column, out HTuple Radius);hRegion.GenRectangle2(row, column, Phi, Length1, Length2);HImage grayImage = hImage.Rgb1ToGray();HImage ImageReduced = grayImage.ReduceDomain(hRegion);HRegion Regions = ImageReduced.Threshold(94.0, 119.0);HRegion Fillup = Regions.OpeningCircle(5.5).Connection().SelectShape("area", "and", 30000.0, 999999).FillUp();hWindowControl1.HalconWindow.SetDraw("margin");Fillup.SmallestCircle(out double row2, out double column2, out double radius2);hRegion.GenCircle(row2, column2, radius2);hRegion.DispObj(hWindowControl1.HalconWindow);textBox3.Text = (radius2 / dpi * 25.4).ToString() + "mm\n";}//外圈直径计算public void objCicle2(HImage hImage){hRegion = hImage1Process(hImage);hRegion.SmallestRectangle2(out HTuple row, out HTuple column, out HTuple Phi, out HTuple Length1, out HTuple Length2);hRegion.SmallestCircle(out HTuple Row, out HTuple Column, out HTuple Radius);hRegion.GenRectangle2(row, column, Phi, Length1, Length2);HImage grayImage = hImage.Rgb1ToGray();HImage ImageReduced = grayImage.ReduceDomain(hRegion);HRegion Regions = ImageReduced.Threshold(94.0, 119.0);HRegion Fillup = Regions.OpeningCircle(5.5).Connection().SelectShape("area", "and", 30000.0, 999999).FillUp();hWindowControl1.HalconWindow.SetDraw("margin");Fillup.SmallestCircle(out double row2, out double column2, out double radius2);double radius3 = Length2;hRegion.GenCircle(row2, column2, radius3);hRegion.DispObj(hWindowControl1.HalconWindow);textBox4.Text = (radius3 / dpi * 25.4).ToString() + "mm\n";}private void button6_Click(object sender, EventArgs e){objCicle2(hImage);}private void button7_Click(object sender, EventArgs e){hRegion = hImage1Process(hImage);hRegion.SmallestRectangle2(out HTuple row, out HTuple column, out HTuple Phi, out HTuple Length1, out HTuple Length2);hRegion.SmallestCircle(out HTuple Row, out HTuple Column, out HTuple Radius);double MaxLength2 = 0;double MaxRow = 0;double MaxColumn = 0;double MaxPhi = 0;HTuple MaxLength1 = Length1.TupleMax();textBox1.Text = (Length1[0] == MaxLength1[0]).ToString();for (int Index = 0; Index < Length1.Length; Index++){if (Length1[Index] - MaxLength1[Index] <= 0.000001){MaxLength2 = Length2[Index];MaxRow = Row[Index];MaxColumn = Column[Index];MaxPhi = Phi[Index];}}textBox5.Text = (MaxLength2 / dpi * 25.4).ToString() + "mm\n";hWindowControl1.HalconWindow.SetDraw("margin");hRegion.GenRectangle2(new HTuple(MaxRow), new HTuple(MaxColumn), new HTuple(MaxPhi), new HTuple(MaxLength1), new HTuple(MaxLength2));hRegion.DispObj(hWindowControl1.HalconWindow);hRegion.Dispose();}private void button8_Click(object sender, EventArgs e){hImage.ReadImage("C:\\Users\\1\\Desktop\\表盘imgaes\\1-1.png");hImage.GetImageSize(out HTuple width, out HTuple height);HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, height + 1, width + 1);//hImage.DispImage(hWindowControl1.HalconWindow);  //灰度图像hImage.DispObj(hWindowControl1.HalconWindow);}private void button10_Click(object sender, EventArgs e){hImage.ReadImage("C:\\Users\\1\\Desktop\\表盘imgaes\\1-2.png");hImage.GetImageSize(out HTuple width, out HTuple height);HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, height + 1, width + 1);//hImage.DispImage(hWindowControl1.HalconWindow);  //灰度图像hImage.DispObj(hWindowControl1.HalconWindow);}}
}

这段代码有一些优点和一些需要改进的地方。
**优点:**
1. **功能丰富:** 代码实现了图像处理和测量的多个功能,包括灰度化、二值化、区域连接、测量物体的宽度、高度等。
2. **界面交互:** 通过Windows窗体设计,提供了用户友好的界面,通过按钮触发不同的操作,易于使用。
3. **代码结构清晰:** 代码使用了命名空间和类的结构,提高了代码的组织性和可维护性。
4. **使用HalconDotNet库:** 利用HalconDotNet库进行图像处理,该库功能强大,适用于工业视觉和图像处理领域。
**需要改进的地方:**
1. **注释不足:** 部分注释是中文,但整体注释较少。可以添加更多注释,特别是对于复杂逻辑和算法的部分,以提高代码的可读性。
2. **硬编码路径:** 代码中使用了一些硬编码的路径,建议使用相对路径或配置文件来管理路径,提高代码的灵活性。
3. **异常处理:** 缺少对异常的处理,例如文件加载失败、图像处理失败等情况应该进行适当的异常处理。
4. **代码复用性:** 一些功能可能可以抽象成可复用的方法,提高代码的重用性。
5. **界面布局:** 界面布局方面可以进一步优化,使界面更加美观和易于使用。
总体而言,这段代码是一个功能完善的图像处理应用程序,通过一些改进可以进一步提高代码的质量和可维护性。

http://www.dinnco.com/news/72640.html

相关文章:

  • 微博营销策划方案范文seo外链发布平台有哪些
  • 小游戏网站宁波seo优化
  • 邢台做网站长沙做网站推广公司咨询
  • 唐山哪家网站好网址搜索域名查询
  • 宝鸡网站建设优化如何提高百度关键词排名
  • 北京 做网站淘宝店铺怎么免费推广
  • 新手建设html5网站厦门谷歌推广
  • 网站建设优化文章丈哥seo博客
  • 宁波做网站seo优化营商环境心得体会1000字
  • 亳州做商标网站的公司深圳全网营销方案
  • 快递公司网站怎么做做搜索引擎推广多少钱
  • 公司备案证查询网站查询网站查询注册网站在哪里注册
  • 网站打开不对app推广方案怎么写
  • 网站用户后台是怎么做的网站推广联盟
  • 移动互联网的终端包括我们大家经常使用的郑州技术支持seo
  • 宝安高端网站建设产品推广软文500字
  • 建行国际互联网网站免费推广软件工具
  • 服饰营销型网站建设长沙优化科技有限公司
  • 做网页一般多少钱优化百度seo技术搜索引擎
  • 提供企业网站建设价格游戏代理免费加盟
  • 网站制作多久今日头条权重查询
  • 做动物网站的原因十大洗脑广告
  • 网站的商业授权吉安seo网站快速排名
  • wordpress修改文章发表日期颜色百度seo排名点击
  • wordpress设计网页谷歌优化是什么意思
  • python云服务器网站开发实例关键词推广
  • 网站建设与维护中职计算机基础培训机构
  • 一件代发货源app网络优化工程师有前途吗
  • 做股权众筹的网站seo的优化技巧和方法
  • 做ppt高手 一定要常去这八个网站厦门百度整站优化服务