请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 6279|回复: 0

20-图像循环处理_中途stop停止

[复制链接]

1288

主题

1514

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22589
发表于 2019-3-31 22:37:48 | 显示全部楼层 |阅读模式
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

代码如下:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using HalconDotNet;

  11. namespace ThreadStop
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         string FilePath = null;
  16.         BackgroundWorker Worker = null;
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }

  21.         private void bt_Run_Click(object sender, EventArgs e)
  22.         {
  23.             FolderBrowserDialog FilesPath = new FolderBrowserDialog();
  24.             if (FilesPath.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  25.             {
  26.                 FilePath = FilesPath.SelectedPath;
  27.             }

  28.             Worker = new BackgroundWorker();
  29.             Worker.WorkerSupportsCancellation = true;
  30.             Worker.DoWork += new DoWorkEventHandler(RunImageProcess);
  31.             Worker.RunWorkerAsync();

  32.         }

  33.         private void RunImageProcess(object sender, EventArgs e)
  34.         {
  35.             BackgroundWorker newWorker = sender as BackgroundWorker;
  36.             ImageProcessFuns(newWorker);
  37.         }

  38.         private void ImageProcessFuns(BackgroundWorker newWorker)
  39.         {
  40.             HObject ho_Image = null, ho_RegionUnion = null;
  41.             HTuple hv_ImageFiles = null;
  42.             HTuple hv_ImageLength = null, hv_i = null;
  43.             HTuple Width = null, Height = null;
  44.             // Initialize local and output iconic variables
  45.             HOperatorSet.GenEmptyObj(out ho_Image);
  46.             HOperatorSet.GenEmptyObj(out ho_RegionUnion);

  47.             ImageProcess.list_image_files(FilePath, "default", new HTuple(), out hv_ImageFiles);
  48.             hv_ImageLength = new HTuple(hv_ImageFiles.TupleLength());

  49.             HTuple end_val6 = hv_ImageLength - 1;
  50.             HTuple step_val6 = 1;
  51.             for (hv_i = 0; hv_i.Continue(end_val6, step_val6); hv_i = hv_i.TupleAdd(step_val6))
  52.             {
  53.                 ho_Image.Dispose();
  54.                 HOperatorSet.ReadImage(out ho_Image, hv_ImageFiles.TupleSelect(hv_i));

  55.                 ho_RegionUnion.Dispose();
  56.                 ImageProcess.threSeg(ho_Image, out ho_RegionUnion);

  57.                 HOperatorSet.GetImageSize(ho_Image, out Width, out Height);

  58.                 HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, Height - 1, Width - 1);
  59.                 HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
  60.                 HOperatorSet.DispObj(ho_RegionUnion, hWindowControl1.HalconWindow);

  61.                 this.tB_PicIndex.Text = hv_i.ToString();

  62.                 if (newWorker.CancellationPending == true)
  63.                 {
  64.                     break;
  65.                 }

  66.             }
  67.             MessageBox.Show("done!!!");

  68.         }

  69.         private void chB_Stop_CheckedChanged(object sender, EventArgs e)
  70.         {
  71.             if (this.chB_Stop.Checked)
  72.             {
  73.                 if (Worker.IsBusy)
  74.                 {
  75.                     Worker.CancelAsync();
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 if (!Worker.IsBusy)
  81.                 {
  82.                     Worker.RunWorkerAsync();
  83.                 }
  84.             }
  85.         }
  86.     }
  87. }
复制代码






算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-29 20:05 , Processed in 0.202304 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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