学习VISIONPRO各控件的C#中类库--应用(CogImageFileTool,CogImageConvert,图片显示cogRecordDisplay)
我使用VISIONPRO 的版本为9.0;往往很多USB相机没有办法使用,我们可以采用拍图在文档下再同步抓取图片,再使用。
1.实现配置好CogImageFileTool工具,保存在文档中为img.vpp,步骤如下4步。
CogImageFileTool 序列化回来:
CogImageFileTool file1 = (CogImageFileTool)CogSerializer.LoadObjectFromFile(@"D:\AVI\img.vpp");
CogImageFileTool 运行很简单:
file1.Run();
图片显示:
cogRecordDisplay1.Image = file1.OutputImage;
CogImageConvert类为静态类使用(用的多我们用于灰图转换红色标注
)
cogRecordDisplay1.Image = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
原代码如下:
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;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro.ImageFile;
using System.IO;
using Cognex.VisionPro.OCRMax;
using Cognex.VisionPro.ID;
using System.Diagnostics;
using Cognex.VisionPro.PMAlign;
using Cognex.VisionPro.Blob;
namespace qj
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
chushua();
}
CogAcqFifoTool camtool = null;
ICogFrameGrabber cam1 = null;
ICogAcqFifo cam = null;
// CogImageFile file = null;
CogImageFileTool file1 = null;
CogImageConvert covet1 = null;
private void chushua()
{
// camtool = new CogAcqFifoTool();
// cam = camtool.Operator;
// covet1 = new CogImageConvert();
file1 = (CogImageFileTool)CogSerializer.LoadObjectFromFile(@"D:\AVI\img.vpp");
file1.Run();
// cogRecordDisplay1.Image = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
cogRecordDisplay1.Image = file1.OutputImage;
}
private void button1_Click(object sender, EventArgs e)
{
// file1.Run();
cogRecordDisplay1.Image = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
}
}
}