核心内容摘要
从零开始:BGE-Large-Zh 语义向量化工具部署与使用
加载单个工具例子//保存到一个地方 让vs进行读取namespace 加载单个pma工具{public partial class Form1 : Form{CogPMAlignTool pma;public Form1(){InitializeComponent();cogRecordDisplay
Fit();}//窗体加载事件private void Form1_Load(object sender, EventArgs e){//加载vpp资源(重点)pma CogSerializer.LoadObjectFromFile(模版匹配.vpp) as CogPMAlignTool;//位置//Subject 属性 工具展示的内容cogPMAlignEditV
Subject pma;//MessageBox.Show(加载成功);}private void button1_Click(object sender, EventArgs e){if (pmanull){MessageBox.Show(加载失败);return;}OpenFileDialog dia new OpenFileDialog();//文件对话框dia.Filter All Image Files|*.jpg;*.png;*.jpeg;*.ico;*.tif;*.tiff;*.idb;*.bmp\;dia.Title 请选择文件;if (dia.ShowDialog() DialogResult.OK){Bitmap map Image.FromFile(dia.FileName) as Bitmap;//加载图片路径pma.InputImage new CogImage8Grey(map);//转成8位灰图赋值给pma}}private void button2_Click(object sender, EventArgs e){if (pma null){MessageBox.Show(加载资源失败);return;}pma.Run();//record 展示一条记录//CreateLastRunRecord 创建最近的运行记录//SubRecords 子记录cogRecordDisplay
Record pma.CreateLastRunRecord().SubRecords[0];cogRecordDisplay
Fit();}}}ini格式读写namespace ini文件存储读取{public partial class Form1 : Form{public Form1(){InitializeComponent();// FileStream a new FileStream(1, FileMode.Open, FileAccess.Write);//StreamWriter a2 new StreamWriter(a, Encoding.UTF
;}//写入private void button2_Click(object sender, EventArgs e){//1 写入指定节点指定的键 (没用则创建一个新键)//IniAPI.INIWriteValue(C:\\Users\\12345\\OneDrive\\Desktop\\
ini,net,ip,
;//2 删除节点//IniAPI.INIDeleteSection(C:\\Users\\12345\\OneDrive\\Desktop\\
ini,data);//3 删除键//IniAPI.INIDeleteKey(C:\\Users\\12345\\OneDrive\\Desktop\\
ini,net,ip);}//读取private void button1_Click(object sender, EventArgs e){// //1 获取所有的节点名称//string[] s1 IniAPI.INIGetAllSectionNames(C:\\Users\\18060\\OneDrive\\Desktop\\
ini);// foreach (string item in s
// {// richTextBox
Text item \n;// }// 2 获取所有的items//string[] s1 IniAPI.INIGetAllItems(C:\\Users\\18060\\OneDrive\\Desktop\\
ini,net);//foreach (string item in s
//{// richTextBox
Text item \n;//}// 3 获取对应节点的键的值(重要)//string s1 IniAPI.INIGetStringValue(C:\\Users\\18060\\OneDrive\\Desktop\\
ini,net,ip,);//richTextBox
Text s1;}}}图片读写操作namespace 图片读写操作{public partial class Form1 : Form{public Form1(){InitializeComponent();}方法一private void button1_Click(object sender, EventArgs e){//1 创建CogImageFileTool工具CogImageFileTool fileTool new CogImageFileTool();OpenFileDialog dia new OpenFileDialog();//文件对话框dia.Filter All Image Files|*.jpg;*.png;*.jpeg;*.ico;*.tif;*.tiff;*.idb;*.bmp\;dia.Title 请选择文件;if (dia.ShowDialog() DialogResult.OK){//可以获取选择文件的路径//fileTool.Operator.Open 打开fileTool工具//参数1 路径//参数2 读取fileTool工具// 2 使用fileTool工具读取图片fileTool.Operator.Open(dia.FileName,CogImageFileModeConstants.Read);// 3 运行工具fileTool.Run();// 4 获取输出图 展示cogRecordDisplay
Image fileTool.OutputImage;// 5 自适应大小cogRecordDisplay
Fit();}}private void button2_Click(object sender, EventArgs e){CogImageFileTool fileTool new CogImageFileTool();//保存控件展示的图片//把控件图片赋值给工具的输入图参数中fileTool.InputImage cogRecordDisplay
Image;//fileTool.Operator.Open 打开fileTool工具//参数1 路径//参数2 写入fileTool工具// 2 使用fileTool工具写入图片fileTool.Operator.Open(
png, CogImageFileModeConstants.Write);// 3 运行工具fileTool.Run();}方法二//使用位图进行读取展示private void button3_Click(object sender, EventArgs e){OpenFileDialog dia new OpenFileDialog();//文件对话框dia.Filter All Image Files|*.jpg;*.png;*.jpeg;*.ico;*.tif;*.tiff;*.idb;*.bmp\;dia.Title 请选择文件;if (dia.ShowDialog() DialogResult.OK){Bitmap bit Image.FromFile(dia.FileName) as Bitmap;CogImage8Grey bit1 new CogImage8Grey(bit);//转化8位灰图CogImage24PlanarColor bit2 new CogImage24PlanarColor(bit);//转化为24位彩色图cogRecordDisplay
Image bit2; //展示图片cogRecordDisplay
Fit();}}//使用位图进行写入保存private void button4_Click(object sender, EventArgs e){string path Directory.GetCurrentDirectory()\\data;if (!Directory.Exists(path)){Directory.CreateDirectory(path);}string path2 path \\
png;//if (!File.Exists(path
)//{// return;//}//CreateContentBitmap创建位图内容//参数1 把图片转成位图Bitmap map cogRecordDisplay
CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Image)as Bitmap;map.Save(path$\\{DateTime.Now:yyyyMMddhhmmss}.png);}}setting存储private void button1_Click(object sender, EventArgs e){Settings set Settings.Default;//获取配置对象set.name textBox
Text;set.age int.Parse(textBox
Text);set.weight float.Parse(textBox
Text);set.sex bool.Parse(textBox
Text);set.Save();//保存更改}//读取数据private void button2_Click(object sender, EventArgs e){Settings settings Settings.Default;string name settings.name;//获取配置表数据int age settings.age;float weight settings.weight;bool sex settings.sex;richTextBox
Text name\nage\nweight\nsex;}//持久化存储//json格式 {age:10}//file文件存储//二进制存储方式//csv存储格式 姓名,年龄// 张三,10//setting存储格式//ini存储格式 [net]// IP
127.
0.