显示Linef的points信息的小程序,C#代码

在视觉调试的时候,如果断点查看Linef对象的Points信息(即线的点集合),都是包含点位置x,y信息的数据,有些时候想显示Linef对象的points信息为图形化,则可以使用下面的小程序。

你只需要vs的“即时窗口”输出这个Points对象,然后把它复制下来,粘贴到程序窗体中,然后点击“计算窗口内points”转换即可。


下面的复制下来的Points对象:

 [0]: {4086.82373046875,1817.00036621094,0,0}
    [1]: {4086.76611328125,1845.00036621094,0,0}
    [2]: {4086.21850585938,1874.00036621094,0,0}
    [3]: {4085.49389648438,1902.00024414063,0,0}
    [4]: {4084.75708007813,1931.00024414063,0,0}
    [5]: {4083.83666992188,1959.00024414063,0,0}
    [6]: {4082.8125,1988.00024414063,0,0}
    [7]: {4052.86499023438,2016.00024414063,0,0}
    [8]: {4051.03979492188,2045.00012207031,0,0}
    [9]: {4049.4716796875,2073.00024414063,0,0}
    [10]: {4048.08666992188,2102.00024414063,0,0}
    [11]: {4047.00903320313,2130.00024414063,0,0}
    [12]: {4046.07202148438,2159.00024414063,0,0}
    [13]: {4045.2900390625,2187.00024414063,0,0}
    [14]: {4044.646484375,2216.00024414063,0,0}
    [15]: {4044.02661132813,2244.00024414063,0,0}
    [16]: {4043.42919921875,2272.00024414063,0,0}
    [17]: {4042.57739257813,2301.00024414063,0,0}
    [18]: {4041.91528320313,2329.00024414063,0,0}
    [19]: {4042.28564453125,2358.00024414063,0,0}
    [20]: {4042.7216796875,2386.00024414063,0,0}
    [21]: {4042.83325195313,2415.00024414063,0,0}
    [22]: {4042.90356445313,2443.00024414063,0,0}
    [23]: {4042.96875,2472.00024414063,0,0}
    [24]: {4043.00366210938,2500.00024414063,0,0}
    [25]: {4043.0244140625,2529.00024414063,0,0}
    [26]: {4043.037109375,2557.00024414063,0,0}
    [27]: {4043.04931640625,2586.00024414063,0,0}
    [28]: {4043.02783203125,2614.00024414063,0,0}
    [29]: {4042.99267578125,2643.00024414063,0,0}
    [30]: {4042.9228515625,2671.00024414063,0,0}
    [31]: {4042.82861328125,2700.00024414063,0,0}
    [32]: {4042.712890625,2728.00024414063,0,0}
    [33]: {4042.55932617188,2757.00024414063,0,0}
    [34]: {4042.3408203125,2785.00024414063,0,0}
    [35]: {4042.1298828125,2814.00024414063,0,0}
    [36]: {4041.90673828125,2842.00024414063,0,0}
    [37]: {4041.62475585938,2870.00024414063,0,0}
    [38]: {4041.28540039063,2899.00024414063,0,0}
    [39]: {4040.95678710938,2927.00024414063,0,0}
    [40]: {4040.55200195313,2956.00024414063,0,0}
    [41]: {4040.18188476563,2984.00024414063,0,0}
    [42]: {4039.8447265625,3013.00024414063,0,0}
    [43]: {4039.36401367188,3041.00024414063,0,0}
    [44]: {4038.93774414063,3070.00024414063,0,0}
    [45]: {4038.59497070313,3098.00024414063,0,0}
    [46]: {4038.25073242188,3127.00024414063,0,0}
    [47]: {4038.02661132813,3155.00024414063,0,0}
    [48]: {4037.79370117188,3184.00024414063,0,0}
    [49]: {4037.41552734375,3212.00024414063,0,0}
    [50]: {4036.80419921875,3241.00024414063,0,0}
    [51]: {4036.58471679688,3269.00024414063,0,0}
    [52]: {4036.79370117188,3298.00024414063,0,0}
    [53]: {4037.07592773438,3326.00024414063,0,0}
    [54]: {4037.90380859375,3355.00024414063,0,0}
    [55]: {4038.87963867188,3383.00024414063,0,0}
    [56]: {4039.92163085938,3412.00024414063,0,0}
    [57]: {4041.08618164063,3440.00024414063,0,0}
    [58]: {4042.7470703125,3469.00024414063,0,0}
    [59]: {4044.57006835938,3497.00024414063,0,0}
    [60]: {4080.923828125,3525.00024414063,0,0}
    [61]: {4080.77563476563,3554.00024414063,0,0}
    [62]: {4081.08935546875,3582.00024414063,0,0}
    [63]: {4081.5693359375,3611.00024414063,0,0}
    [64]: {4081.81298828125,3639.00024414063,0,0}
    [65]: {4081.75463867188,3668.00024414063,0,0}

下面的软件转换后的halcon代码:

gen_circle(Circle, 86.82373046875, 17.00036621094, 2)
gen_circle(Circle, 86.76611328125, 45.00036621094, 2)
gen_circle(Circle, 86.21850585938, 74.00036621094, 2)
gen_circle(Circle, 85.49389648438, 102.00024414063, 2)
gen_circle(Circle, 84.75708007813, 131.00024414063, 2)
gen_circle(Circle, 83.83666992188, 159.00024414063, 2)
gen_circle(Circle, 82.8125, 188.00024414063, 2)
gen_circle(Circle, 52.86499023438, 216.00024414063, 2)
gen_circle(Circle, 51.03979492188, 245.00012207031, 2)
gen_circle(Circle, 49.4716796875, 273.00024414063, 2)
gen_circle(Circle, 48.08666992188, 302.00024414063, 2)
gen_circle(Circle, 47.00903320313, 330.00024414063, 2)
gen_circle(Circle, 46.07202148438, 359.00024414063, 2)
gen_circle(Circle, 45.2900390625, 387.00024414063, 2)
gen_circle(Circle, 44.646484375, 416.00024414063, 2)
gen_circle(Circle, 44.02661132813, 444.00024414063, 2)
gen_circle(Circle, 43.42919921875, 472.00024414063, 2)
gen_circle(Circle, 42.57739257813, 501.00024414063, 2)
gen_circle(Circle, 41.91528320313, 529.00024414063, 2)
gen_circle(Circle, 42.28564453125, 558.00024414063, 2)
gen_circle(Circle, 42.7216796875, 586.00024414063, 2)
gen_circle(Circle, 42.83325195313, 615.00024414063, 2)
gen_circle(Circle, 42.90356445313, 643.00024414063, 2)
gen_circle(Circle, 42.96875, 672.00024414063, 2)
gen_circle(Circle, 43.00366210938, 700.00024414063, 2)
gen_circle(Circle, 43.0244140625, 729.00024414063, 2)
gen_circle(Circle, 43.037109375, 757.00024414063, 2)
gen_circle(Circle, 43.04931640625, 786.00024414063, 2)
gen_circle(Circle, 43.02783203125, 814.00024414063, 2)
gen_circle(Circle, 42.99267578125, 843.00024414063, 2)
gen_circle(Circle, 42.9228515625, 871.00024414063, 2)
gen_circle(Circle, 42.82861328125, 900.00024414063, 2)
gen_circle(Circle, 42.712890625, 928.00024414063, 2)
gen_circle(Circle, 42.55932617188, 957.00024414063, 2)
gen_circle(Circle, 42.3408203125, 985.00024414063, 2)
gen_circle(Circle, 42.1298828125, 1014.00024414063, 2)
gen_circle(Circle, 41.90673828125, 1042.00024414063, 2)
gen_circle(Circle, 41.62475585938, 1070.00024414063, 2)
gen_circle(Circle, 41.28540039063, 1099.00024414063, 2)
gen_circle(Circle, 40.95678710938, 1127.00024414063, 2)
gen_circle(Circle, 40.55200195313, 1156.00024414063, 2)
gen_circle(Circle, 40.18188476563, 1184.00024414063, 2)
gen_circle(Circle, 39.8447265625, 1213.00024414063, 2)
gen_circle(Circle, 39.36401367188, 1241.00024414063, 2)
gen_circle(Circle, 38.93774414063, 1270.00024414063, 2)
gen_circle(Circle, 38.59497070313, 1298.00024414063, 2)
gen_circle(Circle, 38.25073242188, 1327.00024414063, 2)
gen_circle(Circle, 38.02661132813, 1355.00024414063, 2)
gen_circle(Circle, 37.79370117188, 1384.00024414063, 2)
gen_circle(Circle, 37.41552734375, 1412.00024414063, 2)
gen_circle(Circle, 36.80419921875, 1441.00024414063, 2)
gen_circle(Circle, 36.58471679688, 1469.00024414063, 2)
gen_circle(Circle, 36.79370117188, 1498.00024414063, 2)
gen_circle(Circle, 37.07592773438, 1526.00024414063, 2)
gen_circle(Circle, 37.90380859375, 1555.00024414063, 2)
gen_circle(Circle, 38.87963867188, 1583.00024414063, 2)
gen_circle(Circle, 39.92163085938, 1612.00024414063, 2)
gen_circle(Circle, 41.08618164063, 1640.00024414063, 2)
gen_circle(Circle, 42.7470703125, 1669.00024414063, 2)
gen_circle(Circle, 44.57006835938, 1697.00024414063, 2)
gen_circle(Circle, 80.923828125, 1725.00024414063, 2)
gen_circle(Circle, 80.77563476563, 1754.00024414063, 2)
gen_circle(Circle, 81.08935546875, 1782.00024414063, 2)
gen_circle(Circle, 81.5693359375, 1811.00024414063, 2)
gen_circle(Circle, 81.81298828125, 1839.00024414063, 2)
gen_circle(Circle, 81.75463867188, 1868.00024414063, 2)


image.png

在halcon中,先打开一张原图,然后把上面的代码复制到后面。即可以画出点的位置。


源码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using netMarketing.http;

namespace pointsxy
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openfile = new OpenFileDialog();
                //初始显示文件目录
                //openfile.InitialDirectory = @"";
                openfile.Title = "请points文件";
                //过滤文件类型
                openfile.Filter = "文本文件|*.txt";
                if (DialogResult.OK == openfile.ShowDialog())
                {
                    //将选择的文件的全路径赋值给文本框
                    richTextBox1.Text = work(File.ReadAllText(openfile.FileName),
                        double.Parse( tbXsub.Text),double.Parse(tbYsub.Text));
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private string work(string txt,double xsub,double ysub)
        {
            var sb1 = new StringBuilder();
            var dataYx=new List<Tuple<string,string>>();
            var rowsAry=txt.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach(var m in rowsAry)
            {
                var tmp=httpExterend.getAllMidString(m, "{", "}");
                if(tmp.Count>=1)
                {
                    var tmp2= tmp[0].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    if (tmp2.Count() >= 2)
                    {
                        var ysubStr = (double.Parse(tmp2[0]) - ysub).ToString();
                        var xsubStr = (double.Parse(tmp2[1]) - xsub).ToString();
                        dataYx.Add(new Tuple<string, string>(ysubStr, xsubStr));
                        sb1.Append(string.Format("gen_circle(Circle, {0}, {1}, 2)\r\n", ysubStr, xsubStr));
                    }
                }
            }

            return sb1.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = work(richTextBox1.Text,
                      double.Parse(tbXsub.Text), double.Parse(tbYsub.Text));
        }


    }
}


--------------------- 

作者:hackpig
来源:www.skcircle.com


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864