public void GetCamNames() { foreach (var dev in UsbCamera.FindDevices()) { CamNames.Add(dev); } }
/// <summary> /// Start automatically capturing images to send to the dashboard. /// </summary> /// <remarks> /// You should call this method to see a camera feed on the dashboard. /// If you also want to perform vision processing on the roboRIO, use /// <see cref="GetVideo()"/> to get access to the camera images /// </remarks> /// <param name="name">The name to give the camera</param> /// <param name="dev">The device number for the camera interface</param> /// <returns>The <see cref="UsbCamera"/> object that was created to stream from</returns> public UsbCamera StartAutomaticCapture(string name, int dev) { UsbCamera camera = new UsbCamera(name, dev); StartAutomaticCapture(camera); return(camera); }
/// <summary> /// Start automatically capturing images to send to the dashboard. /// </summary> /// <remarks> /// You should call this method to see a camera feed on the dashboard. /// If you also want to perform vision processing on the roboRIO, use /// <see cref="GetVideo()"/> to get access to the camera images /// </remarks> /// <param name="name">The name to give the camera</param> /// <param name="path">The device path (e.g. "/dev/video0") of the camera</param> /// <returns>The <see cref="UsbCamera"/> object that was created to stream from</returns> public UsbCamera StartAutomaticCapture(string name, string path) { UsbCamera camera = new UsbCamera(name, path); StartAutomaticCapture(camera); return(camera); }
/// <summary> /// Start automatically capturing images to send to the dashboard. /// </summary> /// <remarks> /// You should call this method to see a camera feed on the dashboard. /// If you also want to perform vision processing on the roboRIO, use /// <see cref="GetVideo()"/> to get access to the camera images /// /// <para> /// This overload calls <see cref="StartAutomaticCapture(string, int)"/> with device 0, /// creating a camera named "USB Camera {dev}" /// </para> /// </remarks> /// <param name="dev">The device number for the camera interface</param> /// <returns>The <see cref="UsbCamera"/> object that was created to stream from</returns> public UsbCamera StartAutomaticCapture(int dev) { UsbCamera camera = new UsbCamera($"USB Camera {dev.ToString()}", dev); StartAutomaticCapture(camera); return(camera); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { sendingPhoto = false; panicLed = DeviceFactory.Build.Led(Pin.DigitalPin2); infoLed = DeviceFactory.Build.Led(Pin.DigitalPin4); ranger = DeviceFactory.Build.UltraSonicSensor(Pin.DigitalPin3); screen = DeviceFactory.Build.RgbLcdDisplay(); screen.SetText("setting up..."); screen.SetBacklightRgb(0, 0, 200); // init mode -> Both Led's are on panicLed.ChangeState(SensorStatus.On); infoLed.ChangeState(SensorStatus.On); // init camera camera = new UsbCamera(); var initWorked = await camera.InitializeAsync(); // Something went wrong if (!initWorked || ranger.MeasureInCentimeters() == -1) { infoLed.ChangeState(SensorStatus.Off); screen.SetText("Camera or Sensor not connected!"); screen.SetBacklightRgb(200, 0, 0); blink(panicLed); return; } // init photobackend Microsoft.WindowsAzure.Storage.Auth.StorageCredentials credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accountKey); //credentials.UpdateSASToken("?sv=2015-04-05&ss=b&srt=sco&sp=rwlac&se=2016-11-20T04:05:54Z&st=2016-11-12T20:05:54Z&spr=https,http&sig=B0zDabRXoO7LfWy5iACsn0sHOnWzvmmrDv8fAqITPgI%3D"); CloudStorageAccount acc = new CloudStorageAccount(credentials, true); CloudBlobClient client = acc.CreateCloudBlobClient(); container = client.GetContainerReference("picture-storage"); previewElement.Source = camera.MediaCaptureInstance; await camera.StartCameraPreview(); // init finished - turn off panic Led infoLed.ChangeState(SensorStatus.Off); panicLed.ChangeState(SensorStatus.Off); screen.SetText(""); screen.SetBacklightRgb(0, 0, 0); DispatcherTimer mainThread = new DispatcherTimer(); mainThread.Interval = TimeSpan.FromSeconds(0.5); mainThread.Tick += run; mainThread.Start(); }
public override void RobotInit() { int status = 0; var ret = HALThreads.HAL_SetCurrentThreadPriority(true, 25, ref status); Console.WriteLine(status); Console.WriteLine(ret); Thread cameraThread = new Thread(() => { // Get the USB Camera from the camera server UsbCamera camera = CameraServer.Instance.StartAutomaticCapture(); camera.SetResolution(640, 480); // Get a CvSink. This will capture Mats from the Camera CvSink cvSink = CameraServer.Instance.GetVideo(); // Setup a CvSource. This will send images back to the dashboard CvSource outputStream = CameraServer.Instance.PutVideo("Rectangle", 640, 480); // Mats are very expensive. Let's reuse this Mat. Mat mat = new Mat(); while (true) { // Tell the CvSink to grab a frame from the camera and put it // in the source mat. If there is an error notify the output. if (cvSink.GrabFrame(mat) == 0) { Console.WriteLine("Timeout"); // Send the output the error. outputStream.NotifyError(cvSink.GetError()); // skip the rest of the current iteration continue; } // Put a rectangle on the image Cv2.Rectangle(mat, new Point(100, 100), new Point(400, 400), new Scalar(255, 255, 255), 5); // Give the output stream a new image to display outputStream.PutFrame(mat); } }); cameraThread.IsBackground = true; cameraThread.Start(); servo = new Servo(0); joystick = new Joystick(0); gyro = new AnalogGyro(0); }
public void CamStop() { try { CamEn = false; if (camTimer != null) { camTimer.Dispose(); } if (cam != null) { cam.Release(); cam = null; } } catch (Exception) { } }
public Task CamCaptureAsync() { CamCaptureCancelTokenSrc = new CancellationTokenSource(); CamCaptureCancelToken = CamCaptureCancelTokenSrc.Token; var camNo = UsbCamera.FindDevices().Length - 1; return(Task.Run(() => { //cam = new UsbCamera(camNo, 320, 180); cam = new UsbCamera(camNo, 640, 360); //cam = new UsbCamera(camNo, 1280, 720); cam.Start(); camTimer = new System.Timers.Timer(1000d / CamFps.Value); camTimer.Elapsed += camCaptureTimerElapsed; CamCaptureBusy = false; camTimer.Start(); }, CamCaptureCancelToken)); }
public override void RobotInit() { Console.WriteLine("Hello, FRC2017!"); Console.WriteLine("TrueMoe RobotCode 2017i"); chooser = new SendableChooser(); chooser.AddDefault("Default Auto", defaultAuto); chooser.AddObject("My Auto", customAuto); SmartDashboard.PutData("Chooser", chooser); usbCamera = new UsbCamera("USB Camera 0", 0); mjpegServer = new MjpegServer("USB Camera 0 Server", 1181); mjpegServer.Source = usbCamera; driveCtl = new drivingControl(); operateCtl = new operatingControl(); opIf = new operatorInterface(); }
/******************************************************************************************* * PUBLIC METHODS *******************************************************************************************/ public async Task Initialize() { webcam = new UsbCamera(); try { await webcam.InitializeAsync(); this.isEnabled = true; } catch (Exception ex) { var events = new Dictionary<string, string> { { "UsbCamera", ex.Message } }; TelemetryHelper.TrackEvent("FailedToInitializeMediaCapture", events); } //Initialize PIR Sensor pirSensor = new PirSensor(App.Controller.XmlSettings.GpioMotionPin, PirSensor.SensorType.ActiveLow); pirSensor.motionDetected += PirSensor_MotionDetected; Interlocked.Exchange(ref isCapturing, 0); }
private void btnStartCapture_Click(object sender, EventArgs e) { // [How to use] // check USB camera is available. string[] devices = UsbCamera.FindDevices(); if (devices.Length == 0) { return; // no camera. } // check format. int cameraIndex = 0; UsbCamera.VideoFormat[] formats = UsbCamera.GetVideoFormat(cameraIndex); for (int i = 0; i < formats.Length; i++) { Console.WriteLine("{0}:{1}", i, formats[i]); } // create usb camera and start. camera = new UsbCamera(cameraIndex, formats[0]); camera.Start(); // get image. // Immediately after starting the USB camera, // GetBitmap() fails because image buffer is not prepared yet. var bmp = camera.GetBitmap(); // show image in PictureBox. var timer = new System.Timers.Timer(5) { SynchronizingObject = this }; //timer.Elapsed += (s, ev) => pbxScreen.Image = camera.GetBitmap(); timer.Elapsed += Timer_Elapsed; timer.Start(); // release resource when close. this.FormClosing += (s, ev) => timer.Stop(); this.FormClosing += (s, ev) => camera.Stop(); }
public override void RobotInit() { System.Console.WriteLine("Hello, FRC2017!"); System.Console.WriteLine("TrueMoe RobotCode 2017c"); oi = new OI(); FRC2017c.gyroSys.reset(); chooser = new WPILib.SmartDashboard.SendableChooser(); camServer = CameraServer.Instance; nt = NetworkTables.NetworkTable.GetTable("Forgiving/Vision"); chooser.AddDefault("Center", new AutonomousCommand("center")); chooser.AddObject("turn Right", new AutonomousCommand("left")); chooser.AddObject("turn Left", new AutonomousCommand("right")); WPILib.SmartDashboard.SmartDashboard.PutData("Autonomous Mode", chooser); WPILib.SmartDashboard.SmartDashboard.PutString("Team", "5453"); WPILib.SmartDashboard.SmartDashboard.PutNumber("AutonomousRushing1Delay", 900); FRC2017c.gyroSys.resetDisplacement(); usbCamera = new UsbCamera("USB Camera 0", 0); usbCamera.SetFPS(12); camServer.StartAutomaticCapture(usbCamera); }
/******************************************************************************************* * PUBLIC METHODS *******************************************************************************************/ public async Task Initialize() { webcam = new UsbCamera(); try { await webcam.InitializeAsync(); this.isEnabled = true; } catch (Exception ex) { var events = new Dictionary <string, string> { { "UsbCamera", ex.Message } }; TelemetryHelper.TrackEvent("FailedToInitializeMediaCapture", events); } //Initialize PIR Sensor pirSensor = new PirSensor(App.Controller.XmlSettings.GpioMotionPin, PirSensor.SensorType.ActiveLow); pirSensor.motionDetected += PirSensor_MotionDetected; Interlocked.Exchange(ref isCapturing, 0); }
private void FrameworkElement_OnInitialized(object sender, EventArgs e) { var networkItem = new MenuItem() { Header = "Network camera" }; networkItem.Click += delegate { var dia = new NetworkCameraDialog(); dia.Show(); dia.Closing += delegate(object o, CancelEventArgs args) { if (!dia.ok) { return; } try { System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(dia.IpBlock1.Text + "." + dia.IpBlock2.Text + "." + dia.IpBlock3.Text + "." + dia.IpBlock4.Text); _viewModel.Items.Add(new NetworkCamera(ipaddress.ToString())); } catch (Exception ex) { LogManager.GetCurrentClassLogger().Warn(ex, "Can't open camera, not a valid network address"); } }; }; Camera.Items.Add(networkItem); Camera.Items.Add(new Separator()); List <string> cameraList = UsbCamera.GetDevices(); if (cameraList.Count > 0) { Camera.IsEnabled = true; } MenuItem menuItem; foreach (var camera in cameraList.Select((value, i) => new { i, value })) { menuItem = new MenuItem(); menuItem.Header = camera.value; menuItem.Click += delegate { if (!UsbCamera.IsCameraOpened(camera.i)) { _viewModel.Items.Add(new UsbCamera(camera.i)); } }; Camera.Items.Add(menuItem); } Camera.Items.Add(new Separator()); menuItem = new MenuItem(); menuItem.Header = "All local cameras"; menuItem.Click += delegate { foreach (var camera in cameraList.Select((value, i) => new { i, value })) { if (!UsbCamera.IsCameraOpened(camera.i)) { _viewModel.Items.Add(new UsbCamera(camera.i)); } } }; Camera.Items.Add(menuItem); }
public static List <string> GetCaptureCamera() { return(UsbCamera.FindDevices().ToList()); }