123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json;
- using System.Drawing;
- using Extender;
- namespace WebManager
- {
- public class WebResult
- {
- #region
- /// <summary>
- /// 数据定义
- /// </summary>
- private String webServer_IP = "";
- private String webServer_Port = "";
- private String webServer_Path = "";
- private String Url = "";
- private const String Post = "Post";
- private const String Content_Type= "Content-Type:application/json";
- private String[] _url = new string[10];
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="ws_ip">WebServer的IP地址</param>
- /// <param name="ws_port">WebServer的端口号</param>
- public WebResult(String ws_ip,String ws_port,String ws_url)
- {
- this.webServer_IP = ws_ip;
- this.webServer_Port = ws_port;
- this._url = ws_url.Split(',');
- //更新Web网址
- Update_Url();
- }
- /// <summary>
- /// 更新Web网址
- /// </summary>
- private void Update_Url()
- {
- this.webServer_Path = "/" + this.webServer_Path;
- this.Url = "http://" + this.webServer_IP + ":" + this.webServer_Port + this.webServer_Path;
- }
- /// <summary>
- /// WebServer的IP地址
- /// </summary>
- public String WebServer_IP
- {
- //get { return this.webServer_IP; }
- set
- {
- this.webServer_IP = value;
- }
- }
- /// <summary>
- /// WebServer的端口号
- /// </summary>
- public String WebServer_Port
- {
- //get { return this.webServer_IP; }
- set
- {
- this.webServer_Port = value;
- }
- }
- /// <summary>
- /// 向WebServer请求数据及返回结果
- /// </summary>
- /// <param name="postString">请求数据的JSON</param>
- /// <returns>返回结果的JSON</returns>
- private String RequestString(String postString)
- {
- try
- {
- String res = HttpRequestHelper.DoRequest(this.Url, Post, Content_Type, postString);
- return res;
- }
- catch
- {
- return "";
- }
- }
- /// <summary>
- /// 计算原始图像偏移角度及方向
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="imageType">孔类型</param>
- /// <param name="firm">厂家类型</param>
- /// <returns>json字符串</returns>
- public void Img_OffsetAngle_Direction(String imagePath, int imageType, String firm, out float degree, out int direction, out int state)
- {
- try
- {
- this.webServer_Path = this._url[0];
- }
- catch
- {
- this.webServer_Path = "FIB_degree_recognize";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- json.Add("img_type", imageType);
- json.Add("firm", firm);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret= (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
- {
- JObject jname = JObject.Parse(jret[imagePath].ToString());
- state = Convert.ToInt32(jname["state"].ToString());
- if (state == 1)
- {
- degree = Convert.ToSingle(jname["degree"].ToString());
- direction = Convert.ToInt32(jname["direction"].ToString());
- }
- else
- {
- degree = 0;
- direction = 0;
- }
- }
- else
- {
- state = 0;
- direction = 0;
- degree = 0;
- }
- }
- /// <summary>
- /// 计算切割点位置
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="imageType">孔类型</param>
- /// <param name="firm">厂家类型</param>
- /// <param name="offsetx1">切割点相对于原点坐标左上角x值</param>
- /// <param name="offsetx2">切割点相对于原点坐标左上角y值</param>
- /// <param name="offsety1">切割点相对于原点坐标右上角x值</param>
- /// <param name="offsety2">切割点相对于原点坐标右上角y值</param>
- /// <param name="state">返回状态</param>
- /// <returns>json字符串</returns>
- public void Img_Cut_Position(String imagePath, int imageType, String firm, out float offsetx1, out float offsety1, out float offsetx2, out float offsety2, out int state)
- {
- try
- {
- this.webServer_Path = this._url[1];
- }
- catch
- {
- this.webServer_Path = "test2";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- json.Add("img_type", imageType);
- json.Add("firm", firm);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
- {
- JObject jname = JObject.Parse(jret[imagePath].ToString());
- JArray jlocation = JArray.Parse(jname["location"].ToString());
-
- state = Convert.ToInt32(jname["state"].ToString());
- if (state == 1)
- {
- offsetx1 = Convert.ToSingle(jlocation[0][0].ToString());
- offsety1 = Convert.ToSingle(jlocation[0][1].ToString());
- offsetx2 = Convert.ToSingle(jlocation[1][0].ToString());
- offsety2 = Convert.ToSingle(jlocation[1][1].ToString());
- }
- else
- {
- offsetx1 = 0;
- offsety1 = 0;
- offsetx2 = 0;
- offsety2 = 0;
- }
- }
- else
- {
- state = 0;
- offsetx1 = 0;
- offsety1 = 0;
- offsetx2 = 0;
- offsety2 = 0;
- }
- }
- /// <summary>
- /// 是否切割成功验证
- /// </summary>
- /// <param name="imageBefore">切割前图像路径</param>
- /// <param name="imageAfter">切割后图像路径</param>
- /// <returns>json字符串</returns>
- public void Img_Cut_Success(String imageBefore, String imageAfter, out int state)
- {
- try
- {
- this.webServer_Path = this._url[2];
- }
- catch
- {
- this.webServer_Path = "FIB_verify";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_before_path", imageBefore);
- json.Add("img_after_path", imageAfter);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property("state") != null && jret.Property("state").ToString() != "")
- {
- state = Convert.ToInt32(jret["state"].ToString());
- }
- else
- {
- state = 0;
- }
- }
- /// <summary>
- /// 计算切割后图像梯形区域上边中心点坐标
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <returns>json字符串</returns>
- public void Img_Trapezoid_Top_Center_Position(String imagePath, out float offsetx, out float offsety, out int state)
- {
- try
- {
- this.webServer_Path = this._url[3];
- }
- catch
- {
- this.webServer_Path = "test4";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
- {
- JObject jname = JObject.Parse(jret[imagePath].ToString());
- JArray jlocation = JArray.Parse(jname["top_center"].ToString());
-
- state = Convert.ToInt32(jname["state"].ToString());
- if(state==1)
- {
- offsetx = Convert.ToSingle(jlocation[0].ToString());
- offsety = Convert.ToSingle(jlocation[1].ToString());
- }
- else
- {
- offsetx = 0;
- offsety = 0;
- }
- }
- else
- {
- state = 0;
- offsetx = 0;
- offsety = 0;
- }
- }
- /// <summary>
- /// 自动对焦
- /// </summary>
- /// <param name="imagePath">一组图片路径</param>
- /// <returns>json字符串</returns>
- public String Img_Auto_Focus(List<String> imagePath)
- {
- try
- {
- this.webServer_Path = this._url[4];
- }
- catch
- {
- this.webServer_Path = "test5";
- }
- Update_Url();
- JObject json = new JObject();
- for(int i=0;i<imagePath.Count;i++)
- {
- json.Add("img_path" + i.ToString(), imagePath[i]);
- }
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property("img_path") != null && jret.Property("img_path").ToString() != "")
- {
- return jret["img_path"].ToString();
- }
- else
- {
- return "";
- }
- }
- /// <summary>
- /// 自动消像散
- /// </summary>
- /// <param name="imagePath">一组图片路径</param>
- /// <returns>json字符串</returns>
- public String Img_Auto_Stigmatic(List<String> imagePath)
- {
- try
- {
- this.webServer_Path = this._url[5];
- }
- catch
- {
- this.webServer_Path = "test6";
- }
- Update_Url();
- JObject json = new JObject();
- for (int i = 0; i < imagePath.Count; i++)
- {
- json.Add("img_path" + i.ToString(), imagePath[i]);
- }
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property("img_path") != null && jret.Property("img_path").ToString() != "")
- {
- return jret["img_path"].ToString();
- }
- else
- {
- return "";
- }
- }
- /// <summary>
- /// 计算切割面区域偏移角度及方向
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <returns>json字符串</returns>
- public void Img_Center_Position_OffsetAngle_Direction(String imagePath, out float degree, out int direction, out int state)
- {
- try
- {
- this.webServer_Path = this._url[6];
- }
- catch
- {
- this.webServer_Path = "test7";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
- {
- JObject jname = JObject.Parse(jret[imagePath].ToString());
- state = Convert.ToInt32(jname["state"].ToString());
- if (state == 1)
- {
- degree = Convert.ToSingle(jname["degree"].ToString());
- direction = Convert.ToInt32(jname["direction"].ToString());
- }
- else
- {
- degree = 0;
- direction = 0;
- }
- }
- else
- {
- state = 0;
- direction = 0;
- degree = 0;
- //offsetx = 0;
- //offsety = 0;
- }
- }
- ///// <summary>
- ///// 计算切割后图像梯形区域上边中心点坐标
- ///// </summary>
- ///// <param name="imagePath">图片路径</param>
- ///// <returns>json字符串</returns>
- //public void Img_Surface_Center_Position(String imagePath, out float offsetx, out float offsety, out int state)
- //{
- // try
- // {
- // this.webServer_Path = this._url[7];
- // }
- // catch
- // {
- // this.webServer_Path = "test4";
- // }
- // Update_Url();
- // JObject json = new JObject();
- // json.Add("img_path", imagePath);
- // String res = RequestString(JsonConvert.SerializeObject(json));
- // JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- // if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
- // {
- // JObject jname = JObject.Parse(jret[imagePath].ToString());
- // JArray jlocation = JArray.Parse(jname["top_center"].ToString());
- // state = Convert.ToInt32(jname["state"].ToString());
- // if(state==1)
- // {
- // offsetx = Convert.ToSingle(jlocation[0].ToString());
- // offsety = Convert.ToSingle(jlocation[1].ToString());
- // }
- // else
- // {
- // offsetx = 0;
- // offsety = 0;
- // }
- // }
- // else
- // {
- // state = 0;
- // offsetx = 0;
- // offsety = 0;
- // }
- //}
- /// <summary>
- /// 计算两个测量区域坐标
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <returns>json字符串</returns>
- public void Img_Two_Region_Position(String imagePath, int imageType, String firm, out Point center1, out float mag1, out Point center2, out float mag2, out int state)
- {
- try
- {
- this.webServer_Path = this._url[7];
- }
- catch
- {
- this.webServer_Path = "test8";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- json.Add("img_type", imageType);
- json.Add("firm", firm);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
- {
- JObject jname = JObject.Parse(jret[imagePath].ToString());
- state = Convert.ToInt32(jname["state"].ToString());
- if (state == 1)
- {
- JArray jcenter1 = JArray.Parse(jname["center1"].ToString());
- String ptx = jcenter1[0].ToString();
- String pty = jcenter1[1].ToString();
- center1 = new Point(Convert.ToInt32(ptx),Convert.ToInt32(pty));
- String jmag1 = jname["magnification1"].ToString();
- mag1 = Convert.ToSingle(jmag1.ToString());
- JArray jcenter2 = JArray.Parse(jname["center2"].ToString());
- ptx = jcenter2[0].ToString();
- pty = jcenter2[1].ToString();
- center2 = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
- String jmag2 = jname["magnification2"].ToString();
- mag2 = Convert.ToSingle(jmag2.ToString());
- }
- else
- {
- center1 = new Point(0, 0);
- center2 = new Point(0, 0);
- mag1 = 0;
- mag2 = 0;
- state = 0;
- }
- }
- else
- {
- center1 = new Point(0, 0);
- center2 = new Point(0, 0);
- mag1 = 0;
- mag2 = 0;
- state = 0;
- }
- }
- /// <summary>
- /// 测量尺寸
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="ratio">放大倍数</param>
- /// <param name="size">一像素代表**mm/um</param>
- /// <returns>json字符串</returns>
- public void Img_Measure_Size(String imagePath1, String imagePath2, float size1, float size2, String resultPath, int imageType, String firm, out int state)
- {
- try
- {
- this.webServer_Path = this._url[8];
- }
- catch
- {
- this.webServer_Path = "test9";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path1", imagePath1);
- json.Add("img_path2", imagePath2);
- json.Add("size1", size1);
- json.Add("size2", size2);
- json.Add("result_path", resultPath);
- json.Add("img_type", imageType);
- json.Add("firm", firm);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property("state") != null && jret.Property("state").ToString() != "")
- {
- state = Convert.ToInt32(jret["state"].ToString());
- }
- else
- {
- state = 0;
- }
- }
- /// <summary>
- /// 测试-ESD返回数据
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <returns>json字符串</returns>
- public void EDS_Param(String imagePath, out List<Point> listPoints, out List<List<Segment>> listFeature, out int state)
- {
- try
- {
- this.webServer_Path = this._url[9];
- }
- catch
- {
- this.webServer_Path = "test9";
- }
- listPoints = new List<Point>();
- listFeature = new List<List<Segment>>();
- List<Segment> listSegment = new List<Segment>();
- state = 0;
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- String res = RequestString(JsonConvert.SerializeObject(json));
- JObject jret = (JObject)JsonConvert.DeserializeObject(res);
- if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
- {
- JObject jname = JObject.Parse(jret[imagePath].ToString());
- state = Convert.ToInt32(jname["state"].ToString());
- if(state==1)
- {
- JArray jpoints = JArray.Parse(jname["points"].ToString());
- for(int i=0;i<jpoints.Count;i++)
- {
- Point pt = new Point();
- pt.X = Convert.ToInt32(jpoints[i][0].ToString());
- pt.Y = Convert.ToInt32(jpoints[i][1].ToString());
- listPoints.Add(pt);
- }
- JArray jareas = JArray.Parse(jname["areas"].ToString());
- for(int i=0;i<jareas.Count;i++)
- {
- listSegment = new List<Segment>();
- JArray jarea = JArray.Parse(jareas[i].ToString());
- for(int j=0;j<jarea.Count;j++)
- {
- Segment st = new Segment();
- st.X = Convert.ToInt32(jarea[j][0].ToString());
- st.Y = Convert.ToInt32(jarea[j][1].ToString());
- st.Length = Convert.ToInt32(jarea[j][2].ToString());
- listSegment.Add(st);
- }
- listFeature.Add(listSegment);
- }
- }
-
- }
- }
- }
- }
|