我使用VISIONPRO 的版本为9.0;往往很多USB相机没有办法使用,我们可以采用拍图在文档下再同步抓取图片,再使用。
1.实现配置好CogImageFileTool工具,保存在文档中为img.vpp,步骤如下4步。
CogImageFileTool 序列化回来:
CogImageFileTool file1 = (CogImageFileTool)CogSerializer.LoadObjectFromFile(@"D:AVIimg.vpp");
CogImageFileTool 运行很简单:
file1.Run();
图片显示:
cogRecordDisplay1.Image = file1.OutputImage;
CogImageConvert类为静态类使用(用的多我们用于灰图转换红色标注)
cogRecordDisplay1.Image = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
原代码如下:
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using Cognex.VisionPro;
10 using Cognex.VisionPro.ToolBlock;
11 using Cognex.VisionPro.ImageFile;
12 using System.IO;
13 using Cognex.VisionPro.OCRMax;
14 using Cognex.VisionPro.ID;
15 using System.Diagnostics;
16 using Cognex.VisionPro.PMAlign;
17 using Cognex.VisionPro.Blob;
18
19 namespace qj
20 {
21 public partial class Form1 : Form
22 {
23 public Form1()
24 {
25 InitializeComponent();
26 chushua();
27 }
28 CogAcqFifoTool camtool = null;
29 ICogFrameGrabber cam1 = null;
30 ICogAcqFifo cam = null;
31 // CogImageFile file = null;
32 CogImageFileTool file1 = null;
33 CogImageConvert covet1 = null;
34 private void chushua()
35 {
36 // camtool = new CogAcqFifoTool();
37 // cam = camtool.Operator;
38 // covet1 = new CogImageConvert();
39 file1 = (CogImageFileTool)CogSerializer.LoadObjectFromFile(@"D:AVIimg.vpp");
40 file1.Run();
41 // cogRecordDisplay1.Image = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
42 cogRecordDisplay1.Image = file1.OutputImage;
43 }
44
45 private void button1_Click(object sender, EventArgs e)
46 {
47 // file1.Run();
48 cogRecordDisplay1.Image = CogImageConvert.GetIntensityImage(file1.OutputImage, 0, 0, file1.OutputImage.Width, file1.OutputImage.Height);
49 }
50 }
51 }