Ejemplo n.º 1
0
        public static void ApplyTypeSetting(int type)
        {
            int value = GameQualitySettingManager.GetSettingByType(type);

            var list = GetSubOptions(type);

            foreach (var item in list)
            {
                VideoSetting data = GameQualitySettingManager.VideoSettingDic[item];
                if (data.ValuePerLevel != null && data.ValuePerLevel.Count > 0)
                {
                    if (value > -1 && value < data.ValuePerLevel.Count)
                    {
                        int index = data.ValuePerLevel[value];
                        if (index > -1 && index < data.LevelDatas.Count)
                        {
                            float fdata = data.LevelDatas[index];
                            ApplyVideoEffect((EVideoSettingId)item, fdata);
                        }
                        else
                        {
                            Debug.Log("error videosetting id" + item + " value " + value + "index" + index);
                        }
                    }
                    else
                    {
                        Debug.Log("error videosetting id" + item + " value " + value);
                    }
                }
            }
        }
        private void InitCombox(VideoSetting config)
        {
            var comboxModel   = GetNewControlWithTitle(_comboxModel, config.Description);
            var uiCombox      = new UICombox(comboxModel);
            var cComboxDic    = new Dictionary <string, object>();
            int selectedIndex = -1;

            for (int i = 0; i < config.LevelDatas.Count; i++)
            {
                cComboxDic[config.LevelNames[i]] = config.Id + ":" + config.LevelDatas[i];
                float targetVal;
                if (_sendValList.TryGetValue(config.Id, out targetVal))
                {
                    if (Math.Abs(config.LevelDatas[i] - targetVal) < 0.0001f)
                    {
                        selectedIndex = i;
                    }
                }
            }
            uiCombox.RegisteComBox(cComboxDic);
            uiCombox.itemSelect = ComBoxItemClick;
            uiCombox.SetSelectByIndex(selectedIndex);
            //这里会报错,字典里已存在这个字段,看上去像是重复加载,为了进入游戏先临时修复 by wzq
            if (_uiControlDict.ContainsKey(config.Id))
            {
                Debug.LogError(config.Id + " is already in _uiControlDict");
                _uiControlDict[config.Id] = uiCombox;
            }
            else
            {
                _uiControlDict.Add(config.Id, uiCombox);
            }
        }
        private void InitProgressBar(VideoSetting config)
        {
            var   sliderModel = GetNewControlWithTitle(_sliderModel, config.Description);
            var   slider      = sliderModel.Find("Slider").GetComponent <Slider>();
            float defaultVal  = _sendValList[config.Id];

            sliderModel.Find("curText").GetComponent <Text>().text =
                defaultVal.ToString();
            slider.value = (defaultVal - config.MinValue) / (config.MaxValue - config.MinValue);
            slider.onValueChanged.AddListener((float val) =>
            {
                float curVal = config.MinValue + val * (config.MaxValue - config.MinValue);
                sliderModel.Find("curText").GetComponent <Text>().text =
                    curVal.ToString();
                _sendValList[config.Id] = curVal;
            });
            if (_uiControlDict.ContainsKey(config.Id))
            {
                Debug.LogError(config.Id + " is already in _uiControlDict");
                _uiControlDict[config.Id] = slider;
            }
            else
            {
                _uiControlDict.Add(config.Id, slider);
            }
        }
Ejemplo n.º 4
0
        public async Task Initialize(VideoSetting videoSetting)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAndAwaitAsync(CoreDispatcherPriority.Normal, async() =>
            {
                _threadsCount   = videoSetting.UsedThreads;
                _stoppedThreads = videoSetting.UsedThreads;

                _lastFrameAdded.Start();

                _imageQuality         = new BitmapPropertySet();
                var imageQualityValue = new BitmapTypedValue(videoSetting.VideoQuality, Windows.Foundation.PropertyType.Single);
                _imageQuality.Add("ImageQuality", imageQualityValue);

                _mediaCapture = new MediaCapture();

                var frameSourceGroups = await MediaFrameSourceGroup.FindAllAsync();

                var settings = new MediaCaptureInitializationSettings()
                {
                    SharingMode = MediaCaptureSharingMode.ExclusiveControl,

                    //With CPU the results contain always SoftwareBitmaps, otherwise with GPU
                    //they preferring D3DSurface
                    MemoryPreference = MediaCaptureMemoryPreference.Cpu,

                    //Capture only video, no audio
                    StreamingCaptureMode = StreamingCaptureMode.Video
                };

                await _mediaCapture.InitializeAsync(settings);

                var mediaFrameSource      = _mediaCapture.FrameSources.First().Value;
                var videoDeviceController = mediaFrameSource.Controller.VideoDeviceController;

                videoDeviceController.DesiredOptimization = Windows.Media.Devices.MediaCaptureOptimization.Quality;
                videoDeviceController.PrimaryUse          = Windows.Media.Devices.CaptureUse.Video;

                //Set exposure (auto light adjustment)
                if (_mediaCapture.VideoDeviceController.Exposure.Capabilities.Supported &&
                    _mediaCapture.VideoDeviceController.Exposure.Capabilities.AutoModeSupported)
                {
                    _mediaCapture.VideoDeviceController.Exposure.TrySetAuto(true);
                }

                var videoResolutionWidthHeight = VideoResolutionWidthHeight.Get(videoSetting.VideoResolution);
                var videoSubType = VideoSubtypeHelper.Get(videoSetting.VideoSubtype);

                //Set resolution, frame rate and video subtyp
                var videoFormat = mediaFrameSource.SupportedFormats.Where(sf => sf.VideoFormat.Width == videoResolutionWidthHeight.Width &&
                                                                          sf.VideoFormat.Height == videoResolutionWidthHeight.Height &&
                                                                          sf.Subtype == videoSubType)
                                  .OrderByDescending(m => m.FrameRate.Numerator / m.FrameRate.Denominator)
                                  .First();

                await mediaFrameSource.SetFormatAsync(videoFormat);

                _mediaFrameReader = await _mediaCapture.CreateFrameReaderAsync(mediaFrameSource);
                await _mediaFrameReader.StartAsync();
            });
        }
Ejemplo n.º 5
0
        private void InitCheckBox(VideoSetting config)
        {
            var toggleModel = GetNewControlWithTitle(_toggleModel, config.Description);
            var toggle      = toggleModel.GetComponent <Toggle>();

            toggle.isOn = (int)_sendValList[config.Id] != 0;
            toggle.onValueChanged.AddListener((bool isOn) => { _sendValList[config.Id] = isOn ? 1 : 0; });
            _uiControlDict.Add(config.Id, toggle);
        }
Ejemplo n.º 6
0
        private VideoSetting NewVideoSetting()
        {
            VideoSetting setting = new VideoSetting {
                ActivityGuid = CO_IA.Client.RiasPortal.ModuleContainer.Activity.Guid, Key = Utility.NewGuid()
            };

            setting.OwnerType = "Place";
            return(setting);
        }
Ejemplo n.º 7
0
        // GET: Setting
        public ActionResult Video()
        {
            var videoSetting = new VideoSetting
            {
                AdvertiserOrder = _settingRepository.GetValue("AdvertiserOrder"),
                SkipTime        = _settingRepository.GetValue("SkipTime"),
            };

            return(View(videoSetting));
        }
 public void EditVideoSetting(VideoSetting setting, ActivityPlace[] places)
 {
     this.editVideoSetting            = setting;
     this.comboBoxPlace.ItemsSource   = places;
     this.textBoxName.Text            = setting.Name;
     this.comboBoxPlace.SelectedValue = setting.OwnerGuid;
     this.textBoxIP.Text       = setting.IP;
     this.textBoxPort.Text     = setting.Port.ToString();
     this.textBoxUserName.Text = setting.UserName;
     this.passwordBox.Password = setting.Password;
 }
Ejemplo n.º 9
0
        private void btnPreviewStart_Click(object sender, EventArgs e)
        {
            vgPreview.Stop();

            VideoSetting setting = _settings[_camaraActual];

            SaveCamara(setting);

            txtLogPreview.Text = "";

            if (setting.Apply(vgPreview))
            {
                vgPreview.StartPreview();
            }
        }
        private void InitControl(VideoSetting config)
        {
            if (!_sendValList.ContainsKey(config.Id))
            {
                return;
            }
            switch ((EControlType)config.ControlType)
            {
            case EControlType.CheckBox: InitCheckBox(config); break;

            case EControlType.Combox: InitCombox(config); break;

            case EControlType.ProgressBar: InitProgressBar(config); break;
            }
        }
Ejemplo n.º 11
0
        public bool SetDefaultSettings(VideoSetting setting)
        {
            if (setting == null)
            {
                return(false);
            }
            List <VideoSetting> settings = GetAllVideoSettings();

            settings.ForEach(m => m.DefaultSetting = false);
            var defaultSetting = settings.Find(m => m.VideoSettingName == setting.VideoSettingName);

            defaultSetting.DefaultSetting = true;
            FlushDataToXmlFile(settings);
            return(true);
        }
Ejemplo n.º 12
0
        public HttpServer(Camera camera, VideoSetting videoSetting)
        {
            this._camera      = camera;
            this.videoSetting = videoSetting;
            this.isFeedActive = false;

            this._listener = new StreamSocketListener();
            this._listener.ConnectionReceived      += this.ProcessRequest;
            this._listener.Control.KeepAlive        = false;
            this._listener.Control.NoDelay          = false;
            this._listener.Control.QualityOfService = SocketQualityOfService.LowLatency;
            this._listener.BindServiceNameAsync(80.ToString()).GetAwaiter();
            this.openCvHelper = new OpenCVHelper();
            this.LoadModelAsync().GetAwaiter();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 保存视频参数配置方案
        /// </summary>
        /// <param name="setting"></param>
        public void SaveVideoSetting(VideoSetting setting, bool AsDefault = false)
        {
            List <VideoSetting> settings = GetAllVideoSettings();

            if (settings == null)
            {
                settings = new List <VideoSetting>();
            }

            settings.ForEach(m => m.DefaultSetting = false);
            setting.DefaultSetting = true;
            if (setting != null)
            {
                settings.Add(setting);
            }
            FlushDataToXmlFile(settings);
        }
        private void InitCheckBox(VideoSetting config)
        {
            var toggleModel = GetNewControlWithTitle(_toggleModel, config.Description);
            var toggle      = toggleModel.GetComponent <Toggle>();

            toggle.isOn = (int)_sendValList[config.Id] != 0;
            toggle.onValueChanged.AddListener((bool isOn) => { _sendValList[config.Id] = isOn ? 1 : 0; });
            if (_uiControlDict.ContainsKey(config.Id))
            {
                Debug.LogError(config.Id + " is already in _uiControlDict");
                _uiControlDict[config.Id] = toggle;
            }
            else
            {
                _uiControlDict.Add(config.Id, toggle);
            }
        }
        /// <summary>
        /// 保存设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            FrmVideoSetting settingView = new FrmVideoSetting();

            if (settingView.ShowDialog() == DialogResult.OK)
            {
                VideoSetting setting = new VideoSetting()
                {
                    Saturation       = tbarSaturation.Value,
                    ContrastRatio    = tbarContrast.Value,
                    Brightness       = tbarLight.Value,
                    DefaultSetting   = settingView.CbDefaultSetting,
                    VideoSettingName = settingView.SettingName
                };
                VideoSettingUtils.Instance.SaveVideoSetting(setting);
                ReadSetting();
            }
        }
Ejemplo n.º 16
0
        public ActionResult Video(VideoSetting videoSetting)
        {
            var adOrderSetting = new Setting()
            {
                Name  = "AdvertiseOrder",
                Value = videoSetting.AdvertiserOrder
            };

            _settingRepository.InsertOrUpdate(adOrderSetting);

            var skipTimeSetting = new Setting()
            {
                Name  = "SkipTime",
                Value = videoSetting.SkipTime
            };

            _settingRepository.InsertOrUpdate(skipTimeSetting);

            _settingRepository.Save();

            return(View(videoSetting));
        }
Ejemplo n.º 17
0
        public override void SaveConfig(Config config)
        {
            VideoSetting setting = _settings[_camaraActual];

            SaveCamara(setting);

            config.VideoSourceCount = 1;

            if (rdLayout2.Checked)
            {
                config.VideoSourceCount = 2;
            }
            if (rdLayout4.Checked)
            {
                config.VideoSourceCount = 4;
            }
            if (rdLayout6.Checked)
            {
                config.VideoSourceCount = 6;
            }

            config.VideoSettings = _settings;
        }
Ejemplo n.º 18
0
        private void InitCombox(VideoSetting config)
        {
            var comboxModel   = GetNewControlWithTitle(_comboxModel, config.Description);
            var uiCombox      = new UICombox(comboxModel);
            var cComboxDic    = new Dictionary <string, object>();
            int selectedIndex = -1;

            for (int i = 0; i < config.LevelDatas.Count; i++)
            {
                cComboxDic.Add(config.LevelNames[i], config.Id + ":" + config.LevelDatas[i]);
                float targetVal;
                if (_sendValList.TryGetValue(config.Id, out targetVal))
                {
                    if (Math.Abs(config.LevelDatas[i] - targetVal) < 0.0001f)
                    {
                        selectedIndex = i;
                    }
                }
            }
            uiCombox.RegisteComBox(cComboxDic);
            uiCombox.itemSelect = ComBoxItemClick;
            uiCombox.SetSelectByIndex(selectedIndex);
            _uiControlDict.Add(config.Id, uiCombox);
        }
Ejemplo n.º 19
0
        private void SaveCamara(VideoSetting setting)
        {
            setting.Clean();

            setting.IsEnabled = chkHabilitada.Checked;

            if (chkHabilitada.Checked)
            {
                if (this.VideoSource == VidGrab.TVideoSource.vs_IPCamera)
                {
                    setting.VideoSource = VideoSources.IpCamera;
                }
                else
                {
                    setting.VideoSource = VideoSources.VideoCapture;
                }

                if (VideoSource == VidGrab.TVideoSource.vs_IPCamera)
                {
                    setting.Host = txtIpHost.Text;

                    int port = 0;
                    setting.Port = 0;

                    if (int.TryParse(txtIpPort.Text, out port))
                    {
                        setting.Port = port;
                    }

                    ComboBoxItem item = cboPresetPosition.SelectedItem as ComboBoxItem;

                    if (item != null)
                    {
                        setting.PresetStartupPosition = item.Value;
                    }
                    else
                    {
                        setting.PresetStartupPosition = "";
                    }

                    item = cboPerfiles.SelectedItem as ComboBoxItem;

                    if (item != null)
                    {
                        setting.Profile = item.Value;
                    }
                    else
                    {
                        setting.Profile = "";
                    }

                    setting.Username  = txtIpUsuario.Text;
                    setting.Password  = txtIpPassword.Text;
                    setting.StreamUrl = txtUrl.Text;
                }
                else
                {
                    if (cbVideoDevice.SelectedItem != null)
                    {
                        setting.VideoDevice = cbVideoDevice.SelectedItem.ToString();
                    }

                    if (cbVideoSize.SelectedItem != null)
                    {
                        setting.VideoSize = cbVideoSize.SelectedItem.ToString();
                    }

                    if (cbVideoSubtype.SelectedItem != null)
                    {
                        setting.VideoFormatSubType = cbVideoSubtype.SelectedItem.ToString();
                    }

                    if (cbNorma.SelectedItem != null)
                    {
                        setting.VideoNorma = cbNorma.SelectedItem.ToString();
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public async Task Initialize(VideoSetting videoSetting)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAndAwaitAsync(CoreDispatcherPriority.Normal, async() =>
            {
                _threadsCount   = videoSetting.UsedThreads;
                _stoppedThreads = videoSetting.UsedThreads;

                _lastFrameAdded.Start();

                _imageQuality         = new BitmapPropertySet();
                var imageQualityValue = new BitmapTypedValue(videoSetting.VideoQuality, Windows.Foundation.PropertyType.Single);
                _imageQuality.Add("ImageQuality", imageQualityValue);

                _mediaCapture = new MediaCapture();

                var frameSourceGroups = await MediaFrameSourceGroup.FindAllAsync();
                var sourceGroups      = frameSourceGroups.Select(g => new
                {
                    Group      = g,
                    SourceInfo = g.SourceInfos.FirstOrDefault(i => i.SourceKind == MediaFrameSourceKind.Color)
                }).Where(g => g.SourceInfo != null).ToList();

                var settings = new MediaCaptureInitializationSettings()
                {
                    SourceGroup = sourceGroups?.FirstOrDefault()?.Group,

                    SharingMode = MediaCaptureSharingMode.ExclusiveControl,

                    //With CPU the results contain always SoftwareBitmaps, otherwise with GPU
                    //they preferring D3DSurface
                    MemoryPreference = MediaCaptureMemoryPreference.Cpu,

                    //Capture only video, no audio
                    StreamingCaptureMode = StreamingCaptureMode.Video
                };

                await _mediaCapture.InitializeAsync(settings);

                var mediaFrameSource = this._mediaCapture.FrameSources[sourceGroups?.FirstOrDefault()?.SourceInfo.Id];

                /*
                 * // Commented to reduce CPU usage.
                 * var videoDeviceController = mediaFrameSource.Controller.VideoDeviceController;
                 *
                 * videoDeviceController.DesiredOptimization = Windows.Media.Devices.MediaCaptureOptimization.Quality;
                 * videoDeviceController.PrimaryUse = Windows.Media.Devices.CaptureUse.Video;
                 *
                 * //Set exposure (auto light adjustment)
                 * if (_mediaCapture.VideoDeviceController.Exposure.Capabilities.Supported
                 *  && _mediaCapture.VideoDeviceController.Exposure.Capabilities.AutoModeSupported)
                 * {
                 *  _mediaCapture.VideoDeviceController.Exposure.TrySetAuto(true);
                 * }
                 *
                 * var videoResolutionWidthHeight = VideoResolutionWidthHeight.Get(videoSetting.VideoResolution);
                 * var videoSubType = VideoSubtypeHelper.Get(videoSetting.VideoSubtype);
                 *
                 * //Set resolution, frame rate and video subtyp
                 * var videoFormat = mediaFrameSource.SupportedFormats.Where(sf => sf.VideoFormat.Width == videoResolutionWidthHeight.Width
                 *                                                              && sf.VideoFormat.Height == videoResolutionWidthHeight.Height
                 *                                                              && sf.Subtype == videoSubType)
                 *                                                  .OrderByDescending(m => m.FrameRate.Numerator / m.FrameRate.Denominator)
                 *                                                  .First();
                 *
                 * await mediaFrameSource.SetFormatAsync(videoFormat);
                 */

                _mediaFrameReader = await _mediaCapture.CreateFrameReaderAsync(mediaFrameSource);
                await _mediaFrameReader.StartAsync();
            });
        }
Ejemplo n.º 21
0
        private async Task WriteResponse(HttpServerRequest request, StreamSocket socket)
        {
            var relativeUrlLower = request.Url.ToLowerInvariant();
            var outputStream     = socket.OutputStream;

            //Get javascript files
            if (relativeUrlLower.StartsWith("/javascript"))
            {
                await HttpServerResponse.WriteResponseFile(ToFolderPath(request.Url), HttpContentType.JavaScript, outputStream);
            }
            //Get css style files
            else if (relativeUrlLower.StartsWith("/styles"))
            {
                await HttpServerResponse.WriteResponseFile(ToFolderPath(request.Url), HttpContentType.Css, outputStream);
            }
            //Get video setting
            else if (relativeUrlLower.StartsWith("/videosetting"))
            {
                HttpServerResponse.WriteResponseJson(ConfigurationFile.VideoSetting.Stringify(), outputStream);
            }
            //Get supported video settings
            else if (relativeUrlLower.StartsWith("/supportedvideosettings"))
            {
                HttpServerResponse.WriteResponseJson(ConfigurationFile.VideoSettingsSupported.Stringify(), outputStream);
            }
            //Set video settings
            else if (relativeUrlLower.StartsWith("/savevideosetting"))
            {
                await _camera.Stop();

                var videoSetting = new VideoSetting
                {
                    VideoSubtype    = VideoSubtypeHelper.Get(request.Body["VideoSubtype"].GetString()),
                    VideoResolution = (VideoResolution)request.Body["VideoResolution"].GetNumber(),
                    VideoQuality    = request.Body["VideoQuality"].GetNumber(),
                    UsedThreads     = (int)request.Body["UsedThreads"].GetNumber()
                };

                await ConfigurationFile.Write(videoSetting);

                await _camera.Initialize(videoSetting);

                _camera.Start();

                HttpServerResponse.WriteResponseOk(outputStream);
            }
            //Get current camera frame
            else if (relativeUrlLower.StartsWith("/videoframe"))
            {
                if (_camera.Frame != null)
                {
                    var webSocket = new WebSocket(socket, request, _camera);
                    await webSocket.Start();
                }
                else
                {
                    HttpServerResponse.WriteResponseError("Not camera fram available. Maybe there is an error or camera is not started.", outputStream);
                }
            }
            //Get index.html page
            else
            {
                await HttpServerResponse.WriteResponseFile(@"\Html\Index.html", HttpContentType.Html, outputStream);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 设置摄像头为此配置
        /// </summary>
        /// <param name="setting">摄像头的配置</param>
        /// <param name="asDefault">是否并设为默认</param>
        /// <returns></returns>
        public int SetSettingValue(VideoSetting setting, bool asDefault = false)
        {
            if (asDefault)
            {
                VideoSettingUtils.Instance.SetDefaultSettings(setting);
            }

            int             iResult      = 0;
            IAMVideoProcAmp videoProcAmp = theDevice as IAMVideoProcAmp;

            if (videoProcAmp == null)
            {
                iResult = -1;
                return(iResult);
            }
            int val;
            int min;
            int max;
            int step;
            int defaultValue;
            VideoProcAmpFlags flags = VideoProcAmpFlags.Manual;

            // 设置亮度
            if (setting.Brightness != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Brightness, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Brightness, out val, out flags);
                    //val = min + (max - min) * setting.Brightness / 255;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Brightness, setting.Brightness, flags);
                }
            }
            //设置对比度
            if (setting.ContrastRatio != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Contrast, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Contrast, out val, out flags);
                    //val = min + (max - min) * setting.ContrastRatio / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Contrast, setting.ContrastRatio, flags);
                }
            }//设置饱和度
            if (setting.Saturation != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Saturation, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Saturation, setting.Saturation, flags);
                }
            }
            //设置色调
            if (setting.Hue != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Hue, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Hue, setting.Hue, flags);
                }
            }
            //设置清晰度
            if (setting.Sharpness != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Sharpness, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Sharpness, setting.Sharpness, flags);
                }
            }
            //设置伽玛
            if (setting.Gamma != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Gamma, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Gamma, setting.Gamma, flags);
                }
            }
            //设置启用颜色
            if (setting.Gamma != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.ColorEnable, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.ColorEnable, Convert.ToInt32(setting.ColorEnable), flags);
                }
            }
            //白平衡
            if (setting.WhiteBalance != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.WhiteBalance, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.WhiteBalance, setting.WhiteBalance, flags);
                }
            }
            //背光补偿
            if (setting.WhiteBalance != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.BacklightCompensation, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.BacklightCompensation, setting.BacklightCompensation, flags);
                }
            }
            //增益
            if (setting.Gain != -1)
            {
                int hr = videoProcAmp.GetRange(VideoProcAmpProperty.Gain, out min, out max, out step, out defaultValue, out flags);
                if (0 == hr)
                {
                    //videoProcAmp.Get(VideoProcAmpProperty.Saturation, out val, out flags);
                    //val = min + (max - min) * setting.Saturation / 100;
                    iResult = videoProcAmp.Set(VideoProcAmpProperty.Gain, setting.Gain, flags);
                }
            }
            return(iResult);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 保存当前的相机设置
        /// </summary>
        public void SaveCurrentOriginSetting(string VideoSettingName, bool AsDefault)
        {
            IAMVideoProcAmp   videoProcAmp = theDevice as IAMVideoProcAmp;
            VideoProcAmpFlags flags        = VideoProcAmpFlags.Manual;
            //亮度值 0到255
            int LightValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Brightness, out LightValue, out flags);
            //对比度 0到255
            int ContrastValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Contrast, out ContrastValue, out flags);
            //饱和度 0到255
            int SaturationValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Saturation, out SaturationValue, out flags);
            //色调 -127 到127
            int HueValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Hue, out HueValue, out flags);
            //清晰度 0到15
            int SharpnessValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Sharpness, out SharpnessValue, out flags);
            //伽玛 1到8
            int GammaValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Gamma, out GammaValue, out flags);
            //启用颜色 不支持
            int ColorEnable = 0;

            videoProcAmp.Get(VideoProcAmpProperty.ColorEnable, out ColorEnable, out flags);
            //白平衡 不支持
            int WhiteBalanceValue = 0;

            videoProcAmp.Get(VideoProcAmpProperty.WhiteBalance, out WhiteBalanceValue, out flags);
            //背光补偿 1 到 5
            int BacklightCompensation = 0;

            videoProcAmp.Get(VideoProcAmpProperty.BacklightCompensation, out BacklightCompensation, out flags);
            //增益 不支持
            int Gain = 0;

            videoProcAmp.Get(VideoProcAmpProperty.Gain, out Gain, out flags);

            VideoSetting setting = new VideoSetting();

            setting.Brightness       = LightValue;
            setting.VideoSettingName = VideoSettingName;
            setting.ContrastRatio    = ContrastValue;
            setting.Saturation       = SaturationValue;
            setting.Hue                   = HueValue;
            setting.Sharpness             = SharpnessValue;
            setting.Gamma                 = GammaValue;
            setting.ColorEnable           = Convert.ToBoolean(ColorEnable);
            setting.WhiteBalance          = WhiteBalanceValue;
            setting.BacklightCompensation = BacklightCompensation;
            setting.Gain                  = Gain;
            setting.DefaultSetting        = AsDefault;
            VideoSettingUtils.Instance.SaveVideoSetting(setting, AsDefault);
        }
Ejemplo n.º 24
0
        public List <VideoSetting> GetAllVideoSettings()
        {
            List <VideoSetting> result = new List <VideoSetting>();

            #region 读取文件
            if (!File.Exists(_VideoSettingRealPath))
            {
                return(null);
            }

            XmlTextReader reader  = new XmlTextReader(_VideoSettingRealPath);
            VideoSetting  setting = null;
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == nameof(VideoSetting))
                    {
                        setting = new VideoSetting();
                        result.Add(setting);
                    }
                    if (reader.Name == nameof(setting.VideoSettingName))
                    {
                        setting.VideoSettingName = reader.ReadElementContentAsString();
                    }
                    else if (reader.Name == nameof(setting.Brightness))
                    {
                        if (setting != null)
                        {
                            setting.Brightness = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoBrightness))
                    {
                        if (setting != null)
                        {
                            setting.AutoBrightness = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.ContrastRatio))
                    {
                        if (setting != null)
                        {
                            setting.ContrastRatio = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoContrastRatio))
                    {
                        if (setting != null)
                        {
                            setting.AutoContrastRatio = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Saturation))
                    {
                        if (setting != null)
                        {
                            setting.Saturation = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoSaturation))
                    {
                        if (setting != null)
                        {
                            setting.AutoSaturation = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.DefaultSetting))
                    {
                        if (setting != null)
                        {
                            setting.DefaultSetting = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Hue))
                    {
                        if (setting != null)
                        {
                            setting.Hue = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoHue))
                    {
                        if (setting != null)
                        {
                            setting.AutoHue = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Sharpness))
                    {
                        if (setting != null)
                        {
                            setting.Sharpness = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoSharpness))
                    {
                        if (setting != null)
                        {
                            setting.AutoSharpness = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Gamma))
                    {
                        if (setting != null)
                        {
                            setting.Gamma = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoGamma))
                    {
                        if (setting != null)
                        {
                            setting.AutoGamma = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.ColorEnable))
                    {
                        if (setting != null)
                        {
                            setting.ColorEnable = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.WhiteBalance))
                    {
                        if (setting != null)
                        {
                            setting.WhiteBalance = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoWhiteBalance))
                    {
                        if (setting != null)
                        {
                            setting.AutoWhiteBalance = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.BacklightCompensation))
                    {
                        if (setting != null)
                        {
                            setting.BacklightCompensation = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoBacklightCompensation))
                    {
                        if (setting != null)
                        {
                            setting.AutoBacklightCompensation = reader.ReadElementContentAsBoolean();
                        }
                    }
                    else if (reader.Name == nameof(setting.Gain))
                    {
                        if (setting != null)
                        {
                            setting.Gain = reader.ReadElementContentAsInt();
                        }
                    }
                    else if (reader.Name == nameof(setting.AutoGain))
                    {
                        if (setting != null)
                        {
                            setting.AutoGain = reader.ReadElementContentAsBoolean();
                        }
                    }
                }
            }
            //关闭流
            reader.Close();
            reader = null;
            GC.Collect();
            #endregion
            return(result);
        }