Beispiel #1
0
        public void AxisM1145()
        {
            MJPEGStream mjpeg = new MJPEGStream("http://" + txtCameraAxisIp.Text + "/axis-cgi/mjpg/video.cgi");

            OpenVideoSource(mjpeg);
        }
Beispiel #2
0
 public Form1()
 {
     InitializeComponent();
     stream           = new MJPEGStream("http://192.168.137.77:8080/video");
     stream.NewFrame += stream_NewFrame;
 }
Beispiel #3
0
        private bool ConnectToDevice(DeviceDescriptor _device)
        {
            log.DebugFormat("Connecting to {0}", _device.Name);

            Disconnect();
            bool created = false;

            if (_device.Network)
            {
                // Network Camera. Connect to last used url.
                // The user will have to open the dialog again if parameters have changed or aren't good.

                // Parse URL for inline username:password.
                string login = "";
                string pass  = "";

                Uri networkCameraUrl = new Uri(_device.NetworkCameraUrl);
                if (!string.IsNullOrEmpty(networkCameraUrl.UserInfo))
                {
                    string [] split = networkCameraUrl.UserInfo.Split(new Char [] { ':' });
                    if (split.Length == 2)
                    {
                        login = split[0];
                        pass  = split[1];
                    }
                }

                if (_device.NetworkCameraFormat == NetworkCameraFormat.JPEG)
                {
                    JPEGStream source = new JPEGStream(_device.NetworkCameraUrl);
                    if (!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(pass))
                    {
                        source.Login    = login;
                        source.Password = pass;
                    }

                    m_VideoSource = source;
                }
                else
                {
                    MJPEGStream source = new MJPEGStream(_device.NetworkCameraUrl);
                    if (!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(pass))
                    {
                        source.Login    = login;
                        source.Password = pass;
                    }

                    m_VideoSource = source;
                }

                /*PreferencesManager.CapturePreferences.NetworkCameraFormat = _device.NetworkCameraFormat;
                 * PreferencesManager.CapturePreferences.NetworkCameraUrl = _device.NetworkCameraUrl;
                 * PreferencesManager.Save();*/

                created = true;
            }
            else
            {
                m_VideoSource = new VideoCaptureDevice(_device.Identification);
                VideoCaptureDevice captureDevice = m_VideoSource as VideoCaptureDevice;
                if (captureDevice != null)
                {
                    if ((captureDevice.VideoCapabilities != null) && (captureDevice.VideoCapabilities.Length > 0))
                    {
                        // Import the capabilities of the device.
                        foreach (VideoCapabilities vc in captureDevice.VideoCapabilities)
                        {
                            DeviceCapability dc = new DeviceCapability(vc.FrameSize, vc.FrameRate);
                            _device.Capabilities.Add(dc);

                            log.Debug(String.Format("Device Capability. {0}", dc.ToString()));
                        }

                        DeviceCapability selectedCapability = null;

                        // Check if we already know this device and have a preferred configuration.

                        /*foreach(DeviceConfiguration conf in PreferencesManager.CapturePreferences.DeviceConfigurations)
                         * {
                         *      if(conf.ID == _device.Identification)
                         *      {
                         *              // Try to find the previously selected capability.
                         *              selectedCapability = _device.GetCapabilityFromSpecs(conf.Capability);
                         *              if(selectedCapability != null)
                         *                      log.Debug(String.Format("Picking capability from preferences: {0}", selectedCapability.ToString()));
                         *      }
                         * }*/

                        /*if(selectedCapability == null)
                         * {
                         *      // Pick the one with max frame size.
                         *      selectedCapability = _device.GetBestSizeCapability();
                         *      log.Debug(String.Format("Picking a default capability (best size): {0}", selectedCapability.ToString()));
                         *      PreferencesManager.CapturePreferences.UpdateDeviceConfiguration(_device.Identification, selectedCapability);
                         *      PreferencesManager.Save();
                         * }*/

                        _device.SelectedCapability     = selectedCapability;
                        captureDevice.DesiredFrameSize = selectedCapability.FrameSize;
                        captureDevice.DesiredFrameRate = selectedCapability.Framerate;
                        m_FrameSize      = selectedCapability.FrameSize;
                        m_FramesInterval = 1000 / (double)selectedCapability.Framerate;
                    }
                    else
                    {
                        captureDevice.DesiredFrameRate = 0;
                    }

                    created = true;
                }
            }

            if (created)
            {
                m_CurrentVideoDevice            = _device;
                m_VideoSource.NewFrame         += new NewFrameEventHandler(VideoDevice_NewFrame);
                m_VideoSource.VideoSourceError += new VideoSourceErrorEventHandler(VideoDevice_VideoSourceError);
                m_bIsConnected = true;
            }
            else
            {
                log.Error("Couldn't create the capture device.");
            }

            return(created);
        }