Esempio n. 1
0
        /// <summary>
        /// 设置视觉算子文件
        /// </summary>
        /// <param name="file">视觉算子文件</param>
        public void SetVisionOperaFile(string file)
        {
            if (VisionFrame == null)
            {
                throw new ArgumentException("VisionFrame cannot be null");
            }

            //还原视觉算子
            if (string.IsNullOrEmpty(file) || !File.Exists(file))
            {
                throw new FileNotFoundException("visionOperaFile invalid");
            }

            //确认文件是否本地路径,如果不是,则复制到本地路径下
            string dstDirectory = $"VisionPlatform/Scene/{EVisionFrameType}/{Name}/VisionOperation";
            string dstFile      = $"{dstDirectory}/{Path.GetFileName(file)}";

            if (!Directory.Exists(dstDirectory))
            {
                Directory.CreateDirectory(dstDirectory);
            }

            if (Path.GetFullPath(dstFile) != file)
            {
                try
                {
                    //如果是dll,则将同级目录下所有的dll都拷贝过来
                    if (Path.GetExtension(file) == ".dll")
                    {
                        FileInfo[] fileList = new DirectoryInfo(Path.GetDirectoryName(file))?.GetFiles("*.dll", SearchOption.TopDirectoryOnly);

                        foreach (var item in fileList)
                        {
                            File.Copy(item.FullName, $"{dstDirectory}/{Path.GetFileName(item.Name)}", true);
                        }
                    }
                    else
                    {
                        File.Copy(file, dstFile, true);
                    }
                }
                catch (IOException)
                {
                    //如果是同一个文件,则会报IO异常,过滤掉此异常
                }
            }

            VisionOperaFile = Path.GetFileName(dstFile);
            VisionFrame.Init(dstFile);

            //创建默认输入输出参数文件
            RecoverInputFile(true);
            RecoverOutputFile(true);
        }
Esempio n. 2
0
        public void Init()
        {
            try
            {
                //还原视觉框架
                if (EVisionFrameType == EVisionFrameType.Unknown)
                {
                    throw new ArgumentException("VisionFrameName invalid");
                }

                if (VisionFrame == null)
                {
                    VisionFrame = VisionFrameFactory.CreateInstance(EVisionFrameType);
                }

                //还原视觉算子
                if (string.IsNullOrEmpty(VisionOperaFile))
                {
                    throw new ArgumentException("VisionOperaFile cannot be null");
                }

                string visionOperaFilePath = $"{System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase}/VisionPlatform/Scene/{EVisionFrameType}/{Name}/VisionOperation/{VisionOperaFile}";
                VisionFrame.Init(visionOperaFilePath);

                //还原输入参数
                RecoverInputFile();

                //还原输出参数
                RecoverOutputFile();

                //还原相机
                if (VisionFrame.IsEnableCamera)
                {
                    if (!string.IsNullOrEmpty(CameraSerial))
                    {
                        //若相机无效,则不报异常
                        try
                        {
                            SetCamera(CameraSerial);
                        }
                        catch (InvalidOperationException)
                        {
                            //若打开相机失败,不抛异常
                        }

                        ////配置相机参数
                        //if (CameraFactory.DefaultCameraSdkType != ECameraSdkType.VirtualCamera)
                        //{
                        //    SetCameraConfigFile(CameraConfigFile);
                        //}

                        ////配置标定信息
                        //SetCameraCalibrationFile(CalibrationFile);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }