VisionPro and C# real-time imaging

VisionPro implements real-time imaging methods in the C# project program, and there are two ways:

1. Add the CogAcqFifoTool control in the interface, assign values ​​to the control properties in the program, and finally run it in the same way as in the VisionPro software;

2. Add the CogRecordDisplay control to the interface, realize the camera connection through the program, capture images in real time and display them on the CogRecordDisplay control.

Enter the display control name, camera number, the sample code is as follows:

using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;

public CogFrameGrabbers mFrameGraber;
public ICogAcqFifo mCogAcqFifo = null;

/// <summary>
/// 实时显示
/// </summary>
/// <param name="cogDisplay">显示控件</param>
/// <param name="cameraN">相机编号</param>
public void VisionLive(CogRecordDisplay cogDisplay, int cameraN)
{

    try
    {
        if (cogDisplay.LiveDisplayRunning)
        {
            //关闭光源

            cogDisplay.StopLiveDisplay();
        }
        else
        {
            mFrameGraber = new Cognex.VisionPro.CogFrameGrabbers();
            int CameraCounts = 1;//设置项目相机数量
            if (mFrameGraber.Count < CameraCounts)
            {
                //throw new Exception("Failed to create the CogFrameGrabbers object.");
                MessageBox.Show("在线相机数量异常,请检查相机连接!");
                return;
            }
            //开启光源

            mCogAcqFifo = mFrameGraber[cameraN].CreateAcqFifo(mFrameGraber[cameraN].AvailableVideoFormats[0],
            CogAcqFifoPixelFormatConstants.Format8Grey, 0, true);
            cogDisplay.StartLiveDisplay(mCogAcqFifo);
            cogDisplay.AutoFit = true;
        }

    }
    catch (Exception ex)
    {
        MessageBox.Show("相机实时显示失败!");
    }

}

Learn from each other and get rich together.

おすすめ

転載: blog.csdn.net/m0_62778855/article/details/125999415