|
20-图像循环处理_中途stop停止
百度网盘链接:https://pan.baidu.com/s/1felOs1ZmUic17YghnVfHug 提取码:4iyk
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,并提交给我,我来设置视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1
代码如下:
- 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 HalconDotNet;
- namespace ThreadStop
- {
- public partial class Form1 : Form
- {
- string FilePath = null;
- BackgroundWorker Worker = null;
- public Form1()
- {
- InitializeComponent();
- }
- private void bt_Run_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog FilesPath = new FolderBrowserDialog();
- if (FilesPath.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- FilePath = FilesPath.SelectedPath;
- }
- Worker = new BackgroundWorker();
- Worker.WorkerSupportsCancellation = true;
- Worker.DoWork += new DoWorkEventHandler(RunImageProcess);
- Worker.RunWorkerAsync();
- }
- private void RunImageProcess(object sender, EventArgs e)
- {
- BackgroundWorker newWorker = sender as BackgroundWorker;
- ImageProcessFuns(newWorker);
- }
- private void ImageProcessFuns(BackgroundWorker newWorker)
- {
- HObject ho_Image = null, ho_RegionUnion = null;
- HTuple hv_ImageFiles = null;
- HTuple hv_ImageLength = null, hv_i = null;
- HTuple Width = null, Height = null;
- // Initialize local and output iconic variables
- HOperatorSet.GenEmptyObj(out ho_Image);
- HOperatorSet.GenEmptyObj(out ho_RegionUnion);
- ImageProcess.list_image_files(FilePath, "default", new HTuple(), out hv_ImageFiles);
- hv_ImageLength = new HTuple(hv_ImageFiles.TupleLength());
- HTuple end_val6 = hv_ImageLength - 1;
- HTuple step_val6 = 1;
- for (hv_i = 0; hv_i.Continue(end_val6, step_val6); hv_i = hv_i.TupleAdd(step_val6))
- {
- ho_Image.Dispose();
- HOperatorSet.ReadImage(out ho_Image, hv_ImageFiles.TupleSelect(hv_i));
- ho_RegionUnion.Dispose();
- ImageProcess.threSeg(ho_Image, out ho_RegionUnion);
- HOperatorSet.GetImageSize(ho_Image, out Width, out Height);
- HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, Height - 1, Width - 1);
- HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
- HOperatorSet.DispObj(ho_RegionUnion, hWindowControl1.HalconWindow);
- this.tB_PicIndex.Text = hv_i.ToString();
- if (newWorker.CancellationPending == true)
- {
- break;
- }
- }
- MessageBox.Show("done!!!");
- }
- private void chB_Stop_CheckedChanged(object sender, EventArgs e)
- {
- if (this.chB_Stop.Checked)
- {
- if (Worker.IsBusy)
- {
- Worker.CancelAsync();
- }
- }
- else
- {
- if (!Worker.IsBusy)
- {
- Worker.RunWorkerAsync();
- }
- }
- }
- }
- }
复制代码
|
|