Ejemplo n.º 1
0
        /// <summary>
        /// 还原输出文件
        /// </summary>
        private void RecoverOutputFile(bool isForceDefault = false)
        {
            if (VisionFrame.IsEnableOutput == true)
            {
                if (string.IsNullOrEmpty(OutputParamFile))
                {
                    OutputParamFile = "default.json";
                }

                //若文件不存在,则创建默认配置到此文件;若文件存在,则从配置文件中加载配置;
                string filePath = $"{System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase}/VisionPlatform/Scene/{EVisionFrameType}/{Name}/OutputParam/{OutputParamFile}";
                if (isForceDefault)
                {
                    JsonSerialization.SerializeObjectToFile(VisionFrame.Outputs, filePath);
                }
                else
                {
                    if (!File.Exists(filePath))
                    {
                        JsonSerialization.SerializeObjectToFile(VisionFrame.Outputs, filePath);
                    }
                    else
                    {
                        VisionFrame.Outputs.Clear();
                        VisionFrame.Outputs.AddRange(JsonSerialization.DeserializeObjectFromFile <ItemCollection>(filePath));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void SetCameraConfigFile(string file)
        {
            CameraConfigFile = file;

            if (!string.IsNullOrEmpty(file))
            {
                //获取相机配置参数
                string configFile = $"{System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase}/VisionPlatform/Camera/CameraConfig/{CameraSerial}/ConfigFile/{CameraConfigFile}";

                if (File.Exists(configFile))
                {
                    cameraConfigParam = JsonSerialization.DeserializeObjectFromFile <CameraConfigParam>(configFile);

                    //还原相机配置
                    try
                    {
                        CameraFactory.ConfigurateCamera(CameraSerial, cameraConfigParam);
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    cameraConfigParam = CameraFactory.GetCameraConfigration(CameraSerial);
                    JsonSerialization.SerializeObjectToFile(cameraConfigParam, configFile);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置相机标定文件
        /// </summary>
        /// <param name="file">配置文件(不需包含目录)</param>
        public void SetCameraCalibrationFile(string file)
        {
            CalibrationFile = file;

            if (!string.IsNullOrEmpty(file))
            {
                //获取相机配置参数
                string calibrationFile = $"{System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase}/VisionPlatform/Camera/CameraConfig/{CameraSerial}/CalibrationFile/{CalibrationFile}";

                if (File.Exists(calibrationFile))
                {
                    calibrationParam = JsonSerialization.DeserializeObjectFromFile <CalibParam>(calibrationFile);
                }
                else
                {
                    calibrationParam = new CalibParam();
                    JsonSerialization.SerializeObjectToFile(calibrationParam, calibrationFile);
                }
            }
            else
            {
                CalibrationFile  = null;
                calibrationParam = new CalibParam();
            }
        }
        /// <summary>
        /// 加载配置文件
        /// </summary>
        /// <param name="file">文件路径</param>
        public void LoadFromFile(string file)
        {
            try
            {
                if (string.IsNullOrEmpty(file))
                {
                    throw new ArgumentException("无效路径/文件不存在");
                }

                CalibrationParam calibrationParam = JsonSerialization.DeserializeObjectFromFile <CalibrationParam>(file);

                if (calibrationParam != null)
                {
                    CalibrationParam = calibrationParam;
                }
                else
                {
                    CalibrationParam = new CalibrationParam();
                }
            }
            catch (Exception ex)
            {
                OnMessageRaised(MessageLevel.Err, ex.Message, ex);
            }
            finally
            {
            }
        }
        /// <summary>
        /// 加载配置文件
        /// </summary>
        /// <param name="file">文件路径</param>
        public void LoadFromFile(string file)
        {
            try
            {
                if (string.IsNullOrEmpty(file))
                {
                    throw new ArgumentException("无效路径/文件不存在");
                }

                CameraConfigParam cameraConfigParam = JsonSerialization.DeserializeObjectFromFile <CameraConfigParam>(file);

                if (Camera?.IsOpen == true)
                {
                    CameraFactory.ConfigurateCamera(Camera.Info.SerialNumber, cameraConfigParam);
                }
            }
            catch (Exception ex)
            {
                OnMessageRaised(MessageLevel.Err, ex.Message, ex);
            }
            finally
            {
                if (CameraConfigViewModel?.Camera?.IsOpen == true)
                {
                    Camera.Grab();

                    //刷新控件显示
                    Camera = Camera;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 反序列化场景
        /// </summary>
        /// <param name="file">序列化文件(*.json)</param>
        /// <returns>场景实例</returns>
        public static Scene Deserialize(string file)
        {
            var scene = JsonSerialization.DeserializeObjectFromFile <Scene>(file);

            try
            {
                scene?.Init();
            }
            catch (ArgumentException)
            {
            }

            return(scene);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载标定文件
        /// </summary>
        /// <param name="file">标定文件路径</param>
        public void LoadCalibrationFile(string file)
        {
            try
            {
                if (string.IsNullOrEmpty(file) || (!File.Exists(file)))
                {
                    throw new ArgumentException("无效文件路径!");
                }

                BaseCalibreationViewModel.CalibParam = JsonSerialization.DeserializeObjectFromFile <CalibParam>(file);
            }
            catch (Exception ex)
            {
                OnMessageRaised(MessageLevel.Err, ex.Message, ex);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 加载参数
        /// </summary>
        /// <param name="file">文件路径</param>
        /// <returns>执行结果</returns>
        public bool LoadParams(string file)
        {
            bool result = true;

            if (File.Exists(file))
            {
                SystemParam = JsonSerialization.DeserializeObjectFromFile <SystemParam>(file);
            }

            if (SystemParam == null)
            {
                SystemParam = new SystemParam();
                result      = false;
            }

            //保存参数到默认配置文件
            JsonSerialization.SerializeObjectToFile(SystemParam, ParamPath);

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 加载用户名
        /// </summary>
        /// <returns></returns>
        public bool LoadUser()
        {
            var dataPath = System.Environment.GetEnvironmentVariable("appdata");
            var file     = $"{dataPath}/.aa";

            bool result = true;

            if (File.Exists(file))
            {
                User = JsonSerialization.DeserializeObjectFromFile <User>(file);
            }

            if (User == null)
            {
                User   = new User();
                result = false;
            }

            //保存参数到默认配置文件
            JsonSerialization.SerializeObjectToFile(User, file);

            return(result);
        }
        /// <summary>
        /// 加载文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadFileButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var ofd = new Microsoft.Win32.OpenFileDialog();

                ofd.DefaultExt = ".json";
                ofd.Filter     = "json file|*.json";

                if (ofd.ShowDialog() == true)
                {
                    _FilePath             = ofd.FileName;
                    CalibFileTextBox.Text = _FilePath;
                    _CalibParam           = JsonSerialization.DeserializeObjectFromFile <CalibParam>(_FilePath);

                    if (_CalibParam == null)
                    {
                        MessageBox.Show("无效文件!");
                        return;
                    }

                    _CalibPointList.Clear();

                    foreach (var item in _CalibParam.CalibPointList)
                    {
                        _CalibPointList.Add(item);
                    }

                    EnableAllControl();

                    DisplayCalibMatrix(_CalibParam.Matrix);
                }
            }
            catch (Exception)
            {
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            SystemParams = new SystemParams();

            if (File.Exists("SystemParams.json"))
            {
                var obj = JsonSerialization.DeserializeObjectFromFile <SystemParams>("SystemParams.json");

                if (obj != null)
                {
                    SystemParams = obj;
                }
            }
            else
            {
                JsonSerialization.SerializeObjectToFile(SystemParams, "SystemParams.json");
            }


            //创建日志接口
            Logging.Init(new Log4Net());
            Logging.LoadConfigFile("LogConfig.xml");

            //更新视觉框架集合
            VisionFrameFactory.UpdateAssembly();
            VisionFrameFactory.DefaultVisionFrameType = SystemParams.DefaultVisionFrameType;

            //更新相机框架集合
            CameraFactory.UpdateAssembly();
            CameraFactory.DefaultCameraSdkType = SystemParams.DefaultCameraSdkType;

            if ((VisionFrameFactory.DefaultVisionFrameType != EVisionFrameType.VisionProVpp) && (CameraFactory.DefaultCameraSdkType == ECameraSdkType.VirtualCamera))
            {
                try
                {
                    CameraFactory.AddCamera(@"C:\Users\Public\Documents\MVTec\HALCON-17.12-Progress\examples\images");
                    CameraFactory.AddCamera(@"D:\20190904CXC\图片");
                    //CameraFactory.AddCamera(@"E:\测试图像\刹车片");
                    //CameraFactory.AddCamera(@"E:\测试图像\AGV标定板");
                    //CameraFactory.AddCamera(@"E:\测试图像\眼镜");
                    //CameraFactory.AddCamera(@"E:\测试图像\定位圆");
                    //CameraFactory.AddCamera(@"E:\测试图像\眼镜腿");
                }
                catch (Exception ex)
                {
                    Logging.Error(ex);
                    MessageBox.Show(ex.Message);
                }
            }

            //获取场景管理器实例(单例)
            SceneManager = SceneManager.GetInstance();

            //恢复场景
            SceneManager.RecoverScenes();

            ScenesListView.Items.Clear();
            foreach (var item in SceneManager.Scenes.Values)
            {
                ScenesListView.Items.Add(item);
            }

            //更新相关控件
            UpdateRobotConnectionControl(IsRobotConnect);
        }
 /// <summary>
 /// 导入配置信息文件
 /// </summary>
 /// <param name="file"></param>
 public void ImportConfigFile(string file)
 {
     importIOData = JsonSerialization.DeserializeObjectFromFile <ImportIOData>(file);
 }