示例:读取并处理图片
halcon源码:
1: *读取图片
'D:/MyFile/C#/HalconCsExample/示例图片.jpg')
3: get_image_size(Image,Width,Height)
4:
5: *图像处理
6: rgb1_to_gray(Image,GrayImage)
导出的代码(ImagePro):
//
// File generated by HDevelop for HALCON/DOTNET (C#) Version 10.0
//
// This file is intended to be used with the HDevelopTemplate or
// HDevelopTemplateWPF projects located under %HALCONEXAMPLES%\c#
6:
using System;
using HalconDotNet;
9:
class HDevelopExport
11: {
public HTuple hv_ExpDefaultWinHandle;
13:
// Main procedure
void action()
16: {
17:
// Local iconic variables
19:
20: HObject ho_Image, ho_GrayImage;
21:
22:
// Local control variables
24:
25: HTuple hv_Width, hv_Height;
26:
// Initialize local and output iconic variables
out ho_Image);
out ho_GrayImage);
30:
//读取图片
//dev_close_window(...);
33: ho_Image.Dispose();
);
out hv_Height);
//dev_open_window(...);
37: HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
38:
//图像处理
40: ho_GrayImage.Dispose();
out ho_GrayImage);
42: HOperatorSet.DispObj(ho_GrayImage, hv_ExpDefaultWinHandle);
43:
44: ho_Image.Dispose();
45: ho_GrayImage.Dispose();
46:
47: }
48:
void InitHalcon()
50: {
// Default settings used in HDevelop
);
53: }
54:
void RunHalcon(HTuple Window)
56: {
57: hv_ExpDefaultWinHandle = Window;
58: action();
59: }
60:
61: }
62:
C#工程:
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;
9:
//添加引用
11:
namespace HalconCsExample
13: {
class Form1 : Form
15: {
//增加代码:
new HDevelopExport();
string ImagePath;
19:
public Form1()
21: {
22: InitializeComponent();
false;
24: }
25:
object sender, EventArgs e)
27: {
;
true;
30: openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
32: {
33: ImagePath = openFileDialog1.FileName;
34: HD.ReadImage(hWindowControl1.HalconWindow, ImagePath);
true;
36: }
37: }
38:
object sender, EventArgs e)
40: {
41: HD.ImagePro();
false;
43: }
44: }
45:
//从导出的ReadImage.cs中拷贝HDevelopExport类到命名空间 HalconCsExample
class HDevelopExport
48: {
public HTuple hv_ExpDefaultWinHandle;
// Local iconic variables
51: HObject ho_Image, ho_GrayImage;
52:
53:
void InitHalcon()
55: {
// Default settings used in HDevelop
);
58: }
59:
string path)
61: {
62: hv_ExpDefaultWinHandle = Window;
63:
// Initialize local and output iconic variables
out ho_Image);
out ho_GrayImage);
67:
//读取图片
//dev_close_window(...);
70: ho_Image.Dispose();
out ho_Image, path);
72:
//dev_open_window(...);
74: HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
75: }
76:
void ImagePro()
78: {
//图像处理
80: ho_GrayImage.Dispose();
out ho_GrayImage);
82: HOperatorSet.DispObj(ho_GrayImage, hv_ExpDefaultWinHandle);
83:
84: ho_Image.Dispose();
85: ho_GrayImage.Dispose();
86:
87: }
88:
89: }
90: }
运行结果:
单击读取图片按钮并选取图片:
点击图像处理按钮: