void InitializeVideoRecorder(Rectangle viewfinderRectangle) { if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); // Initialize the camera if it exists on the device. if (videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); // Display the viewfinder image on the rectangle. viewfinderRectangle.Fill = videoRecorderBrush; // Start video capture and display it on the viewfinder. captureSource.Start(); } else { // A camera is not supported on this device } } }
public void start() { if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); // Initialize the camera if it exists on the device. if (videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); videoRecorderBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 }; viewfinderRectangle.Fill = videoRecorderBrush; // Start video capture and display it on the viewfinder. captureSource.Start(); System.Diagnostics.Debug.WriteLine("Started"); _isRunning = true; } } }
void MainPage_Loaded(object sender, RoutedEventArgs e) { this.source = new CaptureSource(); this.deviceList.ItemsSource = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices(); this.deviceList.SelectedIndex = 0; this.source.VideoCaptureDevice = (VideoCaptureDevice)this.deviceList.SelectedItem; }
void Load() { if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { var devices = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices(); foreach (var device in devices) { var videoItem = new VideoItem(); videoItem.Name = device.FriendlyName; var source = new CaptureSource(); source.VideoCaptureDevice = device; var videoBrush = new VideoBrush(); videoBrush.SetSource(source); videoItem.Brush = videoBrush; this.sources.Add(source); this.sourceItems.Add(videoItem); } this.videoItems.ItemsSource = this.sourceItems; this.StartAll(); } }
public void StartWebCam() { _captureSource = new CaptureSource(); _captureSource.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(_captureSource_CaptureImageCompleted); _captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); try { // Start capturing if (_captureSource.State != CaptureState.Started) { // Create video brush and fill the WebcamVideo rectangle with it var vidBrush = new VideoBrush(); vidBrush.Stretch = Stretch.Uniform; vidBrush.SetSource(_captureSource); WebcamVideo.Fill = vidBrush; // Ask user for permission and start the capturing if (CaptureDeviceConfiguration.RequestDeviceAccess()) { _captureSource.Start(); } } } catch (InvalidOperationException) { InfoTextBox.Text = "Web Cam already started - if not, I can't find it..."; } catch (Exception) { InfoTextBox.Text = "Could not start web cam, do you have one?"; } }
public VideoService( Rectangle viewFinder, MediaElement player ) { // Initial State _State = PlayState.Paused; _CanRecord = false; _Record = new SwitchableCommand(OnRecord); _Play = new SwitchableCommand(OnPlay); _Stop = new SwitchableCommand(OnPause); _ViewFinder = viewFinder; _Player = player; _Player.MediaEnded += MediaEnded; _CaptureSource = new CaptureSource(); _CaptureSource.CaptureFailed += CaptureFailed; _FileSink = new FileSink(); _Brush = new VideoBrush(); _HasRecording = new BehaviorSubject<bool>(false); }
public Microphone() { _cSource = new CaptureSource(); _cSource.Stop(); _acDevice = GetAudioDevice(); _cSource.AudioCaptureDevice = _acDevice; this.CaptureSource = _cSource; }
void MainPage_Loaded(object sender, RoutedEventArgs e) { captureSource = new CaptureSource { VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice() }; var videoBrush = new VideoBrush(); videoBrush.SetSource(captureSource); Viewport.Fill = videoBrush; markerDetector = new CaptureSourceMarkerDetector(); var marker = Marker.LoadFromResource("Bola.pat", 64, 64, 80); markerDetector.Initialize(captureSource, 1d, 4000d, marker); markerDetector.MarkersDetected += (obj, args) => { Dispatcher.BeginInvoke(() => { var results = args.DetectionResults; if (results.HasResults) { var centerAtOrigin = Matrix3DFactory. CreateTranslation( -Imagem.ActualWidth* 0.5, -Imagem. ActualHeight* 0.5, 0); var scale = Matrix3DFactory.CreateScale (0.5, -0.5, 0.5); var world = centerAtOrigin* scale* results[0]. Transformation; var vp = Matrix3DFactory. CreateViewportTransformation (Viewport.ActualWidth, Viewport.ActualHeight); var m = Matrix3DFactory. CreateViewportProjection (world, Matrix3D.Identity, markerDetector. Projection, vp); Imagem.Projection = new Matrix3DProjection {ProjectionMatrix = m}; } }); }; }
public SilverlightWebcamService() { captureSource = new CaptureSource(); captureSource.CaptureImageCompleted += (o, e) => { if (CaptureImageCompleted != null) CaptureImageCompleted(this, e); }; webcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { // Initialize the webcam captureSource = new CaptureSource(); captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Fill the Viewport Rectangle with the VideoBrush var vidBrush = new VideoBrush(); vidBrush.SetSource(captureSource); Viewport.Fill = vidBrush; }
public CaptureDevice(VideoCaptureDevice device) { _device = device; lock(this.GetType()) { if (!sources.ContainsKey(device)) { sources[_device] = new CaptureSource {VideoCaptureDevice = device}; } } }
// Constructor public MainPage() { InitializeComponent(); c = new CaptureSource(); c.VideoCaptureDevice = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices().First(); var vidBrush = new VideoBrush(); vidBrush.SetSource(c); ViewPort.Fill = vidBrush; }
private void DisposeVideoRecorder() { if (_captureSource != null) { if (_captureSource.VideoCaptureDevice != null && _captureSource.State == CaptureState.Started) _captureSource.Stop(); _captureSource.CaptureFailed -= OnCaptureSourceOnCaptureFailed; _captureSource = null; _videoCaptureDevice = null; _fileSink = null; _videoBrush = null; } }
public void InitWebcam() { // Create the CaptureSource. this.captureSource = new CaptureSource(); // async capture failed event handler captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs> (CaptureSource_CaptureFailed); // async capture completed event handler captureSource.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs> (CaptureSource_CaptureImageCompleted); }
public MainPage() { InitializeComponent(); //Register this instance to be accessible from script HtmlPage.RegisterScriptableObject("Barcode2Javascript", this); // Create the CaptureSource. captureSource = new CaptureSource(); captureSource.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(captureSource_CaptureImageCompleted); // Prevent displays from peeking through the expanded webcam display capturedBarcodes.SetValue(Canvas.ZIndexProperty, -1); capturedImage.SetValue(Canvas.ZIndexProperty, -1); }
void ControlLoaded(object sender, RoutedEventArgs e) { var random = new Random(); source = new CaptureSource(); this.deviceList.ItemsSource = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices(); this.deviceList.SelectedIndex = 0; foreach (DoubleAnimation animation in this.spinStoryboard.Children) { int next = random.Next(5, 25); animation.Duration = new Duration(TimeSpan.FromSeconds(next)); if (next > 15) animation.To = -animation.To; } }
private void Button_Click(object sender, RoutedEventArgs e) { CaptureSource captureSource = new CaptureSource(); // obtenemos el medio de video que esta por defecto para grabar y lo guardamos en una variable var vcd = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // le indicamos al capture source por medio de cuál video puede grabar captureSource.VideoCaptureDevice = vcd; // le pasamos a la brocha que está en el xaml el medio de video BrochaVideo.SetSource(captureSource); // iniciamos el medio de video captureSource.Start(); }
public void InitializeVideoRecorder() { try { //fileName = string.Format(@"\Purposecode\Video{0}.mp4", DateTime.Now.ToString("yyyyMMddHHmmss")); fileName = string.Format("Video{0}.mp4", DateTime.Now.ToString("yyyyMMddHHmmss")); if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); // Initialize the camera if it exists on the device. if (videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); // Display the viewfinder image on the rectangle. viewfinderRectangle.Fill = videoRecorderBrush; StopPlaybackRecording.IsEnabled = false; // Start video capture and display it on the viewfinder. captureSource.Start(); // Set the button state and the message. UpdateUI(ButtonState.Initialized, "Tap record to start recording..."); } else { // Disable buttons when the camera is not supported by the device. UpdateUI(ButtonState.CameraNotSupported, "Camera is not supported.."); } } } catch (Exception ex) { var test = ex.Message; } } //InitializeVideoRecorder()
protected override void OnNavigatedFrom(NavigationEventArgs e) { if (captureSource != null) { captureSource.CaptureImageCompleted -= captureSource_CaptureImageCompleted; if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); } captureSource = null; fileSink = null; videoCaptureDevice = null; } base.OnNavigatedFrom(e); }
//http://msdn.microsoft.com/en-us/library/ff602282(VS.95).aspx public static bool RecordStart(SLPlayer.RecordStartPar par, Action<byte[]> onPCMData) { //if (obs == null) throw new Exception(); if (captureSource != null) captureSource.Stop(); //RecordInit(); //result.Format = actFormat; sink.onPCMData = onPCMData; //sink.WithWavHeader = withWavHeader; if (captureSource == null) { captureSource = new CaptureSource() { AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice(), VideoCaptureDevice = null }; AudioFormat fmt = null; if (captureSource.AudioCaptureDevice == null || captureSource.AudioCaptureDevice.SupportedFormats == null) error("RecordStart", new Exception("AudioCaptureDevice == null || SupportedFormats == null")); if (captureSource.AudioCaptureDevice != null && captureSource.AudioCaptureDevice.SupportedFormats != null) { fmt = captureSource.AudioCaptureDevice.SupportedFormats.Where(f => f.BitsPerSample == 16 && f.Channels == 1 && f.SamplesPerSecond >= 11025).OrderBy(f => f.SamplesPerSecond).FirstOrDefault(); //if (!par.slOldBrowser && par.toDisc) // //Minimalni pozadavky na LAME MP3 layer 1 nebo 2 (Silverlight Mp3MediaStreamSource neumi layer 2.5): // fmt = captureSource.AudioCaptureDevice.SupportedFormats.Where(f => f.BitsPerSample == 16 && f.Channels == 1 && f.SamplesPerSecond >= 16000).OrderBy(f => f.SamplesPerSecond).FirstOrDefault(); //else // fmt = captureSource.AudioCaptureDevice.SupportedFormats.Where(f => f.BitsPerSample == 16 && f.Channels == 1).OrderBy(f => f.SamplesPerSecond).FirstOrDefault(); trace("RecordStart: Selected format: BitsPerSample={0}, Channels={1}, SamplesPerSecond={2}", fmt.BitsPerSample, fmt.Channels, fmt.SamplesPerSecond); if (fmt != null) captureSource.AudioCaptureDevice.DesiredFormat = fmt; } if (fmt == null) { captureSource = null; error("RecordStart", new Exception("Missing microphone. You cannot use eTestMe.com recording features without microphone!")); MessageBox.Show("Missing microphone. You cannot use eTestMe.com recording features without microphone!"); return false; } } if (!deviceOK && !AdjustMicrophone() && !MicrophoneOK()) return false; deviceOK = true; try { sink.CaptureSource = captureSource; trace("RecordStart: captureSource.Start"); captureSource.Start(); return true; } catch (Exception exp) { error("RecordStart error", exp); throw new Exception("There was a problem starting the sound recording " + "If using a Mac, verify default devices are set correctly. " + "Right click on a Silverlight app to access the Configuration setings.", exp); } }
private void StartRecordig() { if (m_captureSource == null) { m_captureSource = new CaptureSource(); m_captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); m_captureSource.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice(); m_sink = new FileSink(); m_sink.CaptureSource = m_captureSource; m_sink.IsolatedStorageFileName = m_capturedFileName; } VideoBrush brush = new VideoBrush(); brush.SetSource(m_captureSource); CameraPreview.Fill = brush; m_captureSource.Start(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (captureSource == null) { captureSource = new CaptureSource(); captureSource.CaptureImageCompleted += captureSource_CaptureImageCompleted; fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); if (videoCaptureDevice != null) { videoBrush.SetSource(captureSource); videoBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 }; captureSource.Start(); } } }
public Webcam(String name, VideoCaptureDevice cam) { this.camera = cam; this.src = new CaptureSource(); this.lastImageTaken = DateTime.Now; this.nextImgName = ""; this.nextImgNum = 0; try { // if we found a camera and successfully connected if (camera != null) { // set the camera to its maximum resolution (allow choice in future?) camera.DesiredFormat = (from VideoFormat f in camera.SupportedFormats orderby f.PixelWidth * f.PixelHeight descending select f).FirstOrDefault<VideoFormat>(); // reset the preview source CaptureSource source = new CaptureSource(); // set the global CaptureSource to the selected camera source.VideoCaptureDevice = camera; source.AudioCaptureDevice = null; // set the callback function for this camera's async capture source.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(_src_srcImageCompleted); this.src = source; src.Start(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); throw new Exception("Prepare source failed: " + ex.ToString()); } }
private void Initialize() { try { // Init variables timedRotation = 0; Scale = 0.4; Rotate = 0; // Init capture source captureSource = new CaptureSource(); captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Desired format is 320 x 240 (good tracking results and performance) captureSource.VideoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Unknown, 320, 240, 30); // Init AR markerSlar = Marker.LoadFromResource("data/Marker_SLAR_16x16segments_80width.pat", 16, 16, 80.0, "SLAR"); markerL = Marker.LoadFromResource("data/Marker_L_16x16segments_80width.pat", 16, 16, 80.0, "L"); ArDetector = new CaptureSourceMarkerDetector(captureSource, 1, 4000, new List<Marker> { markerSlar, markerL }); AttachAREvent(); // Init Rest projectionMatrix = Matrix3DFactory.CreatePerspectiveFieldOfViewRH(0.7, ViewportContainer.Width / ViewportContainer.Height, 1, 4000); this.DataContext = this; // Start all SetARObject(); RunUpdate(); } catch (Exception ex) { var builder = new StringBuilder(); foreach (var sf in captureSource.VideoCaptureDevice.SupportedFormats) { builder.AppendFormat("{0}: {1} x {2} @ {3} fps. Stride: {4}\r\n", sf.PixelFormat, sf.PixelWidth, sf.PixelHeight, sf.FramesPerSecond, sf.Stride); } MessageBox.Show("Error during initialization. Please make sure a default webcam was set.\r\nSupported formats:\r\n" + builder.ToString() + "\r\n\r\n" + ex.ToString(), "Error during init.", MessageBoxButton.OK); throw; } }
private void InitializeVideoRecorder() { if (_captureSource == null) { _captureSource = new CaptureSource(); _fileSink = new FileSink(); _videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); _captureSource.CaptureFailed += OnCaptureSourceOnCaptureFailed; _captureSource.CaptureImageCompleted += CaptureSourceOnCaptureImageCompleted; if (_videoCaptureDevice != null) { _videoBrush = new VideoBrush(); _videoBrush.SetSource(_captureSource); ViewFinderRectangle.Fill = _videoBrush; _captureSource.Start(); } } }
public void StopRecording() { if (captureSource != null) { // Stop captureSource if it is running. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); } // Remove the event handlers for capturesource and the shutter button. captureSource.CaptureFailed -= OnCaptureFailed; // Remove the video recording objects. captureSource = null; videoCaptureDevice = null; fileSink = null; videoRecorderBrush = null; } }
/// <summary> /// Initialize the Capture Device /// </summary> private void InitializeCaptureDevice() { //set the video capture device if (captureSource == null) { captureSource = new CaptureSource(); captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); captureSource.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice(); sink = new FileSink(); sink.CaptureSource = captureSource; sink.IsolatedStorageFileName = m_capturedFileName; } //set the video preview var brush = new VideoBrush(); brush.SetSource(captureSource); cameraPreview.Fill = brush; }
public void InitializeVideoRecorder() { if (_captureSource == null) { // Create the VideoRecorder objects. _captureSource = new CaptureSource(); _fileSink = new FileSink(); _videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. _captureSource.CaptureFailed += OnCaptureFailed; // Initialize the camera if it exists on the phone. if (_videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. _videoRecorderBrush = new VideoBrush(); _videoRecorderBrush.SetSource(_captureSource); // Display the viewfinder image on the rectangle. viewfinderRectangle.Fill = _videoRecorderBrush; // Start video capture and display it on the viewfinder. _captureSource.Start(); // Set the button state and the message. UpdateUI(ButtonState.Initialized, "Tap record to start recording..."); } else { // Disable buttons when the camera is not supported by the phone. UpdateUI(ButtonState.NoChange, "Camera Not Supported."); } } }
public Page() { InitializeComponent(); if (App.Current.InstallState != InstallState.Installed) { this.LoginButtonPanel.Visibility = System.Windows.Visibility.Collapsed; this.InstallButtonPanel.Visibility = System.Windows.Visibility.Visible; } else { this.LoginButtonPanel.Visibility = System.Windows.Visibility.Visible; this.InstallButtonPanel.Visibility = System.Windows.Visibility.Collapsed; } //audio hookup _captureSource = new CaptureSource(); _audioSink = new StreamAudioSink(); //drawing stuff drawArea = new DrawingArea(this.DrawingCanvas); drawArea.Tool = CurrentTool.Pencil; drawArea.StrokeColor = new SolidColorBrush(Colors.Gray); drawArea.FillColor = new SolidColorBrush(Colors.Red); drawArea.StrokeWidth = 5; this.DataContext = drawArea; drawArea.DataAdded += (data) => { try { proxy.Client.DrawAsync(data); } catch { } }; }
private void UserControlLoaded(object sender, RoutedEventArgs e) { // Initialize the webcam captureSource = new CaptureSource {VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()}; // Desired format is 640 x 480 (good tracking results and performance) captureSource.VideoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Unknown, 640, 480, 60); captureSource.CaptureImageCompleted += CaptureSourceCaptureImageCompleted; // Fill the Viewport Rectangle with the VideoBrush var vidBrush = new VideoBrush(); vidBrush.SetSource(captureSource); Viewport.Fill = vidBrush; // Conctruct the Detector arDetector = new BitmapMarkerDetector { Threshold = 200, JitteringThreshold = 1 }; // Load the marker patterns. It has 16x16 segments and a width of 80 millimeters slarMarker = Marker.LoadFromResource("data/Marker_SLAR_16x16segments_80width.pat", 16, 16, 80); // Capture or transform periodically CompositionTarget.Rendering += (s, e2) => { if (captureSource.State == CaptureState.Started) { captureSource.CaptureImageAsync(); } else { Game.SetWorldMatrix(Balder.Math.Matrix.Identity); } if (Game.ParticleSystem.Particles != null && Game.ParticleSystem.Particles.Count > 0) { } }; }
public void SetSource(CaptureSource source) { NativeMethods.video_brush_set_source(this.native, source.native); }