求助大佬们,halcon图像采集有问题。。!

1 篇文章 0 订阅
文章讲述了使用Halcon库结合C#进行图像采集时,遇到不明窗口阻碍的问题,涉及定时器控制相机、图像显示以及窗口句柄操作。
摘要由CSDN通过智能技术生成

halcon联合C#做采集,用定时器,遇到了不明窗口挡在前面,到底是个啥啊。。



该窗口会闪烁

**以下是实现代码

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 助手联合相机
{
    public partial class Form1 : Form
    {
        //1、定义变量
        HObject ho_Image = null;

        HTuple hv_AcqHandle = new HTuple(), hv_Width = new HTuple();
        HTuple hv_Height = new HTuple(), hv_MSecond = new HTuple();
        HTuple hv_Second = new HTuple(), hv_Minute = new HTuple();
        HTuple hv_Hour = new HTuple(), hv_Day = new HTuple(), hv_YDay = new HTuple();
        HTuple hv_Month = new HTuple(), hv_Year = new HTuple();
        HTuple hv_WindowHandle = null;//窗口句柄
        private void timer1_Tick(object sender, EventArgs e)
        {
            //3、打开相机
            ho_Image.Dispose();
            HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
            hv_Width.Dispose(); hv_Height.Dispose();
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
            if (HDevWindowStack.IsOpen())
            {
                //图片显示完整,把第一个变量的句柄改一下
                HOperatorSet.SetPart(hWindowControl2.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, hWindowControl2.HalconWindow);
            }
        }
        public Form1()
        {
            InitializeComponent();
        }

        private void OpenCamera_CheckedChanged(object sender, EventArgs e)
        {
            //2、初始化相机
            HOperatorSet.GenEmptyObj(out ho_Image);
            hv_AcqHandle.Dispose();
            HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive",
                -1, "default", -1, "false", "default", "SJH00", 0, -1, out hv_AcqHandle);
            HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "ExposureTime", 15020.0);    //设置曝光
            HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "Gain", 3.9849);           //设置增益
            HOperatorSet.GrabImageStart(hv_AcqHandle, -1);

            timer1.Enabled = true;

            //输入控件的宽和高,控件的句柄
            HOperatorSet.OpenWindow(0, 0, hWindowControl2.Height, hWindowControl2.Width, hWindowControl2.HalconWindow, "visible", "", out hv_WindowHandle);
            HDevWindowStack.Push(hv_WindowHandle);
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值