public override void ForgetCamera(CameraSummary summary) { if (cache.ContainsKey(summary.Identifier)) { cache.Remove(summary.Identifier); } ProfileHelper.Delete(summary.Identifier); }
private void Open() { // Unlike in the DirectShow module, we do not backup and restore camera configuration. // If the user configured the camera outside of Kinovea we respect the new settings. // Two reasons: // 1. In DirectShow we must do the backup/restore to work around drivers that inadvertently reset the camera properties. // 2. Industrial cameras have many properties that won't be configurable in Kinovea // so the user is more likely to configure the camera from the outside. if (grabbing) { Stop(); } try { uEye.Defines.Status status = camera.Init((Int32)deviceId | (Int32)uEye.Defines.DeviceEnumeration.UseDeviceID); if (status != uEye.Defines.Status.SUCCESS) { log.ErrorFormat("Error trying to open IDS uEye camera."); return; } // Load parameter set. ProfileHelper.Load(camera, summary.Identifier); } catch (Exception e) { log.Error("Could not open IDS uEye camera.", e); return; } SpecificInfo specific = summary.Specific as SpecificInfo; if (specific == null) { return; } // Store the camera object into the specific info so that we can retrieve device informations from the configuration dialog. specific.Camera = camera; int currentColorMode = IDSHelper.ReadCurrentStreamFormat(camera); // Some properties can only be changed when the camera is opened but not streaming. Now is the time. // We store them in the summary when coming back from FormConfiguration, and we write them to the camera here. // Only do this if it's not the first time we open the camera, to respect any change that could have been done outside Kinovea. if (firstOpen) { specific.StreamFormat = currentColorMode; } else { if (specific.StreamFormat != currentColorMode) { IDSHelper.WriteStreamFormat(camera, specific.StreamFormat); } CameraPropertyManager.WriteCriticalProperties(camera, specific.CameraProperties); // Save parameter set. ProfileHelper.Save(camera, ProfileHelper.GetProfileFilename(summary.Identifier)); } // Reallocate IDS internal buffers after changing the format. Int32[] memList; camera.Memory.GetList(out memList); camera.Memory.Free(memList); camera.Memory.Allocate(); int memId; camera.Memory.GetActive(out memId); int width, height, bitsPerPixel, pitch; camera.Memory.Inquire(memId, out width, out height, out bitsPerPixel, out pitch); log.DebugFormat("IDS internal buffers allocated: {0}x{1}, {2} bits per pixel, pitch:{3}.", width, height, bitsPerPixel, pitch); }
private void BtnImport_Click(object sender, EventArgs e) { // Locate an .ini file. OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = CameraLang.FormConfiguration_ImportParameters; //openFileDialog.InitialDirectory = Path.GetDirectoryName(ProfileHelper.GetProfileFilename(summary.Identifier)); openFileDialog.RestoreDirectory = true; openFileDialog.Filter = "Ini file (*.ini)" + "|*.ini;"; openFileDialog.FilterIndex = 0; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } string filename = openFileDialog.FileName; if (string.IsNullOrEmpty(filename) || !File.Exists(filename)) { return; } // The timing here is finnicky. // connect() will start the delay buffer allocation on the current image size and start receiving frames. // disconnect prevents reading the new values from the camera. // Load with new sizes while the camera is streaming will fail because the buffers are wrong. // So we need to load the new values with the camera opened but not streaming. this.SuspendLayout(); disconnect(); ProfileHelper.Replace(summary.Identifier, filename); // Reopen the camera but do not start grabbing. uEye.Defines.Status status = camera.Init((Int32)deviceId | (Int32)uEye.Defines.DeviceEnumeration.UseDeviceID); if (status != uEye.Defines.Status.SUCCESS) { log.ErrorFormat("Error trying to open IDS uEye camera."); return; } // Load new parameters. ProfileHelper.Load(camera, summary.Identifier); cameraProperties = CameraPropertyManager.Read(camera, deviceId); SpecificInfo info = summary.Specific as SpecificInfo; PopulateStreamFormat(); info.StreamFormat = this.SelectedStreamFormat.Value; info.CameraProperties = cameraProperties; summary.UpdateDisplayRectangle(Rectangle.Empty); CameraTypeManager.UpdatedCameraSummary(summary); // Reconnect. camera.Exit(); connect(); // Reload UI. RemoveCameraControls(); PopulateCameraControls(); this.ResumeLayout(); }