WebResult.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json.Linq;
  7. using Newtonsoft.Json;
  8. using System.Drawing;
  9. namespace WebManager
  10. {
  11. public class ImageProcess : IImageProcessByWeb
  12. {
  13. #region
  14. /// <summary>
  15. /// 数据定义
  16. /// </summary>
  17. private String webServer_IP = "";
  18. private String webServer_Port = "";
  19. private String webServer_Path = "";
  20. private String Url = "";
  21. private const String Post = "Post";
  22. private const String Content_Type= "Content-Type:application/json";
  23. private String[] _url = new string[9];
  24. #endregion
  25. /// <summary>
  26. /// 构造函数
  27. /// </summary>
  28. /// <param name="ws_ip">WebServer的IP地址</param>
  29. /// <param name="ws_port">WebServer的端口号</param>
  30. public ImageProcess(String ws_ip,String ws_port,String ws_url)
  31. {
  32. this.webServer_IP = ws_ip;
  33. this.webServer_Port = ws_port;
  34. this._url = ws_url.Split(',');
  35. //更新Web网址
  36. Update_Url();
  37. }
  38. /// <summary>
  39. /// 更新Web网址
  40. /// </summary>
  41. private void Update_Url()
  42. {
  43. this.webServer_Path = "/" + this.webServer_Path;
  44. this.Url = "http://" + this.webServer_IP + ":" + this.webServer_Port + this.webServer_Path;
  45. }
  46. /// <summary>
  47. /// WebServer的IP地址
  48. /// </summary>
  49. public String WebServer_IP
  50. {
  51. //get { return this.webServer_IP; }
  52. set
  53. {
  54. this.webServer_IP = value;
  55. }
  56. }
  57. /// <summary>
  58. /// WebServer的端口号
  59. /// </summary>
  60. public String WebServer_Port
  61. {
  62. //get { return this.webServer_IP; }
  63. set
  64. {
  65. this.webServer_Port = value;
  66. }
  67. }
  68. /// <summary>
  69. /// 向WebServer请求数据及返回结果
  70. /// </summary>
  71. /// <param name="postString">请求数据的JSON</param>
  72. /// <returns>返回结果的JSON</returns>
  73. private String RequestString(String postString)
  74. {
  75. try
  76. {
  77. String res = HttpRequestHelper.DoRequest(this.Url, Post, Content_Type, postString);
  78. return res;
  79. }
  80. catch
  81. {
  82. return "";
  83. }
  84. }
  85. /// <summary>
  86. /// 计算原始图像偏移角度及方向
  87. /// </summary>
  88. /// <param name="imagePath">图片路径</param>
  89. /// <param name="imageType">孔类型</param>
  90. /// <param name="firm">厂家类型</param>
  91. /// <param name="degree">返回角度</param>
  92. /// <param name="direction">返回方向</param>
  93. /// <param name="state">图像接口返回状态</param>
  94. /// <returns>json字符串</returns>
  95. public void Img_OffsetAngle_Direction(String imagePath, int imageType, String firm, out float degree, out int direction, out int state)
  96. {
  97. try
  98. {
  99. this.webServer_Path = this._url[0];
  100. }
  101. catch
  102. {
  103. this.webServer_Path = "FIB_degree_recognize";
  104. }
  105. Update_Url();
  106. JObject json = new JObject();
  107. json.Add("img_path", imagePath);
  108. json.Add("img_type", imageType);
  109. json.Add("firm", firm);
  110. String res = RequestString(JsonConvert.SerializeObject(json));
  111. JObject jret= (JObject)JsonConvert.DeserializeObject(res);
  112. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  113. {
  114. JObject jname = JObject.Parse(jret[imagePath].ToString());
  115. state = Convert.ToInt32(jname["state"].ToString());
  116. if (state == 1)
  117. {
  118. degree = Convert.ToSingle(jname["degree"].ToString());
  119. direction = Convert.ToInt32(jname["direction"].ToString());
  120. }
  121. else
  122. {
  123. degree = 0;
  124. direction = 0;
  125. }
  126. }
  127. else
  128. {
  129. state = 0;
  130. direction = 0;
  131. degree = 0;
  132. }
  133. }
  134. /// <summary>
  135. /// 计算切割点位置
  136. /// </summary>
  137. /// <param name="imagePath">图片路径</param>
  138. /// <param name="imageType">样品类型</param>
  139. /// <param name="firm">厂家类型</param>
  140. /// <param name="offsetx1">切割点相对于原点坐标左上角x值</param>
  141. /// <param name="offsetx2">切割点相对于原点坐标左上角y值</param>
  142. /// <param name="offsety1">切割点相对于原点坐标右上角x值</param>
  143. /// <param name="offsety2">切割点相对于原点坐标右上角y值</param>
  144. /// <param name="state">返回状态</param>
  145. /// <returns>json字符串</returns>
  146. 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)
  147. {
  148. try
  149. {
  150. this.webServer_Path = this._url[1];
  151. }
  152. catch
  153. {
  154. this.webServer_Path = "test2";
  155. }
  156. Update_Url();
  157. JObject json = new JObject();
  158. json.Add("img_path", imagePath);
  159. json.Add("img_type", imageType);
  160. json.Add("firm", firm);
  161. String res = RequestString(JsonConvert.SerializeObject(json));
  162. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  163. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  164. {
  165. JObject jname = JObject.Parse(jret[imagePath].ToString());
  166. JArray jlocation = JArray.Parse(jname["location"].ToString());
  167. state = Convert.ToInt32(jname["state"].ToString());
  168. if (state == 1)
  169. {
  170. offsetx1 = Convert.ToSingle(jlocation[0][0].ToString());
  171. offsety1 = Convert.ToSingle(jlocation[0][1].ToString());
  172. offsetx2 = Convert.ToSingle(jlocation[1][0].ToString());
  173. offsety2 = Convert.ToSingle(jlocation[1][1].ToString());
  174. }
  175. else
  176. {
  177. offsetx1 = 0;
  178. offsety1 = 0;
  179. offsetx2 = 0;
  180. offsety2 = 0;
  181. }
  182. }
  183. else
  184. {
  185. state = 0;
  186. offsetx1 = 0;
  187. offsety1 = 0;
  188. offsetx2 = 0;
  189. offsety2 = 0;
  190. }
  191. }
  192. /// <summary>
  193. /// 是否切割成功验证
  194. /// </summary>
  195. /// <param name="imageBefore">切割前图像路径</param>
  196. /// <param name="imageAfter">切割后图像路径</param>
  197. /// <param name="state">图像接口返回状态</param>
  198. /// <returns>json字符串</returns>
  199. public void Img_Cut_Success(String imageBefore, String imageAfter, out int state)
  200. {
  201. try
  202. {
  203. this.webServer_Path = this._url[2];
  204. }
  205. catch
  206. {
  207. this.webServer_Path = "FIB_verify";
  208. }
  209. Update_Url();
  210. JObject json = new JObject();
  211. json.Add("img_before_path", imageBefore);
  212. json.Add("img_after_path", imageAfter);
  213. String res = RequestString(JsonConvert.SerializeObject(json));
  214. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  215. if (jret != null && jret.Property("state") != null && jret.Property("state").ToString() != "")
  216. {
  217. state = Convert.ToInt32(jret["state"].ToString());
  218. }
  219. else
  220. {
  221. state = 0;
  222. }
  223. }
  224. /// <summary>
  225. /// 计算切割后图像梯形区域上边中心点坐标
  226. /// </summary>
  227. /// <param name="imagePath">图片路径</param>
  228. /// <param name="offsetx">梯形中心点X轴坐标</param>
  229. /// <param name="offsety">梯形中心点Y轴坐标</param>
  230. /// <param name="state">图像接口返回状态</param>
  231. /// <returns>json字符串</returns>
  232. 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 两个参数
  233. {
  234. try
  235. {
  236. this.webServer_Path = this._url[3];
  237. }
  238. catch
  239. {
  240. this.webServer_Path = "test4";
  241. }
  242. Update_Url();
  243. JObject json = new JObject();
  244. json.Add("img_path", imagePath);
  245. json.Add("img_type", imageType);
  246. json.Add("firm", firm);
  247. String res = RequestString(JsonConvert.SerializeObject(json));
  248. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  249. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  250. {
  251. JObject jname = JObject.Parse(jret[imagePath].ToString());
  252. JArray jlocation = JArray.Parse(jname["top_center"].ToString());
  253. state = Convert.ToInt32(jname["state"].ToString());
  254. if(state==1)
  255. {
  256. offsetx = Convert.ToSingle(jlocation[0].ToString());
  257. offsety = Convert.ToSingle(jlocation[1].ToString());
  258. }
  259. else
  260. {
  261. offsetx = 0;
  262. offsety = 0;
  263. }
  264. }
  265. else
  266. {
  267. state = 0;
  268. offsetx = 0;
  269. offsety = 0;
  270. }
  271. }
  272. /// <summary>
  273. /// 自动对焦
  274. /// </summary>
  275. /// <param name="imagePath">一组图片路径</param>
  276. /// <returns>json字符串</returns>
  277. public String Img_Auto_Focus(List<String> imagePath)
  278. {
  279. try
  280. {
  281. this.webServer_Path = this._url[4];
  282. }
  283. catch
  284. {
  285. this.webServer_Path = "test5";
  286. }
  287. Update_Url();
  288. JObject json = new JObject();
  289. for(int i=0;i<imagePath.Count;i++)
  290. {
  291. json.Add("img_path" + i.ToString(), imagePath[i]);
  292. }
  293. String res = RequestString(JsonConvert.SerializeObject(json));
  294. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  295. if (jret != null && jret.Property("img_path") != null && jret.Property("img_path").ToString() != "")
  296. {
  297. return jret["img_path"].ToString();
  298. }
  299. else
  300. {
  301. return "";
  302. }
  303. }
  304. /// <summary>
  305. /// 自动消像散
  306. /// </summary>
  307. /// <param name="imagePath">一组图片路径</param>
  308. /// <returns>json字符串</returns>
  309. public String Img_Auto_Stigmatic(List<String> imagePath)
  310. {
  311. try
  312. {
  313. this.webServer_Path = this._url[5];
  314. }
  315. catch
  316. {
  317. this.webServer_Path = "test6";
  318. }
  319. Update_Url();
  320. JObject json = new JObject();
  321. for (int i = 0; i < imagePath.Count; i++)
  322. {
  323. json.Add("img_path" + i.ToString(), imagePath[i]);
  324. }
  325. String res = RequestString(JsonConvert.SerializeObject(json));
  326. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  327. if (jret != null && jret.Property("img_path") != null && jret.Property("img_path").ToString() != "")
  328. {
  329. return jret["img_path"].ToString();
  330. }
  331. else
  332. {
  333. return "";
  334. }
  335. }
  336. /// <summary>
  337. /// 计算切割面区域偏移角度及方向
  338. /// </summary>
  339. /// <param name="imagePath">图片路径</param>
  340. /// <param name="degree">图像偏移角度</param>
  341. /// <param name="direction">旋转方向</param>
  342. /// <param name="state">图像接口返回状态</param>
  343. /// <returns>json字符串</returns>
  344. public void Img_Center_Position_OffsetAngle_Direction(String imagePath, int imageType, String firm, out float degree, out int direction, out int state)
  345. {
  346. try
  347. {
  348. this.webServer_Path = this._url[6];
  349. }
  350. catch
  351. {
  352. this.webServer_Path = "test7";
  353. }
  354. Update_Url();
  355. JObject json = new JObject();
  356. json.Add("img_path", imagePath);
  357. json.Add("img_type", imageType);
  358. json.Add("firm", firm);
  359. String res = RequestString(JsonConvert.SerializeObject(json));
  360. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  361. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  362. {
  363. JObject jname = JObject.Parse(jret[imagePath].ToString());
  364. state = Convert.ToInt32(jname["state"].ToString());
  365. if (state == 1)
  366. {
  367. degree = Convert.ToSingle(jname["degree"].ToString());
  368. direction = Convert.ToInt32(jname["direction"].ToString());
  369. }
  370. else
  371. {
  372. degree = 0;
  373. direction = 0;
  374. }
  375. }
  376. else
  377. {
  378. state = 0;
  379. direction = 0;
  380. degree = 0;
  381. //offsetx = 0;
  382. //offsety = 0;
  383. }
  384. }
  385. /// <summary>
  386. /// 计算两个测量区域坐标
  387. /// </summary>
  388. /// <param name="imagePath">图片路径</param>
  389. /// <param name="imageType">样品类型</param>
  390. /// <param name="firm">厂商</param>
  391. /// <param name="center1">观测点1位置</param>
  392. /// <param name="mag1">观测点1放大倍数</param>
  393. /// <param name="center2">观测点2位置</param>
  394. /// <param name="mag2">观测点2放大倍数</param>
  395. /// <param name="state">返回结果状态</param>
  396. /// <returns>json字符串</returns>
  397. 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)
  398. {
  399. try
  400. {
  401. this.webServer_Path = this._url[7];
  402. }
  403. catch
  404. {
  405. this.webServer_Path = "test8";
  406. }
  407. Update_Url();
  408. JObject json = new JObject();
  409. json.Add("img_path", imagePath);
  410. json.Add("img_type", imageType);
  411. json.Add("firm", firm);
  412. String res = RequestString(JsonConvert.SerializeObject(json));
  413. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  414. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  415. {
  416. JObject jname = JObject.Parse(jret[imagePath].ToString());
  417. state = Convert.ToInt32(jname["state"].ToString());
  418. if (state == 1)
  419. {
  420. JArray jcenter1 = JArray.Parse(jname["center1"].ToString());
  421. String ptx = jcenter1[0].ToString();
  422. String pty = jcenter1[1].ToString();
  423. center1 = new Point(Convert.ToInt32(ptx),Convert.ToInt32(pty));
  424. String jmag1 = jname["magnification1"].ToString();
  425. mag1 = Convert.ToSingle(jmag1.ToString());
  426. JArray jcenter2 = JArray.Parse(jname["center2"].ToString());
  427. ptx = jcenter2[0].ToString();
  428. pty = jcenter2[1].ToString();
  429. center2 = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
  430. String jmag2 = jname["magnification2"].ToString();
  431. mag2 = Convert.ToSingle(jmag2.ToString());
  432. JArray jcenter3 = JArray.Parse(jname["center3"].ToString());
  433. ptx = jcenter3[0].ToString();
  434. pty = jcenter3[1].ToString();
  435. center3 = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
  436. }
  437. else
  438. {
  439. center1 = new Point(0, 0);
  440. center2 = new Point(0, 0);
  441. center3 = new Point(0, 0);
  442. mag1 = 0;
  443. mag2 = 0;
  444. state = 0;
  445. }
  446. }
  447. else
  448. {
  449. center1 = new Point(0, 0);
  450. center2 = new Point(0, 0);
  451. center3 = new Point(0, 0);
  452. mag1 = 0;
  453. mag2 = 0;
  454. state = 0;
  455. }
  456. }
  457. /// <summary>
  458. /// 测量尺寸
  459. /// </summary>
  460. /// <param name="imagePath1">图片1路径</param>
  461. /// <param name="imagePath2">图片2路径</param>
  462. /// <param name="size1">图片1的像素大小</param>
  463. /// <param name="size2">图片2的像素大小</param>
  464. /// <param name="resultPath">测量结果的生成目录</param>
  465. /// <param name="imageType">样品类型</param>
  466. /// <param name="firm">厂类</param>
  467. /// <param name="state">测量结果返回</param>
  468. /// <returns>json字符串</returns>
  469. public void Img_Measure_Size(String imagePath1, String imagePath2, float size1, float size2, String resultPath, int imageType, String firm, out int state)
  470. {
  471. try
  472. {
  473. this.webServer_Path = this._url[8];
  474. }
  475. catch
  476. {
  477. this.webServer_Path = "test9";
  478. }
  479. Update_Url();
  480. JObject json = new JObject();
  481. json.Add("img_path1", imagePath1);
  482. json.Add("img_path2", imagePath2);
  483. json.Add("size1", size1);
  484. json.Add("size2", size2);
  485. json.Add("result_path", resultPath);
  486. json.Add("img_type", imageType);
  487. json.Add("firm", firm);
  488. String res = RequestString(JsonConvert.SerializeObject(json));
  489. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  490. if (jret != null && jret.Property("state") != null && jret.Property("state").ToString() != "")
  491. {
  492. state = Convert.ToInt32(jret["state"].ToString());
  493. }
  494. else
  495. {
  496. state = 0;
  497. }
  498. }
  499. /// <summary>
  500. /// DDIC计算原始图像偏移角度及方向
  501. /// </summary>
  502. /// <param name="imagePath">图片路径</param>
  503. /// <param name="degree">返回角度</param>
  504. /// <param name="direction">返回方向</param>
  505. /// <param name="state">图像接口返回状态</param>
  506. /// <returns>json字符串</returns>
  507. public void Img_DDIC_OffsetAngle_Direction(String imagePath, out float degree, out int direction, out int state)
  508. {
  509. try
  510. {
  511. this.webServer_Path = this._url[9];
  512. }
  513. catch
  514. {
  515. this.webServer_Path = "DDIC_degree_recognize";
  516. }
  517. Update_Url();
  518. JObject json = new JObject();
  519. json.Add("img_path", imagePath);
  520. String res = RequestString(JsonConvert.SerializeObject(json));
  521. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  522. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  523. {
  524. JObject jname = JObject.Parse(jret[imagePath].ToString());
  525. state = Convert.ToInt32(jname["state"].ToString());
  526. if (state == 1)
  527. {
  528. degree = Convert.ToSingle(jname["degree"].ToString());
  529. direction = Convert.ToInt32(jname["direction"].ToString());
  530. }
  531. else
  532. {
  533. degree = 0;
  534. direction = 0;
  535. }
  536. }
  537. else
  538. {
  539. state = 0;
  540. direction = 0;
  541. degree = 0;
  542. }
  543. }
  544. /// <summary>
  545. /// DDIC计算切割点位置
  546. /// </summary>
  547. /// <param name="imagePath">图片路径</param>
  548. /// <param name="offsetx">切割点相对于原点坐标左上角x值</param>
  549. /// <param name="offsety">切割点相对于原点坐标左上角y值</param>
  550. /// <param name="state">返回状态</param>
  551. /// <returns>json字符串</returns>
  552. public void Img_DDIC_Cut_Position(String imagePath, int imageType, String firm, out float offsetx, out float offsety, out int state)
  553. {
  554. try
  555. {
  556. this.webServer_Path = this._url[10];
  557. }
  558. catch
  559. {
  560. this.webServer_Path = "DDIC_cal_cut_location";
  561. }
  562. Update_Url();
  563. JObject json = new JObject();
  564. json.Add("img_path", imagePath);
  565. String res = RequestString(JsonConvert.SerializeObject(json));
  566. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  567. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  568. {
  569. JObject jname = JObject.Parse(jret[imagePath].ToString());
  570. state = Convert.ToInt32(jname["state"].ToString());
  571. if (state == 1)
  572. {
  573. JArray jlocation = JArray.Parse(jname["location"].ToString());
  574. offsetx = Convert.ToSingle(jlocation[0][0].ToString());
  575. offsety = Convert.ToSingle(jlocation[0][1].ToString());
  576. }
  577. else
  578. {
  579. offsetx = 0;
  580. offsety = 0;
  581. }
  582. }
  583. else
  584. {
  585. state = 0;
  586. offsetx = 0;
  587. offsety = 0;
  588. }
  589. }
  590. /// <summary>
  591. /// DDIC梯形位置识别
  592. /// </summary>
  593. /// <param name="imagePath">图片路径</param>
  594. /// <param name="offsetx">梯形中心点X轴坐标</param>
  595. /// <param name="offsety">梯形中心点Y轴坐标</param>
  596. /// <param name="state">图像接口返回状态</param>
  597. /// <returns>json字符串</returns>
  598. public void Img_DDIC_Trapezoid_Top_Center_Position(String imagePath, out float offsetx, out float offsety, out int state)
  599. {
  600. try
  601. {
  602. this.webServer_Path = this._url[11];
  603. }
  604. catch
  605. {
  606. this.webServer_Path = "test4";
  607. }
  608. Update_Url();
  609. JObject json = new JObject();
  610. json.Add("img_path", imagePath);
  611. String res = RequestString(JsonConvert.SerializeObject(json));
  612. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  613. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  614. {
  615. JObject jname = JObject.Parse(jret[imagePath].ToString());
  616. JArray jlocation = JArray.Parse(jname["top_center"].ToString());
  617. state = Convert.ToInt32(jname["state"].ToString());
  618. if (state == 1)
  619. {
  620. offsetx = Convert.ToSingle(jlocation[0].ToString());
  621. offsety = Convert.ToSingle(jlocation[1].ToString());
  622. }
  623. else
  624. {
  625. offsetx = 0;
  626. offsety = 0;
  627. }
  628. }
  629. else
  630. {
  631. state = 0;
  632. offsetx = 0;
  633. offsety = 0;
  634. }
  635. }
  636. /// <summary>
  637. /// DDIC测量点计算
  638. /// </summary>
  639. /// <param name="imagePath">图片路径</param>
  640. /// <param name="state">返回结果状态</param>
  641. /// <returns>json字符串</returns>
  642. public void Img_DDIC_Measure_Location(String imagePath, out List<Point> measure_points, out int state)
  643. {
  644. try
  645. {
  646. this.webServer_Path = this._url[12];
  647. }
  648. catch
  649. {
  650. this.webServer_Path = "DDIC_measure_location";
  651. }
  652. Update_Url();
  653. measure_points = new List<Point>();
  654. JObject json = new JObject();
  655. json.Add("img_path", imagePath);
  656. String res = RequestString(JsonConvert.SerializeObject(json));
  657. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  658. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  659. {
  660. JObject jname = JObject.Parse(jret[imagePath].ToString());
  661. state = Convert.ToInt32(jname["state"].ToString());
  662. if (state == 1)
  663. {
  664. JArray jcenter1 = JArray.Parse(jname["location1"].ToString());
  665. String ptx = jcenter1[0].ToString();
  666. String pty = jcenter1[1].ToString();
  667. measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
  668. jcenter1 = JArray.Parse(jname["location2"].ToString());
  669. ptx = jcenter1[0].ToString();
  670. pty = jcenter1[1].ToString();
  671. measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
  672. jcenter1 = JArray.Parse(jname["location3"].ToString());
  673. ptx = jcenter1[0].ToString();
  674. pty = jcenter1[1].ToString();
  675. measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
  676. jcenter1 = JArray.Parse(jname["location4"].ToString());
  677. ptx = jcenter1[0].ToString();
  678. pty = jcenter1[1].ToString();
  679. measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
  680. jcenter1 = JArray.Parse(jname["location5"].ToString());
  681. ptx = jcenter1[0].ToString();
  682. pty = jcenter1[1].ToString();
  683. measure_points.Add(new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty)));
  684. }
  685. else
  686. {
  687. state = 0;
  688. }
  689. }
  690. else
  691. {
  692. state = 0;
  693. }
  694. }
  695. /// <summary>
  696. /// DDIC测量尺寸
  697. /// </summary>
  698. /// <param name="imagePath1">图片1路径</param>
  699. /// <param name="imagePath2">图片2路径</param>
  700. /// <param name="imagePath3">图片3路径</param>
  701. /// <param name="imagePath4">图片4路径</param>
  702. /// <param name="imagePath5">图片5路径</param>
  703. /// <param name="resultPath">测量结果的生成目录</param>
  704. /// <param name="state">测量结果返回</param>
  705. /// <returns>json字符串</returns>
  706. public void Img_DDIC_Measure_Size(String imagePath1, String imagePath2, String imagePath3, String imagePath4, String imagePath5, String resultPath, out int state)
  707. {
  708. try
  709. {
  710. this.webServer_Path = this._url[13];
  711. }
  712. catch
  713. {
  714. this.webServer_Path = "DDIC_measure_parameter";
  715. }
  716. Update_Url();
  717. JObject json = new JObject();
  718. json.Add("img_path1", imagePath1);
  719. json.Add("img_path2", imagePath2);
  720. json.Add("img_path3", imagePath3);
  721. json.Add("img_path4", imagePath4);
  722. json.Add("img_path5", imagePath5);
  723. json.Add("result_path", resultPath);
  724. String res = RequestString(JsonConvert.SerializeObject(json));
  725. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  726. if (jret != null && jret.Property("state") != null && jret.Property("state").ToString() != "")
  727. {
  728. state = Convert.ToInt32(jret["state"].ToString());
  729. }
  730. else
  731. {
  732. state = 0;
  733. }
  734. }
  735. /// <summary>
  736. /// EDS返回点信息
  737. /// </summary>
  738. /// <param name="imagePath">图片路径</param>
  739. /// <param name="num">第几张图片</param>
  740. /// <param name="imageType">图片类型</param>
  741. /// <param name="firm">厂商</param>
  742. /// <param name="listPoints">返回点数据</param>
  743. /// <param name="state">返回状态</param>
  744. public void EDS_Param_Points(String imagePath, int num, int imageType, String firm, out List<Point> listPoints, out int state)
  745. {
  746. try
  747. {
  748. this.webServer_Path = this._url[9];
  749. }
  750. catch
  751. {
  752. this.webServer_Path = "test9";
  753. }
  754. listPoints = new List<Point>();
  755. state = 0;
  756. Update_Url();
  757. JObject json = new JObject();
  758. json.Add("img_path", imagePath);
  759. json.Add("num", num);
  760. json.Add("img_type", imageType);
  761. json.Add("firm", firm);
  762. String res = RequestString(JsonConvert.SerializeObject(json));
  763. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  764. if(jret!=null && jret.Property(imagePath)!=null && jret.Property(imagePath).ToString()!="")
  765. {
  766. JObject jname = JObject.Parse(jret[imagePath].ToString());
  767. state = Convert.ToInt32(jname["state"].ToString());
  768. if(state==1)
  769. {
  770. JArray xpoints = JArray.Parse(jname["Xlists"].ToString());
  771. JArray ypoints = JArray.Parse(jname["Ylists"].ToString());
  772. if(xpoints.Count==ypoints.Count)
  773. {
  774. List<int> lt_x = new List<int>();
  775. for(int i=0;i<xpoints.Count;i++)
  776. {
  777. lt_x.Add(Convert.ToInt32(xpoints[i].ToString()));
  778. }
  779. for(int i=0;i<ypoints.Count;i++)
  780. {
  781. for (int j = 0; j < ypoints[i].Count(); j++)
  782. {
  783. Point pt = new Point();
  784. pt.X = lt_x[i];
  785. pt.Y = Convert.ToInt32(ypoints[i][j][0].ToString());
  786. listPoints.Add(pt);
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. /// <summary>
  794. /// EDS返回线信息
  795. /// </summary>
  796. /// <param name="imagePath">图片路径</param>
  797. /// <param name="num">第几张图片</param>
  798. /// <param name="imageType">图片类型</param>
  799. /// <param name="firm">厂商</param>
  800. /// <param name="listPoints">返回点数据</param>
  801. /// <param name="state">返回状态</param>
  802. 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)
  803. {
  804. try
  805. {
  806. this.webServer_Path = this._url[10];
  807. }
  808. catch
  809. {
  810. this.webServer_Path = "test10";
  811. }
  812. list_pt = new List<Point>();
  813. height = new List<int>();
  814. state = 0;
  815. Update_Url();
  816. JObject json = new JObject();
  817. json.Add("img_path", imagePath);
  818. json.Add("num", num);
  819. json.Add("img_type", imageType);
  820. json.Add("firm", firm);
  821. String res = RequestString(JsonConvert.SerializeObject(json));
  822. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  823. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  824. {
  825. JObject jname = JObject.Parse(jret[imagePath].ToString());
  826. state = Convert.ToInt32(jname["state"].ToString());
  827. if (state == 1)
  828. {
  829. JArray lines = JArray.Parse(jname["lines1"].ToString());
  830. int x = Convert.ToInt32(lines[0][0].ToString());
  831. int y1 = Convert.ToInt32(lines[0][1].ToString());
  832. int y2 = Convert.ToInt32(lines[1][1].ToString());
  833. Point pt = new Point();
  834. pt.X = x;
  835. pt.Y = y1;
  836. list_pt.Add(pt);
  837. height.Add(Math.Abs(y2 - y1));
  838. lines = JArray.Parse(jname["lines2"].ToString());
  839. x = Convert.ToInt32(lines[0][0].ToString());
  840. y1 = Convert.ToInt32(lines[0][1].ToString());
  841. y2 = Convert.ToInt32(lines[1][1].ToString());
  842. pt = new Point();
  843. pt.X = x;
  844. pt.Y = y1;
  845. list_pt.Add(pt);
  846. height.Add(Math.Abs(y2 - y1));
  847. lines = JArray.Parse(jname["lines3"].ToString());
  848. x = Convert.ToInt32(lines[0][0].ToString());
  849. y1 = Convert.ToInt32(lines[0][1].ToString());
  850. y2 = Convert.ToInt32(lines[1][1].ToString());
  851. pt = new Point();
  852. pt.X = x;
  853. pt.Y = y1;
  854. list_pt.Add(pt);
  855. height.Add(Math.Abs(y2 - y1));
  856. }
  857. }
  858. }
  859. /// <summary>
  860. /// EDS返回点信息
  861. /// </summary>
  862. /// <param name="imagePath">图片路径</param>
  863. /// <param name="num">第几张图片</param>
  864. /// <param name="imageType">图片类型</param>
  865. /// <param name="firm">厂商</param>
  866. /// <param name="listPoints">返回点数据</param>
  867. /// <param name="state">返回状态</param>
  868. 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)
  869. {
  870. try
  871. {
  872. this.webServer_Path = this._url[11];
  873. }
  874. catch
  875. {
  876. this.webServer_Path = "test11";
  877. }
  878. pt_left_top = new Point();
  879. width = 0;
  880. height = 0;
  881. state = 0;
  882. Update_Url();
  883. JObject json = new JObject();
  884. json.Add("img_path", imagePath);
  885. json.Add("num", num);
  886. json.Add("img_type", imageType);
  887. json.Add("firm", firm);
  888. String res = RequestString(JsonConvert.SerializeObject(json));
  889. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  890. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  891. {
  892. JObject jname = JObject.Parse(jret[imagePath].ToString());
  893. state = Convert.ToInt32(jname["state"].ToString());
  894. if (state == 1)
  895. {
  896. width = Convert.ToInt32(jname["length"].ToString());
  897. JArray lines = JArray.Parse(jname["areas"].ToString());
  898. pt_left_top.X = Convert.ToInt32(lines[0][0].ToString());
  899. int y1 = Convert.ToInt32(lines[0][1].ToString());
  900. pt_left_top.Y = y1;
  901. int y2 = Convert.ToInt32(lines[1][1].ToString());
  902. height = Math.Abs(y2 - y1);
  903. }
  904. }
  905. }
  906. /// <summary>
  907. /// 计算测量区域坐标
  908. /// </summary>
  909. /// <param name="imagePath">图片路径</param>
  910. /// <param name="imageType">样品类型</param>
  911. /// <param name="firm">厂商</param>
  912. /// <param name="center">观测点位置列表</param>
  913. /// <param name="mag1">观测点放大倍数列表</param>
  914. /// <param name="center0">对焦点位置</param>
  915. /// <param name="state">返回结果状态</param>
  916. /// <returns>json字符串</returns>
  917. 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)
  918. {
  919. try
  920. {
  921. this.webServer_Path = this._url[7];
  922. }
  923. catch
  924. {
  925. this.webServer_Path = "test8";
  926. }
  927. Update_Url();
  928. JObject json = new JObject();
  929. json.Add("img_path", imagePath);
  930. json.Add("img_type", imageType);
  931. json.Add("firm", firm);
  932. center = new List<Point>();
  933. mag = new List<float>();
  934. String res = RequestString(JsonConvert.SerializeObject(json));
  935. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  936. if (jret != null && jret.Property(imagePath) != null && jret.Property(imagePath).ToString() != "")
  937. {
  938. JObject jname = JObject.Parse(jret[imagePath].ToString());
  939. state = Convert.ToInt32(jname["state"].ToString());
  940. if (state == 1)
  941. {
  942. JArray jcenter = JArray.Parse(jname["center"].ToString());
  943. String ptx = "";
  944. String pty = "";
  945. for (int i = 0; i < jcenter.Count; i++)
  946. {
  947. ptx = jcenter[i][0].ToString();
  948. pty = jcenter[i][1].ToString();
  949. Point pt = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
  950. center.Add(pt);
  951. }
  952. JArray jmag = JArray.Parse(jname["magnification"].ToString());
  953. for (int i = 0; i < jmag.Count; i++)
  954. {
  955. mag.Add(Convert.ToSingle(jmag[i].ToString()));
  956. }
  957. JArray jcenter0 = JArray.Parse(jname["center0"].ToString());
  958. ptx = jcenter0[0].ToString();
  959. pty = jcenter0[1].ToString();
  960. center0 = new Point(Convert.ToInt32(ptx), Convert.ToInt32(pty));
  961. }
  962. else
  963. {
  964. center0 = new Point(0, 0);
  965. state = 0;
  966. }
  967. }
  968. else
  969. {
  970. center0 = new Point(0, 0);
  971. state = 0;
  972. }
  973. }
  974. /// <summary>
  975. /// 测量尺寸
  976. /// </summary>
  977. /// <param name="imagePath1">图片1路径</param>
  978. /// <param name="imagePath2">图片2路径</param>
  979. /// <param name="size1">图片1的像素大小</param>
  980. /// <param name="size2">图片2的像素大小</param>
  981. /// <param name="resultPath">测量结果的生成目录</param>
  982. /// <param name="imageType">样品类型</param>
  983. /// <param name="firm">厂类</param>
  984. /// <param name="state">测量结果返回</param>
  985. /// <returns>json字符串</returns>
  986. public void Img_Measure_Height(List<String> imagePath, List<float> size, String resultPath, int imageType, String firm, out int state)
  987. {
  988. try
  989. {
  990. this.webServer_Path = this._url[8];
  991. }
  992. catch
  993. {
  994. this.webServer_Path = "test9";
  995. }
  996. Update_Url();
  997. JObject json = new JObject();
  998. JArray jpath = new JArray();
  999. JArray jsize = new JArray();
  1000. for (int i = 0; i < imagePath.Count; i++)
  1001. {
  1002. jpath.Add(imagePath[i]);
  1003. jsize.Add(size[i]);
  1004. }
  1005. json.Add("img_path", jpath);
  1006. json.Add("result_path", resultPath);
  1007. json.Add("size", jsize);
  1008. json.Add("img_type", imageType);
  1009. json.Add("firm", firm);
  1010. String res = RequestString(JsonConvert.SerializeObject(json));
  1011. JObject jret = (JObject)JsonConvert.DeserializeObject(res);
  1012. if (jret != null && jret.Property("state") != null && jret.Property("state").ToString() != "")
  1013. {
  1014. state = Convert.ToInt32(jret["state"].ToString());
  1015. }
  1016. else
  1017. {
  1018. state = 0;
  1019. }
  1020. }
  1021. }
  1022. }