halcon程序导出和C#环境配置
read_image (Image, 'E:/cat.png')
rgb1_to_gray (Image, GrayImage)
threshold (GrayImage, Region, 128, 255)
//
// File generated by HDevelop for HALCON/.NET (C#) Version 18.11.1.0
// Non-ASCII strings in this file are encoded in local-8-bit encoding (cp936).
//
// Please note that non-ASCII characters in string constants are exported
// as octal codes in order to guarantee that the strings are correctly
// created on all systems, independent on any compiler settings.
//
// Source files with different encoding should not be mixed in one project.
//
using HalconDotNet;
public partial class HDevelopExport
{
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public HDevelopExport()
{
// Default settings used in HDevelop
HOperatorSet.SetSystem("width", 512);
HOperatorSet.SetSystem("height", 512);
if (HalconAPI.isWindows)
HOperatorSet.SetSystem("use_window_thread","true");
action();
}
#endif
#if !NO_EXPORT_MAIN
// Main procedure
private void action()
{
// Local iconic variables
HObject ho_Image, ho_GrayImage, ho_Region;
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_GrayImage);
HOperatorSet.GenEmptyObj(out ho_Region);
HOperatorSet.ReadImage(out ho_Image, "E:/cat.png");
HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
HOperatorSet.Threshold(ho_GrayImage, out ho_Region, 128, 255);
ho_Image.Dispose();
ho_GrayImage.Dispose();
ho_Region.Dispose();
}
#endif
}
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public class HDevelopExportApp
{
static void Main(string[] args)
{
new HDevelopExport();
}
}
#endif
private void action()
{
// Local iconic variables
HObject ho_Image, ho_GrayImage, ho_Region;
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_GrayImage);
HOperatorSet.GenEmptyObj(out ho_Region);
HOperatorSet.ReadImage(out ho_Image, "E:/cat.png");
HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
HOperatorSet.Threshold(ho_GrayImage, out ho_Region, 128, 255);
ho_Image.Dispose();
ho_GrayImage.Dispose();
ho_Region.Dispose();
}
Winform
C:\Program Files\MVTec\HALCON-18.11-Steady\bin\dotnet35
using HalconDotNet;
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;
namespace Learning4Halcon
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Local iconic variables
HObject ho_Image, ho_GrayImage, ho_Region;
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_GrayImage);
HOperatorSet.GenEmptyObj(out ho_Region);
HOperatorSet.ReadImage(out ho_Image, "E://cat.png");
HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
HOperatorSet.Threshold(ho_GrayImage, out ho_Region, 128, 255);
hWindowControl1.HalconWindow.DispObj(ho_GrayImage);
hWindowControl1.HalconWindow.DispObj(ho_Region);
ho_Image.Dispose();
ho_GrayImage.Dispose();
ho_Region.Dispose();
}
}
}