private void DisableCamera(RPiCameraClient camera, Action disabletActione) { if (camera.Disable()) { disabletActione.Invoke(); } }
private void EnableCamera(RPiCameraClient camera, Action enableAction) { if (camera.Enable()) { enableAction.Invoke(); } }
private void DisconnectCamera(RPiCameraClient camera, Action disconnectAction) { if (camera.Disconnect()) { disconnectAction.Invoke(); } }
private void EnableDisableCamera(RPiCameraClient camera, Action enableAction, Action disabletAction) { if (camera.Enabled) { this.DisableCamera(camera, disabletAction); } else { this.EnableCamera(camera, enableAction); } }
private void ConnectDisconnectCamera(string side, RPiCameraClient camera, string host, Action connectAction, Action disconnectAction, Action enableAction, Action disabletAction) { if (camera.Connected) { this.DisconnectCamera(camera, disconnectAction); } else { this.ConnectCamera(side, camera, host, connectAction, enableAction, disabletAction); } }
private void ConnectCamera(string side, RPiCameraClient camera, string host, Action connectAction, Action enableAction, Action disabletAction) { if (camera.Connect(host, this._port)) { connectAction.Invoke(); if (camera.Enabled) { enableAction.Invoke(); } else { disabletAction.Invoke(); } } else { MessageBox.Show(side + " camera connection error!"); } }
private void MakeCapture(Object locker, RPiCameraClient camera, ref bool started, ref bool looped, Button btnCameraCapture, Button btnCameraAutoCapture, NumericUpDown nudCameraRotation, NumericUpDown nudCameraXShift, NumericUpDown nudCameraYShift, PictureBox picCamera) { this.Invoke(new Action(() => { btnCameraCapture.Enabled = false; btnCameraAutoCapture.Text = "Auto capture (Enabled)"; btnCameraAutoCapture.Enabled = true; })); started = true; while (looped) { Image image = null; lock (locker) image = camera.Capture(); if (image == null) { break; } unsafe { fixed(byte *pointer = image.Data) { int length = image.Height * image.Width * 3; for (int i = 0; i < length; i += 3) { byte tmp = pointer[i]; pointer[i] = pointer[i + 2]; pointer[i + 2] = tmp; } Bitmap source = new Bitmap(image.Width, image.Height, image.Width * 3, PixelFormat.Format24bppRgb, new IntPtr(pointer)); Bitmap destination = new Bitmap(image.Width, image.Height); int centerX = source.Width / 2; int centerY = source.Height / 2; using (Graphics g = Graphics.FromImage(destination)) { g.Clear(Color.White); float rotation = 0.0f; float xShift = 0.0f; float yShift = 0.0f; this.Invoke(new Action(() => { rotation = (float)nudCameraRotation.Value; xShift = (float)nudCameraXShift.Value; yShift = (float)nudCameraYShift.Value; })); GraphicsState state = g.Save(); g.TranslateTransform(centerX + xShift, centerY + yShift); g.RotateTransform(rotation); g.TranslateTransform(-centerX, -centerY); g.DrawImage(source, 0.0f, 0.0f); g.Restore(state); g.DrawLine(Pens.Red, centerX, 0, centerX, source.Height); // pionowa g.DrawLine(Pens.Red, 0, centerY, source.Width, centerY); // pozioma } this.Invoke(new Action(() => { System.Drawing.Image tmp = picCamera.Image; if (tmp != null) { tmp.Dispose(); } picCamera.Image = destination; })); } } } this.Invoke(new Action(() => { btnCameraCapture.Enabled = true; btnCameraAutoCapture.Text = "Auto capture (Disabled)"; btnCameraAutoCapture.Enabled = true; })); started = false; }
private void CaptureCamera(RPiCameraClient camera, string side, NumericUpDown nudCameraRotation, NumericUpDown nudCameraXShift, NumericUpDown nudCameraYShift, PictureBox picCamera, DateTime now) { Image image = camera.Capture(); if (image == null) { return; } unsafe { fixed(byte *pointer = image.Data) { int length = image.Height * image.Width * 3; for (int i = 0; i < length; i += 3) { byte tmp = pointer[i]; pointer[i] = pointer[i + 2]; pointer[i + 2] = tmp; } Bitmap source = new Bitmap(image.Width, image.Height, image.Width * 3, PixelFormat.Format24bppRgb, new IntPtr(pointer)); Bitmap destination = new Bitmap(image.Width, image.Height); source.Save(now.Hour + "." + now.Minute + "." + now.Second + "." + now.Millisecond + "_" + side + "_camera_v1.png"); int centerX = source.Width / 2; int centerY = source.Height / 2; using (Graphics g = Graphics.FromImage(destination)) { g.Clear(Color.White); float rotation = 0.0f; float xShift = 0.0f; float yShift = 0.0f; this.Invoke(new Action(() => { rotation = (float)nudCameraRotation.Value; xShift = (float)nudCameraXShift.Value; yShift = (float)nudCameraYShift.Value; })); GraphicsState state = g.Save(); g.TranslateTransform(centerX + xShift, centerY + yShift); g.RotateTransform(rotation); g.TranslateTransform(-centerX, -centerY); g.DrawImage(source, 0.0f, 0.0f); g.Restore(state); destination.Save(now.Hour + "." + now.Minute + "." + now.Second + "." + now.Millisecond + "_" + side + "_camera_v2.png"); g.DrawLine(Pens.Red, centerX, 0, centerX, source.Height); // pionowa g.DrawLine(Pens.Red, 0, centerY, source.Width, centerY); // pozioma destination.Save(now.Hour + "." + now.Minute + "." + now.Second + "." + now.Millisecond + "_" + side + "_camera_v3.png"); } picCamera.Image = destination; } } }