|
|
|
@ -11,11 +11,16 @@ using System.Windows; |
|
|
|
|
using System.Windows.Input; |
|
|
|
|
using System.Windows.Media.Imaging; |
|
|
|
|
using System.Windows.Threading; |
|
|
|
|
using SparkClient.Model.Services; |
|
|
|
|
using MessageBox = System.Windows.MessageBox; |
|
|
|
|
|
|
|
|
|
namespace SparkClient.ViewModel.Grading; |
|
|
|
|
|
|
|
|
|
public class DiamondSelectVM : BaseViewModel |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
private SOCClientService _socClientService; |
|
|
|
|
private AlgorithmServer _algorithmServer; |
|
|
|
|
private string DiamondCode { get; set; } |
|
|
|
|
private List<ButtonViewModel> _buttons; |
|
|
|
|
private List<ButtonViewModel> _buttons2; |
|
|
|
@ -123,10 +128,6 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
|
} |
|
|
|
|
SocResultEntity socResolt = new SocResultEntity(); |
|
|
|
|
AlgorithmResultEntity parameter = new AlgorithmResultEntity(); |
|
|
|
|
// 启动soc |
|
|
|
|
socResolt = DoSoc(); |
|
|
|
|
// 启动算法 |
|
|
|
|
parameter = DoAlgorithm(); |
|
|
|
|
parameter.Standard = "IGI 2024"; |
|
|
|
|
string value = param.ToString()??""; |
|
|
|
|
if (value!= null && value.Split(" ").Length==3) |
|
|
|
@ -135,6 +136,13 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
|
parameter.CrownType = value.Split(" ")[1]; |
|
|
|
|
parameter.PavType = value.Split(" ")[2]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 启动soc |
|
|
|
|
socResolt = await DoSoc(); |
|
|
|
|
// 启动算法 |
|
|
|
|
parameter = await DoAlgorithm(socResolt, parameter.Shape, parameter.CrownType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parameter.DiamondCode = DiamondCode; |
|
|
|
|
GradingResult(parameter); |
|
|
|
|
}); |
|
|
|
@ -157,17 +165,131 @@ public class DiamondSelectVM : BaseViewModel |
|
|
|
|
WindowManager.openContent.Add(vm); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private AlgorithmResultEntity DoAlgorithm() |
|
|
|
|
{ |
|
|
|
|
AlgorithmResultEntity param = new AlgorithmResultEntity(); |
|
|
|
|
string json = $"{{\"status\": \"ok\",\r\n \"facets\": [\r\n {{\r\n \"coords\": [\r\n {{\r\n \"x\": 0.03402838855981827,\r\n \"y\": -0.11212713271379471,\r\n \"z\": 5.701290607452393\r\n }},\r\n {{\r\n \"x\": 0.46919262409210205,\r\n \"y\": 0.058160409331321716,\r\n \"z\": 5.289202690124512\r\n }},\r\n {{\r\n \"x\": 0.1256149709224701,\r\n \"y\": 0.3005124032497406,\r\n \"z\": 5.330680847167969\r\n }}\r\n ],\r\n \"facet_id\": \"21_0\",\r\n \"facet_type\": 21\r\n }},\r\n {{\r\n \"coords\": [\r\n {{\r\n \"x\": 2.9093382358551025,\r\n \"y\": 3.4028751850128174,\r\n \"z\": 1.724348783493042\r\n }},\r\n {{\r\n \"x\": 0.46919262409210205,\r\n \"y\": 0.058160409331321716,\r\n \"z\": 5.289202690124512\r\n }},\r\n {{\r\n \"x\": 0.1256149709224701,\r\n \"y\": 0.3005124032497406,\r\n \"z\": 5.330680847167969\r\n }}\r\n ],\r\n \"facet_id\": \"21_1\",\r\n \"facet_type\": 21\r\n }}\r\n ],\r\n \"measurements\": {{\r\n \"DIAMETER\": 6.43,\r\n \"DIAMETER_DEV\": 1.2,\r\n \"M1\": 6.409999847412109,\r\n \"M2\": 6.46999979019165,\r\n \"M3\": 3.9700000286102295,\r\n \"TABLE\": 58.0,\r\n \"TABLE_MIN\": 57.5,\r\n \"TABLE_MAX\": 58.6,\r\n \"CROWN_HEIGHT\": 11.5,\r\n \"CROWN_H_DEV\": 1.4,\r\n \"CROWN_H_MIN\": 10.7,\r\n \"CROWN_H_MAX\": 12.1,\r\n \"CROWN_ANGLE\": 30.5,\r\n \"CROWN_ANGLE_DEV\": 0.9,\r\n \"CROWN_ANGLE_MIN\": 30.2,\r\n \"CROWN_ANGLE_MAX\": 31.1,\r\n \"PAV_DEPTH\": 35.0,\r\n \"PAV_DEPTH_DEV\": 0.8,\r\n \"PAV_DEPTH_MIN\": 34.5,\r\n \"PAV_DEPTH_MAX\": 35.3,\r\n \"PAV_ANGLE\": 35.1,\r\n \"PAV_ANGLE_DEV\": 0.8,\r\n \"PAV_ANGLE_MIN\": 34.7,\r\n \"PAV_ANGLE_MAX\": 35.5,\r\n \"GIRDLE_BEZEL\": 7.1,\r\n \"GIRDLE_BEZEL_DEV\": 1.8,\r\n \"GIRDLE_BEZEL_MIN\": 6.8,\r\n \"GIRDLE_BEZEL_MAX\": 7.5,\r\n \"GIRDLE_BONE\": 7.8,\r\n \"GIRDLE_BONE_MIN\": 7.3,\r\n \"GIRDLE_BONE_MAX\": 8.3,\r\n \"GIRDLE\": 6.3,\r\n \"GIRDLE_DEV\": 3.3,\r\n \"GIRDLE_MIN\": 4.2,\r\n \"GIRDLE_MAX\": 7.5,\r\n \"TOTAL_DEPTH\": 53.5,\r\n \"CULET\": 1.8,\r\n \"LW_RATIO\": 1.0,\r\n \"TOC\": 1.4,\r\n \"COC\": 0.5,\r\n \"TA\": 3.81,\r\n \"LGF\": 75,\r\n \"STAR\": 65,\r\n \"STAR_MIN\": 61.1,\r\n \"STAR_MAX\": 65.4,\r\n \"LOWER_HALVES_RATIO\": 75,\r\n \"LOWER_HALVES_RATIO_MIN\": 73.3,\r\n \"LOWER_HALVES_RATIO_MAX\": 78.1,\r\n \"TWIST\": 1.3,\r\n \"TWIST_DEV\": 2.4,\r\n \"TWIST_MIN\": -0.2,\r\n \"TWIST_MAX\": -2.4,\r\n \"CULET_TO_TABLE\": 1.4\r\n }}\r\n}}\r\n"; |
|
|
|
|
param = JsonConvert.DeserializeObject<AlgorithmResultEntity>(json); |
|
|
|
|
return param; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 启动切工仪接口。 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="index">图片索引</param> |
|
|
|
|
/// <param name="index">图片索引</param> |
|
|
|
|
/// <param name="index">图片索引</param> |
|
|
|
|
/// <returns>图片的字节数组</returns> |
|
|
|
|
private async Task<SocResultEntity> DoSoc() |
|
|
|
|
{ |
|
|
|
|
// 光照度 |
|
|
|
|
int lightLevel = 100; |
|
|
|
|
// 初始化SOC客户端服务,传入SOC端的地址和认证Token |
|
|
|
|
_socClientService = new SOCClientService("http://localhost:5000/api/SoC", "your_basic_auth_token"); |
|
|
|
|
// SOC接口 |
|
|
|
|
string savePath = @"d:\\diamond_images"; |
|
|
|
|
SocResultEntity resultEntity = await _socClientService.ProcessImageCollectionAsync(lightLevel, savePath); |
|
|
|
|
// 转换成json |
|
|
|
|
string jsonResult = JsonConvert.SerializeObject(resultEntity, Formatting.Indented); |
|
|
|
|
ShowMessage(jsonResult); |
|
|
|
|
|
|
|
|
|
return resultEntity; |
|
|
|
|
} |
|
|
|
|
private SocResultEntity DoSoc() |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 启动算法接口。 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="socResolt">切工仪接口返回值</param> |
|
|
|
|
/// <param name="crownType"></param> |
|
|
|
|
/// <param name="shape"></param> |
|
|
|
|
/// <returns>定级参数,3D模型参数</returns> |
|
|
|
|
private Task<AlgorithmResultEntity> DoAlgorithm(SocResultEntity socResolt, String shape, String crownType) |
|
|
|
|
{ |
|
|
|
|
_algorithmServer = new AlgorithmServer(); |
|
|
|
|
//钻石形状:shape |
|
|
|
|
//钻石子形状 |
|
|
|
|
string shape_mode = crownType; |
|
|
|
|
//图片根目录 |
|
|
|
|
string image_file_base_path = "d:\\diamond_images"; |
|
|
|
|
//图片集合 |
|
|
|
|
string image_files = JsonConvert.SerializeObject(socResolt.Images, Formatting.Indented); |
|
|
|
|
|
|
|
|
|
//算法配置参数 |
|
|
|
|
string algo_config = @"
|
|
|
|
|
{ |
|
|
|
|
""edgel_detector"": { |
|
|
|
|
""kernel_size"": 15, |
|
|
|
|
""num_filters"": 16, |
|
|
|
|
""non_max_suppression_winsize"": 17 |
|
|
|
|
}, |
|
|
|
|
""edge_matcher"": { |
|
|
|
|
""grid_size"": 32, |
|
|
|
|
""ransac_iterations"": 10, |
|
|
|
|
""inliner_pts_threshold"": 25, |
|
|
|
|
""inliner_dist_threshold"": 1.0, |
|
|
|
|
""inliner_angle_threshold"": 10.0, |
|
|
|
|
""line_gap_threshold"": 10.0, |
|
|
|
|
""line_length_threshold"": 30.0 |
|
|
|
|
}, |
|
|
|
|
""base_detector"": { |
|
|
|
|
""inliner_dist_threshold"": 30.0, |
|
|
|
|
""inliner_theta_threshold"": 5.0, |
|
|
|
|
""inliner_num_threshold"": 50, |
|
|
|
|
""sample_dist"": 25.0, |
|
|
|
|
""iterations"": 100, |
|
|
|
|
""learning_rate"": 0.0002, |
|
|
|
|
""gradient_clip"": 5.0, |
|
|
|
|
""gradient_momentum"": 0.1, |
|
|
|
|
""base_center_x"": 1296.0 |
|
|
|
|
}, |
|
|
|
|
""girdle_detector"": { |
|
|
|
|
""pavilion_edge_threshold"": 300.0, |
|
|
|
|
""pavilion_angle_min"": 30.0, |
|
|
|
|
""pavilion_angle_max"": 50.0, |
|
|
|
|
""gridle_angle_threshold"": 80.0, |
|
|
|
|
""gridle_to_axis_threshold"": 300.0, |
|
|
|
|
""gridle_y_ratio_min"": 0.2, |
|
|
|
|
""gridle_y_ratio_max"": 0.7, |
|
|
|
|
""gridle_num_candid_threshold"": 30, |
|
|
|
|
""gridle_center_dist_threshold"": 120.0, |
|
|
|
|
""gridle_search_radius"": 80, |
|
|
|
|
""iterations"": 2000, |
|
|
|
|
""learning_rate"": 0.002, |
|
|
|
|
""gradient_clip"": 5.0, |
|
|
|
|
""gradient_momentum"": 0.1 |
|
|
|
|
}, |
|
|
|
|
""pavilion_detector"": { |
|
|
|
|
""pavilion_edge_threshold"": 300.0, |
|
|
|
|
""pavilion_angle_min"": 30.0, |
|
|
|
|
""pavilion_angle_max"": 50.0, |
|
|
|
|
""silhouette_match_samples"": 10, |
|
|
|
|
""silhouette_match_padding"": 0.1, |
|
|
|
|
""iterations"": 10000, |
|
|
|
|
""learning_rate"": 0.02, |
|
|
|
|
""gradient_momentum"": 0.1, |
|
|
|
|
""loss_func_tasks"": 16 |
|
|
|
|
}, |
|
|
|
|
""crown_detector"": { |
|
|
|
|
""sample_point_rate"": 0.1, |
|
|
|
|
""iterations"": 2500, |
|
|
|
|
""learning_rate"": 0.1, |
|
|
|
|
""gradient_momentum"": 0.1, |
|
|
|
|
""loss_func_tasks"": 16 |
|
|
|
|
}, |
|
|
|
|
""output"": { |
|
|
|
|
""pixel_length"": 0.00678, |
|
|
|
|
""girdle_interpolate_pts"": 3 |
|
|
|
|
} |
|
|
|
|
}";
|
|
|
|
|
|
|
|
|
|
AlgorithmResultEntity algoResult = _algorithmServer.CallParseJsonAndReturnActions(shape, shape_mode, image_file_base_path, image_files, algo_config); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将 algoResult 序列化为格式化的 JSON 字符串 |
|
|
|
|
string algoJsonResult = JsonConvert.SerializeObject(algoResult, Formatting.Indented); |
|
|
|
|
ShowMessage(algoJsonResult); |
|
|
|
|
return Task.FromResult(algoResult); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowMessage(string message) |
|
|
|
|
{ |
|
|
|
|
return new SocResultEntity(); |
|
|
|
|
MessageBox.Show(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
public class ButtonInfo |
|
|
|
|
{ |
|
|
|
|