1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057 |
- 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;
-
- namespace WebManager
- {
- public class ImageProcess : IImageProcessByWeb
- {
- #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[9];
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="ws_ip">WebServer的IP地址</param>
- /// <param name="ws_port">WebServer的端口号</param>
- public ImageProcess(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>
- /// <param name="degree">返回角度</param>
- /// <param name="direction">返回方向</param>
- /// <param name="state">图像接口返回状态</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>
- /// <param name="state">图像接口返回状态</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>
- /// <param name="offsetx">梯形中心点X轴坐标</param>
- /// <param name="offsety">梯形中心点Y轴坐标</param>
- /// <param name="state">图像接口返回状态</param>
- /// <returns>json字符串</returns>
- public void Img_Trapezoid_Top_Center_Position(String imagePath, int imageType, String firm, out float offsetx, out float offsety, out int state)//2020-12-15 修改添加 imageType, firm 两个参数
- {
- try
- {
- this.webServer_Path = this._url[3];
- }
- catch
- {
- this.webServer_Path = "test4";
- }
- 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["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>
- /// <param name="degree">图像偏移角度</param>
- /// <param name="direction">旋转方向</param>
- /// <param name="state">图像接口返回状态</param>
- /// <returns>json字符串</returns>
- public void Img_Center_Position_OffsetAngle_Direction(String imagePath, int imageType, String firm, 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);
- 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;
- //offsetx = 0;
- //offsety = 0;
- }
- }
- /// <summary>
- /// 计算两个测量区域坐标
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="imageType">样品类型</param>
- /// <param name="firm">厂商</param>
- /// <param name="center1">观测点1位置</param>
- /// <param name="mag1">观测点1放大倍数</param>
- /// <param name="center2">观测点2位置</param>
- /// <param name="mag2">观测点2放大倍数</param>
- /// <param name="state">返回结果状态</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 Point center3, 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());
- JArray jcenter3 = JArray.Parse(jname["center3"].ToString());
- ptx = jcenter3[0].ToString();
- pty = jcenter3[1].ToString();
- center3 = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
- }
- else
- {
- center1 = new Point(0, 0);
- center2 = new Point(0, 0);
- center3 = new Point(0, 0);
- mag1 = 0;
- mag2 = 0;
- state = 0;
- }
- }
- else
- {
- center1 = new Point(0, 0);
- center2 = new Point(0, 0);
- center3 = new Point(0, 0);
- mag1 = 0;
- mag2 = 0;
- state = 0;
- }
- }
- /// <summary>
- /// 测量尺寸
- /// </summary>
- /// <param name="imagePath1">图片1路径</param>
- /// <param name="imagePath2">图片2路径</param>
- /// <param name="size1">图片1的像素大小</param>
- /// <param name="size2">图片2的像素大小</param>
- /// <param name="resultPath">测量结果的生成目录</param>
- /// <param name="imageType">样品类型</param>
- /// <param name="firm">厂类</param>
- /// <param name="state">测量结果返回</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>
- /// DDIC计算原始图像偏移角度及方向
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="degree">返回角度</param>
- /// <param name="direction">返回方向</param>
- /// <param name="state">图像接口返回状态</param>
- /// <returns>json字符串</returns>
- public void Img_DDIC_OffsetAngle_Direction(String imagePath, out float degree, out int direction, out int state)
- {
- try
- {
- this.webServer_Path = this._url[9];
- }
- catch
- {
- this.webServer_Path = "DDIC_degree_recognize";
- }
- 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;
- }
- }
- /// <summary>
- /// DDIC计算切割点位置
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="offsetx">切割点相对于原点坐标左上角x值</param>
- /// <param name="offsety">切割点相对于原点坐标左上角y值</param>
- /// <param name="state">返回状态</param>
- /// <returns>json字符串</returns>
- public void Img_DDIC_Cut_Position(String imagePath, int imageType, String firm, out float offsetx, out float offsety, out int state)
- {
- try
- {
- this.webServer_Path = this._url[10];
- }
- catch
- {
- this.webServer_Path = "DDIC_cal_cut_location";
- }
- 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 jlocation = JArray.Parse(jname["location"].ToString());
- offsetx = Convert.ToSingle(jlocation[0][0].ToString());
- offsety = Convert.ToSingle(jlocation[0][1].ToString());
- }
- else
- {
- offsetx = 0;
- offsety = 0;
- }
- }
- else
- {
- state = 0;
- offsetx = 0;
- offsety = 0;
- }
- }
- /// <summary>
- /// DDIC梯形位置识别
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="offsetx">梯形中心点X轴坐标</param>
- /// <param name="offsety">梯形中心点Y轴坐标</param>
- /// <param name="state">图像接口返回状态</param>
- /// <returns>json字符串</returns>
- public void Img_DDIC_Trapezoid_Top_Center_Position(String imagePath, out float offsetx, out float offsety, out int state)
- {
- try
- {
- this.webServer_Path = this._url[11];
- }
- 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>
- /// DDIC测量点计算
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="state">返回结果状态</param>
- /// <returns>json字符串</returns>
- public void Img_DDIC_Measure_Location(String imagePath, out List<Point> measure_points, out int state)
- {
- try
- {
- this.webServer_Path = this._url[12];
- }
- catch
- {
- this.webServer_Path = "DDIC_measure_location";
- }
- Update_Url();
- measure_points = new List<Point>();
- 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 jcenter1 = JArray.Parse(jname["location1"].ToString());
- String ptx = jcenter1[0].ToString();
- String pty = jcenter1[1].ToString();
- measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
- jcenter1 = JArray.Parse(jname["location2"].ToString());
- ptx = jcenter1[0].ToString();
- pty = jcenter1[1].ToString();
- measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
- jcenter1 = JArray.Parse(jname["location3"].ToString());
- ptx = jcenter1[0].ToString();
- pty = jcenter1[1].ToString();
- measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
- jcenter1 = JArray.Parse(jname["location4"].ToString());
- ptx = jcenter1[0].ToString();
- pty = jcenter1[1].ToString();
- measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
- jcenter1 = JArray.Parse(jname["location5"].ToString());
- ptx = jcenter1[0].ToString();
- pty = jcenter1[1].ToString();
- measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
- }
- else
- {
- state = 0;
- }
- }
- else
- {
- state = 0;
- }
- }
- /// <summary>
- /// DDIC测量尺寸
- /// </summary>
- /// <param name="imagePath1">图片1路径</param>
- /// <param name="imagePath2">图片2路径</param>
- /// <param name="imagePath3">图片3路径</param>
- /// <param name="imagePath4">图片4路径</param>
- /// <param name="imagePath5">图片5路径</param>
- /// <param name="resultPath">测量结果的生成目录</param>
- /// <param name="state">测量结果返回</param>
- /// <returns>json字符串</returns>
- public void Img_DDIC_Measure_Size(String imagePath1, String imagePath2, String imagePath3, String imagePath4, String imagePath5, String resultPath, out int state)
- {
- try
- {
- this.webServer_Path = this._url[13];
- }
- catch
- {
- this.webServer_Path = "DDIC_measure_parameter";
- }
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path1", imagePath1);
- json.Add("img_path2", imagePath2);
- json.Add("img_path3", imagePath3);
- json.Add("img_path4", imagePath4);
- json.Add("img_path5", imagePath5);
- json.Add("result_path", resultPath);
- 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>
- /// EDS返回点信息
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="num">第几张图片</param>
- /// <param name="imageType">图片类型</param>
- /// <param name="firm">厂商</param>
- /// <param name="listPoints">返回点数据</param>
- /// <param name="state">返回状态</param>
- public void EDS_Param_Points(String imagePath, int num, int imageType, String firm, out List<Point> listPoints, out int state)
- {
- try
- {
- this.webServer_Path = this._url[9];
- }
- catch
- {
- this.webServer_Path = "test9";
- }
- listPoints = new List<Point>();
- state = 0;
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- json.Add("num", num);
- 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 xpoints = JArray.Parse(jname["Xlists"].ToString());
- JArray ypoints = JArray.Parse(jname["Ylists"].ToString());
- if(xpoints.Count==ypoints.Count)
- {
- List<int> lt_x = new List<int>();
- for(int i=0;i<xpoints.Count;i++)
- {
- lt_x.Add(Convert.ToInt32(xpoints[i].ToString()));
- }
- for(int i=0;i<ypoints.Count;i++)
- {
- for (int j = 0; j < ypoints[i].Count(); j++)
- {
- Point pt = new Point();
- pt.X = lt_x[i];
- pt.Y = Convert.ToInt32(ypoints[i][j][0].ToString());
- listPoints.Add(pt);
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// EDS返回线信息
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="num">第几张图片</param>
- /// <param name="imageType">图片类型</param>
- /// <param name="firm">厂商</param>
- /// <param name="listPoints">返回点数据</param>
- /// <param name="state">返回状态</param>
- public void EDS_Param_Lines(String imagePath, int num, int imageType, String firm, out List<Point> list_pt, out List<int> height, out int state)
- {
- try
- {
- this.webServer_Path = this._url[10];
- }
- catch
- {
- this.webServer_Path = "test10";
- }
- list_pt = new List<Point>();
- height = new List<int>();
- state = 0;
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- json.Add("num", num);
- 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 lines = JArray.Parse(jname["lines1"].ToString());
- int x = Convert.ToInt32(lines[0][0].ToString());
- int y1 = Convert.ToInt32(lines[0][1].ToString());
- int y2 = Convert.ToInt32(lines[1][1].ToString());
- Point pt = new Point();
- pt.X = x;
- pt.Y = y1;
- list_pt.Add(pt);
- height.Add(Math.Abs(y2 - y1));
-
- lines = JArray.Parse(jname["lines2"].ToString());
- x = Convert.ToInt32(lines[0][0].ToString());
- y1 = Convert.ToInt32(lines[0][1].ToString());
- y2 = Convert.ToInt32(lines[1][1].ToString());
- pt = new Point();
- pt.X = x;
- pt.Y = y1;
- list_pt.Add(pt);
- height.Add(Math.Abs(y2 - y1));
- lines = JArray.Parse(jname["lines3"].ToString());
- x = Convert.ToInt32(lines[0][0].ToString());
- y1 = Convert.ToInt32(lines[0][1].ToString());
- y2 = Convert.ToInt32(lines[1][1].ToString());
- pt = new Point();
- pt.X = x;
- pt.Y = y1;
- list_pt.Add(pt);
- height.Add(Math.Abs(y2 - y1));
- }
- }
- }
- /// <summary>
- /// EDS返回点信息
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="num">第几张图片</param>
- /// <param name="imageType">图片类型</param>
- /// <param name="firm">厂商</param>
- /// <param name="listPoints">返回点数据</param>
- /// <param name="state">返回状态</param>
- public void EDS_Param_Areas(String imagePath, int num, int imageType, String firm, out Point pt_left_top, out int width, out int height, out int state)
- {
- try
- {
- this.webServer_Path = this._url[11];
- }
- catch
- {
- this.webServer_Path = "test11";
- }
- pt_left_top = new Point();
- width = 0;
- height = 0;
- state = 0;
- Update_Url();
- JObject json = new JObject();
- json.Add("img_path", imagePath);
- json.Add("num", num);
- 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)
- {
- width = Convert.ToInt32(jname["length"].ToString());
- JArray lines = JArray.Parse(jname["areas"].ToString());
- pt_left_top.X = Convert.ToInt32(lines[0][0].ToString());
- int y1 = Convert.ToInt32(lines[0][1].ToString());
- pt_left_top.Y = y1;
- int y2 = Convert.ToInt32(lines[1][1].ToString());
- height = Math.Abs(y2 - y1);
- }
- }
- }
- /// <summary>
- /// 计算测量区域坐标
- /// </summary>
- /// <param name="imagePath">图片路径</param>
- /// <param name="imageType">样品类型</param>
- /// <param name="firm">厂商</param>
- /// <param name="center">观测点位置列表</param>
- /// <param name="mag1">观测点放大倍数列表</param>
- /// <param name="center0">对焦点位置</param>
- /// <param name="state">返回结果状态</param>
- /// <returns>json字符串</returns>
- public void Img_Measure_Region_Position(String imagePath, int imageType, String firm, out List<Point> center, out List<float> mag, out Point center0, 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);
- center = new List<Point>();
- mag = new List<float>();
- 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 jcenter = JArray.Parse(jname["center"].ToString());
- String ptx = "";
- String pty = "";
- for (int i = 0; i < jcenter.Count; i++)
- {
- ptx = jcenter[i][0].ToString();
- pty = jcenter[i][1].ToString();
- Point pt = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
- center.Add(pt);
- }
- JArray jmag = JArray.Parse(jname["magnification"].ToString());
- for (int i = 0; i < jmag.Count; i++)
- {
- mag.Add(Convert.ToSingle(jmag[i].ToString()));
- }
- JArray jcenter0 = JArray.Parse(jname["center0"].ToString());
- ptx = jcenter0[0].ToString();
- pty = jcenter0[1].ToString();
- center0 = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
- }
- else
- {
- center0 = new Point(0, 0);
- state = 0;
- }
- }
- else
- {
- center0 = new Point(0, 0);
- state = 0;
- }
- }
- /// <summary>
- /// 测量尺寸
- /// </summary>
- /// <param name="imagePath1">图片1路径</param>
- /// <param name="imagePath2">图片2路径</param>
- /// <param name="size1">图片1的像素大小</param>
- /// <param name="size2">图片2的像素大小</param>
- /// <param name="resultPath">测量结果的生成目录</param>
- /// <param name="imageType">样品类型</param>
- /// <param name="firm">厂类</param>
- /// <param name="state">测量结果返回</param>
- /// <returns>json字符串</returns>
- public void Img_Measure_Height(List<String> imagePath, List<float> size, 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();
- JArray jpath = new JArray();
- JArray jsize = new JArray();
- for (int i = 0; i < imagePath.Count; i++)
- {
- jpath.Add(imagePath[i]);
- jsize.Add(size[i]);
- }
- json.Add("img_path", jpath);
- json.Add("result_path", resultPath);
- json.Add("size", jsize);
- 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;
- }
- }
- }
- }
|