| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //时间:
- //作者:
- //功能:自动化测试功能
- 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;
- using System.IO;
- using OpenCvSharp;
- using SmartSEMControl;
- namespace AutoDo
- {
- public partial class FormAutoDo : Form
- {
- //全局只有一个fatorySEM
- //static FactoryHardware factorySEM = FactoryHardware.Instance;
- //ISEMControl iSEM = factorySEM.ISEM;
- //图像文件夹
- public string m_strImgPath;
- //显示处理结果
- public Bitmap m_bitmap;
- public FormAutoDo()
- {
- InitializeComponent();
- }
- //自动对焦过程
- private void button1_Click(object sender, EventArgs e)
- {
- //第一种方法
- var files = Directory.GetFiles(m_strImgPath, "*.tif");
- int i = 0;
- foreach (var file in files)
- {
- LoGEdge(file);
-
- }
- }
- //选择图像文件夹
- private void button2_Click(object sender, EventArgs e)
- {
- System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
- dialog.Description = "选择拍图保存的文件夹";
- if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (string.IsNullOrEmpty(dialog.SelectedPath))
- {
- MessageBox.Show("图像文件夹不能为空");
- return;
- }
- m_strImgPath = dialog.SelectedPath;
- tBImgPath.Text = dialog.SelectedPath;
- }
- }
- //LoG算子计算
- private bool LoGEdge(string a_strImgPath)
- {
- //读入Img文件
- if (!File.Exists(a_strImgPath))
- {
- return false;
- }
- Mat src, src_gray;
- int kernel_size = 3;
- src = Cv2.ImRead(a_strImgPath);
- src_gray = new Mat();
- //高斯滤波,噪声消除
- Cv2.GaussianBlur(src, src, new OpenCvSharp.Size(3, 3), 0, 0);
- //转化为灰度图像
- Cv2.CvtColor(src, src_gray, ColorConversionCodes.BayerBG2GRAY);
- Mat dst, abs_dst;
- dst = new Mat();
- abs_dst = new Mat();
- //使用Laplace函数
- Cv2.Laplacian(src_gray, dst, MatType.CV_16S, kernel_size);
- //计算绝对值,并将结果转为8位
- Cv2.ConvertScaleAbs(dst, abs_dst);
- //进行LoG运算
- return true;
- }
-
- }
- }
|