public bool Connect() { if (!_Settings.HasCameraMonikerString()) { _Logger.InformUser(Strings.PasDeCameraConfig); return(false); } _VideoCaptureDevice = new VideoCaptureDevice(_Settings.CameraMonikerString); if (_VideoCaptureDevice == null) { _Logger.InformUser(Strings.ImpossibleCreerVCDevice); return(false); } VideoCapabilities[] videoCapabilities = _VideoCaptureDevice.VideoCapabilities; if (videoCapabilities == null || videoCapabilities.Length == 0) { _Logger.InformUser(Strings.NoVCapabilitiesFound); return(false); } if (!_Settings.HasResolutionCamera()) { _Logger.InformUser(Strings.PasDeResolutionCamConfig); return(false); } int indexResolution = 0; bool found = false; while (indexResolution < videoCapabilities.Length && found == false) { VideoCapabilities capability = videoCapabilities[indexResolution]; if (capability.FrameSize.Equals(_Settings.ResolutionCamera)) { found = true; } else { indexResolution++; } } if (!found) { _Logger.InformUser(Strings.PasDeResolutionCorrespondante); return(false); } _VideoCaptureDevice.VideoResolution = videoCapabilities[indexResolution]; _VideoSourcePlayer.VideoSource = _VideoCaptureDevice; _VideoSourcePlayer.Start(); _Timer.Start(); return(true); }
private void FormCameras_Load(object sender, EventArgs e) { CloseVideoSource(); videoSource = new VideoCaptureDevice(m_deviceMoniker); VideoCapabilities t_c = selectResolution(videoSource);//new line if (m_changed) { videoSource.VideoResolution = t_c; h = videoSource.VideoResolution.FrameSize.Height; w = videoSource.VideoResolution.FrameSize.Width; } //videoSource.VideoResolution = selectResolution(videoSource);//new line videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); //videoSource.DesiredFrameSize = new Size(1920, 1080); //videoSource.DesiredFrameSize = new Size(1920, 120);//new Size(160, 120); //videoSource.DesiredFrameRate = 10; videoSource.Start(); m_startrecording = false; }
public void AddCamerItem(int index, int columns) { string sqlExists = string.Format(" SELECT * FROM camerDevice WHERE deviceID='{0}'", videoDevices[index].MonikerString); DataTable ds = SQLiteHelper.ExecuteQuery(sqlExists).Tables[0]; int videwplayerWidth = 320; int controlWidth = this.Width; // VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[index].MonikerString); VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[index > 1 ? 0 : index].MonikerString); //videoSource.DesiredFrameSize = new System.Drawing.Size(320, 240); // videoSource.DesiredFrameRate = 1; videoSource.VideoResolution = videoSource.VideoCapabilities[Convert.ToInt32(ds.Rows[0]["frameSizeIndex"])]; VideoCapabilities d = videoSource.VideoCapabilities[0];// = new System.Drawing.Size(640, 480); AForge.Controls.VideoSourcePlayer videoplayer = new AForge.Controls.VideoSourcePlayer(); videoplayer.Top = 100; videoplayer.Left = 320 * (index) + 1; videoplayer.Height = 240; videoplayer.Name = "videoplayer" + index; videoplayer.Tag = ds.Rows[0]["name"]; videoplayer.Width = videwplayerWidth; videoplayer.NewFrame += new AForge.Controls.VideoSourcePlayer.NewFrameHandler(this.videoPlayer_NewFrame); videoPlayerlist.Add(videoplayer); int columnsIndex = index % columns == 0 ? index / columns : index % columns; int rowIndex = index % columns == 0 ? (index - columns + 1) / columns : index / columns; tablepanel.Controls.Add(videoplayer, columnsIndex, rowIndex); videoplayer.VideoSource = videoSource; videoplayer.Start(); //videoSourcePlayer.VideoSource = videoSource; //videoSourcePlayer.Start(); }
private void cbVideoResolutions_SelectedIndexChanged(object sender, EventArgs e) { if (CamMonitor[activeCamera].IsRecording) { CamMonitor[activeCamera].StopRecording(); } if (CamMonitor[activeCamera].IsRunning) { CamMonitor[activeCamera].StopCapture(); } VideoCapabilities[] vcs = CamMonitor[activeCamera].cam.VideoCapabilities; VideoCapabilities vc = vcs[cbVideoResolutions.SelectedIndex]; if (!bResolutionEqual && (vc.FrameSize.Width > 1024 || vc.FrameSize.Height > 768)) { int i = 1, selected = 0; for (; i < vcs.Length; ++i) { if (vcs[i].FrameSize.Width <= 1024 && vcs[i].FrameSize.Height <= 768) { if (vcs[i].FrameSize.Width * vcs[i].FrameSize.Height > vcs[selected].FrameSize.Width * vcs[selected].FrameSize.Height) { selected = i; } } } vc = vcs[selected]; } CamMonitor[activeCamera].cam.VideoResolution = vc; startCamera(); }
void OnNewFrame(object sender, NewFrameEventArgs eventArgs) { System.Drawing.Image img = (Bitmap)eventArgs.Frame.Clone(); if (firstStart) { DateTime dt = DateTime.Now; string fname = $"{dt.Year:D4}{dt.Month:D2}{dt.Day:D2}{dt.Hour:D2}{dt.Minute:D2}{dt.Second:D2}"; VideoCapabilities vc = camera.VideoCapabilities.FirstOrDefault(x => x.FrameSize.Width == img.Width && x.FrameSize.Height == img.Height); if (vc == null || !vfw.MakeVidFile(fname, img.Width, img.Height, vc.AverageFrameRate)) { StopCameras(); return; } firstStart = false; return; } try { MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); bi.Freeze(); Dispatcher.BeginInvoke(new ThreadStart(delegate { frameHolder.Source = bi; })); vfw?.AddFrame(img); } catch (Exception ex) { } }
public VideoFormat(VideoCapabilities capabilities) { FrameSize = capabilities.FrameSize; AverageFrameRate = capabilities.AverageFrameRate; MaximumFrameRate = capabilities.MaximumFrameRate; BitCount = capabilities.BitCount; }
private void SetVideoResolution(VideoCapabilities capability) { videoCaptureDevice.VideoResolution = capability; pictureBox1.Width = capability.FrameSize.Width; pictureBox1.Height = capability.FrameSize.Height; }
internal bool Equals(VideoCapabilities capabilities) { return(FrameSize == capabilities.FrameSize && AverageFrameRate == capabilities.AverageFrameRate && MaximumFrameRate == capabilities.MaximumFrameRate && BitCount == capabilities.BitCount); }
private new void DataToControls() { if (itemDescription != null) { var controller = itemDescription as Controller; base.DataToControls(); if (controller != null) { edtDatumPhysicalMemory.DoubleValue = controller.PhysicalMemory; controllerOperatingSystemListControl1.OperatingSystems = controller.OperatingSystems; controllerProcessorControl1.ControllerProcessor = controller.Processor; ControllerDrive.ControllerDrive = controller.Storage; InstalledSoftware.ItemsDescriptions = controller.InstalledSoftware; Peripherals.ItemsDescriptions = controller.Peripherals; if (controller.VideoCapabilities != null) { foreach (string video in controller.VideoCapabilities) { DataGridViewRow row = VideoCapabilities.AddRow(); VideoCapabilities.AddColumnData(row, "capability", video); } } if (controller.AudioCapabilities != null) { foreach (string audio in controller.AudioCapabilities) { DataGridViewRow row = AudioCapabilities1.AddRow(); AudioCapabilities1.AddColumnData(row, "capability", audio); } } } } }
private void cbCapability_SelectedIndexChanged(object sender, EventArgs e) { VideoCapabilities selectedCapability = ((CapabilityInfo)cbCapability.SelectedItem).Capability; cbCapability.DisplayMember = "Name"; SelectedDevice.VideoResolution = selectedCapability; }
public CaptureCapability(VideoCapabilities Capabilities) { _averageFrameRate = Capabilities.AverageFrameRate; _frameSize = Capabilities.FrameSize; _bitCount = Capabilities.BitCount; _maximumFrameRate = Capabilities.MaximumFrameRate; Describe = _frameSize.Width + "×" + _frameSize.Height + " " + _averageFrameRate + " " + _maximumFrameRate + " " + _bitCount; }
public ControllerControl() { InitializeComponent(); VideoCapabilities.AddColumn("Capability", "capability"); AudioCapabilities1.AddColumn("Capability", "capability"); Peripherals.InitializeForm += Peripherals_InitializeForm; InstalledSoftware.InitializeForm += InstalledSoftware_InitializeForm; }
public void Start(VideoCapabilities Capability) { FrameNumber = 0; videoDevice.VideoResolution = Capability; videoDevice.Start(); State = CameraState.CAMERA_STARTED; }
public bool Start(string cam, string MonikerStr) { try { // enumerate video devices FilterInfoCollection videoDevices = new FilterInfoCollection(AForge.Video.DirectShow.FilterCategory.VideoInputDevice); // create the video source (check that the camera exists is already done VideoSource = new VideoCaptureDevice(MonikerStr); VideoSource.VideoResolution = VideoSource.VideoCapabilities[17]; VideoSource.NewFrame += new NewFrameEventHandler(Video_NewFrame); ReceivingFrames = false; // try ten times to start int tries = 0; while (tries < 80) // 4s maximum to a camera to start { // VideoSource.Start() checks running status, is safe to call multiple times tries++; VideoSource.Start(); if (!ReceivingFrames) { // 50 ms pause, processing events so that videosource has a chance for (int i = 0; i < 5; i++) { Thread.Sleep(10); Application.DoEvents(); } } else { break; } } cameraControls = VideoSource.SourceObject as IAMVideoProcAmp; if (!ReceivingFrames) { return(false); } VideoCapabilities Capability = VideoSource.VideoCapabilities[17]; ImgSizeX = Capability.FrameSize.Width; ImgSizeY = Capability.FrameSize.Height; ImgCenterX = ImgSizeX / 2; ImgCenterY = ImgSizeY / 2; lock (_locker) { } // wait //PauseProcessing = false; return(true); } catch { return(false); } }
public DeviceCapabilityInfo(VideoCapabilities orig, string custom = null) { this.origCap = orig; if (orig != null) { FrameSize = orig.FrameSize; MaxFrameRate = orig.AverageFrameRate; } this.customStr = custom; }
private static IEnumerable <VideoCapabilities> GetAllAvailableResolution(DsDevice vidDev) { //I used to use SharpDX.MediaFoundation to enumerate all camera and its supported resolution //however, according to https://stackoverflow.com/questions/24612174/mediafoundation-can%C2%B4t-find-video-capture-emulator-driver-but-directshow-does, //MediaFoundation cannot find virtual camera, so I turned to use IPin.EnumMediaTypes to fetch supported resolution //https://stackoverflow.com/questions/20414099/videocamera-get-supported-resolutions int hr, bitCount = 0; IBaseFilter sourceFilter; var m_FilterGraph2 = new FilterGraph() as IFilterGraph2; hr = m_FilterGraph2.AddSourceFilterForMoniker(vidDev.Mon, null, vidDev.Name, out sourceFilter); DsError.ThrowExceptionForHR(hr); var pRaw2 = DsFindPin.ByCategory(sourceFilter, PinCategory.Capture, 0); var availableResolutions = new List <VideoCapabilities>(); VideoInfoHeader v = new VideoInfoHeader(); IEnumMediaTypes mediaTypeEnum; hr = pRaw2.EnumMediaTypes(out mediaTypeEnum); DsError.ThrowExceptionForHR(hr); AMMediaType[] mediaTypes = new AMMediaType[1]; IntPtr fetched = IntPtr.Zero; hr = mediaTypeEnum.Next(1, mediaTypes, fetched); DsError.ThrowExceptionForHR(hr); while (fetched != null && mediaTypes[0] != null) { Marshal.PtrToStructure(mediaTypes[0].formatPtr, v); if (v.BmiHeader.Size != 0 && v.BmiHeader.BitCount != 0) { if (v.BmiHeader.BitCount > bitCount) { availableResolutions.Clear(); bitCount = v.BmiHeader.BitCount; } VideoCapabilities cap = new VideoCapabilities(); cap.Height = v.BmiHeader.Height; cap.Width = v.BmiHeader.Width; //the unit of AvgTimePerFrame is 100 nanoseconds, //and 10^9 nanosenconds = 1 second cap.FrameRate = (int)(1000_000_000 / 100 / v.AvgTimePerFrame); cap.BitRate = v.BitRate; availableResolutions.Add(cap); } hr = mediaTypeEnum.Next(1, mediaTypes, fetched); DsError.ThrowExceptionForHR(hr); } return(availableResolutions); }
private void StartVideoSource(VideoCapabilities vc) { if (_videoSource == null) { return; } _videoSource.DesiredFrameRate = vc.MaxFrameRate; _videoSource.DesiredFrameSize = vc.FrameSize; _videoSource.NewFrame += VideoNewFrame; _videoSource.Start(); previewPictureBox.Visible = true; }
// Adds a RadioButton to the Control using the passed VideoCapabilities private void AddOption(VideoCapabilities vcap) { RadioButton rbtn = new RadioButton { Text = $"{vcap.FrameSize.Width}x{vcap.FrameSize.Height} {vcap.MaximumFrameRate}fps {vcap.BitCount}bit colors", Width = 160, Checked = webcam.videoSource.VideoResolution == vcap, Tag = vcap, }; flow_videoSettings.Controls.Add(rbtn); }
private void Form1_Load(object sender, EventArgs e) { cameraBitmap = new Bitmap(640, 480); capture = new Capture(cameraFilters.VideoInputDevices[0], cameraFilters.AudioInputDevices[0]); VideoCapabilities vc = capture.VideoCaps; capture.FrameSize = new Size(640, 480); capture.PreviewWindow = cam; capture.FrameEvent2 += new Capture.HeFrame(CaptureDone); capture.GrapImg(); loadSourceCards(); }
public List <DeviceCapabilityInfo> GetDeviceCapability(DeviceInfo deviceInfo) { List <DeviceCapabilityInfo> deviceCapability = new List <DeviceCapabilityInfo>(); VideoCaptureDevice video = new VideoCaptureDevice(deviceInfo.MonikerString); for (int i = 0; i < video.VideoCapabilities.Length; i++) { VideoCapabilities cap = video.VideoCapabilities[i]; DeviceCapabilityInfo capInfo = new DeviceCapabilityInfo(cap.FrameSize, cap.FrameRate); deviceCapability.Add(capInfo); } return(deviceCapability); }
private void comboBoxreso_SelectedIndexChanged(object sender, EventArgs e) { //获取选择的分辨率,选择时没有关闭摄像头时进行关闭 videoCapabilitie = videoCapabilities[comboBoxreso.SelectedIndex]; buttonopencam.Enabled = true; buttonphoto.Enabled = true; if (videoSourcePlayer.IsRunning) { captureDevice.Stop(); videoSourcePlayer.VideoSource = null; videoSourcePlayer.VideoSource = null; buttonopencam.Text = "打开"; } }
/// <summary> /// 获取最大分辨率 /// </summary> private VideoCapabilities GetMaxVideoCapabilities() { if (VideoSource.VideoCapabilities == null || !VideoSource.VideoCapabilities.Any()) { return(null); } VideoCapabilities maxVideoCapabilitie = null; foreach (var item in VideoSource.VideoCapabilities) { maxVideoCapabilitie = Compare(maxVideoCapabilitie, item); } return(maxVideoCapabilitie); }
/// <summary> /// Устанавливает разрешение для активной камеры /// </summary> /// <param name="сapabilitiesWithResolution"></param> public void SetResolution(VideoCapabilities сapabilitiesWithResolution) { if (CaptureDevice == null || сapabilitiesWithResolution == null) { return; } try { CaptureDevice.VideoResolution = сapabilitiesWithResolution; } catch (Exception e) { MessageBox.Show(typeof(AforgeWraper) + @" " + e.Message); } }
private static VideoCapabilities Compare(VideoCapabilities source, VideoCapabilities target) { if (source == null) { return(target); } if (source.FrameSize.Width * source.FrameSize.Height < target.FrameSize.Width * target.FrameSize.Height) { return(target); } else { return(source); } }
private void coBox_Resolution_SelectedIndexChanged(object sender, EventArgs e) { videoCapabilitie = videoCapabilities[coBox_Resolution.SelectedIndex]; btn_cam.Enabled = true; btn_takePic.Enabled = true; if (AVPlayer_Cam1.IsRunning) { captureDevice.NewFrame -= new NewFrameEventHandler(FaceDetection); captureDevice.Stop(); AVPlayer_Cam1.VideoSource = null; AVPlayer_Cam1.VideoSource = null; btn_cam.Text = "Open"; } }
public void SetVideoSettings(FilterInfo device) { // aforge might throw an exception if it finds an unsupported format // why does it not just exclude it from the list and fail silently? joost mag het weten try { this.captureDevice = new VideoCaptureDevice(device.MonikerString); VideoCapabilities[] deviceCaps = this.captureDevice.VideoCapabilities; if (deviceCaps != null && deviceCaps.Length != 0) { // just pick the setting with appropriated resolution VideoCapabilities preferCaps = null; for (int i = 0; i < deviceCaps.Length; i++) { VideoCapabilities videoCaps = deviceCaps[i]; if (videoCaps.FrameSize.Width == PreferredCameraWidth && videoCaps.FrameSize.Height == PreferredCameraHeight) { preferCaps = videoCaps; break; } } if (preferCaps == null) { preferCaps = deviceCaps[0]; } this.captureDevice.VideoResolution = preferCaps; } this.captureDevice.ProvideSnapshots = false; this.captureDevice.NewFrame += this.OnCaptureDeviceNewFrame; this.IsRecording = false; Logger.Log(LogLevel.Info, string.Format("Changed video config to : camera source: {0}, resolution: {1}x{2}", device.Name, this.captureDevice.VideoResolution.FrameSize.Width, this.captureDevice.VideoResolution.FrameSize.Height)); } catch (Exception e) { Logger.Log(LogLevel.Error, e.Message); } }
private void button_openCamera_Click(object sender, EventArgs e) { if (videoSource != null) //先判断有木有视频来源 { if (button_openCamera.Text == "打开相机") //打开相机 { //videoSource.DisplayPropertyPage(IntPtr.Zero); videoSourcePlayer1.VideoSource = videoSource; videoResolution = videoSource.VideoResolution; //videoSourcePlayer1.NewFrame += new VideoSourcePlayer.NewFrameHandler(videoPlayerRotate_NewFrame); videoSourcePlayer1.Start(); button_openCamera.BackColor = Color.Yellow; button_openCamera.Text = "关闭相机"; // 开启帧率显示 frame_timer.Start(); frame_timer.Elapsed += new ElapsedEventHandler(FrameCount); SavePics.SetVideoSourcePlayer(videoSourcePlayer1, button_multpic); } else // 关闭相机 { videoSource.SignalToStop(); videoSource.WaitForStop(); videoSource.Stop(); videoSourcePlayer1.SignalToStop(); videoSourcePlayer1.WaitForStop(); videoSourcePlayer1.Stop(); button_openCamera.Text = "打开相机"; button_openCamera.BackColor = Color.White; frame_timer.Stop(); frame_timer.Elapsed -= new ElapsedEventHandler(FrameCount); label2.Text = null; } } else { MessageBox.Show("未连接到相机,请检测相机!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void InitializeVideoCaptureDevice() { if (_videoCaptureDevice != null) { _videoCaptureDevice.NewFrame -= OnFrameReceived; //unsubscribe previous device } var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); _videoCaptureDevice = new VideoCaptureDevice(videoDevices[0].MonikerString); VideoCapabilities capabilities = _videoCaptureDevice.VideoCapabilities[0]; _videoCaptureDevice.VideoResolution = capabilities; _width = (int)(capabilities.FrameSize.Width / _resolutionDivisor); _height = (int)(capabilities.FrameSize.Height / _resolutionDivisor); _videoCaptureDevice.NewFrame += OnFrameReceived; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { List <VideoCapabilities> list = value as List <VideoCapabilities>; List <string> newList = new List <string>(); foreach (var item in list) { VideoCapabilities cap = item as VideoCapabilities; if (cap == null) { return(string.Empty); } newList.Add(string.Format("{0}x{1}", item.Resolution.Width, item.Resolution.Height)); } return(newList); }
// viewer resizing private void viewerResize(int idx, Size sz) { int center = sz.Width / 2; int margin = 5; if (videoCaps[idx] != null) { VideoCapabilities cap = videoCaps[idx][cbResolutions[idx].SelectedIndex]; videoPlayers[idx].Size = CalcHalfSize(sz, cap.FrameSize, videoPlayers[idx].Location.Y, margin, ref ratios[idx]); if (idx == 0) { videoPlayers[idx].Location = new Point(center - margin - videoPlayers[idx].Size.Width, videoPlayers[0].Location.Y); } else { videoPlayers[idx].Location = new Point(center + margin, videoPlayers[idx].Location.Y); } } }
/// <summary> /// Sets the camera current resolution. /// </summary> /// <param name="capabilities"></param> public void SetResolution(VideoCapabilities capabilities) { if (camera!= null) { camera.Resolution=capabilities.Resolution; } }