Halcon联合C#实现相机实时显示采集图像
窗体如图:
本窗体功能为打开相机、相机的实时显示采集、关闭相机。
HALCON代码:
* Image Acquisition 01: Code generated by Image Acquisition 01
* Image Acquisition 01: Attention: The initialization may fail in case parameters need to
* Image Acquisition 01: be set in a specific order (e.g., image resolution vs. offset).
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] Integrated Webcam', 0, -1, AcqHandle)
set_framegrabber_param (AcqHandle, 'grab_timeout', 2000)
set_framegrabber_param (AcqHandle, 'gamma', 116)
grab_image_start (AcqHandle, -1)
while (true)grab_image_async (Image, AcqHandle, -1)* Image Acquisition 01: Do somethingget_image_size (Image, Width, Height)dev_set_part (0, 0, Height, Width)
endwhile
close_framegrabber (AcqHandle)
HALCON导出的C#代码:
//
// File generated by HDevelop for HALCON/.NET (C#) Version 19.11.0.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 HDevelopHOperatorSet.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=null;// Local control variables HTuple hv_AcqHandle = new HTuple(), hv_Width = new HTuple();HTuple hv_Height = new HTuple();// Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image);//Image Acquisition 01: Code generated by Image Acquisition 01//Image Acquisition 01: Attention: The initialization may fail in case parameters need to//Image Acquisition 01: be set in a specific order (e.g., image resolution vs. offset).hv_AcqHandle.Dispose();HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb", -1, "false", "default", "[0] Integrated Webcam", 0, -1, out hv_AcqHandle);HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "grab_timeout", 2000);HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "gamma", 116);HOperatorSet.GrabImageStart(hv_AcqHandle, -1);while ((int)(1) != 0){ho_Image.Dispose();HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);//Image Acquisition 01: Do somethinghv_Width.Dispose();hv_Height.Dispose();HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);if (HDevWindowStack.IsOpen()){HOperatorSet.SetPart(HDevWindowStack.GetActive(), 0, 0, hv_Height, hv_Width);}}HOperatorSet.CloseFramegrabber(hv_AcqHandle);ho_Image.Dispose();hv_AcqHandle.Dispose();hv_Width.Dispose();hv_Height.Dispose();}#endif}
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public class HDevelopExportApp
{static void Main(string[] args){new HDevelopExport();}
}
#endif
程序源码:
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;
using HalconDotNet;namespace open_cam
{public partial class Form1 : Form{public Form1(){InitializeComponent();}HObject ho_Image = null;HTuple hv_AcqHandle = new HTuple();HTuple hv_Width = new HTuple();HTuple hv_Height = new HTuple();private void button1_Click(object sender, EventArgs e){//HTuple hv_AcqHandle = new HTuple();// Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image);//Image Acquisition 01: Code generated by Image Acquisition 01//Image Acquisition 01: Attention: The initialization may fail in case parameters need to//Image Acquisition 01: be set in a specific order (e.g., image resolution vs. offset).hv_AcqHandle.Dispose();HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",-1, "false", "default", "[0] Integrated Webcam", 0, -1, out hv_AcqHandle);HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "grab_timeout", 2000);HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "gamma", 116);HOperatorSet.GrabImageStart(hv_AcqHandle, -1);}HTuple hv_WindowHandle = new HTuple();private void button2_Click(object sender, EventArgs e){timer1.Enabled = true;HOperatorSet.OpenWindow(0, 0, hWindowControl1.Width, hWindowControl1.Height, hWindowControl1.HalconWindow, "visible", "", out hv_WindowHandle);//open window,将图片的长宽改为控件的长宽HDevWindowStack.Push(hv_WindowHandle);//入栈}private void timer1_Tick(object sender, EventArgs e){ho_Image.Dispose();//hv_AcqHandle.Dispose();HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);//Image Acquisition 01: Do somethinghv_Width.Dispose(); hv_Height.Dispose();HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);if (HDevWindowStack.IsOpen()){HOperatorSet.SetPart(HDevWindowStack.GetActive(), 0, 0, hv_Height, hv_Width);}if (HDevWindowStack.IsOpen())//实时显示{HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());}}private void button3_Click(object sender, EventArgs e){timer1.Enabled = false;//一定要关闭timerHOperatorSet.CloseFramegrabber(hv_AcqHandle);ho_Image.Dispose();}}
}
注意:
在button3的事件中记得关闭timer
private void button3_Click(object sender, EventArgs e){timer1.Enabled = false;//一定要关闭timerHOperatorSet.CloseFramegrabber(hv_AcqHandle);ho_Image.Dispose();}
图像的显示函数:
if (HDevWindowStack.IsOpen())//实时显示{HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());}
图像显示效果:
Halcon联合C#实现相机实时显示采集图像相关推荐
- Halcon联合VS2010打开相机并显示
在开始之前需要安装好Halcon 12和VS2010,具体的话VS2010是免费的可以直接在微软官方下载,Halcon12这个可以参考Halcon学习网(http://www.ihalcon.com/ ...
- [求助]谁能给我讲解一下,iOS编程要如何实时显示采集到的图像???
rt,最近搞一个高清图传,本着自(bu)主(mai)创(da)新(jiang)的原则,打算利用手中的iPad当作辅助飞行屏幕,USB传输数据.再说某疆图传7999(还只支持自家云台录像拍照),哪是我这 ...
- 树莓派驱动1.44寸TFT液晶并实时显示摄像头图像
** 需要什么 ** 一块lcd ,市面上大多数为spi ,i2c驱动的lcd,我这块是比赛剩下的模拟8080端口驱动.区别不大,仅需改动发送数据的函数 一个摄像头,我这里使用的是某宝17块钱买来的o ...
- Python 实现海康机器人工业相机 MV-CU060-10GM 的实时显示视频流及拍照功能
一.背景介绍 1.最近项目中需要给客户对接海康机器人工业相机 MV-CU060-10GM: 2.客户要求通过部署的管理平台,可以在页面上实现如下功能: 1)相机视频流开始预览: 2)相机视频流停止预览 ...
- pylon保存图片_Basler SDK pylon6使用C#采集图像实例
重要:本文最后更新于2020-08-19 08:27:19,某些文章具有时效性,若有错误或已失效,请在下方留言或联系代码狗. 有人问到如何使用相机的SDK采集图像,其实这个问题相机的生产厂家已经给了答 ...
- android相机采集sdk,C#用basler相机sdk采集图像并用halcon显示的小程序
C#用basler相机sdk采集图像并用halcon显示的小程序 C#用basler相机sdk采集图像并用halcon显示的小程序 本人在用halcon做图像处理做视觉项目时,通常都是用c#写程序的主 ...
- COI实验室技能:python控制相机的方法——采集、处理、显示、实时
COI实验室技能:python控制相机的方法--采集.处理.显示.实时 本文介绍如何利用python控制办公摄像头.工业相机和科研相机.将数据采集和处理统一到python代码中. 主要围绕解决 ...
- SDI相机实时采集处理DSP系统 目标跟踪
1.系统平台介绍 HD-SDI相机通过75Ω同轴电缆接入到HD-SDI分配器输入端口,如图所示.HD-SDI分配器有两个HD-SDI输出端口,其中一路输出通过同轴电缆线连接到目标跟踪处理板上的BNC接 ...
- halcon 连接相机采集图像
相机采集图像(以笔记本摄像头为例) 执行"助手"--"打开新的Image Acquisition": 如果没连其他的相机,那么点击"自动检测接口&qu ...
最新文章
- 以太坊源码分析之随心笔记
- vi profile
- boost::mpi模块all_to_all() 集合的测试
- 【转】使用PowerApps快速构建基于主题的轻业务应用 —— 进阶篇
- gem install sass 本地配置和淘宝源无效的解决办法
- rf扫描枪_RF枪操作的简要步骤
- mac10.15切换大小写指示灯不亮
- 台式计算机怎么安装无线网卡,台式机装无线网卡,详细教您台式机怎么使用无线网卡上网...
- Kylin 之Cube 构建优化
- 如何判断患者服用的温度敏感性药品依旧安全有效?
- 【51单片机】OOK无线通讯在无线门磁报警中的应用
- 源支付5.18源码/三网免挂/带云端/附源码搭建教程
- 一只兔子帮你理解KNN
- html svg文件怎么打开,SVG 在 HTML 页面
- 微信小程序开发笔记 进阶篇④——getPhoneNumber 获取用户手机号码(小程序云)
- php订阅号网页登录,微信订阅号怎么使用网页授权登录
- HFDS的Shell操作
- 关于巴伦——Marchand巴伦
- 查看WIN10 SDK的版本
- 截图神器推荐 ShareX