首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ozeki SDK摄像头流断开

Ozeki SDK摄像头流断开
EN

Stack Overflow用户
提问于 2017-11-06 15:42:13
回答 1查看 937关注 0票数 0

所以我正在为onvif IP摄像头建立一个应用程序,我把它设置成这样:

代码语言:javascript
复制
public partial class MainWindow : Window
{
    private VideoViewerWPF _videoViewerWpf;
    private BitmapSourceProvider _provider;
    private IIPCamera _ipCamera;
    private MediaConnector _connector;
    private MotionDetector _detector;

    public MainWindow()
    {
        InitializeComponent();
        _connector = new MediaConnector();
        _provider = new BitmapSourceProvider();
        _detector = new MotionDetector();
        SetVideoViewer();

    }

    private void SetVideoViewer()
    {
        _videoViewerWpf = new VideoViewerWPF
        {
            HorizontalAlignment = HorizontalAlignment.Stretch,
            VerticalAlignment = VerticalAlignment.Stretch,
            Background = Brushes.Black,
            Width = 1280,
            Height = 720
        };

        CameraBox.Children.Add(_videoViewerWpf);
        _videoViewerWpf.SetImageProvider(_provider);
    }

    private void CameraStateChanged(object sender, CameraStateEventArgs e)
    {
        Dispatcher.Invoke(() => {
            labeltest.Content = e.State.ToString();
        });
    }

    private void ConnectIPCamera_Click(object sender, RoutedEventArgs e)
    {
        var host = HostTextBox.Text;
        var user = UserTextBox.Text;
        var pass = Password.Password;

        _ipCamera = IPCameraFactory.GetCamera(host, user, pass);
        if (_ipCamera == null) return;
        _connector.Connect(_ipCamera.VideoChannel, _detector);
        _connector.Connect(_detector, _provider);
        _ipCamera.Connect();
        _ipCamera.CameraStateChanged += CameraStateChanged;
        _videoViewerWpf.Start();
    }

    private void DisconnectIPCamera_Click(object sender, RoutedEventArgs e)
    {
        _videoViewerWpf.Stop();

        _ipCamera.Disconnect();
        _ipCamera.Dispose();

        _connector.Disconnect(_ipCamera.VideoChannel, _detector);
        _connector.Disconnect(_detector, _provider);
    }

    void GuiThread(Action action)
    {
        Dispatcher.BeginInvoke(action);
    }

    private void StartMotionDetection()
    {
        _detector.HighlightMotion = HighlightMotion.Highlight;
        _detector.MotionColor = MotionColor.Red;
        _detector.MotionDetection += Detector_MotionDetection;
        _detector.Start();
    }

    void Detector_MotionDetection(object sender, MotionDetectionEvent e)
    {
        GuiThread(() =>
        {
            if (e.Detection)
                MotionEventLabel.Content = "Motion Detected";
            else
                MotionEventLabel.Content = "Motion Stopped";
        });
    }

    private void StopMotionDetection()
    {
        _detector.Stop();
        _detector.MotionDetection -= Detector_MotionDetection;
        _detector.Dispose();
    }

    private void MotionChecked(object sender, RoutedEventArgs e)
    {
        MotionEventLabel.Content = String.Empty;
        if (sender is CheckBox check)
        {
            if ((bool)check.IsChecked)
                StartMotionDetection();
            else
                StopMotionDetection();
        }
    }

    private void Start_Click(object sender, RoutedEventArgs e)
    {
        if(_ipCamera.State == IPCameraState.Connected)
        {
            _ipCamera.CurrentStream = _ipCamera.AvailableStreams.FirstOrDefault(x => x.Name == "MJPEG");

            _ipCamera.Start();
        }
    }

它连接得很好,但在我启动流的那一刻,它就开始连接流一秒钟,然后断开与网络的连接。我尝试了什么,我可以在互联网上找到,但没有解决的问题,我觉得我没有它设置正确,但这是第一次与onvif相机和图书馆,任何建议或信息评估,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-11-06 21:02:59

这可能是因为错误的流,这就是上次发生在我身上的事情。你可以在profiles...Make上的onvif设备管理器上修改一个新的配置文件,选择H264流(不管是哪一个)并删除所有其他已经存在的配置文件,然后保存它并给你的程序员试一试,然后它应该可以工作了:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47131993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档