• 大小: 706KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-18
  • 语言: C#
  • 标签: HALCON  C#  

资源简介

这个程序有两种对图像的读取办法,1.打开摄像头拍照提取。2直接读取文件中的图片,并将其轮廓矢量化,保存得到相应的文本数据。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;
namespace draw_Contours
{
    public partial class Form1 : Form
    {
        public Hobject srcsrc_image;
        HTuple windowIDhwindow;
        bool TP = false OC = false OP = false DW = false;
        public Form1()
        {
            InitializeComponent();
            src = new Hobject();
            //src_image = new Hobject();
            HOperatorSet.SetWindowAttr(“background_color“ “green“);
            HOperatorSet.OpenWindow(0 0 this.pictureBox1.Width this.pictureBox1.Height this.pictureBox1.Handle “visible“ ““ out windowID);
        }
        Thread dispig;
        private string  imagePath;
        HTuple width = null height = null;      
        string[] writeLineBeginRow writeLineBeginCol writeLineEndRow writeLineEndCol writeLineNR writeLineNC writeLineDist;
        int i = 0;
        private void btn_openCamera_Click(object sender EventArgs e)
        {
            i = 1;
            if (btn_openCamera.Text == “Open Camera“)
            {
                btn_openCamera.Text = “Close Camera“;
                OC = true;
                dispig = new Thread(getin);
                dispig.Start();
            }
            else if(btn_openCamera.Text==“Close Camera“)
            {
                btn_openCamera.Text = “Open Camera“;
                TP = false; OC = false; OP = false; DW = false;
                dispig.Abort();
                HOperatorSet.Closeframegrabber(hwindow);
            }
        }

        public void getin()
        {
            HOperatorSet.GenEmptyObj(out src_image);         
            HOperatorSet.Openframegrabber(“DirectShow“ 1 1 0 0 0 0 “default“ 8 “rgb“ -1 “false“ “default“ “[0] Webcam SC-10HDD12636P“ 0 -1 out hwindow);
            HOperatorSet.GrabImageStart(hwindow -1);
            while (true)
            {
                HOperatorSet.GrabImageAsync(out src_image hwindow -1);
                HOperatorSet.GetImageSize(src_imageout widthout height);
                HOperatorSet.SetPart(hWindowControl1.HalconWindow 0 0 height width);
                HOperatorSet.DispObj(src_image hWindowControl1.HalconWindow);
            }
        }

        private void Form1_FormClosing(object sender FormClosingEventArgs e)
        {
            if (btn_openCamera.Text==“Close Camera“)
            {
                dispig.Abort();
                HOperatorSet.Closeframegrabber(hwindow);
            }
        }

        private void btn_takephoto_Click(object sender EventArgs e)
        {
            if (OC == true)
            {
                TP = true;
                src = src_image.Clone();
                HO

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-09-22 00:50  draw_Contours\
     文件         189  2018-09-21 13:23  draw_Contours\App.config
     文件       10954  2018-09-22 00:43  draw_Contours\Form1.Designer.cs
     文件       10501  2018-09-22 00:50  draw_Contours\Form1.cs
     文件        6603  2018-09-22 00:43  draw_Contours\Form1.resx
     文件         525  2018-09-21 13:23  draw_Contours\Program.cs
     目录           0  2018-09-21 13:23  draw_Contours\Properties\
     文件        1324  2018-09-21 13:23  draw_Contours\Properties\AssemblyInfo.cs
     文件        2839  2018-09-21 13:23  draw_Contours\Properties\Resources.Designer.cs
     文件        5612  2018-09-21 13:23  draw_Contours\Properties\Resources.resx
     文件        1100  2018-09-21 13:23  draw_Contours\Properties\Settings.Designer.cs
     文件         249  2018-09-21 13:23  draw_Contours\Properties\Settings.settings
     目录           0  2018-09-21 13:23  draw_Contours\bin\
     目录           0  2018-09-21 20:14  draw_Contours\bin\Debug\
     文件       17920  2018-09-22 00:50  draw_Contours\bin\Debug\draw_Contours.exe
     文件         189  2018-09-21 13:23  draw_Contours\bin\Debug\draw_Contours.exe.config
     文件       24064  2018-09-22 00:50  draw_Contours\bin\Debug\draw_Contours.pdb
     文件     1409680  2016-10-28 00:54  draw_Contours\bin\Debug\halcondotnet.dll
     文件     4357073  2016-10-27 00:02  draw_Contours\bin\Debug\halcondotnet.xml
     文件        3880  2018-09-21 13:38  draw_Contours\draw_Contours.csproj
     目录           0  2018-09-21 13:23  draw_Contours\obj\
     目录           0  2018-09-22 00:43  draw_Contours\obj\Debug\
     文件        9913  2018-09-22 00:42  draw_Contours\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7602  2018-09-21 13:23  draw_Contours\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2018-09-22 00:52  draw_Contours\obj\Debug\TempPE\
     文件           0  2018-09-21 13:23  draw_Contours\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2018-09-21 13:23  draw_Contours\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2018-09-21 13:23  draw_Contours\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     文件         180  2018-09-22 00:43  draw_Contours\obj\Debug\draw_Contours.Form1.resources
     文件         180  2018-09-21 13:39  draw_Contours\obj\Debug\draw_Contours.Properties.Resources.resources
     文件           0  2018-09-22 00:50  draw_Contours\obj\Debug\draw_Contours.csproj.CopyComplete
............此处省略6个文件信息

评论

共有 条评论