• 大小: 236KB
    文件类型: .zip
    金币: 2
    下载: 2 次
    发布日期: 2024-01-16
  • 语言: C#
  • 标签: LMI  HALCON  C#  

资源简介

C#程序连接LMI3D相机,获取数据后通过halcon转化成png,12位深图像文件。再使用halcon计算,拟合平面,自动分割,计算平面高度。

资源截图

代码片段和文件信息

using HalconDotNet;
using Lmi3d.GoSdk;
using Lmi3d.GoSdk.Messages;
using Lmi3d.Zen;
using Lmi3d.Zen.Io;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace LMI_HalconAcqTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string SENSOR_IP = “127.0.0.1“;
        private void Form1_Load(object sender EventArgs e)
        {
            KApiLib.Construct();
            GoSdkLib.Construct();
            GoSystem system = new GoSystem();
            GoSensor sensor;
            KIpAddress ipAddress = KIpAddress.Parse(SENSOR_IP);
            GoDataSet dataSet = new GoDataSet();
            sensor = system.FindSensorByIpAddress(ipAddress);
            sensor.Connect();
            system.EnableData(true);
            system.Start();
            Console.WriteLine(“Waiting for Whole Part Data...“);
            dataSet = system.ReceiveData(30000000);

            for (UInt32 i = 0; i < dataSet.Count; i++)
            {
                GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i);
                switch (dataObj.MessageType)
                {
                    case GoDataMessageType.UniformSurface:
                        {
                            GoSurfaceMsg surfaceMsg = (GoSurfaceMsg)dataObj;
                            long width = surfaceMsg.Width;
                            long length = surfaceMsg.Length;
                            long bufferSize = width * length;
                            IntPtr bufferPointer = surfaceMsg.Data;

                            HImage image = new HImage(“uint2“ (int)width (int)length bufferPointer);
                            HOperatorSet.WriteImage(image “png“0“C:\\Users\\zzheng\\Desktop\\123.png“);

                            //Console.WriteLine(“Whole Part Height Map received:“);
                            //Console.WriteLine(“ Buffer width: {0}“ width);
                            //Console.WriteLine(“ Buffer length: {0}“ length);

                            //short[] ranges = new short[bufferSize];
                            //Marshal.Copy(bufferPointer ranges 0 ranges.Length);

                        }
                        break;
                }
            }
            system.Stop();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-12-30 10:29  LMI_HalconAcqTest\
     目录           0  2019-12-30 10:29  LMI_HalconAcqTest\.vs\
     目录           0  2020-02-28 20:08  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\
     目录           0  2019-12-30 10:29  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v14\
     文件       36864  2020-02-28 19:06  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v14\.suo
     目录           0  2020-02-28 20:09  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v16\
     文件       58880  2020-02-28 20:10  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v16\.suo
     目录           0  2020-02-28 20:09  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v16\Server\
     目录           0  2020-02-28 20:10  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v16\Server\sqlite3\
     文件           0  2020-02-28 20:09  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v16\Server\sqlite3\db.lock
     文件      667648  2020-02-28 20:09  LMI_HalconAcqTest\.vs\LMI_HalconAcqTest\v16\Server\sqlite3\storage.ide
     目录           0  2020-02-28 20:09  LMI_HalconAcqTest\LMI_HalconAcqTest\
     文件         189  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\App.config
     文件        1478  2019-11-04 13:20  LMI_HalconAcqTest\LMI_HalconAcqTest\Form1.Designer.cs
     文件        2578  2020-02-28 20:09  LMI_HalconAcqTest\LMI_HalconAcqTest\Form1.cs
     文件        5817  2019-11-04 13:20  LMI_HalconAcqTest\LMI_HalconAcqTest\Form1.resx
     文件        5902  2020-02-28 19:05  LMI_HalconAcqTest\LMI_HalconAcqTest\LMI_HalconAcqTest.csproj
     文件         529  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\Program.cs
     目录           0  2019-12-30 10:29  LMI_HalconAcqTest\LMI_HalconAcqTest\Properties\
     文件        1342  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\Properties\AssemblyInfo.cs
     文件        2847  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\Properties\Resources.Designer.cs
     文件        5612  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\Properties\Resources.resx
     文件        1104  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\Properties\Settings.Designer.cs
     文件         249  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\Properties\Settings.settings
     目录           0  2019-12-30 10:29  LMI_HalconAcqTest\LMI_HalconAcqTest\bin\
     目录           0  2019-12-30 10:29  LMI_HalconAcqTest\LMI_HalconAcqTest\obj\
     目录           0  2019-12-30 10:29  LMI_HalconAcqTest\LMI_HalconAcqTest\obj\Debug\
     文件         868  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7357  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件          42  2019-12-18 12:16  LMI_HalconAcqTest\LMI_HalconAcqTest\obj\Debug\LMI_HalconAcqTest.csproj.CoreCompileInputs.cache
     文件         130  2019-11-04 13:16  LMI_HalconAcqTest\LMI_HalconAcqTest\obj\Debug\LMI_HalconAcqTest.csproj.FileListAbsolute.txt
............此处省略29个文件信息

评论

共有 条评论