• 大小: 18.24MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-02
  • 语言: C#
  • 标签: halcon  c#  

资源简介

博客文章《halcon联合C#实现实时显示》的源代码,使用C#联合halcon12打开自己电脑的摄像头,并实时采集图像。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HalconDotNet;
using System.Threading;

namespace LwVisionCs
{
    public partial class MainWnd : Form
    {
        HTuple hv_WindowId;
        HTuple hv_AcqHandle;

        Hobject ho_Image;
        HTuple hv_With hv_Height;

        Hobject ho_RegionRoi;

        bool m_fContinueGrab = false;
        
        public MainWnd()
        {
            InitializeComponent();
            
        }

        private void MainWnd_Load(object sender EventArgs e)
        {
            //开窗口
            HOperatorSet.OpenWindow(0 0 pictureBoxShow.Width pictureBoxShow.Height pictureBoxShow.Handle ““ ““ out hv_WindowId);
            //开相机
            HOperatorSet.Openframegrabber(“DirectShow“ 1 1 0 0 0 0 “default“ 8 “rgb“
                -1 “false“ “default“ “[0] Integrated Webcam“ 0 -1 out hv_AcqHandle);
            //采图
            HOperatorSet.GrabImage(out ho_Image hv_AcqHandle);
            //获取图像大小
            HOperatorSet.GetImageSize(ho_Image out hv_With out hv_Height);
            //设置在窗口上显示整幅图,该函数是设置在窗口上显示图像的那部分
            HOperatorSet.SetPart(hv_WindowId 0 0 hv_Height hv_With);
            //在窗口上显示图像
            HOperatorSet.DispObj(ho_Image hv_WindowId);
        }

        Thread thContiGrab;

        private void bntContinueGrab_Click(object sender EventArgs e)
        {
            if (m_fContinueGrab == false)
            {
                m_fContinueGrab = true;
                thContiGrab = new Thread(ThreadContinueGrab);
                thContiGrab.Start();
                thContiGrab.IsBackground = true;

                bntContinueGrab.Text = “停止“;

            }
            else
            {
                m_fContinueGrab = false;
                thContiGrab.Abort();
                bntContinueGrab.Text = “实时“;
            }
        }

        private void ThreadContinueGrab()
        {

            while (true)
            {
                //先要销毁对象,否则就会造成内存泄露
                ho_Image.Dispose();
                //采图显示
                HOperatorSet.GrabImage(out ho_Image hv_AcqHandle);
                HOperatorSet.DispObj(ho_Image hv_WindowId);
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     307768  2014-11-15 02:27  LwVisionCsCsdn\bin\x64\Debug\hAcqDirectShow.dll

     文件   54483000  2015-01-26 09:49  LwVisionCsCsdn\bin\x64\Debug\halcon.dll

     文件    1279544  2014-11-15 02:27  LwVisionCsCsdn\bin\x64\Debug\halcondotnet.dll

     文件    4074746  2014-11-15 01:07  LwVisionCsCsdn\bin\x64\Debug\halcondotnet.xml

     文件       9216  2018-11-11 10:49  LwVisionCsCsdn\bin\x64\Debug\LwVisionCs.exe

     文件      44544  2018-11-11 10:49  LwVisionCsCsdn\bin\x64\Debug\LwVisionCs.pdb

     文件      11592  2018-11-11 10:50  LwVisionCsCsdn\bin\x64\Debug\LwVisionCs.vshost.exe

     文件        490  2015-04-21 05:26  LwVisionCsCsdn\bin\x64\Debug\LwVisionCs.vshost.exe.manifest

     文件       2591  2018-11-11 10:46  LwVisionCsCsdn\Form1.cs

     文件       2981  2018-11-11 10:41  LwVisionCsCsdn\Form1.Designer.cs

     文件       5817  2018-11-11 10:41  LwVisionCsCsdn\Form1.resx

     文件       6213  2018-05-10 11:39  LwVisionCsCsdn\LwVisionCs.csproj

     文件       1215  2018-05-10 11:39  LwVisionCsCsdn\LwVisionCs.sln

    ..A..H.     23552  2018-11-11 10:50  LwVisionCsCsdn\LwVisionCs.suo

     文件       5420  2018-05-10 12:46  LwVisionCsCsdn\obj\x64\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6387  2018-11-11 10:49  LwVisionCsCsdn\obj\x64\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       4362  2018-11-11 10:50  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.csproj.FileListAbsolute.txt

     文件        975  2018-11-11 10:41  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.csproj.GenerateResource.Cache

     文件      16860  2018-05-10 12:56  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.csprojResolveAssemblyReference.cache

     文件       9216  2018-11-11 10:49  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.exe

     文件        180  2018-05-10 18:21  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.Form1.resources

     文件        180  2018-11-11 10:41  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.MainWnd.resources

     文件      44544  2018-11-11 10:49  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.pdb

     文件        180  2018-05-10 12:52  LwVisionCsCsdn\obj\x64\Debug\LwVisionCs.Properties.Resources.resources

     文件       2867  2018-05-10 11:21  LwVisionCsCsdn\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6563  2018-05-10 11:25  LwVisionCsCsdn\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        493  2018-05-14 17:12  LwVisionCsCsdn\Program.cs

     文件       1370  2018-05-10 11:21  LwVisionCsCsdn\Properties\AssemblyInfo.cs

     文件       2872  2018-05-10 11:21  LwVisionCsCsdn\Properties\Resources.Designer.cs

     文件       5612  2018-05-10 11:21  LwVisionCsCsdn\Properties\Resources.resx

............此处省略18个文件信息

评论

共有 条评论