public void TakeAPicture(ICameraInfo cameraInfo, IShootParameters shootingParameters, IImageHandler imageHandler) { _dispatcher.BeginInvoke((Action)(() => { GetCameraProcessor(cameraInfo).TakeAPicture(shootingParameters, imageHandler); })); }
public static void Orbit(ICameraInfo cameraInfoStart, Vector3D mouseOffsetView, Point3D orbitOrigin, out Point3D cameraPosition, out Point3D cameraTarget) { var eye = cameraInfoStart.Position; var target = cameraInfoStart.Target; var zAxis = cameraInfoStart.UpVector; var yzPlane = new Plane(new Point3D(), cameraInfoStart.GetEyeDirection().ToPoint3D(), zAxis.ToPoint3D()); var xAxis = yzPlane.Normal; var xzPlane = new Plane(new Point3D(), zAxis.ToPoint3D(), xAxis.ToPoint3D()); var yAxis = xzPlane.Normal; var matrixWorldToLocal = Matrix4DEx.CoordinateSystem(new Point3D(), xAxis, yAxis, zAxis); orbitOrigin = matrixWorldToLocal.Transform(orbitOrigin); eye = matrixWorldToLocal.Transform(eye); target = matrixWorldToLocal.Transform(target); GetSphereAngles(mouseOffsetView, (target - eye).Normalize(), out var thetaDelta, out var phiDelta); var matrixRotationHorizontal = Matrix4DEx.Rotate(UnitVector3D.ZAxis, thetaDelta.Radians).TransformAround(orbitOrigin); eye = matrixRotationHorizontal.Transform(eye); target = matrixRotationHorizontal.Transform(target); var phiPlane = new Plane(eye, target, target + UnitVector3D.ZAxis); var matrixRotationVertical = Matrix4DEx.Rotate(phiPlane.Normal, phiDelta.Radians).TransformAround(orbitOrigin); eye = matrixRotationVertical.Transform(eye); target = matrixRotationVertical.Transform(target); var matrixLocalToWorld = matrixWorldToLocal.Inverse(); cameraPosition = matrixLocalToWorld.Transform(eye); cameraTarget = matrixLocalToWorld.Transform(target); }
//set the camera readout speed public static bool SetReadoutSpeed(this Int16 cameraHandle, ICameraInfo cameraInfo) { //select the port and speed index according to the speed table index selected by the user var options = cameraInfo.CameraSettings.ReadOutOptions as CameraOptionParameter; var index = (int)cameraInfo.CameraSettings.ReadOutOptions.Value; if (!(cameraInfo.CameraParas.SpeedTable is SpeedTable speedTable)) { return(false); } var option = speedTable.ReadoutOptions.FirstOrDefault(x => x.ToString() == options.Options[index]); Int32 port = option.Port; Int16 speedIndex = option.Speed; var unmngValue = Marshal.AllocHGlobal(sizeof(Int32)); Marshal.WriteInt32(unmngValue, port); Pvcam.pl_set_param(cameraHandle, PvTypes.PARAM_READOUT_PORT, unmngValue); Marshal.FreeHGlobal(unmngValue); unmngValue = IntPtr.Zero; unmngValue = Marshal.AllocHGlobal(sizeof(Int16)); Marshal.WriteInt32(unmngValue, speedIndex); Pvcam.pl_set_param(cameraHandle, PvTypes.PARAM_SPDTAB_INDEX, unmngValue); Marshal.FreeHGlobal(unmngValue); unmngValue = IntPtr.Zero; return(true); }
public void StartListenTakeImage(ICameraInfo cameraInfo, IImageHandler imageHandler) { ICamera camera = GetCameraProcessor(cameraInfo).Camera; camera.SaveToValue = (uint)SaveToEnum.Save_by_downloading_to_a_host_computer; camera.SetDownloadImageHandler(imageHandler); }
public void StopListenTakeImage(ICameraInfo cameraInfo) { ICamera camera = GetCameraProcessor(cameraInfo).Camera; camera.SaveToValue = (uint)SaveToEnum.Save_on_a_memory_card_of_a_remote_camera; camera.SetDownloadImageHandler(null); }
//构造时初始化相机和端口 public CameraStrategy(ICameraInfo cameraInfo, ParameterPackage parameters) : base(cameraInfo, parameters) { this.cameraInfo = cameraInfo; this.parameters = parameters; //getCameraInfo.TryGetConnect(DeviceType.GigE, out DeviceNum, out AllCameraInfo, out ErrorMessage); Icamera = ICamera.getInstance(cameraInfo); }
/// <inheritdoc /> public CameraInfoCache(ICameraInfo cameraInfo) { // raw // world space -> camera space MatrixView = Matrix4DEx.LookAtRH(cameraInfo.Position.ToVector3D(), cameraInfo.Target.ToVector3D(), cameraInfo.UpVector); MatrixViewInverse = MatrixView.Inverse(); // camera space -> clip space MatrixProjection = cameraInfo.Projection.GetMatrixProjection(); MatrixProjectionInverse = MatrixProjection.Inverse(); // clip space -> screen space MatrixViewport = Matrix4DEx.Viewport(cameraInfo.Viewport); MatrixViewportInverse = MatrixViewport.Inverse(); // multiplicatives // world space -> camera space -> clip space MatrixViewProjection = MatrixView * MatrixProjection; MatrixViewProjectionInverse = MatrixViewProjection.Inverse(); // world space -> camera space -> clip space -> screen space MatrixViewProjectionViewport = MatrixViewProjection * MatrixViewport; MatrixViewProjectionViewportInverse = MatrixViewProjectionViewport.Inverse(); }
public void MoveFocus(ICameraInfo cameraInfo, uint value, Action afterMove) { _dispatcher.BeginInvoke((Action)(() => { GetCameraProcessor(cameraInfo).Camera.MoveFocus(value); afterMove(); })); }
public void SetUp() { _mockery = new Mockery(); _camera = (ICamera)_mockery.NewMock(typeof(ICamera)); _cameraInfo = (ICameraInfo)_mockery.NewMock(typeof(ICameraInfo)); _imageFile = new ImageFile(); }
private void LiveViewCameraChanged(ICameraInfo cameraInfo) { if (IsInLiveView) { SelectedCamera = cameraInfo; StartLiveView(); } }
private void DoMoveFocus(uint howMuch) { foreach (Object o in listBox1.ItemsSource) { ICameraInfo cameraInfo = (ICameraInfo)o; _cameraPool.MoveFocus(cameraInfo, howMuch, ResumeLiveViewAfter(listBox1.Items.Count)); } }
private void FindAndOpenCamera() { bool cameraPermissions = CheckCameraPermissions(); if (!cameraPermissions) { return; } string errorMessage = "Unknown error"; bool foundCamera = false; IListenableFuture cameraProviderFuture = ProcessCameraProvider.GetInstance(this); cameraProviderFuture.AddListener(new Runnable(() => { // Camera provider is now guaranteed to be available mCameraProvider = cameraProviderFuture.Get() as ProcessCameraProvider; try { // Find first back-facing camera that has necessary capability. CameraSelector cameraSelector = new CameraSelector.Builder().RequireLensFacing((int)mLensFacing).Build(); // Find a good size for output - largest 4:3 aspect ratio that's less than 720p Preview.Builder previewBuilder = new Preview.Builder() .SetTargetAspectRatio(AspectRatio.Ratio43); Camera2Interop.Extender previewExtender = new Camera2Interop.Extender(previewBuilder); previewExtender.SetSessionCaptureCallback(mCaptureCallback); Preview preview = previewBuilder.Build(); // Must unbind the use-cases before rebinding them mCameraProvider.UnbindAll(); ICamera camera = mCameraProvider.BindToLifecycle( this as ILifecycleOwner, cameraSelector, preview); if (camera != null) { // Found suitable camera - get info, open, and set up outputs mCameraInfo = camera.CameraInfo; mCameraControl = camera.CameraControl; preview.SetSurfaceProvider(this); foundCamera = true; } if (!foundCamera) { errorMessage = GetString(Resource.String.camera_no_good); } SwitchRenderMode(0); } catch (CameraAccessException e) { errorMessage = GetErrorString(e); } if (!foundCamera) { ShowErrorDialog(errorMessage); } }), ContextCompat.GetMainExecutor(this)); }
public LiveViewThread(ICameraPool cameraPool, Action <MemoryStream, uint> onImageRecieved) { _cameraPool = cameraPool; _onImageRecieved = onImageRecieved; _cameraInfo = null; _isRunning = false; _thread = null; _syncObject = new object(); }
/// <summary> /// Get transformation matrix from one space to another. /// </summary> public static Matrix <double> GetTransformationMatrix(this ICameraInfo cameraInfo, Space from, Space to) { switch (from) { case Space.World: switch (to) { case Space.World: return(MatrixEx.Identity); case Space.View: return(cameraInfo.Cache.MatrixViewProjection); case Space.Screen: return(cameraInfo.Cache.MatrixViewProjectionViewport); default: throw new ArgumentOutOfRangeException(nameof(to), to, null); } case Space.View: switch (to) { case Space.World: return(cameraInfo.Cache.MatrixViewProjectionInverse); case Space.View: return(MatrixEx.Identity); case Space.Screen: return(cameraInfo.Cache.MatrixViewport); default: throw new ArgumentOutOfRangeException(nameof(to), to, null); } case Space.Screen: switch (to) { case Space.World: return(cameraInfo.Cache.MatrixViewProjectionViewportInverse); case Space.View: return(cameraInfo.Cache.MatrixViewportInverse); case Space.Screen: return(MatrixEx.Identity); default: throw new ArgumentOutOfRangeException(nameof(to), to, null); } default: throw new ArgumentOutOfRangeException(nameof(from), from, null); } }
public static void GetCameraParas(this Int16 cameraHandle, ICameraInfo cameraInfo) { cameraInfo.CameraParas.IsMetadataAvailable = IsParamAvailable(cameraHandle, PvTypes.PARAM_METADATA_ENABLED); cameraInfo.CameraSettings.IsMetadataEnabled = false; //default cameraInfo.CameraParas.IsCentroidAvailable = IsParamAvailable(cameraHandle, PvTypes.PARAM_CENTROIDS_ENABLED); cameraInfo.CameraSettings.IsCentroidEnabled = false; //default //even mutliple region is supported, but we only support one and it is the deafult setting, //so no bothering to any reading and setting }
public static ICamera getInstance(ICameraInfo cameraInfo) { //ICamera Icamera; if (Icamera == null) { Icamera = new ICamera(cameraInfo); } return(Icamera); }
public ICamera OpenCamera(ICameraInfo cameraInfo) { if (cameraInfo.CameraType == CameraType.Prime) { var camera = new Prime95SingleTypeCamera(cameraInfo); Cameras.Add(camera); camera.Open(); return(camera); } return(null); }
//set public static void SetInfosToCameraParameters(this Int16 cameraHandle, ICameraInfo cameraInfo) { ////set readout cameraHandle.SetReadoutSpeed(cameraInfo); SetDefualt(cameraHandle, cameraInfo); // exposuretime and bins used in the camera setup //// set temp // SetTemperature(cameraHandle, cameraInfo, cameraInfo.CameraSettings.Temperature); }
public Control_BaslerCamera(ICameraInfo cameraInfo) { _ngrabCount = -1; _ncount = 0; _camera = new Camera(cameraInfo); _camera.StreamGrabber.ImageGrabbed += StreamGrabber_ImageGrabbed; _camera.Open(); _converter = new Basler.Pylon.PixelDataConverter(); _converter.OutputPixelFormat = Basler.Pylon.PixelType.RGB8packed; }
public Ray3D GetMouseRay(ICameraInfo cameraInfo, Point3D mouseWorld) { var mouseRay0 = Projection0.GetMouseRay(cameraInfo, mouseWorld); var mouseRay1 = Projection1.GetMouseRay(cameraInfo, mouseWorld); var plane = new Plane(cameraInfo.Position, (cameraInfo.Target - cameraInfo.Position).Normalize()); var rayOrigin0 = plane.IntersectionWith(mouseRay0); var rayOrigin1 = plane.IntersectionWith(mouseRay1); var rayOriginCombined = rayOrigin0.InterpolateLinear(rayOrigin1, Weight1); var rayDirectionCombined = mouseRay0.Direction.InterpolateLinear(mouseRay1.Direction, Weight1); return(new Ray3D(rayOriginCombined, rayDirectionCombined)); }
public static bool SetDefualt(this Int16 cameraHandle, ICameraInfo cameraInfo) { var result = true; if (cameraInfo.CameraParas.IsMetadataAvailable) { result &= SetMetadata(cameraHandle, false); } if (cameraInfo.CameraParas.IsCentroidAvailable) { result &= SetCentroiding(cameraHandle, false, 0, 0); } return(result); }
// 相机初始化 public Camera CameraInit(int index) { if (null == camera) { // 获取所选相机 ICameraInfo selectedCamera = allCameraInfos[index]; camera = new Camera(selectedCamera); } //打开相机 if (true == camera.IsOpen) { camera.Close(); } camera.Open(); return(camera); }
public CameraInfoCache(ICameraInfo cameraInfo) { MatrixView = Matrix4DEx.LookAtRH(cameraInfo.Position.ToVector3D(), cameraInfo.Target.ToVector3D(), cameraInfo.UpVector); MatrixViewInverse = MatrixView.Inverse(); MatrixProjection = cameraInfo.Projection.GetMatrixProjection(); MatrixProjectionInverse = MatrixProjection.Inverse(); MatrixViewport = Matrix4DEx.Viewport(cameraInfo.Viewport); MatrixViewportInverse = MatrixViewport.Inverse(); MatrixViewProjection = MatrixView * MatrixProjection; MatrixViewProjectionInverse = MatrixViewProjection.Inverse(); MatrixViewProjectionViewport = MatrixViewProjection * MatrixViewport; MatrixViewProjectionViewportInverse = MatrixViewProjectionViewport.Inverse(); }
public void Stop() { lock (_syncObject) { if (_isRunning) { _isRunning = false; _thread.Join(); _thread = null; _cameraPool.StopLiveView(_cameraInfo, Foo); _cameraInfo = null; } else { Thread.Sleep(500); } } }
public void ToStringTest() { const string parameters = "parameters"; const string imagehandler = "imageHandler"; const string model = "model"; const string userName = "******"; ICameraInfo cameraInfo = (ICameraInfo)_mockery.NewMock(typeof(ICameraInfo)); Expect.Once.On(_parameters).GetProperty("DisplayString").Will(Return.Value(parameters)); Expect.Once.On(_imageHandler).GetProperty("DisplayString").Will(Return.Value(imagehandler)); Image image = new Image(new CameraInfo(CameraId, model, userName), _parameters, _imageHandler); Assert.AreEqual(string.Format("{0} - {1}\t{2}\t{3}", model, userName, parameters, imagehandler), image.DisplayString); _mockery.VerifyAllExpectationsHaveBeenMet(); }
/// <summary> /// Create new <see cref="ICameraInfo"/> based on mouse offset in view space and orbit origin. /// </summary> public static ICameraInfo Orbit(ICameraInfo cameraInfoStart, Vector3D mouseOffsetView, Point3D orbitOrigin) { // default input var eye = cameraInfoStart.Position; var target = cameraInfoStart.Target; // create local coordinate system var zAxis = cameraInfoStart.UpVector; var yzPlane = new Plane(new Point3D(), cameraInfoStart.GetEyeDirection().ToPoint3D(), zAxis.ToPoint3D()); var xAxis = yzPlane.Normal; var xzPlane = new Plane(new Point3D(), zAxis.ToPoint3D(), xAxis.ToPoint3D()); var yAxis = xzPlane.Normal; var matrixWorldToLocal = Matrix4DEx.CoordinateSystem(new Point3D(), xAxis, yAxis, zAxis); // transform to local system orbitOrigin = matrixWorldToLocal.Transform(orbitOrigin); eye = matrixWorldToLocal.Transform(eye); target = matrixWorldToLocal.Transform(target); // figure out angles (how much to rotate) GetSphereAngles(mouseOffsetView, (target - eye).Normalize(), out var thetaDelta, out var phiDelta); // rotate horizontally var matrixRotationHorizontal = Matrix4DEx.Rotate(UnitVector3D.ZAxis, thetaDelta.Radians).TransformAround(orbitOrigin); eye = matrixRotationHorizontal.Transform(eye); target = matrixRotationHorizontal.Transform(target); // rotate vertically var phiPlane = new Plane(eye, target, target + UnitVector3D.ZAxis); var matrixRotationVertical = Matrix4DEx.Rotate(phiPlane.Normal, phiDelta.Radians).TransformAround(orbitOrigin); eye = matrixRotationVertical.Transform(eye); target = matrixRotationVertical.Transform(target); // transform back to world system var matrixLocalToWorld = matrixWorldToLocal.Inverse(); eye = matrixLocalToWorld.Transform(eye); target = matrixLocalToWorld.Transform(target); // update camera info return(new CameraInfo(eye, target, cameraInfoStart.UpVector, cameraInfoStart.Projection.Cloned(), cameraInfoStart.Viewport)); }
public static bool SetTemperature(this Int16 cameraHandle, ICameraInfo cameraInfo, Int16 setPoint) { //Check if value is in range if (setPoint < cameraInfo.CameraParas.TemperatureMin || setPoint > cameraInfo.CameraParas.TemperatureMax) { return(false); } var unmngSetpoint = Marshal.AllocHGlobal(sizeof(Int16)); Marshal.WriteInt16(unmngSetpoint, setPoint); var result = Pvcam.pl_set_param(cameraHandle, PvTypes.PARAM_TEMP_SETPOINT, unmngSetpoint); Marshal.FreeHGlobal(unmngSetpoint); unmngSetpoint = IntPtr.Zero; return(result); }
private void cameraBindingSource_CurrentChanged(object sender, EventArgs e) { ICameraInfo cameraInfo = CameraInfo; if (cameraInfo != null) { SetControlsEnabled(true); UIHelper.FillComboBoxWith(isoComboBox, cameraInfo.AvailableIsoSpeeds, cameraInfo.CurrentIsoSpeed); UIHelper.FillComboBoxWith(apertureComboBox, cameraInfo.AvailableApertures, cameraInfo.CurrentAperture); UIHelper.FillComboBoxWith(exposalComboBox, cameraInfo.AvailableExposals, cameraInfo.CurrentExposal); UIHelper.FillComboBoxWith(saveToComboBox, SaveTo.SaveToValues, SaveTo.With(SaveToEnum.Save_by_downloading_to_a_host_computer)); UIHelper.FillComboBoxWith(imageQualityComboBox, cameraInfo.AvailableImageQualities, cameraInfo.CurrentImageQuality); } else { SetControlsEnabled(false); } }
// Occurs when a new camera has been selected in the list. Destroys the object of the currently opened camera device and // creates a new object for the selected camera device. After that, the connection to the selected camera device is opened. public bool ConnectToDevice() { // Destroy the old camera object. if (objCamera != null) { DestroyCamera(); } // Open the connection to the selected camera device. //if (deviceListView.SelectedItems.Count > 0) { // Get the attached device data. ICameraInfo selectedCamera = objICameraInfo;//item.Tag as ICameraInfo; try { // Create a new camera object. objCamera = new Camera(selectedCamera); objCamera.CameraOpened += Configuration.AcquireContinuous; // Register for the events of the image provider needed for proper operation. objCamera.ConnectionLost += OnConnectionLost; objCamera.CameraOpened += OnCameraOpened; objCamera.CameraClosed += OnCameraClosed; objCamera.StreamGrabber.GrabStarted += OnGrabStarted; objCamera.StreamGrabber.ImageGrabbed += OnImageGrabbed; objCamera.StreamGrabber.GrabStopped += OnGrabStopped; // Open the connection to the camera device. objCamera.Open(); } catch (Exception exception) { ShowException(exception); return(false); } } return(true); }
public BaslerCamera(ICameraInfo info, BaslerCameraPlugin provider) { this.info = info; this.provider = provider; camera = new Basler.Pylon.Camera(info); camera.CameraOpened += Configuration.AcquireContinuous; camera.StreamGrabber.ImageGrabbed += OnImageGrabbed; parameters = new List <ICameraParameter> { new CameraParameter("Exposure Time", () => ExposureTime, (value) => ExposureTime = (double)value), new CameraParameter("Frame Rate", () => FrameRate, (value) => FrameRate = (double)value) // new CameraParameter("Binning", () => Binning, (value) => Binning = (Point)value), // new CameraParameter("AOI Offset", () => AOIOffset, (value) => AOIOffset = (Point)value), // new CameraParameter("AOI Size", () => AOISize, (value) => AOISize = (Point)value), // new CameraParameter("Pixel Clock", () => PixelClock, (value) => PixelClock = (int)value), // new CameraParameter("Managed Image", () => ManagedImages, (value) => ManagedImages = (bool)value), }; }